@@ -45,7 +45,7 @@ void write_tables(void);
/****** rpc_util.c ******/
void reinitialize(void);
int streq(const char *a, const char *b);
-void error(const char *msg) __attribute__ ((noreturn));
+void error(const char *msg, ...) __attribute__ ((noreturn, __format__ (__printf__, 1, 2)));
void crash(void) __attribute__ ((noreturn));
void tabify(FILE *f, int tab);
char *make_argname(const char *pname, const char *vname);
@@ -409,27 +409,18 @@ static void
check_type_name (const char *name, int new_type)
{
int i;
- char tmp[100];
for (i = 0; reserved_words[i] != NULL; i++)
{
if (strcmp (name, reserved_words[i]) == 0)
- {
- sprintf (tmp,
- "illegal (reserved) name :\'%s\' in type definition", name);
- error (tmp);
- }
+ error ("illegal (reserved) name :\'%s\' in type definition", name);
}
if (new_type)
{
for (i = 0; reserved_types[i] != NULL; i++)
{
if (strcmp (name, reserved_types[i]) == 0)
- {
- sprintf (tmp,
- "illegal (reserved) name :\'%s\' in type definition", name);
- error (tmp);
- }
+ error ("illegal (reserved) name :\'%s\' in type definition", name);
}
}
}
@@ -303,19 +303,12 @@ get_token (token *tokp)
if (!(isalpha (*where) || *where == '_'))
{
char buf[100];
- char *p;
- s_print (buf, _("illegal character in file: "));
- p = buf + strlen (buf);
if (isprint (*where))
- {
- s_print (p, "%c", *where);
- }
+ s_print (buf, "%c", *where);
else
- {
- s_print (p, "%d", *where);
- }
- error (buf);
+ s_print (buf, "%d", *where);
+ error (_("illegal character in file: %s"), buf);
}
findkind (&where, tokp);
break;
@@ -35,6 +35,7 @@
*/
#include <stdio.h>
#include <ctype.h>
+#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include "rpc_scan.h"
@@ -270,11 +271,16 @@ pvname (const char *pname, const char *vnum)
* print a useful (?) error message, and then die
*/
void
-error (const char *msg)
+error (const char *msg, ...)
{
+ va_list arg;
+
printwhere ();
f_print (stderr, "%s, line %d: ", infilename, linenum);
- f_print (stderr, "%s\n", msg);
+ va_start (arg, msg);
+ vfprintf (stderr, msg, arg);
+ f_print (stderr, "\n");
+ va_end (arg);
crash ();
}
@@ -308,17 +314,13 @@ record_open (const char *file)
}
}
-static char expectbuf[100];
-
/*
* error, token encountered was not the expected one
*/
void
expected1 (tok_kind exp1)
{
- s_print (expectbuf, "expected '%s'",
- toktostr (exp1));
- error (expectbuf);
+ error ("expected '%s'", toktostr (exp1));
}
/*
@@ -327,10 +329,7 @@ expected1 (tok_kind exp1)
void
expected2 (tok_kind exp1, tok_kind exp2)
{
- s_print (expectbuf, "expected '%s' or '%s'",
- toktostr (exp1),
- toktostr (exp2));
- error (expectbuf);
+ error ("expected '%s' or '%s'", toktostr (exp1), toktostr (exp2));
}
/*
@@ -339,11 +338,8 @@ expected2 (tok_kind exp1, tok_kind exp2)
void
expected3 (tok_kind exp1, tok_kind exp2, tok_kind exp3)
{
- s_print (expectbuf, "expected '%s', '%s' or '%s'",
- toktostr (exp1),
- toktostr (exp2),
- toktostr (exp3));
- error (expectbuf);
+ error ("expected '%s', '%s' or '%s'", toktostr (exp1), toktostr (exp2),
+ toktostr (exp3));
}
void
@@ -115,7 +115,7 @@ void pvname(const char *pname, const char *vnum);
void ptype(const char *prefix, const char *type, int follow);
int isvectordef(const char *type, relation rel);
int streq(const char *a, const char *b);
-void error(const char *msg);
+void error(const char *msg, ...);
void tabify(FILE *f, int tab);
void record_open(const char *file);
bas_type *find_type(const char *type);