From: Mariusz PluciƄski Date: Fri, 25 Jul 2014 13:22:01 +0000 (+0200) Subject: Allow error reporting routines to accept varying number of arguments in modern style X-Git-Tag: v2.6.0~100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d257614dd66f410375f24ce1f2306b3c260bd29;p=flex Allow error reporting routines to accept varying number of arguments in modern style --- diff --git a/src/flexdef.h b/src/flexdef.h index 693f9f9..15b344d 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -904,13 +904,13 @@ extern void flexfatal PROTO ((const char *)); extern int htoi PROTO ((Char[])); /* Report an error message formatted with one integer argument. */ -extern void lerrif PROTO ((const char *, int)); +extern void lerrif PROTO ((const char *, ...)); /* Report an error message formatted with one string argument. */ -extern void lerrsf PROTO ((const char *, const char *)); +extern void lerrsf PROTO ((const char *, ...)); /* Like lerrsf, but also exit after displaying message. */ -extern void lerrsf_fatal PROTO ((const char *, const char *)); +extern void lerrsf_fatal PROTO ((const char *, ...)); /* Spit out a "#line" statement. */ extern void line_directive_out PROTO ((FILE *, int)); diff --git a/src/misc.c b/src/misc.c index 0dd8f50..0632d3e 100644 --- a/src/misc.c +++ b/src/misc.c @@ -385,25 +385,27 @@ int htoi (str) /* lerrif - report an error message formatted with one integer argument */ -void lerrif (msg, arg) - const char *msg; - int arg; -{ +void lerrif (const char *msg, ...) { char errmsg[MAXLINE]; + va_list args; - snprintf (errmsg, sizeof(errmsg), msg, arg); + va_start(args, msg); + vsnprintf (errmsg, sizeof(errmsg), msg, args); + va_end(args); flexerror (errmsg); } /* lerrsf - report an error message formatted with one string argument */ -void lerrsf (msg, arg) - const char *msg, arg[]; +void lerrsf (const char *msg, ...) { char errmsg[MAXLINE]; + va_list args; - snprintf (errmsg, sizeof(errmsg)-1, msg, arg); + va_start(args, msg); + vsnprintf (errmsg, sizeof(errmsg)-1, msg, args); + va_end(args); errmsg[sizeof(errmsg)-1] = 0; /* ensure NULL termination */ flexerror (errmsg); } @@ -411,12 +413,14 @@ void lerrsf (msg, arg) /* lerrsf_fatal - as lerrsf, but call flexfatal */ -void lerrsf_fatal (msg, arg) - const char *msg, arg[]; +void lerrsf_fatal (const char *msg, ...) { char errmsg[MAXLINE]; + va_list args; + va_start(args, msg); - snprintf (errmsg, sizeof(errmsg)-1, msg, arg); + vsnprintf (errmsg, sizeof(errmsg)-1, msg, args); + va_end(args); errmsg[sizeof(errmsg)-1] = 0; /* ensure NULL termination */ flexfatal (errmsg); } diff --git a/src/scanflags.c b/src/scanflags.c index f75aa82..c61d47f 100644 --- a/src/scanflags.c +++ b/src/scanflags.c @@ -61,8 +61,7 @@ sf_init (void) assert(_sf_stk == NULL); _sf_stk = (scanflags_t*) flex_alloc ( sizeof(scanflags_t) * (_sf_max = 32)); if (!_sf_stk) - lerrsf_fatal(_("Unable to allocate %ld of stack"), - (long)sizeof(scanflags_t)); + lerrsf_fatal(_("Unable to allocate %ld of stack"), sizeof(scanflags_t)); _sf_stk[_sf_top_ix] = 0; }