Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion sc-tools/sc-builder/src/sc_builder_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "sc_builder_runner.hpp"

#include <iostream>
#include <fstream>

#include <sc-config/sc_options.hpp>
#include <sc-config/sc_config.hpp>
#include <sc-config/sc_memory_config.hpp>

#include "sc-builder/builder.hpp"
#include "gwf_translator.hpp"

void PrintHelpMessage(std::string const & binaryName)
{
Expand Down Expand Up @@ -44,7 +46,10 @@ void PrintHelpMessage(std::string const & binaryName)
<< " --clear Run sc-builder in a mode that overwrites existing knowledge base "
"binaries.\n"
<< " --version Display the version of " << binaryName << ".\n"
<< " --help Display this help message.\n";
<< " --help Display this help message.\n"
<< " --gwf-to-scs <file> Translate a GWF file to SCs and save the result to a specified file.\n"
<< " --gwf-output <file> Specify the output file for the GWF-to-SCs translation (default: <input>.scs).\n"
<< " --verbose|-v Enable verbose logging.\n";
}

sc_int RunBuilder(sc_int argc, sc_char * argv[])
Expand All @@ -65,6 +70,36 @@ try
return EXIT_SUCCESS;
}

if (options.Has({"gwf-to-scs"}))
{
std::string gwfFile = options[{"gwf-to-scs"}].second;
std::string outputFile = options.Has({"gwf-output"}) ? options[{"gwf-output"}].second : gwfFile + ".scs";

// Инициализация контекста для транслятора
ScMemoryContext ctx;
GWFTranslator translator(ctx);
std::string scsText = translator.TranslateXMLFileContentToSCs(gwfFile);

// Сохранение результата в файл
std::ofstream output(outputFile, std::ios::binary);
if (!output.is_open())
{
std::cout << "Error: Cannot open output file `" << outputFile << "`.\n";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using std::cerr for error messages instead of std::cout.

Suggested change
std::cout << "Error: Cannot open output file `" << outputFile << "`.\n";
std::cerr << "Error: Cannot open output file `" << outputFile << "`.\n";

return EXIT_FAILURE;
}
output << scsText;
output.close();

if (output.fail())
{
std::cout << "Error: Failed to write to output file `" << outputFile << "`.\n";
return EXIT_FAILURE;
}

std::cout << "GWF file `" << gwfFile << "` successfully translated to SCs and saved as `" << outputFile << "`.\n";
return EXIT_SUCCESS;
}

BuilderParams params;
if (options.Has({"input", "i"}))
params.m_inputPath = options[{"input", "i"}].second;
Expand Down Expand Up @@ -155,8 +190,11 @@ try
"[sc-builder] group.\n"
<< "Make sure this path is a valid directory where you have write permissions and that it exists.\n"
<< "For more information, run with --help.\n";


return EXIT_FAILURE;
}

params.m_resultStructureUpload = formedMemoryParams.init_memory_generated_upload;
if (formedMemoryParams.init_memory_generated_structure != nullptr)
params.m_resultStructureSystemIdtf = formedMemoryParams.init_memory_generated_structure;
Expand Down
Loading