diff options
Diffstat (limited to 'fluid/io')
| -rw-r--r-- | fluid/io/Code_Writer.cxx | 66 | ||||
| -rw-r--r-- | fluid/io/Project_Reader.cxx | 39 | ||||
| -rw-r--r-- | fluid/io/Project_Writer.cxx | 26 | ||||
| -rw-r--r-- | fluid/io/String_Writer.cxx | 6 |
4 files changed, 65 insertions, 72 deletions
diff --git a/fluid/io/Code_Writer.cxx b/fluid/io/Code_Writer.cxx index f451d187e..ffa63514a 100644 --- a/fluid/io/Code_Writer.cxx +++ b/fluid/io/Code_Writer.cxx @@ -31,9 +31,6 @@ #include <stdlib.h> #include <string.h> -using namespace fld; -using namespace fld::io; - // ---- Fd_Id_Map implementation ---- void Fd_Id_Map::clear() { @@ -144,7 +141,7 @@ int is_id(char c) { \param[in] label else if label is set, it is appended, skipping non-keyword characters \return buffer to a unique identifier, managed by Code_Writer, so caller must NOT free() it */ -const char* Code_Writer::unique_id(void* o, const char* type, const char* name, const char* label) { +const char* fld::io::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 @@ -189,7 +186,7 @@ const char* Code_Writer::unique_id(void* o, const char* type, const char* name, \param[in] set generate this indent depth \return pointer to a static string */ -const char *Code_Writer::indent(int set) { +const char *fld::io::Code_Writer::indent(int set) { static const char* spaces = " "; int i = set * 2; if (i>64) i = 64; @@ -201,7 +198,7 @@ const char *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 *Code_Writer::indent() { +const char *fld::io::Code_Writer::indent() { return indent(indentation); } @@ -211,7 +208,7 @@ const char *Code_Writer::indent() { change the `indentation` variable; offset can be negative \return pointer to a static string */ -const char *Code_Writer::indent_plus(int offset) { +const char *fld::io::Code_Writer::indent_plus(int offset) { return indent(indentation+offset); } @@ -222,7 +219,7 @@ const char *Code_Writer::indent_plus(int offset) { \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 Code_Writer::write_h_once(const char *format, ...) { +int fld::io::Code_Writer::write_h_once(const char *format, ...) { va_list args; char buf[1024]; va_start(args, format); @@ -242,7 +239,7 @@ int 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 Code_Writer::write_c_once(const char *format, ...) { +int fld::io::Code_Writer::write_c_once(const char *format, ...) { va_list args; char buf[1024]; va_start(args, format); @@ -267,7 +264,7 @@ int 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 Code_Writer::c_contains(void *pp) { +bool fld::io::Code_Writer::c_contains(void *pp) { if (ptr_in_code.contains(pp)) { return true; } @@ -292,7 +289,7 @@ bool Code_Writer::c_contains(void *pp) { \see f.write_cstring(const char*) */ -void Code_Writer::write_cstring(const char *s, int length) { +void fld::io::Code_Writer::write_cstring(const char *s, int length) { const char *next_line = "\"\n\""; if (varused_test) { varused = 1; @@ -373,7 +370,7 @@ void Code_Writer::write_cstring(const char *s, int length) { \param[in] s write this string \see f.write_cstring(const char*, int) */ -void Code_Writer::write_cstring(const char *s) { +void fld::io::Code_Writer::write_cstring(const char *s) { write_cstring(s, (int)strlen(s)); } @@ -385,7 +382,7 @@ void 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 Code_Writer::write_cdata(const char *s, int length) { +void fld::io::Code_Writer::write_cdata(const char *s, int length) { if (varused_test) { varused = 1; return; @@ -423,7 +420,7 @@ void Code_Writer::write_cdata(const char *s, int length) { \param[in] format printf-style formatting text \param[in] args list of arguments */ -void Code_Writer::vwrite_c(const char* format, va_list args) { +void fld::io::Code_Writer::vwrite_c(const char* format, va_list args) { if (varused_test) { varused = 1; return; @@ -435,7 +432,7 @@ void 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 Code_Writer::write_c(const char* format,...) { +void fld::io::Code_Writer::write_c(const char* format,...) { va_list args; va_start(args, format); vwrite_c(format, args); @@ -450,7 +447,7 @@ void Code_Writer::write_c(const char* format,...) { \param[in] c line of code \param[in] com optional commentary */ -void Code_Writer::write_cc(const char *indent, int n, const char *c, const char *com) { +void fld::io::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!=';') @@ -464,7 +461,7 @@ void Code_Writer::write_cc(const char *indent, int n, const char *c, const char Print a formatted line to the header file. \param[in] format printf-style formatting text, followed by a vararg list */ -void Code_Writer::write_h(const char* format,...) { +void fld::io::Code_Writer::write_h(const char* format,...) { if (varused_test) return; va_list args; va_start(args, format); @@ -480,7 +477,7 @@ void Code_Writer::write_h(const char* format,...) { \param[in] c line of code \param[in] com optional commentary */ -void Code_Writer::write_hc(const char *indent, int n, const char* c, const char *com) { +void fld::io::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!=';') @@ -497,7 +494,7 @@ void Code_Writer::write_hc(const char *indent, int n, const char* c, const char \param[in] inTrailWith append this character if the last line did not end with a newline, usually 0 or newline. */ -void Code_Writer::write_c_indented(const char *textlines, int inIndent, char inTrailWith) { +void fld::io::Code_Writer::write_c_indented(const char *textlines, int inIndent, char inTrailWith) { if (textlines) { indentation += inIndent; for (;;) { @@ -570,7 +567,7 @@ bool is_comment_before_class_member(Node *q) { \param[in] p write this type and all its children \return pointer to the next sibling */ -Node* Code_Writer::write_static(Node* p) { +Node* fld::io::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); @@ -592,7 +589,7 @@ Node* Code_Writer::write_static(Node* p) { \param[in] p write this node and all its children \return pointer to the next sibling */ -Node* Code_Writer::write_code(Node* p) { +Node* fld::io::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==Fluid.proj.tree.last && p->is_a(FLD_NODE_TYPE_Comment))) { @@ -661,7 +658,7 @@ Node* Code_Writer::write_code(Node* p) { \param[in] t filename of the header file \return 0 if the operation failed, 1 if it was successful */ -int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { +int fld::io::Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_codeview = to_codeview; unique_id_list.clear(); indentation = 0; @@ -835,7 +832,8 @@ int Code_Writer::write_code(const char *s, const char *t, bool to_codeview) { write_c("#endif\n"); } } - for (Node* p = first_node; p;) { + Node *p; + for (p = first_node; p;) { // write all static data for this & all children first write_static(p); // then write the nested code: @@ -875,7 +873,7 @@ int 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 Code_Writer::write_public(int state) { +void fld::io::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; @@ -891,7 +889,7 @@ void Code_Writer::write_public(int state) { /** Create and initialize a new C++ source code writer. */ -Code_Writer::Code_Writer(Project &proj) +fld::io::Code_Writer::Code_Writer(Project &proj) : proj_ { proj } { block_crc_ = crc32(0, 0, 0); @@ -900,7 +898,7 @@ Code_Writer::Code_Writer(Project &proj) /** Release all resources. */ -Code_Writer::~Code_Writer() +fld::io::Code_Writer::~Code_Writer() { if (block_buffer_) ::free(block_buffer_); } @@ -913,7 +911,7 @@ Code_Writer::~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 Code_Writer::tag(Mergeback::Tag prev_type, Mergeback::Tag next_type, unsigned short uid) { +void fld::io::Code_Writer::tag(Mergeback::Tag prev_type, Mergeback::Tag next_type, unsigned short uid) { if (proj_.write_mergeback_data) { ::Mergeback::print_tag(code_file, prev_type, next_type, uid, (uint32_t)block_crc_); } @@ -931,7 +929,7 @@ void Code_Writer::tag(Mergeback::Tag prev_type, Mergeback::Tag next_type, unsign if we are the start of a line, used to find leading whitespace \return the new CRC */ -unsigned long Code_Writer::block_crc(const void *data, int n, unsigned long in_crc, bool *inout_line_start) { +unsigned long fld::io::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; @@ -958,7 +956,7 @@ unsigned long Code_Writer::block_crc(const void *data, int n, unsigned long in_c \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 Code_Writer::crc_add(const void *data, int n) { +void fld::io::Code_Writer::crc_add(const void *data, int n) { block_crc_ = block_crc(data, n, block_crc_, &block_line_start_); } @@ -967,7 +965,7 @@ void Code_Writer::crc_add(const void *data, int n) { \param[in] format printf style formatting string \return see fprintf(FILE *, *const char*, ...) */ -int Code_Writer::crc_printf(const char *format, ...) { +int fld::io::Code_Writer::crc_printf(const char *format, ...) { va_list args; va_start(args, format); int ret = crc_vprintf(format, args); @@ -981,7 +979,7 @@ int Code_Writer::crc_printf(const char *format, ...) { \param[in] args list of arguments \return see fprintf(FILE *, *const char*, ...) */ -int Code_Writer::crc_vprintf(const char *format, va_list args) { +int fld::io::Code_Writer::crc_vprintf(const char *format, va_list args) { if (proj_.write_mergeback_data) { int n = vsnprintf(block_buffer_, block_buffer_size_, format, args); if (n > block_buffer_size_) { @@ -1002,7 +1000,7 @@ int 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 Code_Writer::crc_puts(const char *text) { +int fld::io::Code_Writer::crc_puts(const char *text) { if (proj_.write_mergeback_data) { crc_add(text); } @@ -1011,11 +1009,11 @@ int 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 Code_Writer::crc_puts(const char *text) + \note to write UTF-8 characters, use fld::io::Code_Writer::crc_puts(const char *text) \param[in] c any character between 0 and 127 inclusive \return see fputc(int, FILE*) */ -int Code_Writer::crc_putc(int c) { +int fld::io::Code_Writer::crc_putc(int c) { if (proj_.write_mergeback_data) { uchar uc = (uchar)c; crc_add(&uc, 1); diff --git a/fluid/io/Project_Reader.cxx b/fluid/io/Project_Reader.cxx index 3bf9608a3..54baa9a85 100644 --- a/fluid/io/Project_Reader.cxx +++ b/fluid/io/Project_Reader.cxx @@ -41,9 +41,6 @@ /// \defgroup flfile .fl Project File Operations /// \{ -using namespace fld; -using namespace fld::io; - // This file contains code to read and write .fl files. /// If set, we read an old fdesign file and widget y coordinates need to be flipped. @@ -85,7 +82,7 @@ static int hexdigit(int x) { Oh how I wish sometimes we would upgrade to modern C++. \param[in] length minimum length in bytes */ -void Project_Reader::expand_buffer(int length) { +void fld::io::Project_Reader::expand_buffer(int length) { if (length >= buflen) { if (!buflen) { buflen = length+1; @@ -99,13 +96,13 @@ void Project_Reader::expand_buffer(int length) { } /** \brief Construct local project reader. */ -Project_Reader::Project_Reader(Project &proj) +fld::io::Project_Reader::Project_Reader(Project &proj) : proj_(proj) { } /** \brief Release project reader resources. */ -Project_Reader::~Project_Reader() +fld::io::Project_Reader::~Project_Reader() { // fname is not copied, so do not free it if (buffer) @@ -117,7 +114,7 @@ Project_Reader::~Project_Reader() \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) { +int fld::io::Project_Reader::open_read(const char *s) { lineno = 1; if (!s) { fin = stdin; @@ -136,7 +133,7 @@ int Project_Reader::open_read(const char *s) { Close the .fl file. \return 0 if the operation failed, 1 if it succeeded */ -int Project_Reader::close_read() { +int fld::io::Project_Reader::close_read() { if (fin != stdin) { int x = fclose(fin); fin = 0; @@ -149,7 +146,7 @@ int Project_Reader::close_read() { Return the name part of the current filename and path. \return a pointer into a string that is not owned by this class */ -const char *Project_Reader::filename_name() { +const char *fld::io::Project_Reader::filename_name() { return fl_filename_name(fname); } @@ -159,7 +156,7 @@ const char *Project_Reader::filename_name() { values, and \\o### octal values. \return a character in the ASCII range */ -int Project_Reader::read_quoted() { // read whatever character is after a \ . +int fld::io::Project_Reader::read_quoted() { // read whatever character is after a \ . int c,d,x; switch(c = nextchar()) { case '\n': lineno++; return -1; @@ -204,7 +201,7 @@ int Project_Reader::read_quoted() { // read whatever character is after a \ a previous call, and there is no need to waste time searching for them. \return the last node that was created */ -Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char skip_options) { +Node *fld::io::Project_Reader::read_children(Node *p, int merge, Strategy strategy, char skip_options) { Fluid.proj.tree.current = p; Node *last_child_read = 0; Node *t = 0; @@ -388,7 +385,7 @@ Node *Project_Reader::read_children(Node *p, int merge, Strategy strategy, char \param[in] strategy add new nodes after current or as last child \return 0 if the operation failed, 1 if it succeeded */ -int Project_Reader::read_project(const char *filename, int merge, Strategy strategy) { +int fld::io::Project_Reader::read_project(const char *filename, int merge, Strategy strategy) { Node *o; proj_.undo.suspend(); read_version = 0.0; @@ -438,7 +435,7 @@ int Project_Reader::read_project(const char *filename, int merge, Strategy strat operations. \param[in] format printf style format string, followed by an argument list */ -void Project_Reader::read_error(const char *format, ...) { +void fld::io::Project_Reader::read_error(const char *format, ...) { va_list args; va_start(args, format); if (!fin) { // FIXME: this line suppresses any error messages in interactive mode @@ -471,7 +468,7 @@ void Project_Reader::read_error(const char *format, ...) { overwrite this buffer. If wantbrace is not set, but we read a leading '{', the returned string will be stripped of its leading and trailing braces. */ -const char *Project_Reader::read_word(int wantbrace) { +const char *fld::io::Project_Reader::read_word(int wantbrace) { int x; // skip all the whitespace before it: @@ -541,7 +538,7 @@ const char *Project_Reader::read_word(int wantbrace) { /** Read a word and interpret it as an integer value. \return integer value, or 0 if the word is not an integer */ -int Project_Reader::read_int() { +int fld::io::Project_Reader::read_int() { const char *word = read_word(); if (word) { return atoi(word); @@ -557,7 +554,7 @@ int Project_Reader::read_int() { \param[out] value string \return 0 if end of file, else 1 */ -int Project_Reader::read_fdesign_line(const char*& name, const char*& value) { +int fld::io::Project_Reader::read_fdesign_line(const char*& name, const char*& value) { int length = 0; int x; // find a colon: @@ -646,6 +643,7 @@ static const char *class_matcher[] = { static void forms_end(Fl_Group *g, int flip) { // set the dimensions of a group to surround its contents const int nc = g->children(); + int i; if (nc && !g->w()) { Fl_Widget*const* a = g->array(); Fl_Widget* o = *a++; @@ -653,7 +651,7 @@ static void forms_end(Fl_Group *g, int flip) { int ry = o->y(); int rw = rx+o->w(); int rh = ry+o->h(); - for (int i = nc - 1; i--;) { + for (i = nc - 1; i--;) { o = *a++; if (o->x() < rx) rx = o->x(); if (o->y() < ry) ry = o->y(); @@ -667,7 +665,7 @@ static void forms_end(Fl_Group *g, int flip) { Fl_Widget* o = (g->as_window()) ? g : g->window(); int Y = o->h(); Fl_Widget*const* a = g->array(); - for (int i = nc; i--;) { + for (i = nc; i--;) { Fl_Widget* ow = *a++; int newy = Y - ow->y() - ow->h(); ow->Fl_Widget::resize(ow->x(), newy, ow->w(), ow->h()); @@ -683,7 +681,7 @@ static void forms_end(Fl_Group *g, int flip) { FLTK widgets. \see http://xforms-toolkit.org */ -void Project_Reader::read_fdesign() { +void fld::io::Project_Reader::read_fdesign() { int fdesign_magic = atoi(read_word()); fdesign_flip = (fdesign_magic < 13000); Widget_Node *window = 0; @@ -721,7 +719,8 @@ void Project_Reader::read_fdesign() { group = widget = 0; Fluid.proj.tree.current = window; } else { - for (int i = 0; class_matcher[i]; i += 2) + int i; + for (i = 0; class_matcher[i]; i += 2) if (!strcmp(value,class_matcher[i])) { value = class_matcher[i+1]; break;} widget = (Widget_Node*)add_new_widget_from_file(value, Strategy::FROM_FILE_AS_LAST_CHILD); diff --git a/fluid/io/Project_Writer.cxx b/fluid/io/Project_Writer.cxx index 9af369c93..e2f670f8f 100644 --- a/fluid/io/Project_Writer.cxx +++ b/fluid/io/Project_Writer.cxx @@ -32,9 +32,6 @@ /// \defgroup flfile .fl Project File Operations /// \{ -using namespace fld; -using namespace fld::io; - /** \brief Write an .fl design description file. The .fl file format is documented in `fluid/README_fl.txt`. @@ -52,13 +49,13 @@ int fld::io::write_file(Project &proj, const char *filename, int selected_only, // ---- Project_Writer ---------------------------------------------- MARK: - /** \brief Construct local project writer. */ -Project_Writer::Project_Writer(Project &proj) +fld::io::Project_Writer::Project_Writer(Project &proj) : proj_(proj) { } /** \brief Release project writer resources. */ -Project_Writer::~Project_Writer() +fld::io::Project_Writer::~Project_Writer() { } @@ -68,7 +65,7 @@ Project_Writer::~Project_Writer() \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) { +int fld::io::Project_Writer::open_write(const char *s) { if (!s) { fout = stdout; } else { @@ -84,7 +81,7 @@ int Project_Writer::open_write(const char *s) { Don't close, if data was sent to stdout. \return 1 if succeeded, 0 if fclose failed */ -int Project_Writer::close_write() { +int fld::io::Project_Writer::close_write() { if (fout != stdout) { int x = fclose(fout); fout = stdout; @@ -100,7 +97,7 @@ int Project_Writer::close_write() { \param[in] sv if set, this file will be used by codeview \return 0 if the operation failed, 1 if it succeeded */ -int Project_Writer::write_project(const char *filename, int selected_only, bool sv) { +int fld::io::Project_Writer::write_project(const char *filename, int selected_only, bool sv) { write_codeview_ = sv; proj_.undo.suspend(); if (!open_write(filename)) { @@ -131,7 +128,8 @@ int Project_Writer::write_project(const char *filename, int selected_only, bool write_string("\nmergeback %d", proj_.write_mergeback_data); } - for (Node *p = proj_.tree.first; p;) { + Node *p; + for (p = proj_.tree.first; p;) { if (!selected_only || p->selected) { p->write(*this); write_string("\n"); @@ -150,7 +148,7 @@ int Project_Writer::write_project(const char *filename, int selected_only, bool Write a string to the .fl file, quoting characters if necessary. \param[in] w NUL terminated text */ -void Project_Writer::write_word(const char *w) { +void fld::io::Project_Writer::write_word(const char *w) { if (needspace) putc(' ', fout); needspace = 1; if (!w || !*w) {fprintf(fout,"{}"); return;} @@ -188,7 +186,7 @@ void Project_Writer::write_word(const char *w) { unless the format starts with a newline character \\n. \param[in] format printf style formatting string followed by a list of arguments */ -void Project_Writer::write_string(const char *format, ...) { +void fld::io::Project_Writer::write_string(const char *format, ...) { va_list args; va_start(args, format); if (needspace && *format != '\n') fputc(' ',fout); @@ -201,7 +199,7 @@ void Project_Writer::write_string(const char *format, ...) { Start a new line in the .fl file and indent it for a given nesting level. \param[in] n indent level */ -void Project_Writer::write_indent(int n) { +void fld::io::Project_Writer::write_indent(int n) { fputc('\n',fout); while (n--) {fputc(' ',fout); fputc(' ',fout);} needspace = 0; @@ -210,7 +208,7 @@ void Project_Writer::write_indent(int n) { /** Write a '{' to the .fl file at the given indenting level. */ -void Project_Writer::write_open() { +void fld::io::Project_Writer::write_open() { if (needspace) fputc(' ',fout); fputc('{',fout); needspace = 0; @@ -220,7 +218,7 @@ void Project_Writer::write_open() { Write a '}' to the .fl file at the given indenting level. \param[in] n indent level */ -void Project_Writer::write_close(int n) { +void fld::io::Project_Writer::write_close(int n) { if (needspace) write_indent(n); fputc('}',fout); needspace = 1; diff --git a/fluid/io/String_Writer.cxx b/fluid/io/String_Writer.cxx index 97245697b..891fc5a25 100644 --- a/fluid/io/String_Writer.cxx +++ b/fluid/io/String_Writer.cxx @@ -21,9 +21,6 @@ #include "nodes/Window_Node.h" #include "nodes/Function_Node.h" -using namespace fld; -using namespace fld::io; - /** Write a string to a file, replacing all non-ASCII characters with octal codes. \param[in] out output file @@ -33,7 +30,8 @@ using namespace fld::io; static 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) { + const unsigned char *s; + for (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 |
