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 | |
| 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
| -rw-r--r-- | fluid/Fluid_Image.cxx | 22 | ||||
| -rw-r--r-- | fluid/code.cxx | 60 |
2 files changed, 53 insertions, 29 deletions
diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index 7c1686c99..a58ace755 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fluid_Image.cxx,v 1.7 1999/03/04 18:45:31 mike Exp $" +// "$Id: Fluid_Image.cxx,v 1.7.2.1 1999/07/31 08:00:08 bill Exp $" // // Pixmap label support for the Fast Light Tool Kit (FLTK). // @@ -75,7 +75,7 @@ void pixmap_image::write_static() { int l; for (l = 0; p->data[l]; l++) { if (l) write_c(",\n"); - write_c("(unsigned char *)"); + write_c("(unsigned char*)\n"); write_cstring(p->data[l],linelength[l]); } write_c("\n};\n"); @@ -239,14 +239,26 @@ void bitmap_image::write_static() { write_c("#include <FL/Fl_Bitmap.H>\n"); bitmap_header_written = write_number; } +#if 0 // older one write_c("static unsigned char %s[] = { \n", unique_id(this, "bits", filename_name(name()), 0)); int n = ((p->w+7)/8)*p->h; + int linelength = 0; for (int i = 0; i < n; i++) { - if (i) write_c(", "); - write_c("%d",p->array[i]); + if (i) {write_c(","); linelength++;} + if (linelength > 75) {write_c("\n"); linelength=0;} + int v = p->array[i]; + write_c("%d",v); + linelength++; if (v>9) linelength++; if (v>99) linelength++; } write_c("\n};\n"); +#else // this seems to produce slightly shorter c++ files + write_c("static unsigned char %s[] =\n", + unique_id(this, "bits", filename_name(name()), 0)); + int n = ((p->w+7)/8)*p->h; + write_cstring((const char*)(p->array), n); + write_c(";\n"); +#endif write_c("static Fl_Bitmap %s(%s, %d, %d);\n", unique_id(this, "bitmap", filename_name(name()), 0), unique_id(this, "bits", filename_name(name()), 0), @@ -405,5 +417,5 @@ Fluid_Image *ui_find_image(const char *oldname) { } // -// End of "$Id: Fluid_Image.cxx,v 1.7 1999/03/04 18:45:31 mike Exp $". +// End of "$Id: Fluid_Image.cxx,v 1.7.2.1 1999/07/31 08:00:08 bill Exp $". // 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 $". // |
