Break out "GenerateFromScript" into a function

This commit is contained in:
Henrik Rydgård
2025-09-10 13:19:29 -06:00
parent 7deaec781c
commit 43c254cf06
+16 -7
View File
@@ -903,6 +903,8 @@ static bool WriteCompressed(const void *src, size_t sz, size_t num, FILE *fp) {
return true;
}
int GenerateFromScript(const char *script_file, const char *atlas_name, bool highcolor);
int main(int argc, char **argv) {
// initProgram(&argc, const_cast<const char ***>(&argv));
// /usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf
@@ -922,19 +924,25 @@ int main(int argc, char **argv) {
}
}
printf("Reading script %s\n", argv[1]);
const char *atlas_name = argv[2];
string image_name = string(atlas_name) + "_atlas.zim";
string meta_name = string(atlas_name) + "_atlas.meta";
out_prefix = argv[2];
return GenerateFromScript(argv[1], argv[2], highcolor);
}
//argv[1], argv[2], argv[3]
int GenerateFromScript(const char *script_file, const char *atlas_name, bool highcolor) {
map<string, FontReferenceList> fontRefs;
vector<FontDesc> fonts;
vector<ImageDesc> images;
Bucket bucket;
std::string image_name = string(atlas_name) + "_atlas.zim";
std::string meta_name = string(atlas_name) + "_atlas.meta";
const std::string out_prefix = atlas_name;
char line[512]{};
FILE *script = fopen(argv[1], "r");
FILE *script = fopen(script_file, "r");
if (!fgets(line, 512, script)) {
printf("Error fgets-ing\n");
}
@@ -1059,7 +1067,7 @@ int main(int argc, char **argv) {
}
FILE *cpp_file = fopen((out_prefix + "_atlas.cpp").c_str(), "wb");
fprintf(cpp_file, "// C++ generated by atlastool from %s (hrydgard@gmail.com)\n\n", argv[1]);
fprintf(cpp_file, "// C++ generated by atlastool from %s (hrydgard@gmail.com)\n\n", script_file);
fprintf(cpp_file, "#include \"%s\"\n\n", (out_prefix + "_atlas.h").c_str());
for (int i = 0; i < (int)fonts.size(); i++) {
FontDesc &xfont = fonts[i];
@@ -1100,7 +1108,7 @@ int main(int argc, char **argv) {
fclose(cpp_file);
FILE *h_file = fopen((out_prefix + "_atlas.h").c_str(), "wb");
fprintf(h_file, "// Header generated by atlastool from %s (hrydgard@gmail.com)\n\n", argv[1]);
fprintf(h_file, "// Header generated by atlastool from %s (hrydgard@gmail.com)\n\n", script_file);
fprintf(h_file, "#pragma once\n");
fprintf(h_file, "#include \"gfx/texture_atlas.h\"\n\n");
if (fonts.size()) {
@@ -1120,4 +1128,5 @@ int main(int argc, char **argv) {
fprintf(h_file, "extern const Atlas %s_atlas;\n", atlas_name);
fprintf(h_file, "extern const AtlasImage %s_images[%i];\n", atlas_name, (int)images.size());
fclose(h_file);
return 0;
}