Use err(3). Silent -Wall.

This commit is contained in:
Philippe Charnier 1997-11-03 07:44:25 +00:00
parent 00be5a552a
commit e21108a205
8 changed files with 167 additions and 113 deletions

View file

@ -55,8 +55,8 @@ traditional methods of scribbling abbreviations of errors on paper, and
permits error messages and source code to be viewed simultaneously
without machinations of multiple windows in a screen editor.
.Pp
Options are:
.Bl -tag -width Ds
The following options are available:
.Bl -tag -width indent
.It Fl n
Do
.Em not
@ -94,7 +94,7 @@ Thus the suffix list:
.Dl ".c.y.foo*.h"
.Pp
allows
.Nm error
.Nm
to touch files ending with ``.c'', ``.y'', ``.foo*'' and ``.h''.
.It Fl s
Print out
@ -128,7 +128,7 @@ connected via a pipe to the error message source.
Some language processors put error messages on their standard error file;
others put their messages on the standard output.
Hence, both error sources should be piped together into
.Nm error .
.Nm Ns .
For example, when using the
.Xr csh 1
syntax,
@ -163,7 +163,7 @@ For all languages except
error messages are restricted to be on one line.
Some error messages refer to more than one line in more than
one files;
.Nm error
.Nm
will duplicate the error message and insert it at
all of the places referenced.
.Pp
@ -177,7 +177,7 @@ which file it is processing.
uses these to determine the file name for languages that
don't include the file name in each error message.
These synchronization messages are consumed entirely by
.Nm error .
.Nm Ns .
.It Em discard
Error messages from
.Xr lint 1
@ -190,7 +190,7 @@ and
are discarded,
to prevent accidently touching these libraries.
Again, these error messages are consumed entirely by
.Nm error .
.Nm Ns .
.It Em nullify
Error messages from
.Xr lint 1
@ -226,7 +226,7 @@ insertion into the file to which they refer.
Only true error messages are candidates for inserting into
the file they refer to.
Other error messages are consumed entirely by
.Nm error
.Nm
or are written to the standard output.
.Nm Error
inserts the error messages into the source file on the line
@ -267,12 +267,12 @@ user's teletype
.El
.Sh HISTORY
The
.Nm error
.Nm
command
appeared in
.Bx 4.0 .
.Sh AUTHOR
Robert Henry
.An Robert Henry
.Sh BUGS
.Pp
Opens the teletype directly to do user querying.
@ -282,7 +282,7 @@ only one link to it.
.Pp
Changing a language processor's format of error messages
may cause
.Nm error
.Nm
to not understand the error message.
.Pp
.Nm Error ,
@ -294,7 +294,7 @@ Humans are still much better at discarding these related errors.
Pascal error messages belong after the lines affected
(error puts them before). The alignment of the `\\' marking
the point of error is also disturbed by
.Nm error .
.Nm Ns .
.Pp
.Nm Error
was designed for work on

View file

@ -113,7 +113,6 @@ FILE *errorfile; /* where error file comes from */
FILE *queryfile; /* where the query responses from the user come from*/
extern char *currentfilename;
extern char *processname;
extern char *scriptname;
extern boolean query;
@ -222,3 +221,21 @@ boolean persperdexplode();
* Printing hacks
*/
char *plural(), *verbform();
void arrayify __P((int *, Eptr **, Eptr));
void clob_last __P((char *, char));
Errorclass discardit __P((Eptr));
void eaterrors __P((int *, Eptr **));
void erroradd __P((int, char **, Errorclass, Errorclass));
void filenames __P((int, Eptr **));
void findfiles __P((int, Eptr *, int *, Eptr ***));
void getignored __P((char *));
void onintr __P((void));
int position __P((char *, char));
void printerrors __P((boolean, int, Eptr []));
char *substitute __P((char *, char, char));
boolean touchfiles __P((int, Eptr **, int *, char ***));
void wordvbuild __P((char *, int *, char ***));
void wordvprint __P((FILE *, int, char *[]));

View file

@ -32,16 +32,20 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)filter.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "error.h"
#include "pathnames.h"
@ -52,12 +56,14 @@ char *lint_libs[] = {
IG_FILE4,
0
};
extern char* processname;
int lexsort();
/*
* Read the file ERRORNAME of the names of functions in lint
* to ignore complaints about.
*/
void
getignored(auxname)
char *auxname;
{
@ -91,8 +97,7 @@ getignored(auxname)
#endif
if ( (fyle = fopen(filename, "r")) == NULL){
#ifdef FULLDEBUG
fprintf(stderr, "%s: Can't open file \"%s\"\n",
processname, filename);
warnx("can't open file \"%s\"", filename);
#endif
return;
}
@ -105,8 +110,7 @@ getignored(auxname)
fclose(fyle);
if (freopen(filename, "r", fyle) == NULL){
#ifdef FULLDEBUG
fprintf(stderr, "%s: Failure to open \"%s\" for second read.\n",
processname, filename);
warnx("failure to open \"%s\" for second read", filename);
#endif
nignored = 0;
return;

View file

@ -32,11 +32,15 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
@ -61,17 +65,18 @@ Errorclass pi();
Errorclass ri();
Errorclass troff();
Errorclass mod2();
Errorclass catchall __P((void));
/*
* Eat all of the lines in the input file, attempting to categorize
* them by their various flavors
*/
static char inbuffer[BUFSIZ];
void
eaterrors(r_errorc, r_errorv)
int *r_errorc;
Eptr **r_errorv;
{
extern boolean piflag;
Errorclass errorclass = C_SYNC;
for (;;){
@ -113,6 +118,7 @@ eaterrors(r_errorc, r_errorv)
/*
* create a new error entry, given a zero based array and count
*/
void
erroradd(errorlength, errorv, errorclass, errorsubclass)
int errorlength;
char **errorv;
@ -404,6 +410,8 @@ char *F77_fatal[3] = {"Compiler", "error", "line"};
char *F77_error[3] = {"Error", "on", "line"};
char *F77_warning[3] = {"Warning", "on", "line"};
char *F77_no_ass[3] = {"Error.","No","assembly."};
Errorclass
f77()
{
char **nwordv;

View file

@ -32,21 +32,26 @@
*/
#ifndef lint
static char copyright[] =
static const char copyright[] =
"@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "error.h"
#include "pathnames.h"
@ -59,7 +64,6 @@ Eptr **files; /* array of pointers into errors*/
int language = INCC;
char *currentfilename = "????";
char *processname;
char im_on[] = _PATH_TTY; /* my tty name */
boolean query = FALSE; /* query the operator if touch files */
@ -69,8 +73,10 @@ boolean terse = FALSE; /* Terse output */
char *suffixlist = ".*"; /* initially, can touch any file */
int errorsort();
void onintr();
int errorsort __P((Eptr *, Eptr *));
void forkvi __P((int, char **));
void try __P((char *, int, char **));
/*
* error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile]
*
@ -114,6 +120,7 @@ void onintr();
* infile: The error messages come from this file.
* Default: stdin
*/
int
main(argc, argv)
int argc;
char *argv[];
@ -127,14 +134,11 @@ main(argc, argv)
boolean pr_summary = FALSE;
boolean edit_files = FALSE;
processname = argv[0];
errorfile = stdin;
if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){
for (cp = argv[1] + 1; *cp; cp++) switch(*cp){
default:
fprintf(stderr, "%s: -%c: Unknown flag\n",
processname, *cp);
warnx("-%c: unknown flag", *cp);
break;
case 'n': notouch = TRUE; break;
@ -159,24 +163,16 @@ main(argc, argv)
if (notouch)
suffixlist = 0;
if (argc > 1){
if (argc > 3){
fprintf(stderr, "%s: Only takes 0 or 1 arguments\n",
processname);
exit(3);
}
if ( (errorfile = fopen(argv[1], "r")) == NULL){
fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n",
processname, argv[1]);
exit(4);
}
if (argc > 3)
errx(3, "only takes 0 or 1 argument");
if ( (errorfile = fopen(argv[1], "r")) == NULL)
errx(4,
"%s: no such file or directory for reading errors",
argv[1]);
}
if ( (queryfile = fopen(im_on, "r")) == NULL){
if (query){
fprintf(stderr,
"%s: Can't open \"%s\" to query the user.\n",
processname, im_on);
exit(9);
}
if (query)
errx(9, "can't open \"%s\" to query the user", im_on);
}
if (signal(SIGINT, onintr) == SIG_IGN)
signal(SIGINT, SIG_IGN);
@ -213,8 +209,10 @@ main(argc, argv)
fflush(stdout);
if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files)
forkvi(ed_argc, ed_argv);
return(0);
}
void
forkvi(argc, argv)
int argc;
char **argv;
@ -241,6 +239,7 @@ forkvi(argc, argv)
fprintf(stdout, "Can't find any editors.\n");
}
void
try(name, argc, argv)
char *name;
int argc;

View file

@ -32,11 +32,15 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)pi.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "error.h"

View file

@ -32,17 +32,23 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <stdio.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
/*
* Arrayify a list of rules
*/
void
arrayify(e_length, e_array, header)
int *e_length;
Eptr **e_array;
@ -68,27 +74,14 @@ arrayify(e_length, e_array, header)
*e_array = array;
}
/*VARARGS1*/
error(msg, a1, a2, a3)
char *msg;
{
fprintf(stderr, "Error: ");
fprintf(stderr, msg, a1, a2, a3);
fprintf(stderr, "\n");
fflush(stdout);
fflush(stderr);
exit(6);
}
/*ARGSUSED*/
char *Calloc(nelements, size)
int nelements;
int size;
{
char *back;
if ( (back = (char *)calloc(nelements, size)) == (char *)NULL){
error("Ran out of memory.\n");
exit(1);
}
if ( (back = (char *)calloc(nelements, size)) == (char *)NULL)
errx(6, "ran out of memory");
return(back);
}
@ -169,6 +162,7 @@ char next_lastchar(string)
return('\0');
}
void
clob_last(string, newstuff)
char *string, newstuff;
{
@ -258,29 +252,30 @@ static char mod2incomment[] = MOD2INCOMMENT;
static char mod2outcomment[] = MOD2OUTCOMMENT;
struct lang_desc lang_table[] = {
/*INUNKNOWN 0*/ "unknown", cincomment, coutcomment,
/*INCPP 1*/ "cpp", cincomment, coutcomment,
/*INCC 2*/ "cc", cincomment, coutcomment,
/*INAS 3*/ "as", ASINCOMMENT, newline,
/*INLD 4*/ "ld", cincomment, coutcomment,
/*INLINT 5*/ "lint", cincomment, coutcomment,
/*INF77 6*/ "f77", fincomment, foutcomment,
/*INPI 7*/ "pi", piincomment, pioutcomment,
/*INPC 8*/ "pc", piincomment, pioutcomment,
/*INFRANZ 9*/ "franz",lispincomment, newline,
/*INLISP 10*/ "lisp", lispincomment, newline,
/*INVAXIMA 11*/ "vaxima",lispincomment,newline,
/*INRATFOR 12*/ "ratfor",fincomment, foutcomment,
/*INLEX 13*/ "lex", cincomment, coutcomment,
/*INYACC 14*/ "yacc", cincomment, coutcomment,
/*INAPL 15*/ "apl", ".lm", newline,
/*INMAKE 16*/ "make", ASINCOMMENT, newline,
/*INRI 17*/ "ri", riincomment, rioutcomment,
/*INTROFF 18*/ "troff",troffincomment,troffoutcomment,
/*INMOD2 19*/ "mod2", mod2incomment, mod2outcomment,
0, 0, 0
/*INUNKNOWN 0*/ {"unknown", cincomment, coutcomment},
/*INCPP 1*/ {"cpp", cincomment, coutcomment},
/*INCC 2*/ {"cc", cincomment, coutcomment},
/*INAS 3*/ {"as", ASINCOMMENT, newline},
/*INLD 4*/ {"ld", cincomment, coutcomment},
/*INLINT 5*/ {"lint", cincomment, coutcomment},
/*INF77 6*/ {"f77", fincomment, foutcomment},
/*INPI 7*/ {"pi", piincomment, pioutcomment},
/*INPC 8*/ {"pc", piincomment, pioutcomment},
/*INFRANZ 9*/ {"franz",lispincomment, newline},
/*INLISP 10*/ {"lisp", lispincomment, newline},
/*INVAXIMA 11*/ {"vaxima",lispincomment,newline},
/*INRATFOR 12*/ {"ratfor",fincomment, foutcomment},
/*INLEX 13*/ {"lex", cincomment, coutcomment},
/*INYACC 14*/ {"yacc", cincomment, coutcomment},
/*INAPL 15*/ {"apl", ".lm", newline},
/*INMAKE 16*/ {"make", ASINCOMMENT, newline},
/*INRI 17*/ {"ri", riincomment, rioutcomment},
/*INTROFF 18*/ {"troff",troffincomment,troffoutcomment},
/*INMOD2 19*/ {"mod2", mod2incomment, mod2outcomment},
{0, 0, 0}
};
void
printerrors(look_at_subclass, errorc, errorv)
boolean look_at_subclass;
int errorc;
@ -303,6 +298,7 @@ printerrors(look_at_subclass, errorc, errorv)
}
}
void
wordvprint(fyle, wordc, wordv)
FILE *fyle;
int wordc;
@ -322,6 +318,7 @@ wordvprint(fyle, wordc, wordv)
* Given a string, parse it into a number of words, and build
* a wordc wordv combination pointing into it.
*/
void
wordvbuild(string, r_wordc, r_wordv)
char *string;
int *r_wordc;
@ -354,7 +351,7 @@ wordvbuild(string, r_wordc, r_wordv)
*cp++ = '\0';
}
if (wordcount != 0)
error("Initial miscount of the number of words in a line\n");
errx(6, "initial miscount of the number of words in a line");
wordv[wordindex] = (char *)0;
#ifdef FULLDEBUG
for (wordcount = 0; wordcount < wordindex; wordcount++)
@ -377,7 +374,7 @@ int wordvcmp(wordv1, wordc, wordv2)
for (i = 0; i < wordc; i++){
if (wordv1[i] == 0 || wordv2[i] == 0)
return(-1);
if (back = strcmp(wordv1[i], wordv2[i])){
if ((back = strcmp(wordv1[i], wordv2[i]))){
return(back);
}
}

View file

@ -32,18 +32,23 @@
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "error.h"
#include "pathnames.h"
@ -56,6 +61,23 @@ static char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93";
#define FILEITERATE(fi, lb) for (fi = lb; fi <= nfiles; fi++)
int touchstatus = Q_YES;
int countfiles __P((Eptr *));
boolean edit __P((char *));
void errorprint __P((FILE *, Eptr, boolean));
void execvarg __P((int, int *, char ***));
void diverterrors __P((char *, int, Eptr **, int, boolean, int));
void hackfile __P((char *, Eptr **, int, int));
void insert __P((int));
int mustoverwrite __P((FILE *, FILE *));
int mustwrite __P((char *, int, FILE *));
int nopertain __P((Eptr **));
int oktotouch __P((char *));
boolean preview __P((char *, int, Eptr **, int));
int settotouch __P((char *));
void text __P((Eptr, boolean));
boolean writetouched __P((int));
void
findfiles(nerrors, errors, r_nfiles, r_files)
int nerrors;
Eptr *errors;
@ -143,6 +165,7 @@ char *class_table[] = {
int class_count[C_LAST - C_FIRST] = {0};
void
filenames(nfiles, files)
int nfiles;
Eptr **files;
@ -274,13 +297,14 @@ boolean touchfiles(nfiles, files, r_edargc, r_edargv)
}
}
void
hackfile(name, files, ix, nerrors)
char *name;
Eptr **files;
int ix;
{
boolean previewed;
int errordest; /* where errors go*/
int errordest; /* where errors go */
if (!oktotouch(name)) {
previewed = FALSE;
@ -384,6 +408,7 @@ int settotouch(name)
return(dest);
}
void
diverterrors(name, dest, files, ix, previewed, nterrors)
char *name;
int dest;
@ -480,6 +505,7 @@ int oktotouch(filename)
* We fill in the initial search string.
* We fill in the arguments, and the null.
*/
void
execvarg(n_pissed_on, r_argc, r_argv)
int n_pissed_on;
int *r_argc;
@ -531,8 +557,7 @@ boolean edit(name)
o_name = name;
if ( (o_touchedfile = fopen(name, "r")) == NULL){
fprintf(stderr, "%s: Can't open file \"%s\" to touch (read).\n",
processname, name);
warnx("can't open file \"%s\" to touch (read)", name);
return(TRUE);
}
(void)strcpy(n_name, canon_name);
@ -541,8 +566,7 @@ boolean edit(name)
if ( fd < 0 || (n_touchedfile = fdopen(fd, "w")) == NULL) {
if (fd >= 0)
close(fd);
fprintf(stderr,"%s: Can't open file \"%s\" to touch (write).\n",
processname, name);
warnx("can't open file \"%s\" to touch (write)", name);
return(TRUE);
}
tempfileopen = TRUE;
@ -554,6 +578,8 @@ boolean edit(name)
* Position to the line (before, after) the line given by place
*/
char edbuf[BUFSIZ];
void
insert(place)
int place;
{
@ -565,6 +591,7 @@ insert(place)
}
}
void
text(p, use_all)
reg Eptr p;
boolean use_all;
@ -584,6 +611,7 @@ text(p, use_all)
* write the touched file to its temporary copy,
* then bring the temporary in over the local file
*/
boolean
writetouched(overwrite)
int overwrite;
{
@ -601,9 +629,8 @@ writetouched(overwrite)
* Catastrophe in temporary area: file system full?
*/
botch = 1;
fprintf(stderr,
"%s: write failure: No errors inserted in \"%s\"\n",
processname, o_name);
warnx("write failure: no errors inserted in \"%s\"",
o_name);
}
}
fclose(n_touchedfile);
@ -617,14 +644,11 @@ writetouched(overwrite)
localfile = NULL;
tmpfile = NULL;
if ((localfile = fopen(o_name, "w")) == NULL){
fprintf(stderr,
"%s: Can't open file \"%s\" to overwrite.\n",
processname, o_name);
warnx("can't open file \"%s\" to overwrite", o_name);
botch++;
}
if ((tmpfile = fopen(n_name, "r")) == NULL){
fprintf(stderr, "%s: Can't open file \"%s\" to read.\n",
processname, n_name);
warnx("can't open file \"%s\" to read", n_name);
botch++;
}
if (!botch)
@ -634,11 +658,9 @@ writetouched(overwrite)
if (tmpfile != NULL)
fclose(tmpfile);
}
if (oktorm == 0){
fprintf(stderr, "%s: Catastrophe: A copy of \"%s\": was saved in \"%s\"\n",
processname, o_name, n_name);
exit(1);
}
if (oktorm == 0)
errx(1, "catastrophe: a copy of \"%s\" was saved in \"%s\"",
o_name, n_name);
/*
* Kiss the temp file good bye
*/
@ -649,7 +671,8 @@ writetouched(overwrite)
/*
* return 1 if the tmpfile can be removed after writing it out
*/
int mustoverwrite(preciousfile, tmpfile)
int
mustoverwrite(preciousfile, tmpfile)
FILE *preciousfile;
FILE *tmpfile;
{
@ -664,6 +687,7 @@ int mustoverwrite(preciousfile, tmpfile)
/*
* return 0 on catastrophe
*/
int
mustwrite(base, n, preciousfile)
char *base;
int n;
@ -676,7 +700,7 @@ mustwrite(base, n, preciousfile)
nwrote = fwrite(base, 1, n, preciousfile);
if (nwrote == n)
return(1);
perror(processname);
warn("fwrite");
switch(inquire(terse
? "Botch overwriting: retry? "
: "Botch overwriting the source file: retry? ")){
@ -722,6 +746,7 @@ onintr()
/*NOTREACHED*/
}
void
errorprint(place, errorp, print_all)
FILE *place;
Eptr errorp;