diff options
| author | Bill Spitzak <spitzak@gmail.com> | 1999-07-31 08:00:09 +0000 |
|---|---|---|
| committer | Bill Spitzak <spitzak@gmail.com> | 1999-07-31 08:00:09 +0000 |
| commit | a7ae9b3c49be0f53d3c1e870850a7021e8945596 (patch) | |
| tree | 58abbc30f14b930b8c6827cadb9cc397dc67038e /fluid/code.cxx | |
| parent | bc5a58036a6919a6704739db55fd0838484fc9d0 (diff) | |
String output (for images in the C code) does not produce trigraphs
(the ??x sequences) by accident. It also should produce somewhat
shorter output by using only 1 or 2 digits in some \oct characters
and using string constant pasting ("") to shorten some sequences.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@634 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'fluid/code.cxx')
| -rw-r--r-- | fluid/code.cxx | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/fluid/code.cxx b/fluid/code.cxx index f96de3dc4..f21dc7459 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -1,5 +1,5 @@ // -// "$Id: code.cxx,v 1.9 1999/01/19 19:10:38 mike Exp $" +// "$Id: code.cxx,v 1.9.2.1 1999/07/31 08:00:09 bill Exp $" // // Code output routines for the Fast Light Tool Kit (FLTK). // @@ -158,7 +158,6 @@ void write_cstring(const char *w, int length) { int linelength = 1; putc('\"', code_file); for (; w < e;) { - if (linelength >= 75) {fputs("\\\n",code_file); linelength = 0;} int c = *w++; switch (c) { case '\b': c = 'b'; goto QUOTED; @@ -170,32 +169,45 @@ void write_cstring(const char *w, int length) { case '\'': case '\\': QUOTED: - putc('\\',code_file); - putc(c,code_file); + if (linelength >= 77) {fputs("\\\n",code_file); linelength = 0;} + putc('\\', code_file); + putc(c, code_file); linelength += 2; break; - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - if (*w < '0' || *w > '9') {c += '0'; goto QUOTED;} + case '?': // prevent trigraphs by writing ?? as ?\? + if (*(w-2) == '?') goto QUOTED; // else fall through: default: - if (c < ' ' || c >= 127) { - QUOTENEXT: - fprintf(code_file, "\\%03o",c&255); - linelength += 4; - c = *w; - if (w < e && (c>='0'&&c<='9' || c>='a'&&c<='f' || c>='A'&&c<='F')) { - w++; goto QUOTENEXT; - } - } else { - putc(c,code_file); + if (c >= ' ' && c < 127) { + // a legal ASCII character + if (linelength >= 78) {fputs("\\\n",code_file); linelength = 0;} + putc(c, code_file); linelength++; + break; + } + // otherwise we must print it as an octal constant: + c &= 255; + if (c < 8) { + if (linelength >= 76) {fputs("\\\n",code_file); linelength = 0;} + fprintf(code_file, "\\%o",c); + linelength += 2; + } else if (c < 64) { + if (linelength >= 75) {fputs("\\\n",code_file); linelength = 0;} + fprintf(code_file, "\\%o",c); + linelength += 3; + } else { + if (linelength >= 74) {fputs("\\\n",code_file); linelength = 0;} + fprintf(code_file, "\\%o",c); + linelength += 4; + } + // We must not put more numbers after it, because some C compilers + // consume them as part of the quoted sequence. Use string constant + // pasting to avoid this: + c = *w; + if (w < e && (c>='0'&&c<='9' || c>='a'&&c<='f' || c>='A'&&c<='F')) { + putc('\"', code_file); linelength++; + if (linelength >= 79) {fputs("\n",code_file); linelength = 0;} + putc('\"', code_file); linelength++; } break; } @@ -301,5 +313,5 @@ void Fl_Type::write_code1() { void Fl_Type::write_code2() {} // -// End of "$Id: code.cxx,v 1.9 1999/01/19 19:10:38 mike Exp $". +// End of "$Id: code.cxx,v 1.9.2.1 1999/07/31 08:00:09 bill Exp $". // |
