diff options
author | Mariusz PluciĆski <mplucinski@mplucinski.com> | 2014-07-25 15:22:01 +0200 |
---|---|---|
committer | Will Estes <westes575@gmail.com> | 2014-07-25 09:48:16 -0400 |
commit | 2d257614dd66f410375f24ce1f2306b3c260bd29 (patch) | |
tree | be8c3060532fc014ae6bf44d79fc3e24f0a52af6 | |
parent | 681db87f8ffb3d6177f0bfa54d877a88ea0a9ed8 (diff) |
Allow error reporting routines to accept varying number of arguments in modern style
-rw-r--r-- | src/flexdef.h | 6 | ||||
-rw-r--r-- | src/misc.c | 26 | ||||
-rw-r--r-- | src/scanflags.c | 3 |
3 files changed, 19 insertions, 16 deletions
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)); @@ -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; } |