Fluid: fix "trailing whitespace" errors (#100)

Fluid would write trailing whitespace at some points when generating
.cxx and .h files from .fl files.

This was an old issue but became obvious since we removed trailing
whitespace from source and header files recently.

This commit fixes all whitespace errors in files generated from .fl
files in the FLTK repository, i.e. in fluid/, src/, and test/ folders.

I can't guarantee that I found all possible whitespace errors, but
this commit:

Fixes #100
This commit is contained in:
Albrecht Schlosser 2020-07-11 18:45:14 +02:00
parent e5fbfcbec1
commit 8a3d3684ac
5 changed files with 34 additions and 8 deletions

View File

@ -500,10 +500,16 @@ void Fl_Code_Type::write_code1() {
while( (pch=strchr(c,'\n')) )
{
int line_len = 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");
}
void Fl_Code_Type::write_code2() {}
@ -738,23 +744,24 @@ void Fl_Decl_Type::write_code1() {
if (class_name(1)) {
write_public(public_);
write_comment_h(" ");
write_h(" %.*s; %s\n", (int)(e-c), c, csc);
write_hc(" ", int(e-c), c, csc);
} else {
if (public_) {
if (static_)
write_h("extern ");
else
write_comment_h();
write_h("%.*s; %s\n", (int)(e-c), c, csc);
write_hc("", int(e-c), c, csc);
if (static_) {
write_comment_c();
write_c("%.*s; %s\n", (int)(e-c), c, csc);
write_cc("", int(e-c), c, csc);
}
} else {
write_comment_c();
if (static_)
write_c("static ");
write_c("%.*s; %s\n", (int)(e-c), c, csc);
write_cc("", int(e-c), c, csc);
}
}
}

View File

@ -874,8 +874,10 @@ int write_declare(const char *, ...) __fl_attr((__format__ (__printf__, 1, 2)));
int is_id(char);
const char* unique_id(void* o, const char*, const char*, const char*);
void write_c(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
void write_cc(const char *, int, const char*, const char*);
void vwrite_c(const char* format, va_list args);
void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2)));
void write_hc(const char *, int, const char*, const char*);
void write_cstring(const char *);
void write_cstring(const char *,int length);
void write_cdata(const char *,int length);

View File

@ -283,6 +283,14 @@ void write_c(const char* format,...) {
va_end(args);
}
// write code (c) of size (n) to C file, with optional comment (com) w/o trailing space
void write_cc(const char *indent, int n, const char *c, const char *com) {
if (*com)
write_c("%s%.*s; %s\n", indent, n, c, com);
else
write_c("%s%.*s;\n", indent, n, c);
}
void write_h(const char* format,...) {
if (varused_test) return;
va_list args;
@ -291,6 +299,14 @@ void write_h(const char* format,...) {
va_end(args);
}
// write code (c) of size (n) to H file, with optional comment (com) w/o trailing space
void write_hc(const char *indent, int n, const char* c, const char *com) {
if (*com)
write_h("%s%.*s; %s\n", indent, n, c, com);
else
write_h("%s%.*s;\n", indent, n, c);
}
#include <FL/filename.H>
int write_number;
int write_sourceview;

View File

@ -413,7 +413,7 @@ ive to the origin at construction time");
} // Fl_Group* o
{ // This is a special button that grabs keystrokes directly
Shortcut_Button* o = new Shortcut_Button(95, 210, 310, 20, "Shortcut:");
o->tooltip("The shortcut key for the widget.\nUse 'Backspace' key to clear.");
o->tooltip("The shortcut key for the widget.\nUse \'Backspace\' key to clear.");
o->box(FL_DOWN_BOX);
o->color(FL_BACKGROUND2_COLOR);
o->selection_color(FL_BACKGROUND2_COLOR);

View File

@ -362,7 +362,8 @@ Use Ctrl-J for newlines.} xywh {95 40 190 20} labelfont 1 labelsize 11 when 1 te
label {Shortcut:}
callback shortcut_in_cb
comment {This is a special button that grabs keystrokes directly}
tooltip {The shortcut key for the widget.\nUse 'Backspace' key to clear.} xywh {95 210 310 20} box DOWN_BOX color 7 selection_color 7 labelfont 1 labelsize 11 align 4
tooltip {The shortcut key for the widget.
Use 'Backspace' key to clear.} xywh {95 210 310 20} box DOWN_BOX color 7 selection_color 7 labelfont 1 labelsize 11 align 4
code0 {\#include "Shortcut_Button.h"}
class Shortcut_Button
}