X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fwidget-io.c;h=73a7301662033e366a1d8180692c131646b82aac;hb=a70c4580757c19cd5054a470c2c5d497a1e71b4c;hp=81ffd7311dea4273e4557fae687acc945dec746e;hpb=0085c7edf6d3b9c9ee2ce880893023c567886101;p=pspp-builds.git diff --git a/src/ui/gui/widget-io.c b/src/ui/gui/widget-io.c index 81ffd731..73a73016 100644 --- a/src/ui/gui/widget-io.c +++ b/src/ui/gui/widget-io.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007 Free Software Foundation + Copyright (C) 2007, 2009, 2011 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,22 +26,44 @@ #include +#include "xalloc.h" +/* Create a GtkLabel and pack it into BOX. + The label is created using part of the string at S, and the directives + at DIRS[DIR_IDX] and subsequent. + After this function returns, *S points to the first unused character. +*/ static void -ship_label (GtkBox *box, const char **s, const char_directive *dir) +ship_label (GtkBox *box, const char **s, + const char_directives *dirs, size_t dir_idx) { GtkWidget *label ; - gchar *text = g_strdup (*s); + GString *str = g_string_new (*s); - if ( dir ) + if ( dirs) { - text [ dir->dir_start - *s ] = '\0'; - *s = dir->dir_end; + char_directive dir = dirs->dir[dir_idx]; + int n = 0; + + while (dir_idx < dirs->count && dir.conversion == '%' ) + { + g_string_erase (str, dir.dir_start - *s, 1); + dir = dirs->dir[++dir_idx]; + n++; + } + + g_string_truncate (str, dir.dir_start - *s - n); + + if ( dir_idx >= dirs->count) + *s = NULL; + else + *s = dir.dir_end; } - label = gtk_label_new (text); - g_free (text); + label = gtk_label_new (str->str); + + g_string_free (str, TRUE); gtk_box_pack_start (box, label, FALSE, FALSE, 0); gtk_widget_show (label); @@ -69,7 +91,7 @@ widget_printf (const gchar *fmt, ...) if ( 0 != printf_parse (fmt, &d, &a) ) return NULL; - widgets = calloc (sizeof (*widgets), d.count); + widgets = xcalloc (sizeof (*widgets), d.count); va_start (ap, fmt); for (i = 0 ; i < d.count ; ++i ) { @@ -78,7 +100,8 @@ widget_printf (const gchar *fmt, ...) } va_end (ap); - g_free (a.arg); + if (a.arg != a.direct_alloc_arg) + free (a.arg); output = g_string_sized_new (strlen (fmt)); @@ -106,7 +129,8 @@ widget_printf (const gchar *fmt, ...) } free (widgets); - free (d.dir); + if (d.dir != d.direct_alloc_dir) + free (d.dir); if (*s) g_string_append_len (output, s, -1); @@ -140,7 +164,8 @@ widget_scanf (const gchar *fmt, ...) if ( 0 != printf_parse (fmt, &d, &a) ) return NULL; - g_free (a.arg); + if (a.arg != a.direct_alloc_arg) + free (a.arg); va_start (ap, fmt); @@ -158,6 +183,7 @@ widget_scanf (const gchar *fmt, ...) va_end (ap); + for (i = 0 ; i < d.count ; ++i ) { char_directive dir = d.dir[i]; @@ -173,11 +199,11 @@ widget_scanf (const gchar *fmt, ...) width = strtol (dir.width_start, (char **) &dir.width_end, 10); if ( dir.dir_start > s ) - ship_label (GTK_BOX (hbox), &s, &dir); + ship_label (GTK_BOX (hbox), &s, &d, i); if ( dir.conversion == '%') { - s++; + if (s) s++; continue; } @@ -202,13 +228,15 @@ widget_scanf (const gchar *fmt, ...) gtk_widget_show (*w); } - if ( *s ) - ship_label (GTK_BOX (hbox), &s, NULL); + if ( s && *s ) + ship_label (GTK_BOX (hbox), &s, NULL, 0); + g_free (widgets); - free (d.dir); + if (d.dir != d.direct_alloc_dir) + free (d.dir); return hbox; }