#include <iostream>
#include <string>

#include "emc/ini/inifile.hh"

int main(int argc, char **argv) {
    if (argc != 2) {
        std::cerr << "usage: linuxcnc_ini_probe <ini-file>\n";
        return 2;
    }

    const char *ini_path = argv[1];
    linuxcnc::IniFile ini(ini_path);
    if (!ini) {
        std::cerr << "failed to open ini file: " << ini_path << "\n";
        return 1;
    }

    const auto machine = ini.findString("MACHINE", "EMC");
    const auto display = ini.findString("DISPLAY", "DISPLAY");
    const auto kins = ini.findString("KINEMATICS", "KINS");
    const auto coords = ini.findString("COORDINATES", "TRAJ");
    const auto parameter_file = ini.findString("PARAMETER_FILE", "RS274NGC");

    std::cout << "EMC.MACHINE=" << (machine ? *machine : "<missing>") << "\n";
    std::cout << "DISPLAY.DISPLAY=" << (display ? *display : "<missing>") << "\n";
    std::cout << "KINS.KINEMATICS=" << (kins ? *kins : "<missing>") << "\n";
    std::cout << "TRAJ.COORDINATES=" << (coords ? *coords : "<missing>") << "\n";
    std::cout << "RS274NGC.PARAMETER_FILE=" << (parameter_file ? *parameter_file : "<missing>") << "\n";

    return 0;
}
