From ceecfabaa75f4dfc252ed3254218a38adcf6f9fd Mon Sep 17 00:00:00 2001 From: dholland Date: Sat, 9 May 2015 23:12:57 +0000 Subject: [PATCH] Polish the error messages. Don't use warn/err to print error messages about the input, as prepending the program name to those both isn't helpful and confuses programs that try to parse compile logs. --- usr.bin/rpcgen/rpc_cout.c | 8 ++++---- usr.bin/rpcgen/rpc_hout.c | 6 +++--- usr.bin/rpcgen/rpc_main.c | 16 ++++++++-------- usr.bin/rpcgen/rpc_parse.c | 34 +++++++++++++++++----------------- usr.bin/rpcgen/rpc_scan.c | 18 +++++++++--------- usr.bin/rpcgen/rpc_util.c | 15 ++++++++------- 6 files changed, 49 insertions(+), 48 deletions(-) diff --git a/usr.bin/rpcgen/rpc_cout.c b/usr.bin/rpcgen/rpc_cout.c index 7496f4d0404e..ddb93c633788 100644 --- a/usr.bin/rpcgen/rpc_cout.c +++ b/usr.bin/rpcgen/rpc_cout.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_cout.c,v 1.33 2013/12/15 00:40:17 christos Exp $ */ +/* $NetBSD: rpc_cout.c,v 1.34 2015/05/09 23:12:57 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_cout.c 1.13 89/02/22 (C) 1987 SMI"; #else -__RCSID("$NetBSD: rpc_cout.c,v 1.33 2013/12/15 00:40:17 christos Exp $"); +__RCSID("$NetBSD: rpc_cout.c,v 1.34 2015/05/09 23:12:57 dholland Exp $"); #endif #endif @@ -112,7 +112,7 @@ emit(definition *def) break; case DEF_PROGRAM: case DEF_CONST: - errx(1, "Internal error %s, %d: Case %d not handled", + errx(1, "Internal error at %s:%d: Case %d not handled", __FILE__, __LINE__, def->def_kind); break; } @@ -660,7 +660,7 @@ emit_inline(declaration *decl, int flag) break; case REL_ARRAY: case REL_POINTER: - errx(1, "Internal error %s, %d: Case %d not handled", + errx(1, "Internal error at %s:%d: Case %d not handled", __FILE__, __LINE__, decl->rel); } } diff --git a/usr.bin/rpcgen/rpc_hout.c b/usr.bin/rpcgen/rpc_hout.c index c7d0af1aadbf..741f00cd48b1 100644 --- a/usr.bin/rpcgen/rpc_hout.c +++ b/usr.bin/rpcgen/rpc_hout.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_hout.c,v 1.22 2013/12/15 00:40:17 christos Exp $ */ +/* $NetBSD: rpc_hout.c,v 1.23 2015/05/09 23:12:57 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_hout.c 1.12 89/02/22 (C) 1987 SMI"; #else -__RCSID("$NetBSD: rpc_hout.c,v 1.22 2013/12/15 00:40:17 christos Exp $"); +__RCSID("$NetBSD: rpc_hout.c,v 1.23 2015/05/09 23:12:57 dholland Exp $"); #endif #endif @@ -281,7 +281,7 @@ define_printed(proc_list *stop, version_list *start) } } } - errx(1, "Internal error %s, %d: procedure not found", + errx(1, "Internal error at %s:%d: procedure not found", __FILE__, __LINE__); /* NOTREACHED */ } diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c index 1e2e37d4f228..1e660453617c 100644 --- a/usr.bin/rpcgen/rpc_main.c +++ b/usr.bin/rpcgen/rpc_main.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_main.c,v 1.41 2015/05/09 22:58:22 dholland Exp $ */ +/* $NetBSD: rpc_main.c,v 1.42 2015/05/09 23:12:57 dholland Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI"; #else -__RCSID("$NetBSD: rpc_main.c,v 1.41 2015/05/09 22:58:22 dholland Exp $"); +__RCSID("$NetBSD: rpc_main.c,v 1.42 2015/05/09 23:12:57 dholland Exp $"); #endif #endif @@ -300,11 +300,11 @@ open_output(const char *infile, const char *outfile) return; } if (infile != NULL && streq(outfile, infile)) { - errx(EXIT_FAILURE, "output would overwrite `%s'", infile); + errx(EXIT_FAILURE, "Output would overwrite `%s'", infile); } fout = fopen(outfile, "w"); if (fout == NULL) { - err(EXIT_FAILURE, "Can't to open `%s'", outfile); + err(EXIT_FAILURE, "Can't open `%s'", outfile); } record_open(outfile); @@ -359,7 +359,7 @@ open_input(const char *infile, const char *define) retval = spawnvp(P_WAIT, arglist[0], arglist); if (retval != 0) { - err(EXIT_FAILURE, "C PreProcessor failed"); + err(EXIT_FAILURE, "C preprocessor failed"); } fnsplit(infile, drive, dir, name, ext); fnmerge(cppfile, drive, dir, name, ".i"); @@ -832,7 +832,7 @@ static void addarg(const char *cp) { if (argcount >= ARGLISTLEN) { - errx(EXIT_FAILURE, "too many defines"); + errx(EXIT_FAILURE, "Internal error: too many defines"); /* NOTREACHED */ } arglist[argcount++] = cp; @@ -843,7 +843,7 @@ static void putarg(int pwhere, const char *cp) { if (pwhere >= ARGLISTLEN) { - errx(EXIT_FAILURE, "arglist coding error"); + errx(EXIT_FAILURE, "Internal error: arglist coding error"); /* NOTREACHED */ } arglist[pwhere] = cp; @@ -871,7 +871,7 @@ checkfiles(const char *infile, const char *outfile) return; /* file does not exist */ else { errx(EXIT_FAILURE, - "`%s' already exists and may be overwritten", + "`%s' already exists and would be overwritten", outfile); } } diff --git a/usr.bin/rpcgen/rpc_parse.c b/usr.bin/rpcgen/rpc_parse.c index 918553de5a5d..d3da09a6f578 100644 --- a/usr.bin/rpcgen/rpc_parse.c +++ b/usr.bin/rpcgen/rpc_parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_parse.c,v 1.18 2013/12/15 00:40:17 christos Exp $ */ +/* $NetBSD: rpc_parse.c,v 1.19 2015/05/09 23:12:57 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.18 2013/12/15 00:40:17 christos Exp $"); +__RCSID("$NetBSD: rpc_parse.c,v 1.19 2015/05/09 23:12:57 dholland Exp $"); #endif #endif @@ -103,7 +103,7 @@ get_definition(void) free(defp); return (NULL); default: - error("definition keyword expected"); + error("Expected definition keyword"); } scan(TOK_SEMICOLON, &tok); isdefined(defp); @@ -175,7 +175,7 @@ def_program(definition *defp) get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM); if (streq(plist->res_type, "opaque")) { - error("illegal result type"); + error("Illegal result type"); } scan(TOK_IDENT, &tok); plist->proc_name = tok.str; @@ -207,10 +207,10 @@ def_program(definition *defp) } /* multiple arguments are only allowed in newstyle */ if (!newstyle && num_args > 1) { - error("only one argument is allowed"); + error("Only one argument is allowed"); } if (isvoid && num_args > 1) { - error("illegal use of void in program definition"); + error("Illegal use of void in program definition"); } *tailp = NULL; scan(TOK_RPAREN, &tok); @@ -382,7 +382,7 @@ check_type_name(const char *name, int new_type) 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); + "Illegal (reserved) name '%s' in type definition", name); error(tmp); } } @@ -390,7 +390,7 @@ check_type_name(const char *name, int 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); + "Illegal (reserved) name '%s' in type definition", name); error(tmp); } } @@ -432,7 +432,7 @@ get_declaration(declaration *dec, defkind dkind) dec->name = tok.str; if (peekscan(TOK_LBRACKET, &tok)) { if (dec->rel == REL_POINTER) { - error("no array-of-pointer declarations -- use typedef"); + error("No array-of-pointer declarations -- use typedef"); } dec->rel = REL_VECTOR; scan_num(&tok); @@ -441,7 +441,7 @@ get_declaration(declaration *dec, defkind dkind) } else if (peekscan(TOK_LANGLE, &tok)) { if (dec->rel == REL_POINTER) { - error("no array-of-pointer declarations -- use typedef"); + error("No array-of-pointer declarations -- use typedef"); } dec->rel = REL_ARRAY; if (peekscan(TOK_RANGLE, &tok)) { @@ -455,12 +455,12 @@ get_declaration(declaration *dec, defkind dkind) } if (streq(dec->type, "opaque")) { if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) { - error("array declaration expected"); + error("Array declaration expected"); } } else if (streq(dec->type, "string")) { if (dec->rel != REL_ARRAY) { - error("variable-length array declaration expected"); + error("Variable-length array declaration expected"); } } } @@ -495,11 +495,11 @@ get_prog_declaration(declaration *dec, defkind dkind, int num /* arg number */) return; } if (streq(dec->type, "opaque")) { - error("opaque -- illegal argument type"); + error("Opaque -- illegal argument type"); } if (peekscan(TOK_STAR, &tok)) { if (streq(dec->type, "string")) { - error("pointer to string not allowed in program arguments\n"); + error("Pointer to string not allowed in program arguments\n"); } dec->rel = REL_POINTER; if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ @@ -507,7 +507,7 @@ get_prog_declaration(declaration *dec, defkind dkind, int num /* arg number */) } if (peekscan(TOK_LANGLE, &tok)) { if (!streq(dec->type, "string")) { - error("arrays cannot be declared as arguments to procedures -- use typedef"); + error("Arrays cannot be declared as arguments to procedures -- use typedef"); } dec->rel = REL_ARRAY; if (peekscan(TOK_RANGLE, &tok)) { @@ -567,7 +567,7 @@ get_type(const char **prefixp, const char **typep, defkind dkind) break; case TOK_VOID: if (dkind != DEF_UNION && dkind != DEF_PROGRAM) { - error("voids allowed only inside union and program definitions with one argument"); + error("Void is allowed only inside union and program definitions with one argument"); } *typep = tok.str; break; @@ -582,7 +582,7 @@ get_type(const char **prefixp, const char **typep, defkind dkind) *typep = tok.str; break; default: - error("expected type specifier"); + error("Type specifier expected"); } } diff --git a/usr.bin/rpcgen/rpc_scan.c b/usr.bin/rpcgen/rpc_scan.c index 1e95248e7fe2..8e2907ad2bac 100644 --- a/usr.bin/rpcgen/rpc_scan.c +++ b/usr.bin/rpcgen/rpc_scan.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_scan.c,v 1.13 2013/12/15 00:40:17 christos Exp $ */ +/* $NetBSD: rpc_scan.c,v 1.14 2015/05/09 23:12:57 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.13 2013/12/15 00:40:17 christos Exp $"); +__RCSID("$NetBSD: rpc_scan.c,v 1.14 2015/05/09 23:12:57 dholland Exp $"); #endif #endif @@ -115,7 +115,7 @@ scan_num(token *tokp) case TOK_IDENT: break; default: - error("constant or identifier expected"); + error("Expected constant or identifier"); } } /* @@ -286,7 +286,7 @@ get_token(token *tokp) char buf[100]; char *p; - s_print(buf, "illegal character in file: "); + s_print(buf, "Illegal character in file: "); p = buf + strlen(buf); if (isprint((unsigned char)*where)) { s_print(p, "%c", *where); @@ -319,7 +319,7 @@ findstrconst(char **str, const char **val) p++; } while (*p && *p != '"'); if (*p == 0) { - error("unterminated string constant"); + error("Unterminated string constant"); } p++; size = p - *str; @@ -342,12 +342,12 @@ findchrconst(char **str, const char **val) p++; } while (*p && *p != '\''); if (*p == 0) { - error("unterminated string constant"); + error("Unterminated string constant"); } p++; size = p - *str; if (size != 3) { - error("empty char string"); + error("Empty character"); } tmp = alloc(size + 1); (void) strncpy(tmp, *str, size); @@ -477,7 +477,7 @@ docppline(char *line, int *lineno, const char **fname) line++; } if (*line != '"') { - error("preprocessor error"); + error("Preprocessor error"); } line++; p = file = alloc(strlen(line) + 1); @@ -485,7 +485,7 @@ docppline(char *line, int *lineno, const char **fname) *p++ = *line++; } if (*line == 0) { - error("preprocessor error"); + error("Preprocessor error"); } *p = 0; if (*file == 0) { diff --git a/usr.bin/rpcgen/rpc_util.c b/usr.bin/rpcgen/rpc_util.c index 7bdc05a07dab..7e1013d671a4 100644 --- a/usr.bin/rpcgen/rpc_util.c +++ b/usr.bin/rpcgen/rpc_util.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_util.c,v 1.14 2015/05/09 21:44:47 christos Exp $ */ +/* $NetBSD: rpc_util.c,v 1.15 2015/05/09 23:12:57 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.14 2015/05/09 21:44:47 christos Exp $"); +__RCSID("$NetBSD: rpc_util.c,v 1.15 2015/05/09 23:12:57 dholland Exp $"); #endif #endif @@ -258,7 +258,8 @@ void error(const char *msg) { printwhere(); - errx(EXIT_FAILURE, "%s, line %d: %s", infilename, linenum, msg); + f_print(stderr, "%s:%d: %s", infilename, linenum, msg); + errx(EXIT_FAILURE, "Cannot recover from this error"); } /* * Something went wrong, unlink any files that we may have created and then @@ -283,7 +284,7 @@ record_open(const char *file) if (nfiles < NFILES) { outfiles[nfiles++] = file; } else { - errx(EXIT_FAILURE, "too many files!"); + errx(EXIT_FAILURE, "Too many files!"); } } @@ -295,7 +296,7 @@ static char expectbuf[100]; void expected1(tok_kind exp1) { - s_print(expectbuf, "expected '%s'", + s_print(expectbuf, "Expected '%s'", toktostr(exp1)); error(expectbuf); } @@ -305,7 +306,7 @@ expected1(tok_kind exp1) void expected2(tok_kind exp1, tok_kind exp2) { - s_print(expectbuf, "expected '%s' or '%s'", + s_print(expectbuf, "Expected '%s' or '%s'", toktostr(exp1), toktostr(exp2)); error(expectbuf); @@ -316,7 +317,7 @@ 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'", + s_print(expectbuf, "Expected '%s', '%s', or '%s'", toktostr(exp1), toktostr(exp2), toktostr(exp3));