+Sat Dec 9 20:02:25 2006 Ben Pfaff <blp@gnu.org>
+
+ * format.c (fmt_dollar_template): New function, based on
+ dollar_format_template from var-type-dialog.c.
+
Sat Dec 9 18:05:59 2006 Ben Pfaff <blp@gnu.org>
* data-out.c (output_scientific): Fix bad assumption that "buf" is
NOT_REACHED ();
}
}
+
+/* Returns a string of the form "$#,###.##" according to FMT,
+ which must be of type FMT_DOLLAR. The caller must free the
+ string. */
+char *
+fmt_dollar_template (const struct fmt_spec *fmt)
+{
+ struct string s = DS_EMPTY_INITIALIZER;
+ int c;
+
+ ds_put_char (&s, '$');
+ for (c = MAX (fmt->w - fmt->d - 1, 0); c > 0; )
+ {
+ ds_put_char (&s, '#');
+ if (--c % 4 == 0 && c > 0)
+ {
+ ds_put_char (&s, fmt_grouping_char (fmt->type));
+ --c;
+ }
+ }
+ if (fmt->d > 0)
+ {
+ ds_put_char (&s, '.');
+ ds_put_char_multiple (&s, '#', fmt->d);
+ }
+
+ return ds_cstr (&s);
+}
\f
/* Returns true if TYPE is a valid format type,
false otherwise. */
bool fmt_usable_for_input (enum fmt_type) PURE_FUNCTION;
const char *fmt_date_template (enum fmt_type) PURE_FUNCTION;
+char *fmt_dollar_template (const struct fmt_spec *);
\f
/* Maximum length of prefix or suffix string in
struct fmt_number_style. */
+Sat Dec 9 20:03:04 2006 Ben Pfaff <blp@gnu.org>
+
+ * var-type-dialog.c (var_type_dialog_create): Use
+ fmt_dollar_template from data/format.c.
+ (dollar_format_template) Removed.
+
Sat Dec 9 07:19:53 WST 2006 John Darrington <john@darrington.wattle.id.au>
* syntax-editor.c : New file.
#define LEN 20
-/* return a string of the form "$#,###.##" according to FMT.
- FMT must be of type FMT_DOLLAR
- */
-static const gchar *
-dollar_format_template(const struct fmt_spec *fmt)
-{
- static gchar buf[LEN];
- g_assert( fmt->type == FMT_DOLLAR);
-
- {
- gint c ;
- gint int_part = fmt->w - fmt->d;
- if ( fmt->d > 0 ) --int_part;
- g_assert(int_part > 0);
-
- g_strlcpy(buf, "$", LEN);
-
- c = int_part - 1;
- while(c > 0)
- {
- g_strlcat(buf, "#", LEN);
- if(--c % 4 == 0 && c > 0 )
- {
- g_strlcat(buf, ",", LEN);
- --c;
- }
- }
- if ( fmt->d > 0 )
- {
- g_strlcat(buf, ".", LEN);
- for ( c = 0 ; c < fmt->d ; ++c )
- g_strlcat(buf, "#", LEN);
- }
- }
-
- return buf;
-}
-
static void
add_to_group(GtkWidget *w, gpointer data)
{
for ( i = 0 ; i < sizeof(dollar_format)/sizeof(dollar_format[0]) ; ++i )
{
+ char *template = fmt_dollar_template (&dollar_format[i]);
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
- 0, dollar_format_template(&dollar_format[i]),
+ 0, template,
1, &dollar_format[i],
-1);
+ free (template);
}
gtk_tree_view_set_model(GTK_TREE_VIEW(dialog->dollar_treeview),