diff options
| author | maxim nikonov <maxim.nikonov@hqo.co> | 2026-02-06 02:33:41 +0500 |
|---|---|---|
| committer | maxim nikonov <maxim.nikonov@hqo.co> | 2026-02-06 02:33:41 +0500 |
| commit | 43e0a37906afabb0b3b091b8d3eac9a910cae50c (patch) | |
| tree | d2a037c2bf0dc395fddb08e32ebfcf2795503b7c /fluid/io | |
| parent | 4ce4967c33d56e4b56d85d11fe0e0be91e159f5d (diff) | |
wip
Diffstat (limited to 'fluid/io')
| -rw-r--r-- | fluid/io/Code_Writer.cxx | 67 | ||||
| -rw-r--r-- | fluid/io/Code_Writer.h | 8 | ||||
| -rw-r--r-- | fluid/io/Project_Reader.cxx | 44 | ||||
| -rw-r--r-- | fluid/io/Project_Reader.h | 6 | ||||
| -rw-r--r-- | fluid/io/Project_Writer.cxx | 12 | ||||
| -rw-r--r-- | fluid/io/Project_Writer.h | 2 | ||||
| -rw-r--r-- | fluid/io/String_Writer.cxx | 14 |
7 files changed, 83 insertions, 70 deletions
diff --git a/fluid/io/Code_Writer.cxx b/fluid/io/Code_Writer.cxx index 0998ed287..357db80dd 100644 --- a/fluid/io/Code_Writer.cxx +++ b/fluid/io/Code_Writer.cxx @@ -302,14 +302,14 @@ void Code_Writer::write_cstring(const char *s, int length) { } // if we are rendering to the source code preview window, and the text is // longer than four lines, we only render a placeholder. - if (write_codeview && ((s==nullptr) || (length>300))) { + if (write_codeview && ((s==0) || (length>300))) { if (length>=0) crc_printf("\" ... %d bytes of text... \"", length); else crc_puts("\" ... text... \""); return; } - if (length==-1 || s==nullptr) { + if (length==-1 || s==0) { crc_puts("\n#error string not found\n"); crc_puts("\" ... undefined size text... \""); return; @@ -639,7 +639,7 @@ Node* Code_Writer::write_code(Node* p) { } write_h("};\n"); - current_widget_class = nullptr; + current_widget_class = 0; } else { for (q = p->next; q && q->level > p->level;) q = write_code(q); // write all code that come after the children @@ -667,8 +667,8 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_codeview = to_codeview; unique_id_list.clear(); indentation = 0; - current_class = nullptr; - current_widget_class = nullptr; + current_class = 0; + current_widget_class = 0; if (!s) code_file = stdout; else { FILE *f = fl_fopen(s, "wb"); @@ -683,11 +683,16 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { } // Remember the last code file location for MergeBack if (s && proj_.write_mergeback_data && !to_codeview) { - std::string filename = proj_.projectfile_path() + proj_.projectfile_name(); - int i, n = (int)filename.size(); + char filename[FL_PATH_MAX]; + char path_buf[FL_PATH_MAX]; + int i, n; + proj_.projectfile_path(path_buf, FL_PATH_MAX); + const char *pname = proj_.projectfile_name(); + snprintf(filename, FL_PATH_MAX, "%s%s", path_buf, pname ? pname : ""); + n = (int)strlen(filename); for (i=0; i<n; i++) if (filename[i]=='\\') filename[i] = '/'; Fl_Preferences build_records(Fl_Preferences::USER_L, "fltk.org", "fluid-build"); - Fl_Preferences path(build_records, filename.c_str()); + Fl_Preferences path(build_records, filename); path.set("code", s); } // if the first entry in the Type tree is a comment, then it is probably @@ -723,16 +728,18 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { // // To make the include guard consistent across l=platforms, it can be // explicitly set by the user in the Project Settings. - std::string macro_name_str = proj_.include_guard; - if (macro_name_str.empty()) { - char macro_name[1024]; - char *mp = macro_name; - char *mp_end = macro_name + sizeof(macro_name) - 16; - std::string header_name; + char macro_name_str[1024]; + const char *guard = proj_.include_guard(); + if (guard && guard[0]) { + strlcpy(macro_name_str, guard, sizeof(macro_name_str)); + } else { + char *mp = macro_name_str; + char *mp_end = macro_name_str + sizeof(macro_name_str) - 16; + char header_name[FL_PATH_MAX]; const char* a = 0; if (write_codeview) { - header_name = proj_.headerfile_name(); - a = header_name.c_str(); + proj_.headerfile_name(header_name, FL_PATH_MAX); + a = header_name; } else { a = fl_filename_name(t); } @@ -755,10 +762,9 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { a += len; } *mp = 0; - macro_name_str = macro_name; } - fprintf(header_file, "#ifndef %s\n", macro_name_str.c_str()); - fprintf(header_file, "#define %s\n", macro_name_str.c_str()); + fprintf(header_file, "#ifndef %s\n", macro_name_str); + fprintf(header_file, "#define %s\n", macro_name_str); } if (proj_.avoid_early_includes==0) { @@ -767,10 +773,13 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { if (t && proj_.include_H_from_C) { if (to_codeview) { write_c("#include \"CodeView.h\"\n"); - } else if (proj_.header_file_name[0] == '.' && strchr(proj_.header_file_name.c_str(), '/') == nullptr) { - write_c("#include \"%s\"\n", fl_filename_name(t)); } else { - write_c("#include \"%s\"\n", proj_.header_file_name.c_str()); + const char *hfn = proj_.header_file_name(); + if (hfn && hfn[0] == '.' && strchr(hfn, '/') == 0) { + write_c("#include \"%s\"\n", fl_filename_name(t)); + } else { + write_c("#include \"%s\"\n", hfn ? hfn : ""); + } } } std::string loc_include, loc_conditional; @@ -798,7 +807,11 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_c("// Initialize I18N stuff now for menus...\n"); write_c("#%sinclude <locale.h>\n", indent()); write_c("static char *_locale = setlocale(LC_MESSAGES, \"\");\n"); - write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", proj_.basename().c_str()); + { + char basename_buf[FL_PATH_MAX]; + proj_.basename(basename_buf, FL_PATH_MAX); + write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", basename_buf); + } } } if (conditional) { @@ -851,10 +864,10 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { if (code_file != stdout) x = fclose(code_file); - code_file = nullptr; + code_file = 0; if (header_file != stdout) y = fclose(header_file); - header_file = nullptr; + header_file = 0; return x >= 0 && y >= 0; } @@ -883,7 +896,7 @@ void Code_Writer::write_public(int state) { Code_Writer::Code_Writer(Project &proj) : proj_ { proj } { - block_crc_ = crc32(0, nullptr, 0); + block_crc_ = crc32(0, 0, 0); } /** @@ -906,7 +919,7 @@ void Code_Writer::tag(proj::Mergeback::Tag prev_type, proj::Mergeback::Tag next_ if (proj_.write_mergeback_data) { Mergeback::print_tag(code_file, prev_type, next_type, uid, (uint32_t)block_crc_); } - block_crc_ = crc32(0, nullptr, 0); + block_crc_ = crc32(0, 0, 0); } /** diff --git a/fluid/io/Code_Writer.h b/fluid/io/Code_Writer.h index 9d52e0600..f2ca32a3e 100644 --- a/fluid/io/Code_Writer.h +++ b/fluid/io/Code_Writer.h @@ -88,9 +88,9 @@ private: Project &proj_; /// file pointer for the C++ code file - FILE *code_file = nullptr; + FILE *code_file = 0; /// file pointer for the C++ header file - FILE *header_file = nullptr; + FILE *header_file = 0; /// tree of unique but human-readable identifiers Fd_Id_Map unique_id_list; @@ -106,7 +106,7 @@ private: /// if set, we are at the start of a line and can ignore leading spaces in crc bool block_line_start_ = true; /// expanding buffer for vsnprintf - char *block_buffer_ = nullptr; + char *block_buffer_ = 0; /// size of expanding buffer for vsnprintf int block_buffer_size_ = 0; @@ -159,7 +159,7 @@ public: void tag(proj::Mergeback::Tag prev_type, proj::Mergeback::Tag next_type, unsigned short uid); - static unsigned long block_crc(const void *data, int n=-1, unsigned long in_crc=0, bool *inout_line_start=nullptr); + static unsigned long block_crc(const void *data, int n=-1, unsigned long in_crc=0, bool *inout_line_start=0); }; } // namespace io diff --git a/fluid/io/Project_Reader.cxx b/fluid/io/Project_Reader.cxx index e4eb65606..33dce126c 100644 --- a/fluid/io/Project_Reader.cxx +++ b/fluid/io/Project_Reader.cxx @@ -112,7 +112,7 @@ Project_Reader::~Project_Reader() /** Open an .fl file for reading. - \param[in] s filename, if nullptr, read from stdin instead + \param[in] s filename, if 0, read from stdin instead \return 0 if the operation failed, 1 if it succeeded */ int Project_Reader::open_read(const char *s) { @@ -137,7 +137,7 @@ int Project_Reader::open_read(const char *s) { int Project_Reader::close_read() { if (fin != stdin) { int x = fclose(fin); - fin = nullptr; + fin = 0; return x >= 0; } return 1; @@ -195,7 +195,7 @@ int Project_Reader::read_quoted() { // read whatever character is after a \ If this is the first call, also read the global settings for this design. - \param[in] p parent node or nullptr + \param[in] p parent node or 0 \param[in] merge if set, merge into existing design, else replace design \param[in] strategy add nodes after current or as last child \param[in] skip_options this is set if the options were already found in @@ -204,8 +204,8 @@ int Project_Reader::read_quoted() { // read whatever character is after a \ */ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char skip_options) { Fluid.proj.tree.current = p; - Node *last_child_read = nullptr; - Node *t = nullptr; + Node *last_child_read = 0; + Node *t = 0; for (;;) { const char *c = read_word(); REUSE_C: @@ -225,12 +225,12 @@ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char // this is the first word in a .fd file: if (!strcmp(c,"Magic:")) { read_fdesign(); - return nullptr; + return 0; } if (!strcmp(c,"version")) { c = read_word(); - read_version = strtod(c,nullptr); + read_version = strtod(c,0); if (read_version<=0 || read_version>double(FL_VERSION+0.00001)) read_error("unknown version '%s'",c); continue; @@ -266,24 +266,24 @@ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char goto CONTINUE; } if (!strcmp(c,"header_name")) { - if (!proj_.header_file_set) proj_.header_file_name = read_word(); + if (!proj_.header_file_set) proj_.set_header_file_name(read_word()); else read_word(); goto CONTINUE; } if (!strcmp(c,"code_name")) { - if (!proj_.code_file_set) proj_.code_file_name = read_word(); + if (!proj_.code_file_set) proj_.set_code_file_name(read_word()); else read_word(); goto CONTINUE; } if (!strcmp(c,"include_guard")) { - proj_.include_guard = read_word(); + proj_.set_include_guard(read_word()); goto CONTINUE; } if (!strcmp(c, "snap")) { - Fluid.layout_list.read(this); + Fluid.layout_list->read(this); goto CONTINUE; } @@ -400,11 +400,11 @@ int Project_Reader::read_project(const char *filename, int merge, Strategy strat proj_.reset(); read_children(Fluid.proj.tree.current, merge, strategy); // clear this - Fluid.proj.tree.current = nullptr; + Fluid.proj.tree.current = 0; // Force menu items to be rebuilt... for (o = Fluid.proj.tree.first; o; o = o->next) { if (o->is_a(FLD_NODE_TYPE_Menu_Manager_)) { - o->add_child(nullptr,nullptr); + o->add_child(0,0); } } for (o = Fluid.proj.tree.first; o; o = o->next) { @@ -418,7 +418,7 @@ int Project_Reader::read_project(const char *filename, int merge, Strategy strat g_shell_config->rebuild_shell_menu(); g_shell_config->update_settings_dialog(); } - Fluid.layout_list.update_dialogs(); + Fluid.layout_list->update_dialogs(); proj_.update_settings_dialog(); int ret = close_read(); proj_.undo.resume(); @@ -452,7 +452,7 @@ void Project_Reader::read_error(const char *format, ...) { } /** - Return a word read from the .fl file, or nullptr at the EOF. + Return a word read from the .fl file, or 0 at the EOF. This will skip all comments (# to end of line), and evaluate all \\xxx sequences and use \\ at the end of line to remove the newline. @@ -476,7 +476,7 @@ const char *Project_Reader::read_word(int wantbrace) { for (;;) { x = nextchar(); if (x < 0 && feof(fin)) { // eof - return nullptr; + return 0; } else if (x == '#') { // comment do x = nextchar(); while (x >= 0 && x != '\n'); lineno++; @@ -622,7 +622,7 @@ static const char *class_matcher[] = { "2", "FL_BOX", // was FL_TEXT "62","FL_TIMER", "24","Fl_Value_Slider", - nullptr}; + 0}; /** @@ -684,9 +684,9 @@ static void forms_end(Fl_Group *g, int flip) { void Project_Reader::read_fdesign() { int fdesign_magic = atoi(read_word()); fdesign_flip = (fdesign_magic < 13000); - Widget_Node *window = nullptr; - Widget_Node *group = nullptr; - Widget_Node *widget = nullptr; + Widget_Node *window = 0; + Widget_Node *group = 0; + Widget_Node *widget = 0; if (!Fluid.proj.tree.current) { Node *t = add_new_widget_from_file("Function", Strategy::FROM_FILE_AS_LAST_CHILD); t->name("create_the_forms()"); @@ -714,9 +714,9 @@ void Project_Reader::read_fdesign() { Fl_Group* g = (Fl_Group*)(group->o); g->begin(); forms_end(g, fdesign_flip); - Fl_Group::current(nullptr); + Fl_Group::current(0); } - group = widget = nullptr; + group = widget = 0; Fluid.proj.tree.current = window; } else { for (int i = 0; class_matcher[i]; i += 2) diff --git a/fluid/io/Project_Reader.h b/fluid/io/Project_Reader.h index b25b04ead..fe66be689 100644 --- a/fluid/io/Project_Reader.h +++ b/fluid/io/Project_Reader.h @@ -43,13 +43,13 @@ protected: Project &proj_; /// Project input file - FILE *fin = nullptr; + FILE *fin = 0; /// Number of most recently read line int lineno = 0; /// Pointer to the file path and name (not copied!) - const char *fname = nullptr; + const char *fname = 0; /// Expanding buffer to store the most recently read word - char *buffer = nullptr; + char *buffer = 0; /// Exact size of the expanding buffer in bytes int buflen = 0; diff --git a/fluid/io/Project_Writer.cxx b/fluid/io/Project_Writer.cxx index 54af531e9..a3b878c3f 100644 --- a/fluid/io/Project_Writer.cxx +++ b/fluid/io/Project_Writer.cxx @@ -62,8 +62,8 @@ Project_Writer::~Project_Writer() /** Open the .fl design file for writing. - If the filename is nullptr, associate stdout instead. - \param[in] s the filename or nullptr for stdout + If the filename is 0, associate stdout instead. + \param[in] s the filename or 0 for stdout \return 1 if successful. 0 if the operation failed */ int Project_Writer::open_write(const char *s) { @@ -119,10 +119,10 @@ int Project_Writer::write_project(const char *filename, int selected_only, bool proj_.i18n.write(*this); if (!selected_only) { - write_string("\nheader_name"); write_word(proj_.header_file_name); - write_string("\ncode_name"); write_word(proj_.code_file_name); - write_string("\ninclude_guard"); write_word(proj_.include_guard); - Fluid.layout_list.write(this); + write_string("\nheader_name"); write_word(proj_.header_file_name()); + write_string("\ncode_name"); write_word(proj_.code_file_name()); + write_string("\ninclude_guard"); write_word(proj_.include_guard()); + Fluid.layout_list->write(this); if (g_shell_config) g_shell_config->write(this); if (proj_.write_mergeback_data) diff --git a/fluid/io/Project_Writer.h b/fluid/io/Project_Writer.h index c95c9f7cb..64769a762 100644 --- a/fluid/io/Project_Writer.h +++ b/fluid/io/Project_Writer.h @@ -40,7 +40,7 @@ protected: Project &proj_; // Project output file, always opened in "wb" mode - FILE *fout = nullptr; + FILE *fout = 0; /// If set, one space is written before text unless the format starts with a newline character int needspace = 0; /// Set if this file will be used in the codeview dialog diff --git a/fluid/io/String_Writer.cxx b/fluid/io/String_Writer.cxx index 6d7761a49..cf59935aa 100644 --- a/fluid/io/String_Writer.cxx +++ b/fluid/io/String_Writer.cxx @@ -77,8 +77,8 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { write_escaped_strings(fp, w->label()); putc('\n', fp); } - if (!w->tooltip().empty()) { - write_escaped_strings(fp, w->tooltip().c_str()); + if (!(!w->tooltip() || !w->tooltip()[0])) { + write_escaped_strings(fp, w->tooltip()); putc('\n', fp); } } @@ -100,13 +100,13 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { fputs("\"\n", fp); } - if (!w->tooltip().empty()) { + if (!(!w->tooltip() || !w->tooltip()[0])) { fputs("msgid \"", fp); - write_escaped_strings(fp, w->tooltip().c_str()); + write_escaped_strings(fp, w->tooltip()); fputs("\"\n", fp); fputs("msgstr \"", fp); - write_escaped_strings(fp, w->tooltip().c_str()); + write_escaped_strings(fp, w->tooltip()); fputs("\"\n", fp); } } @@ -128,9 +128,9 @@ int fld::io::write_strings(Project &proj, const std::string &filename) { fputs("\"\n", fp); } - if (!w->tooltip().empty()) { + if (!(!w->tooltip() || !w->tooltip()[0])) { fprintf(fp, "%d \"", i ++); - write_escaped_strings(fp, w->tooltip().c_str()); + write_escaped_strings(fp, w->tooltip()); fputs("\"\n", fp); } } |
