mirror of
https://github.com/lucaspalomodevelop/autom.git
synced 2026-03-12 23:27:21 +00:00
commit
2265343538
17
src/main.cpp
17
src/main.cpp
@ -62,17 +62,23 @@ std::string scriptBuilder(std::string script, std::string args, json script_sett
|
|||||||
|
|
||||||
automScript parse(const std::string filecontent)
|
automScript parse(const std::string filecontent)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// std::cout << "filecontent before parse: " << filecontent << std::endl;
|
||||||
std::stringstream file(filecontent);
|
std::stringstream file(filecontent);
|
||||||
|
|
||||||
std::string line, content, script;
|
std::string line, content, script;
|
||||||
int braceCount = 0;
|
int braceCount = 0;
|
||||||
bool isSettings = true;
|
bool isSettings = false;
|
||||||
|
bool start = false;
|
||||||
while (std::getline(file, line))
|
while (std::getline(file, line))
|
||||||
{
|
{
|
||||||
for (char c : line)
|
for (char c : line)
|
||||||
{
|
{
|
||||||
if (c == '{')
|
if (c == '{')
|
||||||
|
{
|
||||||
braceCount++;
|
braceCount++;
|
||||||
|
isSettings = true;
|
||||||
|
}
|
||||||
if (c == '}')
|
if (c == '}')
|
||||||
braceCount--;
|
braceCount--;
|
||||||
if (braceCount == 0 && isSettings)
|
if (braceCount == 0 && isSettings)
|
||||||
@ -128,6 +134,7 @@ automScript parseAndWriteBack(std::string script)
|
|||||||
automScript parsed = parse(filecontent);
|
automScript parsed = parse(filecontent);
|
||||||
|
|
||||||
std::ofstream file2(script);
|
std::ofstream file2(script);
|
||||||
|
// std::cout << "script: " << parsed.script << std::endl;
|
||||||
file2 << parsed.script;
|
file2 << parsed.script;
|
||||||
file2.close();
|
file2.close();
|
||||||
|
|
||||||
@ -145,10 +152,10 @@ std::string saveScriptInTemp(std::string script)
|
|||||||
|
|
||||||
while (std::getline(file2, line))
|
while (std::getline(file2, line))
|
||||||
{
|
{
|
||||||
script_content += line + "\n";
|
file << line << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
file << script_content;
|
file.flush();
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
std::filesystem::permissions(temp_file, std::filesystem::perms::owner_all | std::filesystem::perms::group_all | std::filesystem::perms::others_all);
|
std::filesystem::permissions(temp_file, std::filesystem::perms::owner_all | std::filesystem::perms::group_all | std::filesystem::perms::others_all);
|
||||||
@ -234,6 +241,8 @@ void runScript(int argc, char *argv[])
|
|||||||
|
|
||||||
script = saveScriptInTemp(script);
|
script = saveScriptInTemp(script);
|
||||||
|
|
||||||
|
// std::cout << "script: " << script << std::endl;
|
||||||
|
|
||||||
json json_settings = parseAndWriteBack(script).settings;
|
json json_settings = parseAndWriteBack(script).settings;
|
||||||
|
|
||||||
script_settings = mergeJson(script_settings, json_settings);
|
script_settings = mergeJson(script_settings, json_settings);
|
||||||
@ -253,7 +262,7 @@ void runScript(int argc, char *argv[])
|
|||||||
|
|
||||||
system(script.c_str());
|
system(script.c_str());
|
||||||
|
|
||||||
cleanTempFile();
|
// cleanTempFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user