Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/rpcgen Make error() printflike instead of using spri...



details:   https://anonhg.NetBSD.org/src/rev/a1a9b0f5dc85
branches:  trunk
changeset: 808235:a1a9b0f5dc85
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sat May 09 23:28:43 2015 +0000

description:
Make error() printflike instead of using sprintf before calling it.

diffstat:

 usr.bin/rpcgen/rpc_parse.c |  13 ++++---------
 usr.bin/rpcgen/rpc_scan.c  |  14 ++++----------
 usr.bin/rpcgen/rpc_util.c  |  28 ++++++++++++++--------------
 usr.bin/rpcgen/rpc_util.h  |   4 ++--
 4 files changed, 24 insertions(+), 35 deletions(-)

diffs (181 lines):

diff -r 8be25616ded8 -r a1a9b0f5dc85 usr.bin/rpcgen/rpc_parse.c
--- a/usr.bin/rpcgen/rpc_parse.c        Sat May 09 23:19:34 2015 +0000
+++ b/usr.bin/rpcgen/rpc_parse.c        Sat May 09 23:28:43 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpc_parse.c,v 1.19 2015/05/09 23:12:57 dholland Exp $  */
+/*     $NetBSD: rpc_parse.c,v 1.20 2015/05/09 23:28:43 dholland Exp $  */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_parse.c,v 1.19 2015/05/09 23:12:57 dholland Exp $");
+__RCSID("$NetBSD: rpc_parse.c,v 1.20 2015/05/09 23:28:43 dholland Exp $");
 #endif
 #endif
 
@@ -377,21 +377,16 @@
 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);
                        }
                }
        }
diff -r 8be25616ded8 -r a1a9b0f5dc85 usr.bin/rpcgen/rpc_scan.c
--- a/usr.bin/rpcgen/rpc_scan.c Sat May 09 23:19:34 2015 +0000
+++ b/usr.bin/rpcgen/rpc_scan.c Sat May 09 23:28:43 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpc_scan.c,v 1.14 2015/05/09 23:12:57 dholland Exp $   */
+/*     $NetBSD: rpc_scan.c,v 1.15 2015/05/09 23:28:43 dholland Exp $   */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_scan.c,v 1.14 2015/05/09 23:12:57 dholland Exp $");
+__RCSID("$NetBSD: rpc_scan.c,v 1.15 2015/05/09 23:28:43 dholland Exp $");
 #endif
 #endif
 
@@ -283,17 +283,11 @@
 
        default:
                if (!(isalpha((unsigned char)*where) || *where == '_')) {
-                       char    buf[100];
-                       char   *p;
-
-                       s_print(buf, "Illegal character in file: ");
-                       p = buf + strlen(buf);
                        if (isprint((unsigned char)*where)) {
-                               s_print(p, "%c", *where);
+                               error("Illegal character '%c' in file", *where);
                        } else {
-                               s_print(p, "%d", *where);
+                               error("Illegal character %d in file", *where);
                        }
-                       error(buf);
                }
                findkind(&where, tokp);
                break;
diff -r 8be25616ded8 -r a1a9b0f5dc85 usr.bin/rpcgen/rpc_util.c
--- a/usr.bin/rpcgen/rpc_util.c Sat May 09 23:19:34 2015 +0000
+++ b/usr.bin/rpcgen/rpc_util.c Sat May 09 23:28:43 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpc_util.c,v 1.16 2015/05/09 23:16:51 dholland Exp $   */
+/*     $NetBSD: rpc_util.c,v 1.17 2015/05/09 23:28:43 dholland Exp $   */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_util.c,v 1.16 2015/05/09 23:16:51 dholland Exp $");
+__RCSID("$NetBSD: rpc_util.c,v 1.17 2015/05/09 23:28:43 dholland Exp $");
 #endif
 #endif
 
@@ -254,11 +254,17 @@
 /*
  * print a useful (?) error message, and then die
  */
-void
-error(const char *msg)
+__printflike(1, 2) void
+error(const char *msg, ...)
 {
+       va_list ap;
+
        printwhere();
-       f_print(stderr, "%s:%d: %s", infilename, linenum, msg);
+       fprintf(stderr, "%s:%d: ", infilename, linenum);
+       va_start(ap, msg);
+       vfprintf(stderr, msg, ap);
+       va_end(ap);
+       fprintf(stderr, "\n");
        errx(EXIT_FAILURE, "Cannot recover from this error");
 }
 /*
@@ -288,17 +294,13 @@
        }
 }
 
-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));
 }
 /*
  * error, token encountered was not one of two expected ones
@@ -306,10 +308,9 @@
 void
 expected2(tok_kind exp1, tok_kind exp2)
 {
-       s_print(expectbuf, "Expected '%s' or '%s'",
+       error("Expected '%s' or '%s'",
            toktostr(exp1),
            toktostr(exp2));
-       error(expectbuf);
 }
 /*
  * error, token encountered was not one of 3 expected ones
@@ -317,11 +318,10 @@
 void
 expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3)
 {
-       s_print(expectbuf, "Expected '%s', '%s', or '%s'",
+       error("Expected '%s', '%s', or '%s'",
            toktostr(exp1),
            toktostr(exp2),
            toktostr(exp3));
-       error(expectbuf);
 }
 
 void
diff -r 8be25616ded8 -r a1a9b0f5dc85 usr.bin/rpcgen/rpc_util.h
--- a/usr.bin/rpcgen/rpc_util.h Sat May 09 23:19:34 2015 +0000
+++ b/usr.bin/rpcgen/rpc_util.h Sat May 09 23:28:43 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpc_util.h,v 1.10 2015/05/09 23:19:34 dholland Exp $   */
+/*     $NetBSD: rpc_util.h,v 1.11 2015/05/09 23:28:43 dholland Exp $   */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -114,7 +114,7 @@
 char *locase(const char *);
 void pvname_svc(const char *, const char *);
 void pvname(const char *, const char *);
-void error(const char *);
+__printflike(1, 2) void error(const char *, ...);
 void crash(void);
 void record_open(const char *);
 void expected1(tok_kind) __dead;



Home | Main Index | Thread Index | Old Index