summaryrefslogtreecommitdiff
path: root/fluid/io/Code_Writer.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-03-16 17:16:12 -0400
committerGitHub <noreply@github.com>2025-03-16 17:16:12 -0400
commit51a55bc73660f64e8f4b32b8b4d3858f2a786f7b (patch)
tree122ad9f838fcf8f61ed7cf5fa031e8ed69817e10 /fluid/io/Code_Writer.cxx
parent13a7073a1e007ce5b71ef70bced1a9b15158820d (diff)
Fluid: restructuring and rejuvenation of the source code.
* Add classes for application and project * Removed all globals from Fluid.h * Extracting args and project history into their own classes * Moving globals into Application class * Initialize values inside headers for some classes. * Undo functionality wrapped in a class inside Project. * File reader and writer are now linked to a project. * Avoid global project access * Nodes (former Types) will be managed by a new Tree class. * Removed static members (hidden globals) form Node/Fl_Type. * Adding Tree iterator. * Use nullptr instead of 0, NULL, or 0L * Renamed Fl_..._Type to ..._Node, FL_OVERRIDE -> override * Renaming ..._type to ...::prototype * Splitting Widget Panel into multiple files. * Moved callback code into widget panel file. * Cleaning up Fluid_Image -> Image_asset * Moving Fd_Snap_Action into new namespace fld::app::Snap_Action etc. * Moved mergeback into proj folder. * `enum ID` is now `enum class Type`.
Diffstat (limited to 'fluid/io/Code_Writer.cxx')
-rw-r--r--fluid/io/Code_Writer.cxx430
1 files changed, 108 insertions, 322 deletions
diff --git a/fluid/io/Code_Writer.cxx b/fluid/io/Code_Writer.cxx
index c88ebc147..c9e638c93 100644
--- a/fluid/io/Code_Writer.cxx
+++ b/fluid/io/Code_Writer.cxx
@@ -1,5 +1,5 @@
//
-// Code output routines for the Fast Light Tool Kit (FLTK).
+// Fluid C++ Code Writer code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2025 by Bill Spitzak and others.
//
@@ -16,18 +16,16 @@
#include "io/Code_Writer.h"
-#include "app/project.h"
-#include "nodes/Fl_Window_Type.h"
-#include "nodes/Fl_Function_Type.h"
+#include "Fluid.h"
+#include "Project.h"
+#include "nodes/Window_Node.h"
+#include "nodes/Function_Node.h"
#include <FL/filename.H>
#include "../src/flstring.h"
#include <zlib.h>
-/// \defgroup cfile C Code File Operations
-/// \{
-
using namespace fld;
using namespace fld::io;
@@ -41,146 +39,6 @@ int is_id(char c) {
return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_';
}
-/**
- Write a string to a file, replacing all non-ASCII characters with octal codes.
- \param[in] out output file
- \param[in] text write this NUL terminated utf-8 string
- \return EOF if any of the file access calls failed, 0 if OK
- */
-int write_escaped_strings(FILE *out, const char *text) {
- int ret = 0;
- const unsigned char *utf8_text = (const unsigned char *)text;
- for (const unsigned char *s = utf8_text; *s; ++s) {
- unsigned char c = *s;
- // escape control characters, delete, all utf-8, and the double quotes
- // note: we should have an option in the project settings to allow utf-8
- // characters in the output text and not escape them
- if (c < 32 || c > 126 || c == '\"') {
- if (c == '\r') {
- ret = fputs("\\r", out);
- } else if (c == '\n') {
- ret = fputs("\\n", out);
- } else {
- ret = fprintf(out, "\\%03o", c);
- }
- } else {
- ret = putc((int)c, out);
- }
- }
- return ret;
-}
-
-/**
- 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 `g_project.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`.
- */
-int write_strings(const std::string &filename) {
- Fl_Type *p;
- Fl_Widget_Type *w;
- int i;
-
- FILE *fp = fl_fopen(filename.c_str(), "wb");
- if (!fp) return 1;
-
- switch (g_project.i18n_type) {
- case FD_I18N_NONE : /* None, just put static text out */
- fprintf(fp, "# generated by Fast Light User Interface Designer (fluid) version %.4f\n",
- FL_VERSION);
- for (p = Fl_Type::first; p; p = p->next) {
- if (p->is_widget()) {
- w = (Fl_Widget_Type *)p;
-
- if (w->label()) {
- write_escaped_strings(fp, w->label());
- putc('\n', fp);
- }
-
- if (w->tooltip()) {
- write_escaped_strings(fp, w->tooltip());
- putc('\n', fp);
- }
- }
- }
- break;
- case FD_I18N_GNU : /* GNU gettext, put a .po file out */
- fprintf(fp, "# generated by Fast Light User Interface Designer (fluid) version %.4f\n",
- FL_VERSION);
- for (p = Fl_Type::first; p; p = p->next) {
- if (p->is_widget()) {
- w = (Fl_Widget_Type *)p;
-
- if (w->label()) {
- fputs("msgid \"", fp);
- write_escaped_strings(fp, w->label());
- fputs("\"\n", fp);
-
- fputs("msgstr \"", fp);
- write_escaped_strings(fp, w->label());
- fputs("\"\n", fp);
- }
-
- if (w->tooltip()) {
- fputs("msgid \"", fp);
- write_escaped_strings(fp, w->tooltip());
- fputs("\"\n", fp);
-
- fputs("msgstr \"", fp);
- write_escaped_strings(fp, w->tooltip());
- fputs("\"\n", fp);
- }
- }
- }
- break;
- case FD_I18N_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", g_project.i18n_pos_set.c_str());
- fputs("$quote \"\n", fp);
-
- for (i = 1, p = Fl_Type::first; p; p = p->next) {
- if (p->is_widget()) {
- w = (Fl_Widget_Type *)p;
-
- if (w->label()) {
- fprintf(fp, "%d \"", i ++);
- write_escaped_strings(fp, w->label());
- fputs("\"\n", fp);
- }
-
- if (w->tooltip()) {
- fprintf(fp, "%d \"", i ++);
- write_escaped_strings(fp, w->tooltip());
- fputs("\"\n", fp);
- }
- }
- }
- break;
- }
-
- return fclose(fp);
-}
-
-////////////////////////////////////////////////////////////////
-// Generate unique but human-readable identifiers:
-
-/** A binary searchable tree storing identifiers for quick retrieval. */
-struct Fd_Identifier_Tree {
- char* text;
- void* object;
- Fd_Identifier_Tree *left, *right;
- Fd_Identifier_Tree (const char* t, void* o) : text(fl_strdup(t)), object(o) {left = right = 0;}
- ~Fd_Identifier_Tree();
-};
-
-Fd_Identifier_Tree::~Fd_Identifier_Tree() {
- delete left;
- free((void *)text);
- delete right;
-}
-
/** \brief Return a unique name for the given object.
This function combines the name and label into an identifier. It then checks
@@ -209,22 +67,21 @@ const char* Code_Writer::unique_id(void* o, const char* type, const char* name,
}
*q = 0;
// okay, search the tree and see if the name was already used:
- Fd_Identifier_Tree** p = &id_root;
int which = 0;
- while (*p) {
- int i = strcmp(buffer, (*p)->text);
- if (!i) {
- if ((*p)->object == o) return (*p)->text;
- // already used, we need to pick a new name:
- sprintf(q,"%x",++which);
- p = &id_root;
- continue;
+ for (;;) {
+ auto it = unique_id_list.find(buffer);
+ // If the id does not exist, add it to the map
+ if (it == unique_id_list.end()) {
+ it = unique_id_list.insert(std::make_pair(buffer, o)).first;
+ return it->first.c_str();
}
- else if (i < 0) p = &((*p)->left);
- else p = &((*p)->right);
+ // If it does exist, and the pointers are the same, just return it.
+ if (it->second == o) {
+ return it->first.c_str();
+ }
+ // Else repeat until we have a new id,
+ sprintf(q,"%x",++which);
}
- *p = new Fd_Identifier_Tree(buffer, o);
- return (*p)->text;
}
////////////////////////////////////////////////////////////////
@@ -272,45 +129,6 @@ const char *Code_Writer::indent_plus(int offset) {
}
-////////////////////////////////////////////////////////////////
-// declarations/include files:
-// Each string generated by write_h_once is written only once to
-// the header file. This is done by keeping a binary tree of all
-// the calls so far and not printing it if it is in the tree.
-
-/** A binary searchable tree storing text for quick retrieval. */
-struct Fd_Text_Tree {
- char *text;
- Fd_Text_Tree *left, *right;
- Fd_Text_Tree(const char *t) {
- text = fl_strdup(t);
- left = right = 0;
- }
- ~Fd_Text_Tree();
-};
-
-Fd_Text_Tree::~Fd_Text_Tree() {
- delete left;
- free((void *)text);
- delete right;
-}
-
-/** A binary searchable tree storing pointers for quick retrieval. */
-struct Fd_Pointer_Tree {
- void *ptr;
- Fd_Pointer_Tree *left, *right;
- Fd_Pointer_Tree(void *p) {
- ptr = p;
- left = right = 0;
- }
- ~Fd_Pointer_Tree();
-};
-
-Fd_Pointer_Tree::~Fd_Pointer_Tree() {
- delete left;
- delete right;
-}
-
/**
Print a formatted line to the header file, unless the same line was produced before in this header file.
\note Resulting line is cropped at 1023 bytes.
@@ -323,15 +141,11 @@ int Code_Writer::write_h_once(const char *format, ...) {
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
- Fd_Text_Tree **p = &text_in_header;
- while (*p) {
- int i = strcmp(buf,(*p)->text);
- if (!i) return 0;
- else if (i < 0) p = &((*p)->left);
- else p = &((*p)->right);
+ if (text_in_header.find(buf) != text_in_header.end()) {
+ return 0;
}
- fprintf(header_file,"%s\n",buf);
- *p = new Fd_Text_Tree(buf);
+ fprintf(header_file, "%s\n", buf);
+ text_in_header.insert(buf);
return 1;
}
@@ -347,22 +161,16 @@ int Code_Writer::write_c_once(const char *format, ...) {
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
- Fd_Text_Tree **p = &text_in_header;
- while (*p) {
- int i = strcmp(buf,(*p)->text);
- if (!i) return 0;
- else if (i < 0) p = &((*p)->left);
- else p = &((*p)->right);
+ // Return if the text was already printed to the header file.
+ if (text_in_header.find(buf) != text_in_header.end()) {
+ return 0;
}
- p = &text_in_code;
- while (*p) {
- int i = strcmp(buf,(*p)->text);
- if (!i) return 0;
- else if (i < 0) p = &((*p)->left);
- else p = &((*p)->right);
+ // Return if the text was already printed to the source file.
+ if (text_in_code.find(buf) != text_in_code.end()) {
+ return 0;
}
crc_printf("%s\n", buf);
- *p = new Fd_Text_Tree(buf);
+ text_in_code.insert(buf);
return 1;
}
@@ -373,13 +181,10 @@ int Code_Writer::write_c_once(const char *format, ...) {
\return true if found in the tree, false if added to the tree
*/
bool Code_Writer::c_contains(void *pp) {
- Fd_Pointer_Tree **p = &ptr_in_code;
- while (*p) {
- if ((*p)->ptr == pp) return true;
- else if ((*p)->ptr < pp) p = &((*p)->left);
- else p = &((*p)->right);
+ if (ptr_in_code.find(pp) != ptr_in_code.end()) {
+ return true;
}
- *p = new Fd_Pointer_Tree(pp);
+ ptr_in_code.insert(pp);
return false;
}
@@ -408,14 +213,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==NULL) || (length>300))) {
+ if (write_codeview && ((s==nullptr) || (length>300))) {
if (length>=0)
crc_printf("\" ... %d bytes of text... \"", length);
else
crc_puts("\" ... text... \"");
return;
}
- if (length==-1 || s==0L) {
+ if (length==-1 || s==nullptr) {
crc_puts("\n#error string not found\n");
crc_puts("\" ... undefined size text... \"");
return;
@@ -454,7 +259,7 @@ void Code_Writer::write_cstring(const char *s, int length) {
break;
}
// if the UTF-8 option is checked, write unicode characters verbatim
- if (g_project.utf8_in_src && (c&0x80)) {
+ if (proj_.utf8_in_src && (c&0x80)) {
if ((c&0x40)) {
// This is the first character in a utf-8 sequence (0b11......).
// A line break would be ok here. Do not put linebreak in front of
@@ -644,13 +449,13 @@ void Code_Writer::write_c_indented(const char *textlines, int inIndent, char inT
constructor whereas functions, declarations, and inline data are seen as
members of the class itself.
*/
-bool is_class_member(Fl_Type *t) {
- return t->is_a(ID_Function)
- || t->is_a(ID_Decl)
- || t->is_a(ID_Data);
-// || t->is_a(ID_Class) // FLUID can't handle a class inside a class
-// || t->is_a(ID_Widget_Class)
-// || t->is_a(ID_DeclBlock) // Declaration blocks are generally not handled well
+bool is_class_member(Node *t) {
+ return t->is_a(Type::Function)
+ || t->is_a(Type::Decl)
+ || t->is_a(Type::Data);
+// || t->is_a(Type::Class) // FLUID can't handle a class inside a class
+// || t->is_a(Type::Widget_Class)
+// || t->is_a(Type::DeclBlock) // Declaration blocks are generally not handled well
}
/**
@@ -661,11 +466,11 @@ bool is_class_member(Fl_Type *t) {
\param[in] q should be a comment type
\return true if this comment is followed by a class member
\return false if it is followed by a widget or code
- \see is_class_member(Fl_Type *t)
+ \see is_class_member(Node *t)
*/
-bool is_comment_before_class_member(Fl_Type *q) {
- if (q->is_a(ID_Comment) && q->next && q->next->level==q->level) {
- if (q->next->is_a(ID_Comment))
+bool is_comment_before_class_member(Node *q) {
+ if (q->is_a(Type::Comment) && q->next && q->next->level==q->level) {
+ if (q->next->is_a(Type::Comment))
return is_comment_before_class_member(q->next);
if (is_class_member(q->next))
return true;
@@ -678,14 +483,14 @@ bool is_comment_before_class_member(Fl_Type *q) {
\param[in] p write this type and all its children
\return pointer to the next sibling
*/
-Fl_Type* Code_Writer::write_static(Fl_Type* p) {
+Node* Code_Writer::write_static(Node* p) {
if (write_codeview) p->header_static_start = (int)ftell(header_file);
if (write_codeview) p->code_static_start = (int)ftell(code_file);
p->write_static(*this);
if (write_codeview) p->code_static_end = (int)ftell(code_file);
if (write_codeview) p->header_static_end = (int)ftell(header_file);
- Fl_Type* q;
+ Node* q;
for (q = p->next; q && q->level > p->level;) {
q = write_static(q);
}
@@ -697,13 +502,13 @@ Fl_Type* Code_Writer::write_static(Fl_Type* p) {
/**
Recursively write code, putting children between the two parts of the parent code.
- \param[in] p write this type and all its children
+ \param[in] p write this node and all its children
\return pointer to the next sibling
*/
-Fl_Type* Code_Writer::write_code(Fl_Type* p) {
+Node* Code_Writer::write_code(Node* p) {
// write all code that comes before the children code
// (but don't write the last comment until the very end)
- if (!(p==Fl_Type::last && p->is_a(ID_Comment))) {
+ if (!(p==Fluid.proj.tree.last && p->is_a(Type::Comment))) {
if (write_codeview) p->code1_start = (int)ftell(code_file);
if (write_codeview) p->header1_start = (int)ftell(header_file);
p->write_code1(*this);
@@ -711,7 +516,7 @@ Fl_Type* Code_Writer::write_code(Fl_Type* p) {
if (write_codeview) p->header1_end = (int)ftell(header_file);
}
// recursively write the code of all children
- Fl_Type* q;
+ Node* q;
if (p->is_widget() && p->is_class()) {
// Handle widget classes specially
for (q = p->next; q && q->level > p->level;) {
@@ -745,7 +550,7 @@ Fl_Type* Code_Writer::write_code(Fl_Type* p) {
}
write_h("};\n");
- current_widget_class = 0L;
+ current_widget_class = nullptr;
} else {
for (q = p->next; q && q->level > p->level;) q = write_code(q);
// write all code that come after the children
@@ -771,10 +576,10 @@ Fl_Type* Code_Writer::write_code(Fl_Type* p) {
*/
int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
write_codeview = to_codeview;
- delete id_root; id_root = 0;
+ unique_id_list.clear();
indentation = 0;
- current_class = 0L;
- current_widget_class = 0L;
+ current_class = nullptr;
+ current_widget_class = nullptr;
if (!s) code_file = stdout;
else {
FILE *f = fl_fopen(s, "wb");
@@ -788,29 +593,29 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
header_file = f;
}
// Remember the last code file location for MergeBack
- if (s && g_project.write_mergeback_data && !to_codeview) {
- std::string proj_filename = g_project.projectfile_path() + g_project.projectfile_name();
- int i, n = (int)proj_filename.size();
- for (i=0; i<n; i++) if (proj_filename[i]=='\\') proj_filename[i] = '/';
+ if (s && proj_.write_mergeback_data && !to_codeview) {
+ std::string filename = proj_.projectfile_path() + proj_.projectfile_name();
+ int i, n = (int)filename.size();
+ 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, proj_filename.c_str());
+ Fl_Preferences path(build_records, filename.c_str());
path.set("code", s);
}
// if the first entry in the Type tree is a comment, then it is probably
// a copyright notice. We print that before anything else in the file!
- Fl_Type* first_type = Fl_Type::first;
- if (first_type && first_type->is_a(ID_Comment)) {
+ Node* first_node = Fluid.proj.tree.first;
+ if (first_node && first_node->is_a(Type::Comment)) {
if (write_codeview) {
- first_type->code1_start = first_type->code2_start = (int)ftell(code_file);
- first_type->header1_start = first_type->header2_start = (int)ftell(header_file);
+ first_node->code1_start = first_node->code2_start = (int)ftell(code_file);
+ first_node->header1_start = first_node->header2_start = (int)ftell(header_file);
}
// it is ok to write non-recursive code here, because comments have no children or code2 blocks
- first_type->write_code1(*this);
+ first_node->write_code1(*this);
if (write_codeview) {
- first_type->code1_end = first_type->code2_end = (int)ftell(code_file);
- first_type->header1_end = first_type->header2_end = (int)ftell(header_file);
+ first_node->code1_end = first_node->code2_end = (int)ftell(code_file);
+ first_node->header1_end = first_node->header2_end = (int)ftell(header_file);
}
- first_type = first_type->next;
+ first_node = first_node->next;
}
const char *hdr = "\
@@ -828,27 +633,27 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
fprintf(header_file, "#define %s\n", define_name);
}
- if (g_project.avoid_early_includes==0) {
+ if (proj_.avoid_early_includes==0) {
write_h_once("#include <FL/Fl.H>");
}
- if (t && g_project.include_H_from_C) {
+ if (t && proj_.include_H_from_C) {
if (to_codeview) {
write_c("#include \"CodeView.h\"\n");
- } else if (g_project.header_file_name[0] == '.' && strchr(g_project.header_file_name.c_str(), '/') == NULL) {
+ } 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", g_project.header_file_name.c_str());
+ write_c("#include \"%s\"\n", proj_.header_file_name.c_str());
}
}
std::string loc_include, loc_conditional;
- if (g_project.i18n_type==FD_I18N_GNU) {
- loc_include = g_project.i18n_gnu_include;
- loc_conditional = g_project.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 = g_project.i18n_pos_include;
- loc_conditional = g_project.i18n_pos_conditional;
+ loc_include = proj_.i18n_pos_include;
+ loc_conditional = proj_.i18n_pos_conditional;
}
- if (g_project.i18n_type && !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());
@@ -858,26 +663,26 @@ 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 (g_project.i18n_type == FD_I18N_POSIX) {
- if (!g_project.i18n_pos_file.empty()) {
- write_c("extern nl_catd %s;\n", g_project.i18n_pos_file.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());
} else {
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", g_project.basename().c_str());
+ write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", proj_.basename().c_str());
}
}
if (conditional) {
write_c("#else\n");
- if (g_project.i18n_type == FD_I18N_GNU) {
- if (!g_project.i18n_gnu_function.empty()) {
- write_c("#%sifndef %s\n", indent(), g_project.i18n_gnu_function.c_str());
- write_c("#%sdefine %s(text) text\n", indent_plus(1), g_project.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 (g_project.i18n_type == FD_I18N_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());
@@ -885,13 +690,13 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
indentation--;
write_c("#endif\n");
}
- if (g_project.i18n_type == FD_I18N_GNU && g_project.i18n_gnu_static_function[0]) {
- write_c("#ifndef %s\n", g_project.i18n_gnu_static_function.c_str());
- write_c("#%sdefine %s(text) text\n", indent_plus(1), g_project.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");
}
}
- for (Fl_Type* p = first_type; p;) {
+ for (Node* p = first_node; p;) {
// write all static data for this & all children first
write_static(p);
// then write the nested code:
@@ -902,26 +707,26 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) {
fprintf(header_file, "#endif\n");
- Fl_Type* last_type = Fl_Type::last;
- if (last_type && (last_type != Fl_Type::first) && last_type->is_a(ID_Comment)) {
+ Node* last_node = Fluid.proj.tree.last;
+ if (last_node && (last_node != Fluid.proj.tree.first) && last_node->is_a(Type::Comment)) {
if (write_codeview) {
- last_type->code1_start = last_type->code2_start = (int)ftell(code_file);
- last_type->header1_start = last_type->header2_start = (int)ftell(header_file);
+ last_node->code1_start = last_node->code2_start = (int)ftell(code_file);
+ last_node->header1_start = last_node->header2_start = (int)ftell(header_file);
}
- last_type->write_code1(*this);
+ last_node->write_code1(*this);
if (write_codeview) {
- last_type->code1_end = last_type->code2_end = (int)ftell(code_file);
- last_type->header1_end = last_type->header2_end = (int)ftell(header_file);
+ last_node->code1_end = last_node->code2_end = (int)ftell(code_file);
+ last_node->header1_end = last_node->header2_end = (int)ftell(header_file);
}
}
int x = 0, y = 0;
if (code_file != stdout)
x = fclose(code_file);
- code_file = 0;
+ code_file = nullptr;
if (header_file != stdout)
y = fclose(header_file);
- header_file = 0;
+ header_file = nullptr;
return x >= 0 && y >= 0;
}
@@ -947,23 +752,10 @@ void Code_Writer::write_public(int state) {
/**
Create and initialize a new C++ source code writer.
*/
-Code_Writer::Code_Writer()
-: code_file(NULL),
- header_file(NULL),
- id_root(NULL),
- text_in_header(NULL),
- text_in_code(NULL),
- ptr_in_code(NULL),
- block_crc_(0),
- block_line_start_(true),
- block_buffer_(NULL),
- block_buffer_size_(0),
- indentation(0),
- write_codeview(false),
- varused_test(0),
- varused(0)
+Code_Writer::Code_Writer(Project &proj)
+: proj_ { proj }
{
- block_crc_ = crc32(0, NULL, 0);
+ block_crc_ = crc32(0, nullptr, 0);
}
/**
@@ -971,10 +763,6 @@ Code_Writer::Code_Writer()
*/
Code_Writer::~Code_Writer()
{
- delete id_root;
- delete ptr_in_code;
- delete text_in_code;
- delete text_in_header;
if (block_buffer_) ::free(block_buffer_);
}
@@ -987,9 +775,9 @@ Code_Writer::~Code_Writer()
\param[in] uid the unique id of the current type
*/
void Code_Writer::tag(int type, unsigned short uid) {
- if (g_project.write_mergeback_data)
+ if (proj_.write_mergeback_data)
fprintf(code_file, "//~fl~%d~%04x~%08x~~\n", type, (int)uid, (unsigned int)block_crc_);
- block_crc_ = crc32(0, NULL, 0);
+ block_crc_ = crc32(0, nullptr, 0);
}
/**
@@ -1054,7 +842,7 @@ int Code_Writer::crc_printf(const char *format, ...) {
\return see fprintf(FILE *, *const char*, ...)
*/
int Code_Writer::crc_vprintf(const char *format, va_list args) {
- if (g_project.write_mergeback_data) {
+ if (proj_.write_mergeback_data) {
int n = vsnprintf(block_buffer_, block_buffer_size_, format, args);
if (n > block_buffer_size_) {
block_buffer_size_ = n + 128;
@@ -1075,7 +863,7 @@ int Code_Writer::crc_vprintf(const char *format, va_list args) {
\return see fputs(const char*, FILE*)
*/
int Code_Writer::crc_puts(const char *text) {
- if (g_project.write_mergeback_data) {
+ if (proj_.write_mergeback_data) {
crc_add(text);
}
return fputs(text, code_file);
@@ -1088,12 +876,10 @@ int Code_Writer::crc_puts(const char *text) {
\return see fputc(int, FILE*)
*/
int Code_Writer::crc_putc(int c) {
- if (g_project.write_mergeback_data) {
+ if (proj_.write_mergeback_data) {
uchar uc = (uchar)c;
crc_add(&uc, 1);
}
return fputc(c, code_file);
}
-/// \}
-