From 3459e43ca830959d2b4ca71796a34ae7b21a819e Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 27 Jun 2025 14:34:49 +0200 Subject: FLUID: Move i18n settings into its own class --- fluid/io/Code_Writer.cxx | 34 +++++++++++++++++----------------- fluid/io/Project_Reader.cxx | 34 ++-------------------------------- fluid/io/Project_Writer.cxx | 24 ++---------------------- fluid/io/Project_Writer.h | 1 + fluid/io/String_Writer.cxx | 6 +++--- 5 files changed, 25 insertions(+), 74 deletions(-) (limited to 'fluid/io') diff --git a/fluid/io/Code_Writer.cxx b/fluid/io/Code_Writer.cxx index b7179826d..086244035 100644 --- a/fluid/io/Code_Writer.cxx +++ b/fluid/io/Code_Writer.cxx @@ -648,14 +648,14 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { } } std::string loc_include, loc_conditional; - if (proj_.i18n_type==fld::I18n_Type::GNU) { - loc_include = proj_.i18n_gnu_include; - loc_conditional = proj_.i18n_gnu_conditional; + if (proj_.i18n.type==fld::I18n_Type::GNU) { + loc_include = proj_.i18n.gnu_include; + loc_conditional = proj_.i18n.gnu_conditional; } else { - loc_include = proj_.i18n_pos_include; - loc_conditional = proj_.i18n_pos_conditional; + loc_include = proj_.i18n.posix_include; + loc_conditional = proj_.i18n.posix_conditional; } - if ((proj_.i18n_type != fld::I18n_Type::NONE) && !loc_include.empty()) { + if ((proj_.i18n.type != fld::I18n_Type::NONE) && !loc_include.empty()) { int conditional = !loc_conditional.empty(); if (conditional) { write_c("#ifdef %s\n", loc_conditional.c_str()); @@ -665,9 +665,9 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_c("#%sinclude \"%s\"\n", indent(), loc_include.c_str()); else write_c("#%sinclude %s\n", indent(), loc_include.c_str()); - if (proj_.i18n_type == fld::I18n_Type::POSIX) { - if (!proj_.i18n_pos_file.empty()) { - write_c("extern nl_catd %s;\n", proj_.i18n_pos_file.c_str()); + if (proj_.i18n.type == fld::I18n_Type::POSIX) { + if (!proj_.i18n.posix_file.empty()) { + write_c("extern nl_catd %s;\n", proj_.i18n.posix_file.c_str()); } else { write_c("// Initialize I18N stuff now for menus...\n"); write_c("#%sinclude \n", indent()); @@ -677,14 +677,14 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { } if (conditional) { write_c("#else\n"); - if (proj_.i18n_type == fld::I18n_Type::GNU) { - if (!proj_.i18n_gnu_function.empty()) { - write_c("#%sifndef %s\n", indent(), proj_.i18n_gnu_function.c_str()); - write_c("#%sdefine %s(text) text\n", indent_plus(1), proj_.i18n_gnu_function.c_str()); + if (proj_.i18n.type == fld::I18n_Type::GNU) { + if (!proj_.i18n.gnu_function.empty()) { + write_c("#%sifndef %s\n", indent(), proj_.i18n.gnu_function.c_str()); + write_c("#%sdefine %s(text) text\n", indent_plus(1), proj_.i18n.gnu_function.c_str()); write_c("#%sendif\n", indent()); } } - if (proj_.i18n_type == fld::I18n_Type::POSIX) { + if (proj_.i18n.type == fld::I18n_Type::POSIX) { write_c("#%sifndef catgets\n", indent()); write_c("#%sdefine catgets(catalog, set, msgid, text) text\n", indent_plus(1)); write_c("#%sendif\n", indent()); @@ -692,9 +692,9 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { indentation--; write_c("#endif\n"); } - if (proj_.i18n_type == fld::I18n_Type::GNU && proj_.i18n_gnu_static_function[0]) { - write_c("#ifndef %s\n", proj_.i18n_gnu_static_function.c_str()); - write_c("#%sdefine %s(text) text\n", indent_plus(1), proj_.i18n_gnu_static_function.c_str()); + if (proj_.i18n.type == fld::I18n_Type::GNU && proj_.i18n.gnu_static_function[0]) { + write_c("#ifndef %s\n", proj_.i18n.gnu_static_function.c_str()); + write_c("#%sdefine %s(text) text\n", indent_plus(1), proj_.i18n.gnu_static_function.c_str()); write_c("#endif\n"); } } diff --git a/fluid/io/Project_Reader.cxx b/fluid/io/Project_Reader.cxx index 4ef0c6523..c420824aa 100644 --- a/fluid/io/Project_Reader.cxx +++ b/fluid/io/Project_Reader.cxx @@ -261,38 +261,8 @@ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char proj_.avoid_early_includes=1; goto CONTINUE; } - if (!strcmp(c,"i18n_type")) { - proj_.i18n_type = static_cast(atoi(read_word())); - goto CONTINUE; - } - if (!strcmp(c,"i18n_gnu_function")) { - proj_.i18n_gnu_function = read_word(); - goto CONTINUE; - } - if (!strcmp(c,"i18n_gnu_static_function")) { - proj_.i18n_gnu_static_function = read_word(); - goto CONTINUE; - } - if (!strcmp(c,"i18n_pos_file")) { - proj_.i18n_pos_file = read_word(); - goto CONTINUE; - } - if (!strcmp(c,"i18n_pos_set")) { - proj_.i18n_pos_set = read_word(); - goto CONTINUE; - } - if (!strcmp(c,"i18n_include")) { - if (proj_.i18n_type == fld::I18n_Type::GNU) - proj_.i18n_gnu_include = read_word(); - else if (proj_.i18n_type == fld::I18n_Type::POSIX) - proj_.i18n_pos_include = read_word(); - goto CONTINUE; - } - if (!strcmp(c,"i18n_conditional")) { - if (proj_.i18n_type == fld::I18n_Type::GNU) - proj_.i18n_gnu_conditional = read_word(); - else if (proj_.i18n_type == fld::I18n_Type::POSIX) - proj_.i18n_pos_conditional = read_word(); + if (strncmp(c, "i18n_", 5) == 0) { + proj_.i18n.read(*this, c); goto CONTINUE; } if (!strcmp(c,"header_name")) { diff --git a/fluid/io/Project_Writer.cxx b/fluid/io/Project_Writer.cxx index bfe6e0566..1975ef85d 100644 --- a/fluid/io/Project_Writer.cxx +++ b/fluid/io/Project_Writer.cxx @@ -115,28 +115,8 @@ int Project_Writer::write_project(const char *filename, int selected_only, bool write_string("\nutf8_in_src"); if (proj_.avoid_early_includes) write_string("\navoid_early_includes"); - if ((proj_.i18n_type != fld::I18n_Type::NONE)) { - write_string("\ni18n_type %d", static_cast(proj_.i18n_type)); - switch (proj_.i18n_type) { - case fld::I18n_Type::NONE: - break; - case fld::I18n_Type::GNU : /* GNU gettext */ - write_string("\ni18n_include"); write_word(proj_.i18n_gnu_include.c_str()); - write_string("\ni18n_conditional"); write_word(proj_.i18n_gnu_conditional.c_str()); - write_string("\ni18n_gnu_function"); write_word(proj_.i18n_gnu_function.c_str()); - write_string("\ni18n_gnu_static_function"); write_word(proj_.i18n_gnu_static_function.c_str()); - break; - case fld::I18n_Type::POSIX : /* POSIX catgets */ - write_string("\ni18n_include"); write_word(proj_.i18n_pos_include.c_str()); - write_string("\ni18n_conditional"); write_word(proj_.i18n_pos_conditional.c_str()); - if (!proj_.i18n_pos_file.empty()) { - write_string("\ni18n_pos_file"); - write_word(proj_.i18n_pos_file.c_str()); - } - write_string("\ni18n_pos_set"); write_word(proj_.i18n_pos_set.c_str()); - break; - } - } + + proj_.i18n.write(*this); if (!selected_only) { write_string("\nheader_name"); write_word(proj_.header_file_name.c_str()); diff --git a/fluid/io/Project_Writer.h b/fluid/io/Project_Writer.h index 67aebb46e..4b21cf2fb 100644 --- a/fluid/io/Project_Writer.h +++ b/fluid/io/Project_Writer.h @@ -50,6 +50,7 @@ public: int open_write(const char *s); int close_write(); int write_project(const char *filename, int selected_only, bool codeview); + void NewFunction(); void write_word(const char *); void write_string(const char *,...) __fl_attr((__format__ (__printf__, 2, 3))); void write_indent(int n); diff --git a/fluid/io/String_Writer.cxx b/fluid/io/String_Writer.cxx index 6b70ec1f3..e96d2068e 100644 --- a/fluid/io/String_Writer.cxx +++ b/fluid/io/String_Writer.cxx @@ -56,7 +56,7 @@ static int write_escaped_strings(FILE *out, const char *text) { /** Write a file that contains all label and tooltip strings for internationalization. The user is responsible to set the right file name extension. The file format - is determined by `proj_.i18n_type`. + is determined by `proj_.i18n.type`. \param[in] filename file path and name to a file that will hold the strings \return 1 if the file could not be opened for writing, or the result of `fclose`. */ @@ -68,7 +68,7 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { FILE *fp = fl_fopen(filename.c_str(), "wb"); if (!fp) return 1; - switch (proj.i18n_type) { + switch (proj.i18n.type) { case fld::I18n_Type::NONE : /* None, just put static text out */ fprintf(fp, "# generated by Fast Light User Interface Designer (fluid) version %.4f\n", FL_VERSION); @@ -115,7 +115,7 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { case fld::I18n_Type::POSIX : /* POSIX catgets, put a .msg file out */ fprintf(fp, "$ generated by Fast Light User Interface Designer (fluid) version %.4f\n", FL_VERSION); - fprintf(fp, "$set %s\n", proj.i18n_pos_set.c_str()); + fprintf(fp, "$set %s\n", proj.i18n.posix_set.c_str()); fputs("$quote \"\n", fp); for (i = 1, p = proj.tree.first; p; p = p->next) { -- cgit v1.2.3