+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.
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 \
--- /dev/null
+/* <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 */
#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
}
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);
#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: ");
#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);
+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.
#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
/* 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
/* 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