]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Modernize varargs handling.
authorBruno Haible <bruno@clisp.org>
Fri, 1 Mar 2002 12:28:16 +0000 (12:28 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jun 2009 23:25:17 +0000 (01:25 +0200)
lib/ChangeLog
lib/Makefile.am
lib/libstdarg.h [new file with mode: 0644]
lib/vasprintf.c
lib/xerror.c
src/ChangeLog
src/po-lex.c

index b41427f14665b0d92ab7ca546fc6900b6a78cc51..32ae0d7450143e3b04595a97014c39bf55f8c40e 100644 (file)
@@ -1,3 +1,13 @@
+2002-02-24  Bruno Haible  <bruno@clisp.org>
+
+       * libstdarg.h: New file.
+       * vasprintf.c: Include it.
+       (asprintf): Modernize varargs handling.
+       (checkit): Likewise.
+       * xerror.c: Include libstdarg.h.
+       (xasprintf): Modernize varargs handling.
+       * Makefile.am (LIBADD_SOURCE): Add libstdarg.h.
+
 2002-02-24  Bruno Haible  <bruno@clisp.org>
 
        * vasprintf.h: New file.
index f3e92a780905dc27344fc702e204215c12b0cb4b..39471eca587f841bdd771a42fbe58a03c7e2cd98 100644 (file)
@@ -69,6 +69,7 @@ LIBADD_SOURCE = \
   mkdtemp.h mkdtemp.c \
   pfnmatch.h pfnmatch.c \
   setenv.h setenv.c \
+  libstdarg.h \
   stpcpy.h stpcpy.c \
   stpncpy.h stpncpy.c \
   strcase.h strcasecmp.c strncasecmp.c \
diff --git a/lib/libstdarg.h b/lib/libstdarg.h
new file mode 100644 (file)
index 0000000..8321187
--- /dev/null
@@ -0,0 +1,31 @@
+/* <stdarg.h> with fallback on <varargs.h> for old platforms.
+   Copyright (C) 2001-2002 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifndef _LIBSTDARG_H
+#define _LIBSTDARG_H
+
+#if __STDC__ || defined __cplusplus
+# include <stdarg.h>
+# define VA_START(args, lastarg) va_start (args, lastarg)
+# define VA_PARAMS(stdc_params, oldc_params) stdc_params
+#else
+# include <varargs.h>
+# define VA_START(args, lastarg) va_start (args)
+# define VA_PARAMS(stdc_params, oldc_params) oldc_params
+#endif
+
+#endif /* _LIBSTDARG_H */
index 37ec5959122f0afe127cb07e5c30d893754ef648..e9b70244aed946f47de4ec7287f118ceea862760 100644 (file)
@@ -26,15 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-
-#if __STDC__
-# include <stdarg.h>
-#else
-# include <varargs.h>
-#endif
-
 #include <math.h>
 
+#include "libstdarg.h"
+
 #ifdef TEST
 size_t global_total_width;
 #endif
@@ -139,25 +134,16 @@ vasprintf (result, format, args)
 }
 
 int
-asprintf
-#if __STDC__
-     (char **result, const char *format, ...)
-#else
-     (result, va_alist)
+asprintf VA_PARAMS ((char **result, const char *format, ...),
+                   (result, format, va_alist)
      char **result;
-     va_dcl
-#endif
+     const char *format;
+     va_dcl)
 {
   va_list args;
   int done;
 
-#if __STDC__
-  va_start (args, format);
-#else
-  char *format;
-  va_start (args);
-  format = va_arg (args, char *);
-#endif
+  VA_START (args, format);
   done = vasprintf (result, format, args);
   va_end (args);
 
@@ -171,24 +157,15 @@ asprintf
 #include <float.h>
 
 void
-checkit
-#if __STDC__
-     (const char* format, ...)
-#else
-     (va_alist)
-     va_dcl
-#endif
+checkit VA_PARAMS ((const char* format, ...),
+                  (format, va_alist)
+     const char *format;
+     va_dcl)
 {
   va_list args;
   char *result;
 
-#if __STDC__
-  va_start (args, format);
-#else
-  char *format;
-  va_start (args);
-  format = va_arg (args, char *);
-#endif
+  VA_START (args, format);
   vasprintf (&result, format, args);
   if (strlen (result) < global_total_width)
     printf ("PASS: ");
index c73163641003b4edff145f6792c3054deecaa00a..bab939f6cd7611e78955c10469d016c8e3edde3b 100644 (file)
 #include "exit.h"
 #include "mbswidth.h"
 #include "vasprintf.h"
+#include "libstdarg.h"
 #include "gettext.h"
 
 #define _(str) gettext (str)
 
-#if __STDC__
-# include <stdarg.h>
-# define VA_START(args, lastarg) va_start(args, lastarg)
-#else
-# include <varargs.h>
-# define VA_START(args, lastarg) va_start(args)
-# define NEW_VARARGS 1 /* or 0 if it doesn't work */
-#endif
-
 /* Format a message and return the freshly allocated resulting string.  */
 char *
-#if __STDC__
-xasprintf (const char *format, ...)
-#elif NEW_VARARGS
-xasprintf (format, va_alist)
+xasprintf VA_PARAMS ((const char *format, ...),
+                    (format, va_alist)
      const char *format;
-     va_dcl
-#else
-xasprintf (va_alist)
-     va_dcl
-#endif
+     va_dcl)
 {
-#if !__STDC__ && !NEW_VARARGS
-  const char *format;
-#endif
   va_list args;
   char *result;
 
   VA_START (args, format);
-#if !__STDC__ && !NEW_VARARGS
-  format = va_arg (args, const char *);
-#endif
   if (vasprintf (&result, format, args) < 0)
     error (EXIT_FAILURE, 0, _("memory exhausted"));
   va_end (args);
index 493fcf978e5f8afbc00b7eec7cc1e7236988ced2..a787e89bd8e50719e24a2459bdc8ad055a188950 100644 (file)
@@ -1,3 +1,10 @@
+2002-02-24  Bruno Haible  <bruno@clisp.org>
+
+       * po-lex.c: Include libstdarg.h.
+       (VA_START, va_alist, va_dcl): Remove macros.
+       (po_gram_error): Modernize varargs handling. Fix memory leak.
+       (po_gram_error_at_line): Likewise.
+
 2002-02-21  Bruno Haible  <bruno@clisp.org>
 
        * msggrep.c: Include liballoca.h.
index c71b65d0b8c5f0e4a02d4dc962fb9fdf8bff364f..f428dfd6fce8c5c7ebec68ab5a96201015c9a844 100644 (file)
 
 #include "c-ctype.h"
 #include "linebreak.h"
+#include "vasprintf.h"
+#include "libstdarg.h"
 #include "gettext.h"
-#define _(str) gettext(str)
-
-#if HAVE_VPRINTF || HAVE_DOPRNT
-# if __STDC__
-#  include <stdarg.h>
-#  define VA_START(args, lastarg) va_start(args, lastarg)
-# else
-#  include <varargs.h>
-#  define VA_START(args, lastarg) va_start(args)
-# endif
-#else
-# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
-# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
-#endif
-
 #include "po-charset.h"
 #include "xmalloc.h"
 #include "exit.h"
 #include "error.h"
 #include "open-po.h"
-
 #include "str-list.h"
 #include "po-gram-gen2.h"
 
+#define _(str) gettext(str)
+
 #if HAVE_ICONV
 # include "utf8-ucs4.h"
 #endif
@@ -96,35 +84,23 @@ int gram_pos_column;
 
 /* VARARGS1 */
 void
-# if defined VA_START && __STDC__
-po_gram_error (const char *fmt, ...)
-# else
-po_gram_error (fmt, va_alist)
+po_gram_error VA_PARAMS ((const char *fmt, ...),
+                        (fmt, va_alist)
      const char *fmt;
-     va_dcl
-# endif
+     va_dcl)
 {
-# ifdef VA_START
   va_list ap;
   char *buffer;
 
   VA_START (ap, fmt);
-  vasprintf (&buffer, fmt, ap);
+  if (vasprintf (&buffer, fmt, ap) < 0)
+    error (EXIT_FAILURE, 0, _("memory exhausted"));
   va_end (ap);
   error_with_progname = false;
   error (0, 0, "%s:%lu:%d: %s", gram_pos.file_name,
         (unsigned long) gram_pos.line_number, gram_pos_column + 1, buffer);
   error_with_progname = true;
-# else
-  char *totalfmt = xasprintf ("%s%s", "%s:%lu:%d: ", fmt);
-
-  error_with_progname = false;
-  error (0, 0, totalfmt, gram_pos.file_name,
-        (unsigned long) gram_pos.line_number, gram_pos_column + 1,
-        a1, a2, a3, a4, a5, a6, a7, a8);
-  error_with_progname = true;
-  free (totalfmt);
-# endif
+  free (buffer);
 
   /* Some messages need more than one line.  Continuation lines are
      indicated by using "..." at the start of the string.  We don't
@@ -140,31 +116,23 @@ po_gram_error (fmt, va_alist)
 
 /* VARARGS2 */
 void
-# if defined VA_START && __STDC__
-po_gram_error_at_line (const lex_pos_ty *pp, const char *fmt, ...)
-# else
-po_gram_error_at_line (pp, fmt, va_alist)
+po_gram_error_at_line VA_PARAMS ((const lex_pos_ty *pp, const char *fmt, ...),
+                                (pp, fmt, va_alist)
      const lex_pos_ty *pp;
      const char *fmt;
-     va_dcl
-# endif
+     va_dcl)
 {
-# ifdef VA_START
   va_list ap;
   char *buffer;
 
   VA_START (ap, fmt);
-  vasprintf (&buffer, fmt, ap);
+  if (vasprintf (&buffer, fmt, ap) < 0)
+    error (EXIT_FAILURE, 0, _("memory exhausted"));
   va_end (ap);
   error_with_progname = false;
   error_at_line (0, 0, pp->file_name, pp->line_number, "%s", buffer);
   error_with_progname = true;
-# else
-  error_with_progname = false;
-  error_at_line (0, 0, pp->file_name, pp->line_number, fmt,
-                a1, a2, a3, a4, a5, a6, a7, a8);
-  error_with_progname = true;
-# endif
+  free (buffer);
 
   /* Some messages need more than one line, or more than one location.
      Continuation lines are indicated by using "..." at the start of the