From a4ac3b968fb4e84b7aa428342010c1f439f9f301 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 25 Dec 2012 11:49:35 +0100 Subject: [PATCH] Count Dialog and Recode Dialog: Make syntax generation locale independent --- src/ui/gui/count-dialog.c | 41 ++++++++++----------- src/ui/gui/psppire-val-chooser.c | 20 +++++------ src/ui/gui/psppire-val-chooser.h | 3 +- src/ui/gui/recode-dialog.c | 61 +++++++++++++++----------------- 4 files changed, 60 insertions(+), 65 deletions(-) diff --git a/src/ui/gui/count-dialog.c b/src/ui/gui/count-dialog.c index b0d417f8eb..0aa798b2d9 100644 --- a/src/ui/gui/count-dialog.c +++ b/src/ui/gui/count-dialog.c @@ -237,17 +237,19 @@ generate_syntax (const struct cnt_dialog *cnt) const gchar *s = NULL; gboolean ok; GtkTreeIter iter; - GString *str = g_string_sized_new (100); + struct string dds; + + ds_init_empty (&dds); - g_string_append (str, "\nCOUNT "); + ds_put_cstr (&dds, "\nCOUNT "); - g_string_append (str, gtk_entry_get_text (GTK_ENTRY (cnt->target))); + ds_put_cstr (&dds, gtk_entry_get_text (GTK_ENTRY (cnt->target))); - g_string_append (str, " ="); + ds_put_cstr (&dds, " ="); - psppire_var_view_append_names (PSPPIRE_VAR_VIEW (cnt->variable_treeview), 0, str); + psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (cnt->variable_treeview), 0, &dds); - g_string_append (str, "("); + ds_put_cstr (&dds, "("); for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (cnt->value_list), &iter); ok; @@ -261,36 +263,31 @@ generate_syntax (const struct cnt_dialog *cnt) ov = g_value_get_boxed (&a_value); - g_string_append (str, " "); - old_value_append_syntax (str, ov); + ds_put_cstr (&dds, " "); + old_value_append_syntax (&dds, ov); } - g_string_append (str, ")."); + ds_put_cstr (&dds, ")."); s = gtk_entry_get_text (GTK_ENTRY (cnt->label)); if (0 != strcmp (s, "")) { - struct string ds; - ds_init_empty (&ds); - g_string_append (str, "\nVARIABLE LABELS "); + ds_put_cstr (&dds, "\nVARIABLE LABELS "); - g_string_append (str, gtk_entry_get_text (GTK_ENTRY (cnt->target))); + ds_put_cstr (&dds, gtk_entry_get_text (GTK_ENTRY (cnt->target))); - g_string_append (str, " "); + ds_put_cstr (&dds, " "); - syntax_gen_string (&ds, ss_cstr (s)); + syntax_gen_string (&dds, ss_cstr (s)); - g_string_append (str, ds_cstr (&ds)); - - g_string_append (str, "."); - ds_destroy (&ds); + ds_put_cstr (&dds, "."); } - g_string_append (str, "\nEXECUTE.\n"); + ds_put_cstr (&dds, "\nEXECUTE.\n"); - text = str->str; + text = ds_steal_cstr (&dds); - g_string_free (str, FALSE); + ds_destroy (&dds); return text; } diff --git a/src/ui/gui/psppire-val-chooser.c b/src/ui/gui/psppire-val-chooser.c index 01d694e27e..eb233b4ae5 100644 --- a/src/ui/gui/psppire-val-chooser.c +++ b/src/ui/gui/psppire-val-chooser.c @@ -543,46 +543,46 @@ old_value_get_type (void) /* Generate a syntax fragment for NV and append it to STR */ void -old_value_append_syntax (GString *str, const struct old_value *ov) +old_value_append_syntax (struct string *str, const struct old_value *ov) { switch (ov->type) { case OV_NUMERIC: - g_string_append_printf (str, "%g", ov->v.v); + ds_put_c_format (str, "%g", ov->v.v); break; case OV_STRING: { struct string ds = DS_EMPTY_INITIALIZER; syntax_gen_string (&ds, ss_cstr (ov->v.s)); - g_string_append (str, ds_cstr (&ds)); + ds_put_cstr (str, ds_cstr (&ds)); ds_destroy (&ds); } break; case OV_MISSING: - g_string_append (str, "MISSING"); + ds_put_cstr (str, "MISSING"); break; case OV_SYSMIS: - g_string_append (str, "SYSMIS"); + ds_put_cstr (str, "SYSMIS"); break; case OV_ELSE: - g_string_append (str, "ELSE"); + ds_put_cstr (str, "ELSE"); break; case OV_RANGE: - g_string_append_printf (str, "%g THRU %g", + ds_put_c_format (str, "%g THRU %g", ov->v.range[0], ov->v.range[1]); break; case OV_LOW_UP: - g_string_append_printf (str, "LOWEST THRU %g", + ds_put_c_format (str, "LOWEST THRU %g", ov->v.range[1]); break; case OV_HIGH_DOWN: - g_string_append_printf (str, "%g THRU HIGHEST", + ds_put_c_format (str, "%g THRU HIGHEST", ov->v.range[0]); break; default: g_warning ("Invalid type in old recode value"); - g_string_append (str, "???"); + ds_put_cstr (str, "???"); break; }; } diff --git a/src/ui/gui/psppire-val-chooser.h b/src/ui/gui/psppire-val-chooser.h index 5c8175bae3..0f487a45db 100644 --- a/src/ui/gui/psppire-val-chooser.h +++ b/src/ui/gui/psppire-val-chooser.h @@ -95,7 +95,8 @@ struct old_value GType old_value_get_type (void); -void old_value_append_syntax (GString *str, const struct old_value *ov); +struct string; +void old_value_append_syntax (struct string *str, const struct old_value *ov); void psppire_val_chooser_get_status (PsppireValChooser *vr, struct old_value *ov); void psppire_val_chooser_set_status (PsppireValChooser *vr, const struct old_value *ov); diff --git a/src/ui/gui/recode-dialog.c b/src/ui/gui/recode-dialog.c index 73787b4051..a94d4522bc 100644 --- a/src/ui/gui/recode-dialog.c +++ b/src/ui/gui/recode-dialog.c @@ -955,31 +955,26 @@ run_old_and_new_dialog (struct recode_dialog *rd) /* Generate a syntax fragment for NV and append it to STR */ static void -new_value_append_syntax (GString *str, const struct new_value *nv) +new_value_append_syntax (struct string *dds, const struct new_value *nv) { switch (nv->type) { case NV_NUMERIC: - g_string_append_printf (str, "%g", nv->v.v); + ds_put_c_format (dds, "%g", nv->v.v); break; case NV_STRING: - { - struct string ds = DS_EMPTY_INITIALIZER; - syntax_gen_string (&ds, ss_cstr (nv->v.s)); - g_string_append (str, ds_cstr (&ds)); - ds_destroy (&ds); - } + syntax_gen_string (dds, ss_cstr (nv->v.s)); break; case NV_COPY: - g_string_append (str, "COPY"); + ds_put_cstr (dds, "COPY"); break; case NV_SYSMIS: - g_string_append (str, "SYSMIS"); + ds_put_cstr (dds, "SYSMIS"); break; default: /* Shouldn't ever happen */ g_warning ("Invalid type in new recode value"); - g_string_append (str, "???"); + ds_put_cstr (dds, "???"); break; } } @@ -991,8 +986,10 @@ generate_syntax (const struct recode_dialog *rd) gboolean ok; GtkTreeIter iter; gchar *text; + struct string dds; + + ds_init_empty (&dds); - GString *str = g_string_sized_new (100); /* Declare new string variables if applicable */ if ( rd->different && @@ -1006,24 +1003,24 @@ generate_syntax (const struct recode_dialog *rd) g_hash_table_iter_init (&iter, rd->varmap); while (g_hash_table_iter_next (&iter, (void**) &var, (void**) &nlp)) { - g_string_append (str, "\nSTRING "); - g_string_append (str, nlp->name); - g_string_append_printf (str, " (A%d).", + ds_put_cstr (&dds, "\nSTRING "); + ds_put_cstr (&dds, nlp->name); + ds_put_c_format (&dds, " (A%d).", (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON (rd->width_entry) ) ); } } - g_string_append (str, "\nRECODE "); + ds_put_cstr (&dds, "\nRECODE "); - psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, str); + psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (rd->variable_treeview), 0, &dds); - g_string_append (str, "\n\t"); + ds_put_cstr (&dds, "\n\t"); if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->convert_button))) { - g_string_append (str, "(CONVERT) "); + ds_put_cstr (&dds, "(CONVERT) "); } for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (rd->value_map), @@ -1044,13 +1041,13 @@ generate_syntax (const struct recode_dialog *rd) ov = g_value_get_boxed (&ov_value); nv = g_value_get_boxed (&nv_value); - g_string_append (str, "("); + ds_put_cstr (&dds, "("); - old_value_append_syntax (str, ov); - g_string_append (str, " = "); - new_value_append_syntax (str, nv); + old_value_append_syntax (&dds, ov); + ds_put_cstr (&dds, " = "); + new_value_append_syntax (&dds, nv); - g_string_append (str, ") "); + ds_put_cstr (&dds, ") "); g_value_unset (&ov_value); g_value_unset (&nv_value); } @@ -1060,7 +1057,7 @@ generate_syntax (const struct recode_dialog *rd) { GtkTreeIter iter; - g_string_append (str, "\n\tINTO "); + ds_put_cstr (&dds, "\n\tINTO "); for (ok = psppire_var_view_get_iter_first (PSPPIRE_VAR_VIEW (rd->variable_treeview), &iter); ok; @@ -1071,12 +1068,12 @@ generate_syntax (const struct recode_dialog *rd) nlp = g_hash_table_lookup (rd->varmap, var); - g_string_append (str, nlp->name); - g_string_append (str, " "); + ds_put_cstr (&dds, nlp->name); + ds_put_cstr (&dds, " "); } } - g_string_append (str, "."); + ds_put_cstr (&dds, "."); /* If applicable, set labels for the new variables. */ if ( rd->different ) @@ -1094,7 +1091,7 @@ generate_syntax (const struct recode_dialog *rd) struct string sl; ds_init_empty (&sl); syntax_gen_string (&sl, ss_cstr (nlp->label)); - g_string_append_printf (str, "\nVARIABLE LABELS %s %s.", + ds_put_c_format (&dds, "\nVARIABLE LABELS %s %s.", nlp->name, ds_cstr (&sl)); ds_destroy (&sl); @@ -1102,12 +1099,12 @@ generate_syntax (const struct recode_dialog *rd) } } - g_string_append (str, "\nEXECUTE.\n"); + ds_put_cstr (&dds, "\nEXECUTE.\n"); - text = str->str; + text = ds_steal_cstr (&dds); - g_string_free (str, FALSE); + ds_destroy (&dds); return text; } -- 2.30.2