X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fdemo-Gtk-conf.c;h=262e88eb5aa641c4a2ea2ceb3e94c4d02b996a4c;hb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;hp=d51d1df7b3fe2e3282b8e2fbc51c32f274829130;hpb=a94197e76a5dea5cb60542840809d6c20d0abbf3;p=xscreensaver diff --git a/driver/demo-Gtk-conf.c b/driver/demo-Gtk-conf.c index d51d1df7..262e88eb 100644 --- a/driver/demo-Gtk-conf.c +++ b/driver/demo-Gtk-conf.c @@ -1,5 +1,5 @@ /* demo-Gtk-conf.c --- implements the dynamic configuration dialogs. - * xscreensaver, Copyright (c) 2001 Jamie Zawinski + * xscreensaver, Copyright (c) 2001, 2003, 2004, 2006 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -16,6 +16,8 @@ #if defined(HAVE_GTK) && defined(HAVE_XML) /* whole file */ +#include + #include #ifdef HAVE_UNISTD_H @@ -26,20 +28,47 @@ #include #include -#include /* XML */ +/* + * Both of these workarounds can be removed when support for ancient + * libxml versions is dropped. versions 1.8.11 and 2.3.4 provide the + * correct fixes. + */ + +/* + * Older libxml polluted the global headerspace, while libxml2 fixed + * this. To support both old and recent libxmls, we have this + * workaround. + */ +#ifdef HAVE_OLD_XML_HEADERS +# include +#else /* ! HAVE_OLD_XML_HEADERS */ +# include +#endif /* HAVE_OLD_XML_HEADERS */ + +/* + * handle non-native spelling mistakes in earlier versions and provide + * the source-compat fix for this that may not be in older versions. + */ +#ifndef xmlChildrenNode +# if LIBXML_VERSION >= 20000 +# define xmlChildrenNode children +# define xmlRootNode children +# else +# define xmlChildrenNode childs +# define xmlRootNode root +# endif /* LIBXML_VERSION */ +#endif /* xmlChildrenNode */ #include #include "demo-Gtk-conf.h" -#if (LIBXML_VERSION >= 20000) /* illiteracy finally fixed */ -# define childs children -# define root children -#endif extern const char *blurb (void); +const char *hack_configuration_path = HACK_CONFIGURATION_PATH; + static gboolean debug_p = FALSE; @@ -62,30 +91,29 @@ typedef struct { parameter_type type; - char *id; /* widget name */ - char *label; /* heading label, or null */ + xmlChar *id; /* widget name */ + xmlChar *label; /* heading label, or null */ /* command, fake, description, fakepreview, string, file */ - char *string; /* file name, description, whatever. */ + xmlChar *string; /* file name, description, whatever. */ /* slider, spinbutton */ - char *low_label; /* label for the left side */ - char *high_label; /* label for the right side */ + xmlChar *low_label; /* label for the left side */ + xmlChar *high_label; /* label for the right side */ float low; /* minimum value */ float high; /* maximum value */ float value; /* default value */ gboolean integer_p; /* whether the range is integral, or real */ - char *arg; /* command-line option to set (substitute "%") */ + xmlChar *arg; /* command-line option to set (substitute "%") */ gboolean invert_p; /* whether to flip the value and pretend the range goes from hi-low instead of low-hi. */ /* boolean, select-option */ - char *arg_set; /* command-line option to set for "yes", or null */ - char *arg_unset; /* command-line option to set for "no", or null */ - char *test; /* #### no idea - enablement? */ + xmlChar *arg_set; /* command-line option to set for "yes", or null */ + xmlChar *arg_unset; /* command-line option to set for "no", or null */ /* select */ @@ -93,8 +121,6 @@ typedef struct { /* select_option */ - GList *enable; - GtkWidget *widget; } parameter; @@ -121,19 +147,11 @@ free_parameter (parameter *p) if (p->arg) free (p->arg); if (p->arg_set) free (p->arg_set); if (p->arg_unset) free (p->arg_unset); - if (p->test) free (p->test); for (rest = p->options; rest; rest = rest->next) if (rest->data) free_parameter ((parameter *) rest->data); - for (rest = p->enable; rest; rest = rest->next) - { - free ((char *) rest->data); - rest->data = 0; - } - if (p->enable) g_list_free (p->enable); - memset (p, ~0, sizeof(*p)); free (p); } @@ -173,7 +191,6 @@ describe_parameter (FILE *out, parameter *p) if (p->invert_p) fprintf (out, " convert=\"invert\""); if (p->arg_set) fprintf (out, " arg-set=\"%s\"", p->arg_set); if (p->arg_unset) fprintf (out, " arg-unset=\"%s\"", p->arg_unset); - if (p->test) fprintf (out, " test=\"%s\"", p->test); fprintf (out, ">\n"); if (p->type == SELECT) @@ -188,15 +205,6 @@ describe_parameter (FILE *out, parameter *p) if (o->label) fprintf (out, " _label=\"%s\"", o->label); if (o->arg_set) fprintf (out, " arg-set=\"%s\"", o->arg_set); if (o->arg_unset) fprintf (out, " arg-unset=\"%s\"", o->arg_unset); - if (o->test) fprintf (out, " test=\"%s\"", o->test); - if (o->enable) - { - GList *e; - fprintf (out, " enable=\""); - for (e = o->enable; e; e = e->next) - fprintf (out, "%s%s", (char *) e->data, (e->next ? "," : "")); - fprintf (out, "\""); - } fprintf (out, ">\n"); } fprintf (out, "\n"); @@ -217,9 +225,9 @@ describe_parameter (FILE *out, parameter *p) `floatp' is set to TRUE. Otherwise, it is unchanged. */ static float -xml_get_float (xmlNodePtr node, const char *name, gboolean *floatpP) +xml_get_float (xmlNodePtr node, const xmlChar *name, gboolean *floatpP) { - const char *s = xmlGetProp (node, name); + const char *s = (char *) xmlGetProp (node, name); float f; char c; if (!s || 1 != sscanf (s, "%f %c", &f, &c)) @@ -233,8 +241,13 @@ xml_get_float (xmlNodePtr node, const char *name, gboolean *floatpP) static void sanity_check_parameter (const char *filename, - const char *node_name, + const xmlChar *node_name, parameter *p); +static void sanity_check_text_node (const char *filename, + const xmlNodePtr node); +static void sanity_check_menu_options (const char *filename, + const xmlChar *node_name, + parameter *p); /* Allocates and returns a new `parameter' object based on the properties in the given XML node. Returns 0 if there's nothing @@ -244,7 +257,7 @@ static parameter * make_parameter (const char *filename, xmlNodePtr node) { parameter *p; - const char *name = node->name; + const char *name = (char *) node->name; const char *convert; gboolean floatp = FALSE; @@ -264,6 +277,19 @@ make_parameter (const char *filename, xmlNodePtr node) else if (!strcmp (name, "file")) p->type = FILENAME; else if (!strcmp (name, "number")) p->type = SPINBUTTON; else if (!strcmp (name, "select")) p->type = SELECT; + + else if (!strcmp (name, "xscreensaver-text") || /* these are ignored in X11 */ + !strcmp (name, "xscreensaver-image")) /* (they are used in Cocoa) */ + { + free (p); + return 0; + } + else if (node->type == XML_TEXT_NODE) + { + sanity_check_text_node (filename, node); + free (p); + return 0; + } else { if (debug_p) @@ -275,7 +301,7 @@ make_parameter (const char *filename, xmlNodePtr node) if (p->type == SPINBUTTON) { - const char *type = xmlGetProp (node, "type"); + const char *type = (char *) xmlGetProp (node, (xmlChar *) "type"); if (!type || !strcmp (type, "spinbutton")) p->type = SPINBUTTON; else if (!strcmp (type, "slider")) p->type = SLIDER; else @@ -289,26 +315,26 @@ make_parameter (const char *filename, xmlNodePtr node) } else if (p->type == DESCRIPTION) { - if (node->childs && - node->childs->type == XML_TEXT_NODE && - !node->childs->next) - p->string = strdup (node->childs->content); + if (node->xmlChildrenNode && + node->xmlChildrenNode->type == XML_TEXT_NODE && + !node->xmlChildrenNode->next) + p->string = (xmlChar *) + strdup ((char *) node->xmlChildrenNode->content); } - p->id = xmlGetProp (node, "id"); - p->label = xmlGetProp (node, "_label"); - p->low_label = xmlGetProp (node, "_low-label"); - p->high_label = xmlGetProp (node, "_high-label"); - p->low = xml_get_float (node, "low", &floatp); - p->high = xml_get_float (node, "high", &floatp); - p->value = xml_get_float (node, "default", &floatp); + p->id = xmlGetProp (node, (xmlChar *) "id"); + p->label = xmlGetProp (node, (xmlChar *) "_label"); + p->low_label = xmlGetProp (node, (xmlChar *) "_low-label"); + p->high_label = xmlGetProp (node, (xmlChar *) "_high-label"); + p->low = xml_get_float (node, (xmlChar *) "low", &floatp); + p->high = xml_get_float (node, (xmlChar *) "high", &floatp); + p->value = xml_get_float (node, (xmlChar *) "default", &floatp); p->integer_p = !floatp; - convert = xmlGetProp (node, "convert"); + convert = (char *) xmlGetProp (node, (xmlChar *) "convert"); p->invert_p = (convert && !strcmp (convert, "invert")); - p->arg = xmlGetProp (node, "arg"); - p->arg_set = xmlGetProp (node, "arg-set"); - p->arg_unset = xmlGetProp (node, "arg-unset"); - p->test = xmlGetProp (node, "test"); + p->arg = xmlGetProp (node, (xmlChar *) "arg"); + p->arg_set = xmlGetProp (node, (xmlChar *) "arg-set"); + p->arg_unset = xmlGetProp (node, (xmlChar *) "arg-unset"); /* Check for missing decimal point */ if (debug_p && @@ -323,7 +349,7 @@ make_parameter (const char *filename, xmlNodePtr node) if (p->type == SELECT) { xmlNodePtr kids; - for (kids = node->childs; kids; kids = kids->next) + for (kids = node->xmlChildrenNode; kids; kids = kids->next) { parameter *s = make_select_option (filename, kids); if (s) @@ -331,7 +357,7 @@ make_parameter (const char *filename, xmlNodePtr node) } } - sanity_check_parameter (filename, name, p); + sanity_check_parameter (filename, (const xmlChar *) name, p); return p; } @@ -346,6 +372,11 @@ make_select_option (const char *filename, xmlNodePtr node) { if (node->type == XML_COMMENT_NODE) return 0; + else if (node->type == XML_TEXT_NODE) + { + sanity_check_text_node (filename, node); + return 0; + } else if (node->type != XML_ELEMENT_NODE) { if (debug_p) @@ -354,7 +385,7 @@ make_select_option (const char *filename, xmlNodePtr node) blurb(), filename, node->name, (int)node->type); return 0; } - else if (strcmp (node->name, "option")) + else if (strcmp ((char *) node->name, "option")) { if (debug_p) fprintf (stderr, @@ -365,27 +396,12 @@ make_select_option (const char *filename, xmlNodePtr node) else { parameter *s = calloc (1, sizeof(*s)); - char *enable, *e; s->type = SELECT_OPTION; - s->id = xmlGetProp (node, "id"); - s->label = xmlGetProp (node, "_label"); - s->arg_set = xmlGetProp (node, "arg-set"); - s->arg_unset = xmlGetProp (node, "arg-unset"); - s->test = xmlGetProp (node, "test"); - enable = xmlGetProp (node, "enable"); - - if (enable) - { - enable = strdup (enable); - e = strtok (enable, ", "); - while (e) - { - s->enable = g_list_append (s->enable, strdup (e)); - e = strtok (0, ", "); - } - free (enable); - } + s->id = xmlGetProp (node, (xmlChar *) "id"); + s->label = xmlGetProp (node, (xmlChar *) "_label"); + s->arg_set = xmlGetProp (node, (xmlChar *) "arg-set"); + s->arg_unset = xmlGetProp (node, (xmlChar *) "arg-unset"); sanity_check_parameter (filename, node->name, s); return s; @@ -397,7 +413,7 @@ make_select_option (const char *filename, xmlNodePtr node) when they should have typed "arg=", etc. */ static void -sanity_check_parameter (const char *filename, const char *node_name, +sanity_check_parameter (const char *filename, const xmlChar *node_name, parameter *p) { struct { @@ -501,10 +517,10 @@ sanity_check_parameter (const char *filename, const char *node_name, # define WARN(STR) \ fprintf (stderr, "%s: %s: " STR " in <%s%s id=\"%s\">\n", \ blurb(), filename, node_name, \ - (!strcmp(node_name, "number") \ + (!strcmp((char *) node_name, "number") \ ? (p->type == SPINBUTTON ? " type=spinbutton" : " type=slider")\ : ""), \ - (p->id ? p->id : "")) + (p->id ? (char *) p->id : "")) # define CHECK(SLOT,NAME) \ if (p->SLOT && !allowed.SLOT) \ WARN ("\"" NAME "\" is not a valid option"); \ @@ -525,9 +541,129 @@ sanity_check_parameter (const char *filename, const char *node_name, CHECK (arg_unset, "arg-unset"); # undef CHECK # undef WARN + + if (p->type == SELECT) + sanity_check_menu_options (filename, node_name, p); +} + + +static void +sanity_check_menu_options (const char *filename, const xmlChar *node_name, + parameter *p) +{ + GList *opts; + int noptions = 0; + int nulls = 0; + char *prefix = 0; + +/* fprintf (stderr, "\n## %s\n", p->id);*/ + for (opts = p->options; opts; opts = opts->next) + { + parameter *s = (parameter *) opts->data; + if (!s->arg_set) nulls++; + noptions++; + + if (s->arg_set) + { + char *a = strdup ((char *) s->arg_set); + char *spc = strchr (a, ' '); + if (spc) *spc = 0; + if (prefix) + { + if (strcmp (a, prefix)) + fprintf (stderr, + "%s: %s: both \"%s\" and \"%s\" used in \n", + blurb(), filename, p->id); +} + + +/* "text" nodes show up for all the non-tag text in the file, including + all the newlines between tags. Warn if there is text there that + is not whitespace. + */ +static void +sanity_check_text_node (const char *filename, const xmlNodePtr node) +{ + const char *body = (const char *) node->content; + if (node->type != XML_TEXT_NODE) abort(); + while (isspace (*body)) body++; + if (*body) + fprintf (stderr, "%s: WARNING: %s: random text present: \"%s\"\n", + blurb(), filename, body); } +/* Returns a list of strings, every switch mentioned in the parameters. + The strings must be freed. + */ +static GList * +get_all_switches (const char *filename, GList *parms) +{ + GList *switches = 0; + GList *p; + for (p = parms; p; p = p->next) + { + parameter *pp = (parameter *) p->data; + + if (pp->type == SELECT) + { + GList *list2 = get_all_switches (filename, pp->options); + switches = g_list_concat (switches, list2); + } + if (pp->arg && *pp->arg) + switches = g_list_append (switches, strdup ((char *) pp->arg)); + if (pp->arg_set && *pp->arg_set) + switches = g_list_append (switches, strdup ((char *) pp->arg_set)); + if (pp->arg_unset && *pp->arg_unset) + switches = g_list_append (switches, strdup ((char *) pp->arg_unset)); + } + return switches; +} + + +/* Ensures that no switch is mentioned more than once. + */ +static void +sanity_check_parameters (const char *filename, GList *parms) +{ + GList *list = get_all_switches (filename, parms); + GList *p; + for (p = list; p; p = p->next) + { + char *sw = (char *) p->data; + GList *p2; + + if (*sw != '-' && *sw != '+') + fprintf (stderr, "%s: %s: switch does not begin with hyphen \"%s\"\n", + blurb(), filename, sw); + + for (p2 = p->next; p2; p2 = p2->next) + { + const char *sw2 = (const char *) p2->data; + if (!strcmp (sw, sw2)) + fprintf (stderr, "%s: %s: duplicate switch \"%s\"\n", + blurb(), filename, sw); + } + + free (sw); + } + g_list_free (list); +} + /* Helper for make_parameters() */ @@ -539,7 +675,7 @@ make_parameters_1 (const char *filename, xmlNodePtr node, for (; node; node = node->next) { - const char *name = node->name; + const char *name = (char *) node->name; if (!strcmp (name, "hgroup") || !strcmp (name, "vgroup")) { @@ -558,7 +694,7 @@ make_parameters_1 (const char *filename, xmlNodePtr node, if (row) (*row)++; - list2 = make_parameters_1 (filename, node->childs, box, 0); + list2 = make_parameters_1 (filename, node->xmlChildrenNode, box, 0); if (list2) list = g_list_concat (list, list2); } @@ -587,8 +723,9 @@ make_parameters (const char *filename, xmlNodePtr node, GtkWidget *parent) for (; node; node = node->next) { if (node->type == XML_ELEMENT_NODE && - !strcmp (node->name, "screensaver")) - return make_parameters_1 (filename, node->childs, parent, &row); + !strcmp ((char *) node->name, "screensaver")) + return make_parameters_1 (filename, node->xmlChildrenNode, + parent, &row); } return 0; } @@ -640,17 +777,17 @@ make_adjustment (const char *filename, parameter *p) } #endif /* 0 */ - if (p->integer_p) - { - si = (int) (si + 0.5); - pi = (int) (pi + 0.5); - if (si < 1) si = 1; - if (pi < 1) pi = 1; + si = (int) (si + 0.5); + pi = (int) (pi + 0.5); + if (si < 1) si = 1; + if (pi < 1) pi = 1; - if (range <= 500) si = 1; - } - return GTK_ADJUSTMENT (gtk_adjustment_new (value, p->low, p->high, - si, pi, pi)); + if (range <= 500) si = 1; + + return GTK_ADJUSTMENT (gtk_adjustment_new (value, + p->low, + p->high + 1, + si, pi, 1)); } @@ -664,7 +801,7 @@ static void make_parameter_widget (const char *filename, parameter *p, GtkWidget *parent, int *row) { - const char *label = p->label; + const char *label = (char *) p->label; if (p->widget) return; switch (p->type) @@ -673,7 +810,7 @@ make_parameter_widget (const char *filename, { if (label) { - GtkWidget *w = gtk_label_new (label); + GtkWidget *w = gtk_label_new (_(label)); gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_RIGHT); gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5); gtk_widget_show (w); @@ -686,7 +823,7 @@ make_parameter_widget (const char *filename, p->widget = gtk_entry_new (); if (p->string) - gtk_entry_set_text (GTK_ENTRY (p->widget), p->string); + gtk_entry_set_text (GTK_ENTRY (p->widget), (char *) p->string); if (row) gtk_table_attach (GTK_TABLE (parent), p->widget, 1, 3, *row, *row + 1, @@ -697,9 +834,9 @@ make_parameter_widget (const char *filename, } case FILENAME: { - GtkWidget *L = gtk_label_new (label ? label : ""); + GtkWidget *L = gtk_label_new (label ? _(label) : ""); GtkWidget *entry = gtk_entry_new (); - GtkWidget *button = gtk_button_new_with_label ("Browse..."); + GtkWidget *button = gtk_button_new_with_label (_("Browse...")); gtk_widget_show (entry); gtk_widget_show (button); p->widget = entry; @@ -713,7 +850,7 @@ make_parameter_widget (const char *filename, gtk_widget_show (L); if (p->string) - gtk_entry_set_text (GTK_ENTRY (entry), p->string); + gtk_entry_set_text (GTK_ENTRY (entry), (char *) p->string); if (row) { @@ -743,7 +880,7 @@ make_parameter_widget (const char *filename, if (label) { - labelw = gtk_label_new (label); + labelw = gtk_label_new (_(label)); gtk_label_set_justify (GTK_LABEL (labelw), GTK_JUSTIFY_LEFT); gtk_misc_set_alignment (GTK_MISC (labelw), 0.0, 0.5); gtk_widget_show (labelw); @@ -799,7 +936,7 @@ make_parameter_widget (const char *filename, if (p->low_label) { - GtkWidget *w = gtk_label_new (p->low_label); + GtkWidget *w = gtk_label_new (_((char *) p->low_label)); gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_RIGHT); gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5); gtk_widget_show (w); @@ -811,7 +948,7 @@ make_parameter_widget (const char *filename, } gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_BOTTOM); - gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE); + gtk_scale_set_draw_value (GTK_SCALE (scale), debug_p); gtk_scale_set_digits (GTK_SCALE (scale), (p->integer_p ? 0 : 2)); if (row) gtk_table_attach (GTK_TABLE (parent), scale, 1, 2, @@ -824,7 +961,7 @@ make_parameter_widget (const char *filename, if (p->high_label) { - GtkWidget *w = gtk_label_new (p->high_label); + GtkWidget *w = gtk_label_new (_((char *) p->high_label)); gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT); gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); gtk_widget_show (w); @@ -848,7 +985,7 @@ make_parameter_widget (const char *filename, if (label) { - GtkWidget *w = gtk_label_new (label); + GtkWidget *w = gtk_label_new (_(label)); gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_RIGHT); gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5); gtk_widget_show (w); @@ -877,7 +1014,7 @@ make_parameter_widget (const char *filename, } case BOOLEAN: { - p->widget = gtk_check_button_new_with_label (label); + p->widget = gtk_check_button_new_with_label (_(label)); if (row) gtk_table_attach (GTK_TABLE (parent), p->widget, 0, 3, *row, *row + 1, @@ -894,7 +1031,7 @@ make_parameter_widget (const char *filename, if (label && row) { - GtkWidget *w = gtk_label_new (label); + GtkWidget *w = gtk_label_new (_(label)); gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT); gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); gtk_widget_show (w); @@ -906,7 +1043,7 @@ make_parameter_widget (const char *filename, for (opts = p->options; opts; opts = opts->next) { parameter *s = (parameter *) opts->data; - GtkWidget *i = gtk_menu_item_new_with_label (s->label); + GtkWidget *i = gtk_menu_item_new_with_label (_((char *) s->label)); gtk_widget_show (i); gtk_menu_append (GTK_MENU (menu), i); } @@ -933,7 +1070,7 @@ make_parameter_widget (const char *filename, if (p->widget) { - gtk_widget_set_name (p->widget, p->id); + gtk_widget_set_name (p->widget, (char *) p->id); gtk_widget_show (p->widget); if (row) (*row)++; @@ -963,7 +1100,7 @@ file_sel_ok (GtkWidget *button, gpointer user_data) { GtkWidget *entry = GTK_WIDGET (user_data); GtkWidget *dialog = button; - char *path; + const char *path; while (dialog->parent) dialog = dialog->parent; gtk_widget_hide (dialog); @@ -989,9 +1126,9 @@ static void browse_button_cb (GtkButton *button, gpointer user_data) { GtkWidget *entry = GTK_WIDGET (user_data); - char *text = gtk_entry_get_text (GTK_ENTRY (entry)); + const char *text = gtk_entry_get_text (GTK_ENTRY (entry)); GtkFileSelection *selector = - GTK_FILE_SELECTION (gtk_file_selection_new ("Select file.")); + GTK_FILE_SELECTION (gtk_file_selection_new (_("Select file."))); gtk_file_selection_set_filename (selector, text); gtk_signal_connect (GTK_OBJECT (selector->ok_button), @@ -1095,7 +1232,7 @@ de_stringify (char *s) static char * format_switch (parameter *p, const char *value) { - char *fmt = p->arg; + char *fmt = (char *) p->arg; char *v2; char *result, *s; if (!fmt || !value) return 0; @@ -1127,7 +1264,7 @@ parameter_to_switch (parameter *p) { case COMMAND: if (p->arg) - return strdup (p->arg); + return strdup ((char *) p->arg); else return 0; break; @@ -1138,7 +1275,7 @@ parameter_to_switch (parameter *p) const char *s = gtk_entry_get_text (GTK_ENTRY (p->widget)); char *v; if (!strcmp ((s ? s : ""), - (p->string ? p->string : ""))) + (p->string ? (char *) p->string : ""))) v = 0; /* same as default */ else v = format_switch (p, s); @@ -1157,14 +1294,14 @@ parameter_to_switch (parameter *p) char buf[255]; char *s1; float value = (p->invert_p - ? invert_range (adj->lower, adj->upper, adj->value) + ? invert_range (adj->lower, adj->upper, adj->value) - 1 : adj->value); if (value == p->value) /* same as default */ return 0; if (p->integer_p) - sprintf (buf, "%d", (int) (value + 0.5)); + sprintf (buf, "%d", (int) (value + (value > 0 ? 0.5 : -0.5))); else sprintf (buf, "%.4f", value); @@ -1184,8 +1321,8 @@ parameter_to_switch (parameter *p) { GtkToggleButton *b = GTK_TOGGLE_BUTTON (p->widget); const char *s = (gtk_toggle_button_get_active (b) - ? p->arg_set - : p->arg_unset); + ? (char *) p->arg_set + : (char *) p->arg_unset); if (s) return strdup (s); else @@ -1204,7 +1341,7 @@ parameter_to_switch (parameter *p) const char *s; if (!o) abort(); if (o->type != SELECT_OPTION) abort(); - s = o->arg_set; + s = (char *) o->arg_set; if (s) return strdup (s); else @@ -1330,7 +1467,7 @@ parse_command_line_into_parameters (const char *filename, char *option = rest->data; rest->data = 0; - if (option[0] != '-') + if (option[0] != '-' && option[0] != '+') { if (debug_p) fprintf (stderr, "%s: WARNING: %s: not a switch: \"%s\"\n", @@ -1403,8 +1540,8 @@ parse_command_line_into_parameters_1 (const char *filename, { GList *p; parameter *match = 0; - int which = -1; - int index = 0; + gint which = -1; + gint index = 0; for (p = parms; p; p = p->next) { @@ -1424,7 +1561,7 @@ parse_command_line_into_parameters_1 (const char *filename, } else if (pp->arg) { - if (compare_opts (option, value, pp->arg)) + if (compare_opts (option, value, (char *) pp->arg)) { which = -1; match = pp; @@ -1432,7 +1569,7 @@ parse_command_line_into_parameters_1 (const char *filename, } else if (pp->arg_set) { - if (compare_opts (option, value, pp->arg_set)) + if (compare_opts (option, value, (char *) pp->arg_set)) { which = 1; match = pp; @@ -1440,7 +1577,7 @@ parse_command_line_into_parameters_1 (const char *filename, } else if (pp->arg_unset) { - if (compare_opts (option, value, pp->arg_unset)) + if (compare_opts (option, value, (char *) pp->arg_unset)) { which = 0; match = pp; @@ -1472,11 +1609,11 @@ parse_command_line_into_parameters_1 (const char *filename, break; case BOOLEAN: if (which != 0 && which != 1) abort(); - parameter_set_switch (match, (gpointer) which); + parameter_set_switch (match, GINT_TO_POINTER(which)); break; case SELECT_OPTION: if (which != 1) abort(); - parameter_set_switch (parent, (gpointer) index); + parameter_set_switch (parent, GINT_TO_POINTER(index)); break; default: break; @@ -1515,7 +1652,7 @@ parameter_set_switch (parameter *p, gpointer value) if (1 == sscanf ((char *) value, "%f %c", &f, &c)) { if (p->invert_p) - f = invert_range (adj->lower, adj->upper, f); + f = invert_range (adj->lower, adj->upper, f) - 1; gtk_adjustment_set_value (adj, f); } break; @@ -1523,13 +1660,13 @@ parameter_set_switch (parameter *p, gpointer value) case BOOLEAN: { GtkToggleButton *b = GTK_TOGGLE_BUTTON (p->widget); - gtk_toggle_button_set_active (b, (int) value); + gtk_toggle_button_set_active (b, GPOINTER_TO_INT(value)); break; } case SELECT: { gtk_option_menu_set_history (GTK_OPTION_MENU (p->widget), - (int) value); + GPOINTER_TO_INT(value)); break; } default: @@ -1551,7 +1688,7 @@ restore_defaults (const char *progname, GList *parms) case FILENAME: { gtk_entry_set_text (GTK_ENTRY (p->widget), - (p->string ? p->string : "")); + (p->string ? (char *) p->string : "")); break; } case SLIDER: @@ -1612,7 +1749,7 @@ restore_defaults (const char *progname, GList *parms) */ static char * -get_description (GList *parms) +get_description (GList *parms, gboolean verbose_p) { parameter *doc = 0; for (; parms; parms = parms->next) @@ -1629,8 +1766,9 @@ get_description (GList *parms) return 0; else { - char *d = strdup (doc->string); + char *d = strdup ((char *) doc->string); char *s; + char *p; for (s = d; *s; s++) if (s[0] == '\n') { @@ -1657,7 +1795,27 @@ get_description (GList *parms) d[--L] = 0; } - return d; + /* strip off duplicated whitespaces */ + for (s = d; *s; s++) + if (s[0] == ' ') + { + p = s+1; + while (*s == ' ') + s++; + if (*p && (s != p)) + memmove (p, s, strlen(s)+1); + } + +#if 0 + if (verbose_p) + { + fprintf (stderr, "%s: text read is \"%s\"\n", blurb(),doc->string); + fprintf (stderr, "%s: description is \"%s\"\n", blurb(), d); + fprintf (stderr, "%s: translation is \"%s\"\n", blurb(), _(d)); + } +#endif /* 0 */ + + return (d); } } @@ -1669,17 +1827,27 @@ static conf_data * load_configurator_1 (const char *program, const char *arguments, gboolean verbose_p) { - const char *dir = HACK_CONFIGURATION_PATH; + const char *dir = hack_configuration_path; + char *base_program; int L = strlen (dir); - char *file = (char *) malloc (L + strlen (program) + 10); + char *file; char *s; FILE *f; - conf_data *data = (conf_data *) calloc (1, sizeof(*data)); + conf_data *data; + + if (L == 0) return 0; + + base_program = strrchr(program, '/'); + if (base_program) base_program++; + if (!base_program) base_program = (char *) program; + + file = (char *) malloc (L + strlen (base_program) + 10); + data = (conf_data *) calloc (1, sizeof(*data)); strcpy (file, dir); if (file[L-1] != '/') file[L++] = '/'; - strcpy (file+L, program); + strcpy (file+L, base_program); for (s = file+L; *s; s++) if (*s == '/' || *s == ' ') @@ -1703,7 +1871,12 @@ load_configurator_1 (const char *program, const char *arguments, fprintf (stderr, "%s: reading %s...\n", blurb(), file); res = fread (chars, 1, 4, f); - if (res <= 0) return 0; + if (res <= 0) + { + free (data); + data = 0; + goto DONE; + } ctxt = xmlCreatePushParserCtxt(NULL, NULL, chars, res, file); while ((res = fread(chars, 1, size, f)) > 0) @@ -1721,7 +1894,8 @@ load_configurator_1 (const char *program, const char *arguments, gtk_container_set_border_width (GTK_CONTAINER (table), 8); gtk_widget_show (table); - parms = make_parameters (file, doc->root, table); + parms = make_parameters (file, doc->xmlRootNode, table); + sanity_check_parameters (file, parms); xmlFreeDoc (doc); @@ -1731,7 +1905,7 @@ load_configurator_1 (const char *program, const char *arguments, data->widget = table; data->parameters = parms; - data->description = get_description (parms); + data->description = get_description (parms, verbose_p); } else { @@ -1742,12 +1916,15 @@ load_configurator_1 (const char *program, const char *arguments, p = calloc (1, sizeof(*p)); p->type = COMMAND; - p->arg = strdup (arguments); + p->arg = (xmlChar *) strdup (arguments); data->parameters = g_list_append (0, (gpointer) p); } data->progname = strdup (program); + + DONE: + free (file); return data; } @@ -1793,6 +1970,7 @@ load_configurator (const char *full_command_line, gboolean verbose_p) char *prog; char *args; conf_data *cd; + debug_p = verbose_p; split_command_line (full_command_line, &prog, &args); cd = load_configurator_1 (prog, args, verbose_p); free (prog); @@ -1848,7 +2026,9 @@ free_conf_data (conf_data *data) gtk_widget_destroy (data->widget); if (data->progname) - free (data->progname);; + free (data->progname); + if (data->description) + free (data->description); memset (data, ~0, sizeof(*data)); free (data);