]> Pileus Git - ~andy/gtk/commitdiff
Clean up stupid increment-inside-array-dereference thing
authorHavoc Pennington <hp@pobox.com>
Fri, 22 Oct 1999 23:26:22 +0000 (23:26 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Fri, 22 Oct 1999 23:26:22 +0000 (23:26 +0000)
1999-10-22  Havoc Pennington  <hp@pobox.com>

* src/io-xpm.c (mem_buffer): Clean up stupid
increment-inside-array-dereference thing

* src/testpixbuf.c: Add XPM data tests.

* src/io-xpm.c: Make the XPM data buffer const, fix const
correctness throughout the code.

demos/testpixbuf.c
gdk-pixbuf/ChangeLog
gdk-pixbuf/io-xpm.c

index 96c20bd63e476617deee92636bdd0d24b1778581..374354a050b709b0566c9213f47d5ded48960f96 100644 (file)
@@ -175,6 +175,126 @@ static const unsigned char default_image[] = {
        0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff
 };
 
+
+static const char * book_open_xpm[] = {
+"16 16 4 1",
+"       c None s None",
+".      c black",
+"X      c #808080",
+"o      c white",
+"                ",
+"  ..            ",
+" .Xo.    ...    ",
+" .Xoo. ..oo.    ",
+" .Xooo.Xooo...  ",
+" .Xooo.oooo.X.  ",
+" .Xooo.Xooo.X.  ",
+" .Xooo.oooo.X.  ",
+" .Xooo.Xooo.X.  ",
+" .Xooo.oooo.X.  ",
+"  .Xoo.Xoo..X.  ",
+"   .Xo.o..ooX.  ",
+"    .X..XXXXX.  ",
+"    ..X.......  ",
+"     ..         ",
+"                "};
+
+static const char * book_closed_xpm[] = {
+"16 16 6 1",
+"       c None s None",
+".      c black",
+"X      c red",
+"o      c yellow",
+"O      c #808080",
+"#      c white",
+"                ",
+"       ..       ",
+"     ..XX.      ",
+"   ..XXXXX.     ",
+" ..XXXXXXXX.    ",
+".ooXXXXXXXXX.   ",
+"..ooXXXXXXXXX.  ",
+".X.ooXXXXXXXXX. ",
+".XX.ooXXXXXX..  ",
+" .XX.ooXXX..#O  ",
+"  .XX.oo..##OO. ",
+"   .XX..##OO..  ",
+"    .X.#OO..    ",
+"     ..O..      ",
+"      ..        ",
+"                "};
+
+static const char * mini_page_xpm[] = {
+"16 16 4 1",
+"       c None s None",
+".      c black",
+"X      c white",
+"o      c #808080",
+"                ",
+"   .......      ",
+"   .XXXXX..     ",
+"   .XoooX.X.    ",
+"   .XXXXX....   ",
+"   .XooooXoo.o  ",
+"   .XXXXXXXX.o  ",
+"   .XooooooX.o  ",
+"   .XXXXXXXX.o  ",
+"   .XooooooX.o  ",
+"   .XXXXXXXX.o  ",
+"   .XooooooX.o  ",
+"   .XXXXXXXX.o  ",
+"   ..........o  ",
+"    oooooooooo  ",
+"                "};
+
+static const char * gtk_mini_xpm[] = {
+"15 20 17 1",
+"       c None",
+".      c #14121F",
+"+      c #278828",
+"@      c #9B3334",
+"#      c #284C72",
+"$      c #24692A",
+"%      c #69282E",
+"&      c #37C539",
+"*      c #1D2F4D",
+"=      c #6D7076",
+"-      c #7D8482",
+";      c #E24A49",
+">      c #515357",
+",      c #9B9C9B",
+"'      c #2FA232",
+")      c #3CE23D",
+"!      c #3B6CCB",
+"               ",
+"      ***>     ",
+"    >.*!!!*    ",
+"   ***....#*=  ",
+"  *!*.!!!**!!# ",
+" .!!#*!#*!!!!# ",
+" @%#!.##.*!!$& ",
+" @;%*!*.#!#')) ",
+" @;;@%!!*$&)'' ",
+" @%.%@%$'&)$+' ",
+" @;...@$'*'*)+ ",
+" @;%..@$+*.')$ ",
+" @;%%;;$+..$)# ",
+" @;%%;@$$$'.$# ",
+" %;@@;;$$+))&* ",
+"  %;;;@+$&)&*  ",
+"   %;;@'))+>   ",
+"    %;@'&#     ",
+"     >%$$      ",
+"      >=       "};
+
+const gchar ** xpms[] = { 
+  book_open_xpm,
+  book_closed_xpm,
+  mini_page_xpm,
+  gtk_mini_xpm,
+  NULL
+};
+
 static void
 quit_func (GtkWidget *widget, gpointer dummy)
 {
@@ -299,10 +419,20 @@ main (int argc, char **argv)
 
        i = 1;
        if (argc == 1) {
+                const gchar*** xpmp;
+                
                pixbuf = gdk_pixbuf_new_from_data ((guchar *) default_image, ART_PIX_RGB, FALSE,
                                                   DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
                                                   NULL, NULL);
                new_testrgb_window (pixbuf);
+
+                xpmp = xpms;
+                while (*xpmp) {
+                        pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp);
+                        new_testrgb_window (pixbuf);
+                        ++xpmp;
+                }
+                
                found_valid = TRUE;
        } else {
                for (i = 1; i < argc; i++) {
index 342ce7391060232a15486871d8c699546c1cab14..97d849066ebeb3f83d075dfdbe98accebe49131d 100644 (file)
@@ -1,3 +1,13 @@
+1999-10-22  Havoc Pennington  <hp@pobox.com>
+
+       * src/io-xpm.c (mem_buffer): Clean up stupid
+       increment-inside-array-dereference thing
+
+       * src/testpixbuf.c: Add XPM data tests.
+
+       * src/io-xpm.c: Make the XPM data buffer const, fix const
+       correctness throughout the code.        
+
 1999-10-22  Havoc Pennington  <hp@pobox.com>
 
        * src/gdk-pixbuf.h: Export gdk_pixbuf_new_from_xpm_data()
index babd096a6eaecbaa7e12cefaf030e592b8acb7de..b2f0715c62d9fe4c989033c3fe3b605a6188fc69 100644 (file)
@@ -159,8 +159,8 @@ xpm_read_string (FILE *infile, gchar **buffer, guint *buffer_size)
        return ret;
 }
 
-static gchar *
-xpm_skip_whitespaces (gchar *buffer)
+static const gchar *
+xpm_skip_whitespaces (const gchar *buffer)
 {
        gint32 index = 0;
 
@@ -170,8 +170,8 @@ xpm_skip_whitespaces (gchar *buffer)
        return &buffer[index];
 }
 
-static gchar *
-xpm_skip_string (gchar *buffer)
+static const gchar *
+xpm_skip_string (const gchar *buffer)
 {
        gint32 index = 0;
 
@@ -185,10 +185,11 @@ xpm_skip_string (gchar *buffer)
 #define MAX_COLOR_LEN 120
 
 static gchar *
-xpm_extract_color (gchar *buffer)
+xpm_extract_color (const gchar *buffer)
 {
        gint counter, numnames;
-       gchar *ptr = NULL, ch, temp[128];
+       const gchar *ptr = NULL;
+        gchar ch, temp[128];
        gchar color[MAX_COLOR_LEN], *retcol;
        gint space;
 
@@ -252,7 +253,7 @@ xpm_extract_color (gchar *buffer)
 
 /* (almost) direct copy from gdkpixmap.c... loads an XPM from a file */
 
-static gchar *
+static const gchar *
 file_buffer (enum buf_op op, gpointer handle)
 {
        struct file_handle *h = handle;
@@ -283,7 +284,7 @@ file_buffer (enum buf_op op, gpointer handle)
 }
 
 /* This reads from memory */
-static gchar *
+static const gchar *
 mem_buffer (enum buf_op op, gpointer handle)
 {
        struct mem_handle *h = handle;
@@ -291,11 +292,18 @@ mem_buffer (enum buf_op op, gpointer handle)
        case op_header:
        case op_cmap:
        case op_body:
-               if (h->data[h->offset])
-                       return h->data[h->offset++];
+                if (h->data[h->offset]) {
+                        const gchar* retval;
+
+                        retval = h->data[h->offset];
+                        h->offset += 1;
+                        return retval;
+                }
+                break;
 
        default:
                g_assert_not_reached ();
+                break;
        }
 
        return NULL;
@@ -310,12 +318,13 @@ free_buffer (gpointer user_data, gpointer data)
 
 /* This function does all the work. */
 static GdkPixbuf *
-pixbuf_create_from_xpm (gchar * (*get_buf) (enum buf_op op, gpointer handle), gpointer handle)
+pixbuf_create_from_xpm (const gchar * (*get_buf) (enum buf_op op, gpointer handle), gpointer handle)
 {
        gint w, h, n_col, cpp;
        gint cnt, xcnt, ycnt, wbytes, n, ns;
        gint is_trans = FALSE;
-       gchar *buffer, *name_buf;
+       const gchar *buffer;
+        gchar *name_buf;
        gchar pixel_str[32];
        GHashTable *color_hash;
        _XPMColor *colors, *color, *fallbackcolor;