diff options
| author | Matthias Melcher <git@matthiasm.com> | 2021-12-15 19:29:12 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2021-12-15 19:38:09 +0100 |
| commit | 7161cad2c75c323fe8c9316ab7ac14e84411b37f (patch) | |
| tree | 747a1ec72f30e00d9b5999bb5a32f6bbcb16897d | |
| parent | f57b074378d69d19eb5a70e6335054bada06919a (diff) | |
#329 #318: Fixed Fluid indenting and trailing whitespace
| -rw-r--r-- | fluid/Fl_Function_Type.cxx | 19 | ||||
| -rw-r--r-- | fluid/Fl_Menu_Type.cxx | 2 | ||||
| -rw-r--r-- | fluid/Fl_Widget_Type.cxx | 2 | ||||
| -rw-r--r-- | fluid/code.cxx | 31 | ||||
| -rw-r--r-- | fluid/code.h | 2 |
5 files changed, 28 insertions, 28 deletions
diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index ac367c7b9..ab3672e23 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -634,24 +634,7 @@ void Fl_Code_Type::write_code1() { main_window->redraw(); // tell fluid to redraw; edits may affect tree's contents } - const char* c = name(); - if (!c) return; - - const char *pch; - const char *ind = indent(); - while( (pch=strchr(c,'\n')) ) - { - int line_len = int(pch - c); - if (line_len < 1) - write_c("\n"); - else - write_c("%s%.*s\n", ind, line_len, c); - c = pch+1; - } - if (*c) - write_c("%s%s\n", ind, c); - else - write_c("\n"); + write_c_indented(name(), 0, '\n'); } /** diff --git a/fluid/Fl_Menu_Type.cxx b/fluid/Fl_Menu_Type.cxx index 7bd55ce15..d05f7eadd 100644 --- a/fluid/Fl_Menu_Type.cxx +++ b/fluid/Fl_Menu_Type.cxx @@ -228,7 +228,7 @@ void Fl_Menu_Item_Type::write_static() { write_c(", %s", ut); if (use_v) write_c(" v"); write_c(") {\n"); - write_c_indented(callback()); + write_c_indented(callback(), 1, 0); if (*(d-1) != ';' && *(d-1) != '}') { const char *p = strrchr(callback(), '\n'); if (p) p ++; diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index faee2159e..6ad732fb8 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -2067,7 +2067,7 @@ void Fl_Widget_Type::write_static() { write_c(", %s", ut); if (use_v) write_c(" v"); write_c(") {\n"); - write_c_indented(callback()); + write_c_indented(callback(), 1, 0); if (*(d-1) != ';' && *(d-1) != '}') { const char *p = strrchr(callback(), '\n'); if (p) p ++; diff --git a/fluid/code.cxx b/fluid/code.cxx index 11d8d2d4e..ec61902f1 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -410,18 +410,35 @@ void write_hc(const char *indent, int n, const char* c, const char *com) { Write one or more lines of code, indenting each one of them. \param[in] textlines one or more lines of text, seperated by \\n */ -void write_c_indented(const char *textlines) { +void write_c_indented(const char *textlines, int inIndent, char inTrailwWith) { if (textlines) { - indentation++; + indentation += inIndent; for (;;) { + int line_len; const char *newline = strchr(textlines, '\n'); - if (!newline) break; - write_c("%s%.*s\n", indent(), (int)(newline-textlines), textlines); + if (newline) + line_len = (int)(newline-textlines); + else + line_len = strlen(textlines); + if (textlines[0]=='\n') { + // avoid trailing spaces + } else if (textlines[0]=='#') { + // don't indent preprocessor statments starting with '#' + write_c("%.*s", (int)(newline-textlines), textlines); + } else { + // indent all other text lines + write_c("%s%.*s", indent(), (int)(newline-textlines), textlines); + } + if (newline) { + write_c("\n"); + } else { + if (inTrailwWith) + write_c("%c", inTrailwWith); + break; + } textlines = newline+1; } - if (*textlines) - write_c("%s%s", indent(), textlines); - indentation--; + indentation -= inIndent; } } diff --git a/fluid/code.h b/fluid/code.h index 474b87bf0..5e9a70216 100644 --- a/fluid/code.h +++ b/fluid/code.h @@ -39,7 +39,7 @@ void write_c(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2))); void write_cc(const char *, int, const char*, const char*); void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2))); void write_hc(const char *, int, const char*, const char*); -void write_c_indented(const char *textlines); +void write_c_indented(const char *textlines, int inIndent, char inTrailwWith); int write_code(const char *cfile, const char *hfile); int write_strings(const char *sfile); void write_public(int state); // writes pubic:/private: as needed |
