diff options
| author | Bill Spitzak <spitzak@gmail.com> | 2000-06-16 07:08:16 +0000 |
|---|---|---|
| committer | Bill Spitzak <spitzak@gmail.com> | 2000-06-16 07:08:16 +0000 |
| commit | 084b19e305eccead76c2322d1533af526684ed6b (patch) | |
| tree | 5c1e0698552bd07666e0c58cef2c23d8d5493695 | |
| parent | 4ab82443bd55b96f7db233e47b94338f70c01238 (diff) | |
Patch from Dmitry Potapov for fluid to not crash on (I think)
identifiers with trailing whitespace.
Fluid can now read in .xpm files with more than 2048 lines in them.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1213 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | fluid/Fluid_Image.cxx | 52 | ||||
| -rw-r--r-- | fluid/code.cxx | 6 |
2 files changed, 39 insertions, 19 deletions
diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index 8c4d11844..4efaf3800 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fluid_Image.cxx,v 1.7.2.3 2000/06/05 21:20:41 mike Exp $" +// "$Id: Fluid_Image.cxx,v 1.7.2.4 2000/06/16 07:08:15 bill Exp $" // // Pixmap label support for the Fast Light Tool Kit (FLTK). // @@ -43,6 +43,7 @@ extern void leave_source_dir(); // in fluid.C class pixmap_image : public Fluid_Image { protected: Fl_Pixmap *p; + int numlines; int *linelength; public: pixmap_image(const char *name, FILE *); @@ -70,12 +71,11 @@ void pixmap_image::write_static() { write_c("#include <FL/Fl_Pixmap.H>\n"); pixmap_header_written = write_number; } - write_c("static unsigned char *%s[] = {\n", + write_c("static char *%s[] = {\n", unique_id(this, "image", filename_name(name()), 0)); int l; - for (l = 0; p->data[l]; l++) { + for (l = 0; l < numlines; l++) { if (l) write_c(",\n"); - write_c("(unsigned char*)\n"); write_cstring(p->data[l],linelength[l]); } write_c("\n};\n"); @@ -98,15 +98,19 @@ static int hexdigit(int x) { } #define MAXSIZE 2048 +#define INITIALLINES 1024 pixmap_image::pixmap_image(const char *name, FILE *f) : Fluid_Image(name) { if (!f) return; // for subclasses // read all the c-strings out of the file: - char *data[MAXSIZE+1]; - int length[MAXSIZE+1]; + char* local_data[INITIALLINES]; + char** data = local_data; + int local_length[INITIALLINES]; + int* length = local_length; + int malloc_size = INITIALLINES; char buffer[MAXSIZE+20]; int i = 0; - while (i < MAXSIZE && fgets(buffer,MAXSIZE+20,f)) { + while (fgets(buffer,MAXSIZE+20,f)) { if (buffer[0] != '\"') continue; char *p = buffer; char *q = buffer+1; @@ -145,26 +149,42 @@ pixmap_image::pixmap_image(const char *name, FILE *f) : Fluid_Image(name) { } } *p++ = 0; + if (i >= malloc_size) { + malloc_size = 2*malloc_size; + if (data == local_data) { + data = (char**)malloc(malloc_size*sizeof(char*)); + memcpy(data, local_data, i*sizeof(char*)); + length = (int*)malloc(malloc_size*sizeof(int)); + memcpy(length, local_length, i*sizeof(int)); + } else { + data = (char**)realloc(data, malloc_size*sizeof(char*)); + length = (int*)realloc(length, malloc_size*sizeof(int)); + } + } data[i] = new char[p-buffer]; - memcpy(data[i],buffer,p-buffer); + memcpy(data[i], buffer,p-buffer); length[i] = p-buffer-1; i++; } - data[i++] = 0; // put a null at the end - char** real_data = new char*[i]; - linelength = new int[i]; - while (i--) {real_data[i] = data[i]; linelength[i] = length[i];} - p = new Fl_Pixmap(real_data); + if (data == local_data) { + data = (char**)malloc(i*sizeof(char*)); + memcpy(data, local_data, i*sizeof(char*)); + length = (int*)malloc(i*sizeof(int)); + memcpy(length, local_length, i*sizeof(int)); + } + numlines = i; + linelength = length; + p = new Fl_Pixmap(data); } pixmap_image::~pixmap_image() { if (p && p->data) { char** real_data = (char**)(p->data); for (int i = 0; real_data[i]; i++) delete[] real_data[i]; - delete[] real_data; + free((void*)real_data); } - delete[] linelength; + free((void*)linelength); delete p; } @@ -417,5 +437,5 @@ Fluid_Image *ui_find_image(const char *oldname) { } // -// End of "$Id: Fluid_Image.cxx,v 1.7.2.3 2000/06/05 21:20:41 mike Exp $". +// End of "$Id: Fluid_Image.cxx,v 1.7.2.4 2000/06/16 07:08:15 bill Exp $". // diff --git a/fluid/code.cxx b/fluid/code.cxx index af2ad71e6..49dfe3743 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -1,5 +1,5 @@ // -// "$Id: code.cxx,v 1.9.2.7 2000/06/05 21:20:42 mike Exp $" +// "$Id: code.cxx,v 1.9.2.8 2000/06/16 07:08:16 bill Exp $" // // Code output routines for the Fast Light Tool Kit (FLTK). // @@ -76,7 +76,7 @@ const char* unique_id(void* o, const char* type, const char* name, const char* l const char* n = name; if (!n || !*n) n = label; if (n && *n) { - while (!is_id(*n)) n++; + while (*n && !is_id(*n)) n++; while (is_id(*n)) *q++ = *n++; } *q = 0; @@ -405,5 +405,5 @@ void Fl_Type::write_code1() { void Fl_Type::write_code2() {} // -// End of "$Id: code.cxx,v 1.9.2.7 2000/06/05 21:20:42 mike Exp $". +// End of "$Id: code.cxx,v 1.9.2.8 2000/06/16 07:08:16 bill Exp $". // |
