From: Bruno Haible Date: Fri, 1 Mar 2002 12:28:16 +0000 (+0000) Subject: Modernize varargs handling. X-Git-Tag: v0.11.1~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84001b679c50c28874aeedcfc3dfea2dd223e2f5;p=thirdparty%2Fgettext.git Modernize varargs handling. --- diff --git a/lib/ChangeLog b/lib/ChangeLog index b41427f14..32ae0d745 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,13 @@ +2002-02-24 Bruno Haible + + * 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 * vasprintf.h: New file. diff --git a/lib/Makefile.am b/lib/Makefile.am index f3e92a780..39471eca5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 index 000000000..832118725 --- /dev/null +++ b/lib/libstdarg.h @@ -0,0 +1,31 @@ +/* with fallback on 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 +# define VA_START(args, lastarg) va_start (args, lastarg) +# define VA_PARAMS(stdc_params, oldc_params) stdc_params +#else +# include +# define VA_START(args, lastarg) va_start (args) +# define VA_PARAMS(stdc_params, oldc_params) oldc_params +#endif + +#endif /* _LIBSTDARG_H */ diff --git a/lib/vasprintf.c b/lib/vasprintf.c index 37ec59591..e9b70244a 100644 --- a/lib/vasprintf.c +++ b/lib/vasprintf.c @@ -26,15 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include - -#if __STDC__ -# include -#else -# include -#endif - #include +#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 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: "); diff --git a/lib/xerror.c b/lib/xerror.c index c73163641..bab939f6c 100644 --- a/lib/xerror.c +++ b/lib/xerror.c @@ -33,42 +33,22 @@ #include "exit.h" #include "mbswidth.h" #include "vasprintf.h" +#include "libstdarg.h" #include "gettext.h" #define _(str) gettext (str) -#if __STDC__ -# include -# define VA_START(args, lastarg) va_start(args, lastarg) -#else -# include -# 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); diff --git a/src/ChangeLog b/src/ChangeLog index 493fcf978..a787e89bd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-02-24 Bruno Haible + + * 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 * msggrep.c: Include liballoca.h. diff --git a/src/po-lex.c b/src/po-lex.c index c71b65d0b..f428dfd6f 100644 --- a/src/po-lex.c +++ b/src/po-lex.c @@ -38,31 +38,19 @@ #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 -# define VA_START(args, lastarg) va_start(args, lastarg) -# else -# include -# 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