diff options
Diffstat (limited to 'fluid/io/Code_Writer.cxx')
| -rw-r--r-- | fluid/io/Code_Writer.cxx | 79 |
1 files changed, 35 insertions, 44 deletions
diff --git a/fluid/io/Code_Writer.cxx b/fluid/io/Code_Writer.cxx index b77cad147..cbd6443e2 100644 --- a/fluid/io/Code_Writer.cxx +++ b/fluid/io/Code_Writer.cxx @@ -14,30 +14,21 @@ // https://www.fltk.org/bugs.php // -#include "io/code.h" +#include "io/Code_Writer.h" -#include "app/fluid.h" -#include "app/undo.h" -#include "io/file.h" -#include "nodes/Fl_Group_Type.h" +#include "app/project.h" #include "nodes/Fl_Window_Type.h" #include "nodes/Fl_Function_Type.h" -#include "tools/fluid_filename.h" -#include <FL/Fl.H> -#include <FL/fl_string_functions.h> -#include <FL/fl_ask.H> #include "../src/flstring.h" -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> - #include <zlib.h> /// \defgroup cfile C Code File Operations /// \{ +using namespace fld; +using namespace fld::io; /** Return true if c can be in a C identifier. @@ -201,9 +192,9 @@ Fd_Identifier_Tree::~Fd_Identifier_Tree() { \param[in] type is the first word of the ID \param[in] name if name is set, it is appended to the ID \param[in] label else if label is set, it is appended, skipping non-keyword characters - \return buffer to a unique identifier, managed by Fd_Code_Writer, so caller must NOT free() it + \return buffer to a unique identifier, managed by Code_Writer, so caller must NOT free() it */ -const char* Fd_Code_Writer::unique_id(void* o, const char* type, const char* name, const char* label) { +const char* Code_Writer::unique_id(void* o, const char* type, const char* name, const char* label) { char buffer[128]; char* q = buffer; char* q_end = q + 128 - 8 - 1; // room for hex number and NUL @@ -253,7 +244,7 @@ const char* Fd_Code_Writer::unique_id(void* o, const char* type, const char* nam \param[in] set generate this indent depth \return pointer to a static string */ -const char *Fd_Code_Writer::indent(int set) { +const char *Code_Writer::indent(int set) { static const char* spaces = " "; int i = set * 2; if (i>32) i = 32; @@ -265,7 +256,7 @@ const char *Fd_Code_Writer::indent(int set) { Return a C string that indents code to the current source file depth. \return pointer to a static string */ -const char *Fd_Code_Writer::indent() { +const char *Code_Writer::indent() { return indent(indentation); } @@ -275,7 +266,7 @@ const char *Fd_Code_Writer::indent() { change the `indentation` variable; offset can be negative \return pointer to a static string */ -const char *Fd_Code_Writer::indent_plus(int offset) { +const char *Code_Writer::indent_plus(int offset) { return indent(indentation+offset); } @@ -325,7 +316,7 @@ Fd_Pointer_Tree::~Fd_Pointer_Tree() { \param[in] format printf-style formatting text, followed by a vararg list \return 1 if the text was written to the file, 0 if it was previously written. */ -int Fd_Code_Writer::write_h_once(const char *format, ...) { +int Code_Writer::write_h_once(const char *format, ...) { va_list args; char buf[1024]; va_start(args, format); @@ -349,7 +340,7 @@ int Fd_Code_Writer::write_h_once(const char *format, ...) { \param[in] format printf-style formatting text, followed by a vararg list \return 1 if the text was written to the file, 0 if it was previously written. */ -int Fd_Code_Writer::write_c_once(const char *format, ...) { +int Code_Writer::write_c_once(const char *format, ...) { va_list args; char buf[1024]; va_start(args, format); @@ -380,7 +371,7 @@ int Fd_Code_Writer::write_c_once(const char *format, ...) { \param[in] pp ay pointer \return true if found in the tree, false if added to the tree */ -bool Fd_Code_Writer::c_contains(void *pp) { +bool Code_Writer::c_contains(void *pp) { Fd_Pointer_Tree **p = &ptr_in_code; while (*p) { if ((*p)->ptr == pp) return true; @@ -408,7 +399,7 @@ bool Fd_Code_Writer::c_contains(void *pp) { \see f.write_cstring(const char*) */ -void Fd_Code_Writer::write_cstring(const char *s, int length) { +void Code_Writer::write_cstring(const char *s, int length) { const char *next_line = "\"\n\""; if (varused_test) { varused = 1; @@ -489,7 +480,7 @@ void Fd_Code_Writer::write_cstring(const char *s, int length) { \param[in] s write this string \see f.write_cstring(const char*, int) */ -void Fd_Code_Writer::write_cstring(const char *s) { +void Code_Writer::write_cstring(const char *s) { write_cstring(s, (int)strlen(s)); } @@ -501,7 +492,7 @@ void Fd_Code_Writer::write_cstring(const char *s) { \param[in] s a block of binary data, interpreted as unsigned bytes \param[in] length size of the block in bytes */ -void Fd_Code_Writer::write_cdata(const char *s, int length) { +void Code_Writer::write_cdata(const char *s, int length) { if (varused_test) { varused = 1; return; @@ -539,7 +530,7 @@ void Fd_Code_Writer::write_cdata(const char *s, int length) { \param[in] format printf-style formatting text \param[in] args list of arguments */ -void Fd_Code_Writer::vwrite_c(const char* format, va_list args) { +void Code_Writer::vwrite_c(const char* format, va_list args) { if (varused_test) { varused = 1; return; @@ -551,7 +542,7 @@ void Fd_Code_Writer::vwrite_c(const char* format, va_list args) { Print a formatted line to the source file. \param[in] format printf-style formatting text, followed by a vararg list */ -void Fd_Code_Writer::write_c(const char* format,...) { +void Code_Writer::write_c(const char* format,...) { va_list args; va_start(args, format); vwrite_c(format, args); @@ -566,7 +557,7 @@ void Fd_Code_Writer::write_c(const char* format,...) { \param[in] c line of code \param[in] com optional commentary */ -void Fd_Code_Writer::write_cc(const char *indent, int n, const char *c, const char *com) { +void Code_Writer::write_cc(const char *indent, int n, const char *c, const char *com) { write_c("%s%.*s", indent, n, c); char cc = c[n-1]; if (cc!='}' && cc!=';') @@ -580,7 +571,7 @@ void Fd_Code_Writer::write_cc(const char *indent, int n, const char *c, const ch Print a formatted line to the header file. \param[in] format printf-style formatting text, followed by a vararg list */ -void Fd_Code_Writer::write_h(const char* format,...) { +void Code_Writer::write_h(const char* format,...) { if (varused_test) return; va_list args; va_start(args, format); @@ -596,7 +587,7 @@ void Fd_Code_Writer::write_h(const char* format,...) { \param[in] c line of code \param[in] com optional commentary */ -void Fd_Code_Writer::write_hc(const char *indent, int n, const char* c, const char *com) { +void Code_Writer::write_hc(const char *indent, int n, const char* c, const char *com) { write_h("%s%.*s", indent, n, c); char cc = c[n-1]; if (cc!='}' && cc!=';') @@ -613,7 +604,7 @@ void Fd_Code_Writer::write_hc(const char *indent, int n, const char* c, const ch \param[in] inTrailWith append this character if the last line did not end with a newline, usually 0 or newline. */ -void Fd_Code_Writer::write_c_indented(const char *textlines, int inIndent, char inTrailWith) { +void Code_Writer::write_c_indented(const char *textlines, int inIndent, char inTrailWith) { if (textlines) { indentation += inIndent; for (;;) { @@ -686,7 +677,7 @@ 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* Fd_Code_Writer::write_static(Fl_Type* p) { +Fl_Type* Code_Writer::write_static(Fl_Type* 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); @@ -708,7 +699,7 @@ Fl_Type* Fd_Code_Writer::write_static(Fl_Type* p) { \param[in] p write this type and all its children \return pointer to the next sibling */ -Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) { +Fl_Type* Code_Writer::write_code(Fl_Type* 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))) { @@ -777,7 +768,7 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) { \param[in] t filename of the header file \return 0 if the operation failed, 1 if it was successful */ -int Fd_Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { +int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_codeview = to_codeview; delete id_root; id_root = 0; indentation = 0; @@ -939,7 +930,7 @@ int Fd_Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { This avoids repeating these words if the mode is already set. \param[in] state 0 for private, 1 for public, 2 for protected */ -void Fd_Code_Writer::write_public(int state) { +void Code_Writer::write_public(int state) { if (!current_class && !current_widget_class) return; if (current_class && current_class->write_public_state == state) return; if (current_widget_class && current_widget_class->write_public_state == state) return; @@ -955,7 +946,7 @@ void Fd_Code_Writer::write_public(int state) { /** Create and initialize a new C++ source code writer. */ -Fd_Code_Writer::Fd_Code_Writer() +Code_Writer::Code_Writer() : code_file(NULL), header_file(NULL), id_root(NULL), @@ -977,7 +968,7 @@ Fd_Code_Writer::Fd_Code_Writer() /** Release all resources. */ -Fd_Code_Writer::~Fd_Code_Writer() +Code_Writer::~Code_Writer() { delete id_root; delete ptr_in_code; @@ -994,7 +985,7 @@ Fd_Code_Writer::~Fd_Code_Writer() \param[in] type FD_TAG_GENERIC, FD_TAG_CODE, FD_TAG_MENU_CALLBACK, or FD_TAG_WIDGET_CALLBACK \param[in] uid the unique id of the current type */ -void Fd_Code_Writer::tag(int type, unsigned short uid) { +void Code_Writer::tag(int type, unsigned short uid) { if (g_project.write_mergeback_data) fprintf(code_file, "//~fl~%d~%04x~%08x~~\n", type, (int)uid, (unsigned int)block_crc_); block_crc_ = crc32(0, NULL, 0); @@ -1011,7 +1002,7 @@ void Fd_Code_Writer::tag(int type, unsigned short uid) { if we are the start of a line, used to find leading whitespace \return the new CRC */ -unsigned long Fd_Code_Writer::block_crc(const void *data, int n, unsigned long in_crc, bool *inout_line_start) { +unsigned long Code_Writer::block_crc(const void *data, int n, unsigned long in_crc, bool *inout_line_start) { if (!data) return 0; if (n==-1) n = (int)strlen((const char*)data); bool line_start = true; @@ -1038,7 +1029,7 @@ unsigned long Fd_Code_Writer::block_crc(const void *data, int n, unsigned long i \param[in] data a pointer to the data block \param[in] n the size of the data in bytes, or -1 to use strlen() */ -void Fd_Code_Writer::crc_add(const void *data, int n) { +void Code_Writer::crc_add(const void *data, int n) { block_crc_ = block_crc(data, n, block_crc_, &block_line_start_); } @@ -1047,7 +1038,7 @@ void Fd_Code_Writer::crc_add(const void *data, int n) { \param[in] format printf style formatting string \return see fprintf(FILE *, *const char*, ...) */ -int Fd_Code_Writer::crc_printf(const char *format, ...) { +int Code_Writer::crc_printf(const char *format, ...) { va_list args; va_start(args, format); int ret = crc_vprintf(format, args); @@ -1061,7 +1052,7 @@ int Fd_Code_Writer::crc_printf(const char *format, ...) { \param[in] args list of arguments \return see fprintf(FILE *, *const char*, ...) */ -int Fd_Code_Writer::crc_vprintf(const char *format, va_list args) { +int Code_Writer::crc_vprintf(const char *format, va_list args) { if (g_project.write_mergeback_data) { int n = vsnprintf(block_buffer_, block_buffer_size_, format, args); if (n > block_buffer_size_) { @@ -1082,7 +1073,7 @@ int Fd_Code_Writer::crc_vprintf(const char *format, va_list args) { \param[in] text any text, no requirements to end in a newline or such \return see fputs(const char*, FILE*) */ -int Fd_Code_Writer::crc_puts(const char *text) { +int Code_Writer::crc_puts(const char *text) { if (g_project.write_mergeback_data) { crc_add(text); } @@ -1091,11 +1082,11 @@ int Fd_Code_Writer::crc_puts(const char *text) { /** Write a single ASCII character to the code file. If MergeBack is enabled, the CRC calculation is continued. - \note to write UTF-8 characters, use Fd_Code_Writer::crc_puts(const char *text) + \note to write UTF-8 characters, use Code_Writer::crc_puts(const char *text) \param[in] c any character between 0 and 127 inclusive \return see fputc(int, FILE*) */ -int Fd_Code_Writer::crc_putc(int c) { +int Code_Writer::crc_putc(int c) { if (g_project.write_mergeback_data) { uchar uc = (uchar)c; crc_add(&uc, 1); |
