[AD] Fix dat2c for use with ISO C90 compilers

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I've attached the fix required for dat2c to work with ISO C90 compilers 
(actually those without ISO C99 flexible array members like GCC 2.x).

It is based on Chris Sandberg's idea and partial fix. I simply extended it to 
cover the three structures involved. Tested with GCC 2.95.3 and GCC 3.2.3, 
applied to mainline.

There is one remaining problem though: dat2c has a sophisticated mechanism 
for handling the different line endings (DOS, Unix, Mac) but it doesn't 
correctly detect the native line ending of the platform it runs on, contrary 
to what is advertised. It naturally relies on Allegro's os_type to do so; 
unfortunately, os_type is not set when passing SYSTEM_NONE as the system 
driver so we always end up with DOS line ending...

-- 
Eric Botcazou
Index: tools/dat2c.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/dat2c.c,v
retrieving revision 1.8
diff -u -r1.8 dat2c.c
--- tools/dat2c.c	20 Dec 2002 08:31:46 -0000	1.8
+++ tools/dat2c.c	13 May 2003 13:22:00 -0000
@@ -1104,7 +1104,11 @@
     cwrite(dat2c, C, ";$n$$n$");
 
     /* write out BITMAP structure */
-    cwrite(dat2c, C, "$string$BITMAP $string lower$ = {$n$"
+
+    cwrite(dat2c, C, "$string$struct { int w, h; int clip; int cl, cr, ct, cb;\n"
+                     "                GFX_VTABLE *vtable; void *write_bank; void *read_bank;\n"
+                     "                void *dat; unsigned long id; void *extra;\n"
+                     "                int x_ofs; int y_ofs; int seg; unsigned char *line[$int$]; } $string lower$ = {$n$"
                      "    $int$, $int$, /* width, height */$n$"
                      "    0, 0, 0, 0, 0, /* clip */$n$"
                      "    (GFX_VTABLE *)$int$, /* bpp */$n$"
@@ -1113,6 +1117,7 @@
                      "    0, 0, 0, 0, 0,$n$"
                      "    { /* line[] array */$n$",
         export ? "" : "static ",
+        bmp->h + 1,  /* trailing 0 for convenience */
         name,
         bmp->w, bmp->h,
         bmp->vtable->color_depth,
@@ -1188,11 +1193,12 @@
         for(glyph = iter->begin; glyph < iter->end; glyph++) {
             FONT_GLYPH* fg = iter->glyphs[glyph - iter->begin];
             
-            cwrite(dat2c, C, "static FONT_GLYPH $string lower$_glyph"
+            cwrite(dat2c, C, "static struct { short w,h; char data[$int$]; } $string lower$_glyph"
                              "$int$ = {$n$"
                              "    $int$, $int$, /* width, height */$n$"
                              "    $data$$n$"
                              "};$n$$n$",
+                fg->h * ((fg->w + 7) / 8),
                 name, glyph,
                 fg->w, fg->h,
                 fg->h * ((fg->w + 7) / 8), 4, fg->dat);
@@ -1204,7 +1210,7 @@
             name, data_count);
         
         for(glyph = iter->begin; glyph < iter->end; glyph++) {
-            cwrite(dat2c, C, "    &$string lower$_glyph$int$,$n$",
+            cwrite(dat2c, C, "    (FONT_GLYPH *)&$string lower$_glyph$int$,$n$",
                 name, glyph);
         }
         
@@ -1266,7 +1272,7 @@
             name, data_count);
 
         for(glyph = iter->begin; glyph < iter->end; glyph++) {
-            cwrite(dat2c, C, "    &$string lower$_glyph$int$,$n$",
+            cwrite(dat2c, C, "    (BITMAP *)&$string lower$_glyph$int$,$n$",
                 name, glyph);
         }
         
@@ -1431,7 +1437,7 @@
             name);
     }
 
-    cwrite(dat2c, C, "$string$RLE_SPRITE $string lower$ = {$n$"
+    cwrite(dat2c, C, "$string$struct { int w, h; int color_depth; int size; char data[$int$]; } $string lower$ = {$n$"
                      "    $int$, $int$, /* width, height */$n$"
                      "    $int$, /* color depth */$n$"
                      "    $int$, /* compressed size (bytes) */$n$"
@@ -1439,6 +1445,7 @@
                      "};$n$"
                      "$n$$n$$n$",
         dat2c->global_symbols ? "" : "static ",
+        rle->size,
         name,
         rle->w, rle->h,
         rle->color_depth,


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/