pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

%'d bug fixed


From: Ben Pfaff
Subject: %'d bug fixed
Date: Sat, 07 Jul 2012 11:41:04 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

I pushed the following commit to resolve a problem you reported
with %'d on Windows.  Let me know if you see any problem with it.

Thanks,

Ben.

--8<--------------------------cut here-------------------------->8--

From: Ben Pfaff <address@hidden>
Date: Sat, 7 Jul 2012 11:39:47 -0700
Subject: [PATCH] psppire-data-editor: Avoid ' modifier with 
g_string_append_printf().

On Windows, g_string_append_printf() does not understand the '
modifier, so use ds_put_format() instead, which does.

Reported by John Darrington.
---
 src/libpspp/str.c                |    7 +++++++
 src/libpspp/str.h                |    3 ++-
 src/ui/gui/psppire-data-editor.c |   31 ++++++++++++++++---------------
 3 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/libpspp/str.c b/src/libpspp/str.c
index 79e9ea1..44e4a1d 100644
--- a/src/libpspp/str.c
+++ b/src/libpspp/str.c
@@ -1548,6 +1548,13 @@ ds_put_byte_multiple (struct string *st, int ch, size_t 
cnt)
   memset (ds_put_uninit (st, cnt), ch, cnt);
 }
 
+/* Appends Unicode code point UC to ST in UTF-8 encoding. */
+void
+ds_put_unichar (struct string *st, ucs4_t uc)
+{
+  ds_extend (st, ds_length (st) + 6);
+  st->ss.length += u8_uctomb (CHAR_CAST (uint8_t *, ds_end (st)), uc, 6);
+}
 
 /* If relocation has been enabled, replace ST,
    with its relocated version */
diff --git a/src/libpspp/str.h b/src/libpspp/str.h
index c8ab726..e017696 100644
--- a/src/libpspp/str.h
+++ b/src/libpspp/str.h
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 Free Software 
Foundation, Inc.
 
    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
@@ -223,6 +223,7 @@ bool ds_read_stream (struct string *, size_t size, size_t 
cnt, FILE *stream);
 /* Append. */
 void ds_put_byte (struct string *, int ch);
 void ds_put_byte_multiple (struct string *, int ch, size_t);
+void ds_put_unichar (struct string *, ucs4_t uc);
 void ds_put_cstr (struct string *, const char *);
 void ds_put_substring (struct string *, struct substring);
 void ds_put_vformat (struct string *st, const char *, va_list)
diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c
index b5f2273..5fb04b7 100644
--- a/src/ui/gui/psppire-data-editor.c
+++ b/src/ui/gui/psppire-data-editor.c
@@ -24,6 +24,7 @@
 #include "data/datasheet.h"
 #include "data/value-labels.h"
 #include "libpspp/range-set.h"
+#include "libpspp/str.h"
 #include "ui/gui/helper.h"
 #include "ui/gui/pspp-sheet-selection.h"
 #include "ui/gui/psppire-data-sheet.h"
@@ -427,21 +428,21 @@ refresh_entry (PsppireDataEditor *de)
         }
       else
         {
-          GString *string;
-
-          string = g_string_sized_new (25);
-          g_string_append_printf (string,
-                                  ngettext ("%'d case", "%'d cases", n_cases),
-                                  n_cases);
-          g_string_append_c (string, ' ');
-          g_string_append_unichar (string, 0xd7); /* U+00D7 MULTIPLICATION 
SIGN */
-          g_string_append_c (string, ' ');
-          g_string_append_printf (string,
-                                  ngettext ("%'d variable", "%'d variables",
-                                            n_vars),
-                                  n_vars);
-          ref_cell_text = string->str;
-          g_string_free (string, FALSE);
+          struct string s;
+
+          /* The glib string library does not understand the ' printf modifier
+             on all platforms, but the "struct string" library does (because
+             Gnulib fixes that problem), so use the latter.  */
+          ds_init_empty (&s);
+          ds_put_format (&s, ngettext ("%'d case", "%'d cases", n_cases),
+                         n_cases);
+          ds_put_byte (&s, ' ');
+          ds_put_unichar (&s, 0xd7); /* U+00D7 MULTIPLICATION SIGN */
+          ds_put_byte (&s, ' ');
+          ds_put_format (&s, ngettext ("%'d variable", "%'d variables",
+                                       n_vars),
+                         n_vars);
+          ref_cell_text = ds_steal_cstr (&s);
         }
 
       psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (de->datum_entry),
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]