mirror of
https://github.com/fltk/fltk.git
synced 2026-06-06 00:22:42 +08:00
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
This commit is contained in:
+17
-5
@@ -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).
|
// Pixmap label support for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@@ -75,7 +75,7 @@ void pixmap_image::write_static() {
|
|||||||
int l;
|
int l;
|
||||||
for (l = 0; p->data[l]; l++) {
|
for (l = 0; p->data[l]; l++) {
|
||||||
if (l) write_c(",\n");
|
if (l) write_c(",\n");
|
||||||
write_c("(unsigned char *)");
|
write_c("(unsigned char*)\n");
|
||||||
write_cstring(p->data[l],linelength[l]);
|
write_cstring(p->data[l],linelength[l]);
|
||||||
}
|
}
|
||||||
write_c("\n};\n");
|
write_c("\n};\n");
|
||||||
@@ -239,14 +239,26 @@ void bitmap_image::write_static() {
|
|||||||
write_c("#include <FL/Fl_Bitmap.H>\n");
|
write_c("#include <FL/Fl_Bitmap.H>\n");
|
||||||
bitmap_header_written = write_number;
|
bitmap_header_written = write_number;
|
||||||
}
|
}
|
||||||
|
#if 0 // older one
|
||||||
write_c("static unsigned char %s[] = { \n",
|
write_c("static unsigned char %s[] = { \n",
|
||||||
unique_id(this, "bits", filename_name(name()), 0));
|
unique_id(this, "bits", filename_name(name()), 0));
|
||||||
int n = ((p->w+7)/8)*p->h;
|
int n = ((p->w+7)/8)*p->h;
|
||||||
|
int linelength = 0;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if (i) write_c(", ");
|
if (i) {write_c(","); linelength++;}
|
||||||
write_c("%d",p->array[i]);
|
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");
|
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",
|
write_c("static Fl_Bitmap %s(%s, %d, %d);\n",
|
||||||
unique_id(this, "bitmap", filename_name(name()), 0),
|
unique_id(this, "bitmap", filename_name(name()), 0),
|
||||||
unique_id(this, "bits", 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 $".
|
||||||
//
|
//
|
||||||
|
|||||||
+34
-22
@@ -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).
|
// 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;
|
int linelength = 1;
|
||||||
putc('\"', code_file);
|
putc('\"', code_file);
|
||||||
for (; w < e;) {
|
for (; w < e;) {
|
||||||
if (linelength >= 75) {fputs("\\\n",code_file); linelength = 0;}
|
|
||||||
int c = *w++;
|
int c = *w++;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\b': c = 'b'; goto QUOTED;
|
case '\b': c = 'b'; goto QUOTED;
|
||||||
@@ -170,32 +169,45 @@ void write_cstring(const char *w, int length) {
|
|||||||
case '\'':
|
case '\'':
|
||||||
case '\\':
|
case '\\':
|
||||||
QUOTED:
|
QUOTED:
|
||||||
putc('\\',code_file);
|
if (linelength >= 77) {fputs("\\\n",code_file); linelength = 0;}
|
||||||
putc(c,code_file);
|
putc('\\', code_file);
|
||||||
|
putc(c, code_file);
|
||||||
linelength += 2;
|
linelength += 2;
|
||||||
break;
|
break;
|
||||||
case 0:
|
case '?': // prevent trigraphs by writing ?? as ?\?
|
||||||
case 1:
|
if (*(w-2) == '?') goto QUOTED;
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 7:
|
|
||||||
if (*w < '0' || *w > '9') {c += '0'; goto QUOTED;}
|
|
||||||
// else fall through:
|
// else fall through:
|
||||||
default:
|
default:
|
||||||
if (c < ' ' || c >= 127) {
|
if (c >= ' ' && c < 127) {
|
||||||
QUOTENEXT:
|
// a legal ASCII character
|
||||||
fprintf(code_file, "\\%03o",c&255);
|
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;
|
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;
|
c = *w;
|
||||||
if (w < e && (c>='0'&&c<='9' || c>='a'&&c<='f' || c>='A'&&c<='F')) {
|
if (w < e && (c>='0'&&c<='9' || c>='a'&&c<='f' || c>='A'&&c<='F')) {
|
||||||
w++; goto QUOTENEXT;
|
putc('\"', code_file); linelength++;
|
||||||
}
|
if (linelength >= 79) {fputs("\n",code_file); linelength = 0;}
|
||||||
} else {
|
putc('\"', code_file); linelength++;
|
||||||
putc(c,code_file);
|
|
||||||
linelength++;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -301,5 +313,5 @@ void Fl_Type::write_code1() {
|
|||||||
void Fl_Type::write_code2() {}
|
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 $".
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user