123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #include <algorithm>
- #include <vector>
- #include <iostream>
- #include <filesystem>
- #include <tinyxml2.h>
- #include "class.hpp"
- #include "parser.hpp"
- #include "util.hpp"
- #include "writer.hpp"
- int main(int argc, char** argv)
- {
-
- std::string input_dir, home_tmpl_file, page_tmpl_file, output_dir(".");
- for (int i = 1; i < argc; i++)
- {
- if (param_matches(argc, argv, i, "-d", "--dir", "--directory"))
- input_dir = argv[i + 1];
- else if (param_matches(argc, argv, i, "-h", "--home", "--home-template"))
- home_tmpl_file = argv[i + 1];
- else if (param_matches(argc, argv, i, "-p", "--page", "--page-template"))
- page_tmpl_file = argv[i + 1];
- else if (param_matches(argc, argv, i, "-o", "--output", "--output-directory"))
- output_dir = argv[i + 1];
- }
- if (input_dir.empty() || home_tmpl_file.empty() || page_tmpl_file.empty())
- {
- std::cout << "Usage: [\"-d\", \"--dir\", \"--directory\"] (string [REQUIRED])" << std::endl;
- std::cout << " [\"-h\", \"--home\", \"--home-template\"] (string [REQUIRED])" << std::endl;
- std::cout << " [\"-p\", \"--page\", \"--page-template\"] (string [REQUIRED])" << std::endl;
- std::cout << " [\"-o\", \"--output\", \"--output-directory\"] (string [DEFAULT = \".\" (current)])" << std::endl;
- return 1;
- }
-
- const std::string home_template = read_file(home_tmpl_file);
- const std::string page_template = read_file(page_tmpl_file);
- const std::string home_template_filename = std::filesystem::path(home_tmpl_file).filename();
- const std::string page_template_filename = std::filesystem::path(page_tmpl_file).filename();
-
- std::vector<Class> classes;
- std::filesystem::path output_dir_path = output_dir;
-
- for (const auto& dir_entry : std::filesystem::recursive_directory_iterator(input_dir))
- {
- std::filesystem::path fspath = dir_entry;
- const std::string filename = fspath.filename();
- if (!(std::filesystem::is_regular_file(dir_entry) &&
- (starts_with(filename, "class") || starts_with(filename, "namespace")))) continue;
-
- tinyxml2::XMLDocument doc;
- doc.LoadFile(fspath.c_str());
-
- Class cl;
- Parser::parse_compounddef(doc.RootElement(), cl);
- if (cl.constants.empty() && cl.variables.empty() && cl.functions.empty()) continue;
-
- classes.push_back(std::move(cl));
- }
-
- std::sort(classes.begin(), classes.end(),
- [](const Class& lhs, const Class& rhs) { return lhs.name < rhs.name; });
-
- for (Class& cl : classes)
- {
-
- for (auto it = cl.base_classes.begin(); it != cl.base_classes.end();)
- {
- if (it->second == "ssq::ExposableClass" || it->second == "ExposableClass")
- cl.base_classes.erase(it++);
- else
- ++it;
- }
-
-
- std::string target_data = Writer::write_file_notice(page_template_filename) + page_template;
-
- replace(target_data, "${SRG_CLASSSUMMARY}", cl.summary, "None.");
- replace(target_data, "${SRG_CLASSINSTANCES}", cl.instances, "None.");
- replace(target_data, "${SRG_CLASSINHERITANCE}", Writer::write_inheritance_list(classes, cl.base_classes, cl.derived_classes), "None.");
- replace(target_data, "${SRG_CLASSCONSTANTS}", Writer::write_constants_table(cl.constants), "None.");
- replace(target_data, "${SRG_CLASSVARIABLES}", Writer::write_variables_table(cl.variables), "None.");
- replace(target_data, "${SRG_CLASSFUNCTIONS}", Writer::write_function_table(cl.functions), "None.");
- replace(target_data, "${SRG_CLASSNAME}", "`" + cl.name + "`");
- regex_replace(target_data, std::regex("\\$\\{SRG_REF_(.+?)\\}"), Writer::write_class_ref("$1"));
-
- replace(target_data, "${SRG_NEWPARAGRAPH} ", "\r\n\r\n");
- replace(target_data, "${SRG_TABLENEWPARAGRAPH}", "<br /><br />");
- replace(target_data, "\"\"", "`");
- replace(target_data, "NOTE:", "<br /><br />**NOTE:**");
- replace(target_data, "Note:", "<br /><br />**NOTE:**");
-
- write_file(output_dir_path / std::filesystem::path("Scripting" + cl.name + ".md"), target_data);
- std::cout << "Generated reference for class \"" << cl.name << "\"." << std::endl;
- }
-
-
- std::string target_data = Writer::write_file_notice(home_template_filename) + home_template;
-
- replace(target_data, "${SRG_CLASSLIST}", Writer::write_class_list(classes));
-
- write_file(output_dir_path / std::filesystem::path("Scripting_Reference.md"), target_data);
- return 0;
- }
|