From 539ef6568697c9dc1712fc7a2a379d4e3fb9235c Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Tue, 7 Oct 2025 13:47:34 -0700 Subject: Initial commit --- src/main.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/main.cpp (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..caee08c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include "markdown_translator.h" + +bool parseArguments(int argc, char* argv[], std::unordered_map& params, std::string& inputFile) { + if (argc < 2) { + std::cerr << "Usage: COMMAND [-o ] [-css ] [other options]\n"; + return false; + } + params["-o"] = "index.html"; + params["-css"] = "styles/ffxiv-style.css"; + for (int i = 1; i < argc; ++i) { + std::string arg = argv[i]; + if (arg[0] == '-') { + if (i + 1 < argc) { + params[arg] = argv[i + 1]; + ++i; + } else { + std::cerr << "Error: Missing value for option " << arg << "\n"; + return false; + } + } else { + if (inputFile.empty()) { + inputFile = arg; + } else { + std::cerr << "Error: Multiple input files specified: " << inputFile << " and " << arg << "\n"; + return false; + } + } + } + + if (inputFile.empty()) { + std::cerr << "Error: No input file specified\n"; + return false; + } + + return true; +} + +int main(int argc, char* argv[]) { + std::unordered_map params; + std::string inputFile; + + if (!parseArguments(argc, argv, params, inputFile)) { + return 1; + } + + std::ifstream file(inputFile); + if (!file) { + std::cerr << "Error: Could not open file " << inputFile << "\n"; + return 1; + } + + // Read entire file content + std::stringstream buffer; + buffer << file.rdbuf(); + std::string markdownContent = buffer.str(); + file.close(); + + // Create translator and convert markdown to HTML + MarkdownTranslator translator; + + // Get CSS path from parameters or use default + std::string cssPath = "styles/ffxiv-style.css"; + if (params.find("-css") != params.end()) { + cssPath = params["-css"]; + } + + std::string htmlOutput = translator.translate(markdownContent, cssPath, "XIV Lore"); + + // Write to output file + std::string outputFile = params["-o"]; + std::ofstream outFile(outputFile); + if (!outFile) { + std::cerr << "Error: Could not open output file " << outputFile << "\n"; + return 1; + } + + outFile << htmlOutput; + outFile.close(); + + std::cout << "HTML output written to " << outputFile << std::endl; + return 0; +} -- cgit v1.2.3