Add a test for positional parameters in g_snprintf(). Use g_printf()
authorMatthias Clasen <matthiasc@src.gnome.org>
Thu, 12 Dec 2002 23:52:29 +0000 (23:52 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 12 Dec 2002 23:52:29 +0000 (23:52 +0000)
* tests/string-test.c: Add a test for positional parameters in
g_snprintf().
* glib-genmarshal.c, gobject-query.c: Use g_printf() instead of
system printf.  (#99319)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gobject/ChangeLog
gobject/glib-genmarshal.c
gobject/gobject-query.c
tests/string-test.c

index 4d76e6ac715153fc55e52c7b413e0bd5f7992db9..8fdb5c47f92bfbf60f9f25d82fa6288b1830c7e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/string-test.c: Add a test for positional parameters in
+       g_snprintf().
+
 Thu Dec 12 14:58:55 2002  Manish Singh  <yosh@gimp.org>
 
        * configure.in: pull in trio if host printf doesn't have a known
index 4d76e6ac715153fc55e52c7b413e0bd5f7992db9..8fdb5c47f92bfbf60f9f25d82fa6288b1830c7e8 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/string-test.c: Add a test for positional parameters in
+       g_snprintf().
+
 Thu Dec 12 14:58:55 2002  Manish Singh  <yosh@gimp.org>
 
        * configure.in: pull in trio if host printf doesn't have a known
index 4d76e6ac715153fc55e52c7b413e0bd5f7992db9..8fdb5c47f92bfbf60f9f25d82fa6288b1830c7e8 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/string-test.c: Add a test for positional parameters in
+       g_snprintf().
+
 Thu Dec 12 14:58:55 2002  Manish Singh  <yosh@gimp.org>
 
        * configure.in: pull in trio if host printf doesn't have a known
index 4d76e6ac715153fc55e52c7b413e0bd5f7992db9..8fdb5c47f92bfbf60f9f25d82fa6288b1830c7e8 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/string-test.c: Add a test for positional parameters in
+       g_snprintf().
+
 Thu Dec 12 14:58:55 2002  Manish Singh  <yosh@gimp.org>
 
        * configure.in: pull in trio if host printf doesn't have a known
index 4d76e6ac715153fc55e52c7b413e0bd5f7992db9..8fdb5c47f92bfbf60f9f25d82fa6288b1830c7e8 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/string-test.c: Add a test for positional parameters in
+       g_snprintf().
+
 Thu Dec 12 14:58:55 2002  Manish Singh  <yosh@gimp.org>
 
        * configure.in: pull in trio if host printf doesn't have a known
index 4d76e6ac715153fc55e52c7b413e0bd5f7992db9..8fdb5c47f92bfbf60f9f25d82fa6288b1830c7e8 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/string-test.c: Add a test for positional parameters in
+       g_snprintf().
+
 Thu Dec 12 14:58:55 2002  Manish Singh  <yosh@gimp.org>
 
        * configure.in: pull in trio if host printf doesn't have a known
index 4d76e6ac715153fc55e52c7b413e0bd5f7992db9..8fdb5c47f92bfbf60f9f25d82fa6288b1830c7e8 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/string-test.c: Add a test for positional parameters in
+       g_snprintf().
+
 Thu Dec 12 14:58:55 2002  Manish Singh  <yosh@gimp.org>
 
        * configure.in: pull in trio if host printf doesn't have a known
index 198be61b4f62fd34a6c0c30b1f0a2d98248e1f5c..a3aa8ad740c2e555ed0b63cb4c1e51e4311fbab8 100644 (file)
@@ -1,3 +1,8 @@
+2002-12-13  Matthias Clasen  <maclas@gmx.de>
+
+       * glib-genmarshal.c, gobject-query.c: Use g_printf() instead of 
+       system printf.  (#99319)
+
 Thu Dec 12 15:00:10 2002  Manish Singh  <yosh@gimp.org>
 
        * gvaluetransform.c: use G_G[U]INT64_FORMAT unconditionally,
index 8d8393e3dad15ed4445a5f2eda4d6f9d401d2b60..24dd495e39f4afcdcfa15309df30a3bda267a5bb 100644 (file)
@@ -22,7 +22,7 @@
 #define G_LOG_DOMAIN "GLib-Genmarshal"
 #include       <glib.h>
 
-#include       <stdio.h>
+#include       <glib/gprintf.h>
 #include       <stdlib.h>
 #include       <fcntl.h>
 #include       <string.h>
@@ -352,57 +352,57 @@ generate_marshal (const gchar *signame,
 
   if (gen_cheader && have_std_marshaller)
     {
-      fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, signame, std_marshaller_prefix, signame);
+      g_fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, signame, std_marshaller_prefix, signame);
     }
   if (gen_cheader && !have_std_marshaller)
     {
-      ind = fprintf (fout, "extern void ");
-      ind += fprintf (fout, "%s_%s (", marshaller_prefix, signame);
-      fprintf (fout,   "GClosure     *closure,\n");
-      fprintf (fout, "%sGValue       *return_value,\n", indent (ind));
-      fprintf (fout, "%sguint         n_param_values,\n", indent (ind));
-      fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
-      fprintf (fout, "%sgpointer      invocation_hint,\n", indent (ind));
-      fprintf (fout, "%sgpointer      marshal_data);\n", indent (ind));
+      ind = g_fprintf (fout, "extern void ");
+      ind += g_fprintf (fout, "%s_%s (", marshaller_prefix, signame);
+      g_fprintf (fout,   "GClosure     *closure,\n");
+      g_fprintf (fout, "%sGValue       *return_value,\n", indent (ind));
+      g_fprintf (fout, "%sguint         n_param_values,\n", indent (ind));
+      g_fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
+      g_fprintf (fout, "%sgpointer      invocation_hint,\n", indent (ind));
+      g_fprintf (fout, "%sgpointer      marshal_data);\n", indent (ind));
     }
   if (gen_cbody && !have_std_marshaller)
     {
       /* cfile marhsal header */
-      fprintf (fout, "void\n");
-      ind = fprintf (fout, "%s_%s (", marshaller_prefix, signame);
-      fprintf (fout,   "GClosure     *closure,\n");
-      fprintf (fout, "%sGValue       *return_value,\n", indent (ind));
-      fprintf (fout, "%sguint         n_param_values,\n", indent (ind));
-      fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
-      fprintf (fout, "%sgpointer      invocation_hint,\n", indent (ind));
-      fprintf (fout, "%sgpointer      marshal_data)\n", indent (ind));
-      fprintf (fout, "{\n");
+      g_fprintf (fout, "void\n");
+      ind = g_fprintf (fout, "%s_%s (", marshaller_prefix, signame);
+      g_fprintf (fout,   "GClosure     *closure,\n");
+      g_fprintf (fout, "%sGValue       *return_value,\n", indent (ind));
+      g_fprintf (fout, "%sguint         n_param_values,\n", indent (ind));
+      g_fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
+      g_fprintf (fout, "%sgpointer      invocation_hint,\n", indent (ind));
+      g_fprintf (fout, "%sgpointer      marshal_data)\n", indent (ind));
+      g_fprintf (fout, "{\n");
 
       /* cfile GMarshalFunc typedef */
-      ind = fprintf (fout, "  typedef %s (*GMarshalFunc_%s) (", sig->rarg->ctype, signame);
-      fprintf (fout, "%s data1,\n", pad ("gpointer"));
+      ind = g_fprintf (fout, "  typedef %s (*GMarshalFunc_%s) (", sig->rarg->ctype, signame);
+      g_fprintf (fout, "%s data1,\n", pad ("gpointer"));
       for (a = 1, node = sig->args; node; node = node->next)
        {
          InArgument *iarg = node->data;
 
          if (iarg->getter)
-           fprintf (fout, "%s%s arg_%d,\n", indent (ind), pad (iarg->ctype), a++);
+           g_fprintf (fout, "%s%s arg_%d,\n", indent (ind), pad (iarg->ctype), a++);
        }
-      fprintf (fout, "%s%s data2);\n", indent (ind), pad ("gpointer"));
+      g_fprintf (fout, "%s%s data2);\n", indent (ind), pad ("gpointer"));
 
       /* cfile marshal variables */
-      fprintf (fout, "  register GMarshalFunc_%s callback;\n", signame);
-      fprintf (fout, "  register GCClosure *cc = (GCClosure*) closure;\n");
-      fprintf (fout, "  register gpointer data1, data2;\n");
+      g_fprintf (fout, "  register GMarshalFunc_%s callback;\n", signame);
+      g_fprintf (fout, "  register GCClosure *cc = (GCClosure*) closure;\n");
+      g_fprintf (fout, "  register gpointer data1, data2;\n");
       if (sig->rarg->setter)
-       fprintf (fout, "  %s v_return;\n", sig->rarg->ctype);
+       g_fprintf (fout, "  %s v_return;\n", sig->rarg->ctype);
 
       if (sig->args || sig->rarg->setter)
        {
-         fprintf (fout, "\n");
+         g_fprintf (fout, "\n");
 
          if (sig->rarg->setter)
-           fprintf (fout, "  g_return_if_fail (return_value != NULL);\n");
+           g_fprintf (fout, "  g_return_if_fail (return_value != NULL);\n");
          if (sig->args)
            {
              for (a = 0, node = sig->args; node; node = node->next)
@@ -412,43 +412,43 @@ generate_marshal (const gchar *signame,
                  if (iarg->getter)
                    a++;
                }
-             fprintf (fout, "  g_return_if_fail (n_param_values == %u);\n", 1 + a);
+             g_fprintf (fout, "  g_return_if_fail (n_param_values == %u);\n", 1 + a);
            }
        }
 
       /* cfile marshal data1, data2 and callback setup */
-      fprintf (fout, "\n");
-      fprintf (fout, "  if (G_CCLOSURE_SWAP_DATA (closure))\n    {\n");
-      fprintf (fout, "      data1 = closure->data;\n");
-      fprintf (fout, "      data2 = g_value_peek_pointer (param_values + 0);\n");
-      fprintf (fout, "    }\n  else\n    {\n");
-      fprintf (fout, "      data1 = g_value_peek_pointer (param_values + 0);\n");
-      fprintf (fout, "      data2 = closure->data;\n");
-      fprintf (fout, "    }\n");
-      fprintf (fout, "  callback = (GMarshalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame);
+      g_fprintf (fout, "\n");
+      g_fprintf (fout, "  if (G_CCLOSURE_SWAP_DATA (closure))\n    {\n");
+      g_fprintf (fout, "      data1 = closure->data;\n");
+      g_fprintf (fout, "      data2 = g_value_peek_pointer (param_values + 0);\n");
+      g_fprintf (fout, "    }\n  else\n    {\n");
+      g_fprintf (fout, "      data1 = g_value_peek_pointer (param_values + 0);\n");
+      g_fprintf (fout, "      data2 = closure->data;\n");
+      g_fprintf (fout, "    }\n");
+      g_fprintf (fout, "  callback = (GMarshalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame);
 
       /* cfile marshal callback action */
-      fprintf (fout, "\n");
-      ind = fprintf (fout, " %s callback (", sig->rarg->setter ? " v_return =" : "");
-      fprintf (fout, "data1,\n");
+      g_fprintf (fout, "\n");
+      ind = g_fprintf (fout, " %s callback (", sig->rarg->setter ? " v_return =" : "");
+      g_fprintf (fout, "data1,\n");
       for (a = 1, node = sig->args; node; node = node->next)
        {
          InArgument *iarg = node->data;
 
          if (iarg->getter)
-           fprintf (fout, "%s%s (param_values + %d),\n", indent (ind), iarg->getter, a++);
+           g_fprintf (fout, "%s%s (param_values + %d),\n", indent (ind), iarg->getter, a++);
        }
-      fprintf (fout, "%sdata2);\n", indent (ind));
+      g_fprintf (fout, "%sdata2);\n", indent (ind));
 
       /* cfile marshal return value storage */
       if (sig->rarg->setter)
        {
-         fprintf (fout, "\n");
-         fprintf (fout, "  %s (return_value, v_return);\n", sig->rarg->setter);
+         g_fprintf (fout, "\n");
+         g_fprintf (fout, "  %s (return_value, v_return);\n", sig->rarg->setter);
        }
 
       /* cfile marshal footer */
-      fprintf (fout, "}\n");
+      g_fprintf (fout, "}\n");
     }
 }
 
@@ -492,16 +492,16 @@ process_signature (Signature *sig)
     }
 
   /* introductionary comment */
-  fprintf (fout, "\n/* %s", sig->rarg->keyword);
+  g_fprintf (fout, "\n/* %s", sig->rarg->keyword);
   for (node = sig->args; node; node = node->next)
     {
       InArgument *iarg = node->data;
 
-      fprintf (fout, "%c%s", node->prev ? ',' : ':', iarg->keyword);
+      g_fprintf (fout, "%c%s", node->prev ? ',' : ':', iarg->keyword);
     }
   if (!skip_ploc)
-    fprintf (fout, " (%s)", sig->ploc);
-  fprintf (fout, " */\n");
+    g_fprintf (fout, " (%s)", sig->ploc);
+  g_fprintf (fout, " */\n");
 
   /* ensure technical marshaller exists (<marshaller_prefix>_<sname>) */
   generate_marshal (sname, sig);
@@ -510,7 +510,7 @@ process_signature (Signature *sig)
   tmp = g_strconcat (marshaller_prefix, "_", pname, NULL);
   if (gen_cheader && !g_hash_table_lookup (marshallers, tmp))
     {
-      fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, pname, marshaller_prefix, sname);
+      g_fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, pname, marshaller_prefix, sname);
 
       g_hash_table_insert (marshallers, tmp, tmp);
     }
@@ -630,19 +630,19 @@ main (int   argc,
       }
 
   /* put out initial heading */
-  fprintf (fout, "\n");
+  g_fprintf (fout, "\n");
 
   if (gen_cheader && std_includes)
     {
-      fprintf (fout, "#ifndef __%s_MARSHAL_H__\n", marshaller_prefix);
-      fprintf (fout, "#define __%s_MARSHAL_H__\n\n", marshaller_prefix);
+      g_fprintf (fout, "#ifndef __%s_MARSHAL_H__\n", marshaller_prefix);
+      g_fprintf (fout, "#define __%s_MARSHAL_H__\n\n", marshaller_prefix);
     }
 
   if ((gen_cheader || gen_cbody) && std_includes)
-    fprintf (fout, "#include\t<glib-object.h>\n\n");
+    g_fprintf (fout, "#include\t<glib-object.h>\n\n");
 
   if (gen_cheader)
-    fprintf (fout, "G_BEGIN_DECLS\n");
+    g_fprintf (fout, "G_BEGIN_DECLS\n");
 
   /* generate necessary preprocessor directives */
   if (gen_cbody)
@@ -730,12 +730,12 @@ main (int   argc,
   /* put out trailer */
   if (gen_cheader)
     {
-      fprintf (fout, "\nG_END_DECLS\n");
+      g_fprintf (fout, "\nG_END_DECLS\n");
 
       if (std_includes)
-       fprintf (fout, "\n#endif /* __%s_MARSHAL_H__ */\n", marshaller_prefix);
+       g_fprintf (fout, "\n#endif /* __%s_MARSHAL_H__ */\n", marshaller_prefix);
     }
-  fprintf (fout, "\n");
+  g_fprintf (fout, "\n");
 
   /* clean up */
   g_slist_free (files);
@@ -846,25 +846,25 @@ print_blurb (FILE    *bout,
 {
   if (!print_help)
     {
-      fprintf (bout, "%s version ", PRG_NAME);
-      fprintf (bout, "%u.%u.%u", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
-      fprintf (bout, "\n");
-      fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
-      fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
-      fprintf (bout, "the GNU General Public License which can be found in the\n");
-      fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
-      fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
+      g_fprintf (bout, "%s version ", PRG_NAME);
+      g_fprintf (bout, "%u.%u.%u", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
+      g_fprintf (bout, "\n");
+      g_fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
+      g_fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
+      g_fprintf (bout, "the GNU General Public License which can be found in the\n");
+      g_fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
+      g_fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
     }
   else
     {
-      fprintf (bout, "Usage: %s [options] [files...]\n", PRG_NAME);
-      fprintf (bout, "  --header                   generate C headers\n");
-      fprintf (bout, "  --body                     generate C code\n");
-      fprintf (bout, "  --prefix=string            specify marshaller prefix\n");
-      fprintf (bout, "  --skip-source              skip source location comments\n");
-      fprintf (bout, "  --stdinc, --nostdinc       include/use standard marshallers\n");
-      fprintf (bout, "  -h, --help                 show this help message\n");
-      fprintf (bout, "  -v, --version              print version informations\n");
-      fprintf (bout, "  --g-fatal-warnings         make warnings fatal (abort)\n");
+      g_fprintf (bout, "Usage: %s [options] [files...]\n", PRG_NAME);
+      g_fprintf (bout, "  --header                   generate C headers\n");
+      g_fprintf (bout, "  --body                     generate C code\n");
+      g_fprintf (bout, "  --prefix=string            specify marshaller prefix\n");
+      g_fprintf (bout, "  --skip-source              skip source location comments\n");
+      g_fprintf (bout, "  --stdinc, --nostdinc       include/use standard marshallers\n");
+      g_fprintf (bout, "  -h, --help                 show this help message\n");
+      g_fprintf (bout, "  -v, --version              print version informations\n");
+      g_fprintf (bout, "  --g-fatal-warnings         make warnings fatal (abort)\n");
     }
 }
index e47a8d5dd0fb9fc38b0bdec2ab43039bba1adfce..584c45113245b784ca954b76a43a9d81391a8669 100644 (file)
@@ -20,7 +20,7 @@
 
 #include        <glib-object.h>
 
-#include       <stdio.h>
+#include       <glib/gprintf.h>
 #include       <stdlib.h>
 #include       <string.h>
 #ifdef HAVE_UNISTD_H
@@ -66,9 +66,9 @@ show_nodes (GType        type,
   
   if (type != root)
     for (i = 0; i < spacing; i++)
-      fprintf (f_out, "%s%s\n", indent, O_VLINE);
+      g_fprintf (f_out, "%s%s\n", indent, O_VLINE);
   
-  fprintf (f_out, "%s%s%s%s",
+  g_fprintf (f_out, "%s%s%s%s",
           indent,
           sibling ? O_BRANCH : (type != root ? O_LLEAF : O_SPACE),
           O_ESPACE,
@@ -101,16 +101,16 @@ show_nodes (GType        type,
 static gint
 help (gchar *arg)
 {
-  fprintf (stderr, "usage: query <qualifier> [-r <type>] [-{i|b} \"\"] [-s #] [-{h|x|y}]\n");
-  fprintf (stderr, "       -r       specifiy root type\n");
-  fprintf (stderr, "       -n       don't descend type tree\n");
-  fprintf (stderr, "       -h       guess what ;)\n");
-  fprintf (stderr, "       -b       specify indent string\n");
-  fprintf (stderr, "       -i       specify incremental indent string\n");
-  fprintf (stderr, "       -s       specify line spacing\n");
-  fprintf (stderr, "qualifiers:\n");
-  fprintf (stderr, "       froots   iterate over fundamental roots\n");
-  fprintf (stderr, "       tree     print type tree\n");
+  g_fprintf (stderr, "usage: query <qualifier> [-r <type>] [-{i|b} \"\"] [-s #] [-{h|x|y}]\n");
+  g_fprintf (stderr, "       -r       specifiy root type\n");
+  g_fprintf (stderr, "       -n       don't descend type tree\n");
+  g_fprintf (stderr, "       -h       guess what ;)\n");
+  g_fprintf (stderr, "       -b       specify indent string\n");
+  g_fprintf (stderr, "       -i       specify incremental indent string\n");
+  g_fprintf (stderr, "       -s       specify line spacing\n");
+  g_fprintf (stderr, "qualifiers:\n");
+  g_fprintf (stderr, "       froots   iterate over fundamental roots\n");
+  g_fprintf (stderr, "       tree     print type tree\n");
   
   return arg != NULL;
 }
index 799d086c1510239d95bac5600d36727699c49070..abd85bc81aa461f3a4cae38474110b3a25a1953f 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "glib.h"
+#include "glib/gprintf.h"
 
 int array[10000];
 gboolean failed = FALSE;
@@ -226,6 +227,10 @@ main (int   argc,
   g_assert (g_str_has_suffix("", "xyzzy") == FALSE);
   g_assert (g_str_has_suffix("", "") == TRUE);
 
+  tmp_string = (gchar *) g_malloc (10);
+  g_snprintf (tmp_string, 10, "%2$s %1$s", "a", "b");
+  g_assert (strcmp (tmp_string, "b a") == 0);
   return 0;
 }
 
+