Check to see if GLib's printf routines support the X/Open / POSIX
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 3 Mar 2013 19:34:58 +0000 (19:34 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 3 Mar 2013 19:34:58 +0000 (19:34 +0000)
thousands grouping (') flag and use it in format_size if it's available.
As far as I can tell this translates to "everywhere except Windows and
OpenBSD". According to the various build logs at

https://build.opensuse.org/package/show?package=mingw32-glib2&project=windows%3Amingw%3Awin32

the OBS GLib packages enable GLib's internal printf implementation from
Gnulib which means we *should* be able to enable this on Windows.
Unfortunately this doesn't appear to be the case.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@48042 f5534014-38df-0310-8fa8-9805f1628bb7

config.h.win32
configure.ac
wsutil/str_util.c

index c10c89e5334ef3b782dda8077c18b282e26258f7..8a32639559c99c445cca2f8d319d13a50a73f9b2 100644 (file)
 /* Define if you have the <netinet/in.h> header file.  */
 /* #define HAVE_NETINET_IN_H 1 */
 
+/* Define if your printf() function supports thousands grouping. */
+/* #undef HAVE_GLIB_PRINTF_GROUPING */
+
 /* Define if you have the <snmp/snmp.h> header file.  */
 /* #undef HAVE_SNMP_SNMP_H */
 
index 2d8d9f2465f3bb8ef40e30f685cad4116146d3cd..c9f8818444097cd72c05b32feb8e625addbdb752 100644 (file)
@@ -1245,6 +1245,42 @@ main(void)
        AC_MSG_RESULT($ac_cv_dladdr_finds_executable_path)
 fi
 
+#
+# Check whether GLib's printf supports thousands grouping. (This might
+# be different from the system's printf since GLib can optionally use
+# its own printf implementation.)
+#
+AC_MSG_CHECKING(whether GLib supports POSIX/XSI thousands grouping)
+ac_save_CFLAGS="$CFLAGS"
+ac_save_LIBS="$LIBS"
+CFLAGS="$CFLAGS $GLIB_CFLAGS"
+LIBS="$GLIB_LIBS $LIBS"
+AC_TRY_RUN([
+#include <glib.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+int
+main ()
+{
+  gchar *str;
+  setlocale(LC_ALL, "en_US.UTF-8");
+  str = g_strdup_printf("%'u", 123456);
+  return (strcmp (str, "123,456") != 0);
+}
+], ac_cv_glib_supports_printf_grouping=yes, ac_cv_glib_supports_printf_grouping=no,
+   [echo $ac_n "cross compiling; playing it safe... $ac_c"
+    ac_cv_glib_supports_printf_grouping=no])
+CFLAGS="$ac_save_CFLAGS"
+LIBS="$ac_save_LIBS"
+if test "$ac_cv_glib_supports_printf_grouping" = yes ; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(HAVE_GLIB_PRINTF_GROUPING, 1, [Define if your printf() function supports thousands grouping.])
+else
+  AC_MSG_RESULT(no)
+fi
+
 if test "x$have_gtk" = "xyes"
 then
     #
index f2de5bfbee063b3ebf6293fa7e18066fd68c1b3a..c75442353630302140f4b20d6cfcde331b0e180c 100644 (file)
@@ -92,6 +92,12 @@ isdigit_string(guchar *str)
 #define FORMAT_SIZE_UNIT_MASK 0x00ff
 #define FORMAT_SIZE_PFX_MASK 0xff00
 
+#ifdef HAVE_GLIB_PRINTF_GROUPING
+#define GROUP_FLAG "'"
+#else
+#define GROUP_FLAG ""
+#endif
+
 /* Given a size, return its value in a human-readable format */
 gchar *format_size(gint64 size, format_size_flags_e flags) {
        GString *human_str = g_string_new("");
@@ -107,15 +113,15 @@ gchar *format_size(gint64 size, format_size_flags_e flags) {
        }
 
         if (size / power / power / power / power >= 10) {
-               g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power / power / power / power, prefix[pfx_off]);
+               g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power / power / power / power, prefix[pfx_off]);
        } else if (size / power / power / power >= 10) {
-               g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power / power / power, prefix[pfx_off+1]);
+               g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power / power / power, prefix[pfx_off+1]);
        } else if (size / power / power >= 10) {
-               g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power / power, prefix[pfx_off+2]);
+               g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power / power, prefix[pfx_off+2]);
        } else if (size / power >= 10) {
-               g_string_printf(human_str, "%" G_GINT64_MODIFIER "d %s", size / power, prefix[pfx_off+3]);
+               g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d %s", size / power, prefix[pfx_off+3]);
         } else {
-               g_string_printf(human_str, "%" G_GINT64_MODIFIER "d ", size);
+               g_string_printf(human_str, "%" GROUP_FLAG G_GINT64_MODIFIER "d ", size);
                is_small = TRUE;
        }