2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char copyright[] =
36 "@(#) Copyright (c) 1980, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
41 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
51 #include "pathnames.h"
58 Eptr **files; /* array of pointers into errors*/
61 char *currentfilename = "????";
63 char im_on[] = _PATH_TTY; /* my tty name */
65 boolean query = FALSE; /* query the operator if touch files */
66 boolean notouch = FALSE; /* don't touch ANY files */
67 boolean piflag = FALSE; /* this is not pi */
68 boolean terse = FALSE; /* Terse output */
70 char *suffixlist = ".*"; /* initially, can touch any file */
75 * error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile]
79 * -I: the following name, `ignorename' contains a list of
80 * function names that are not to be treated as hard errors.
81 * Default: ~/.errorsrc
83 * -n: don't touch ANY files!
85 * -q: The user is to be queried before touching each
86 * file; if not specified, all files with hard, non
87 * ignorable errors are touched (assuming they can be).
89 * -t: touch only files ending with the list of suffices, each
90 * suffix preceded by a dot.
92 * will touch only files ending with .c, .y or .l
94 * -s: print a summary of the error's categories.
96 * -v: after touching all files, overlay vi(1), ex(1) or ed(1)
97 * on top of error, entered in the first file with
98 * an error in it, with the appropriate editor
99 * set up to use the "next" command to get the other
100 * files containing errors.
102 * -p: (obsolete: for older versions of pi without bug
103 * fix regarding printing out the name of the main file
104 * with an error in it)
105 * Take the following argument and use it as the name of
106 * the pascal source file, suffix .p
108 * -E: show the errors in sorted order; intended for
111 * -S: show the errors in unsorted order
112 * (as they come from the error file)
114 * infile: The error messages come from this file.
122 char *ignorename = 0;
124 char **ed_argv; /*return from touchfiles*/
125 boolean show_errors = FALSE;
126 boolean Show_Errors = FALSE;
127 boolean pr_summary = FALSE;
128 boolean edit_files = FALSE;
130 processname = argv[0];
133 if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){
134 for (cp = argv[1] + 1; *cp; cp++) switch(*cp){
136 fprintf(stderr, "%s: -%c: Unknown flag\n",
140 case 'n': notouch = TRUE; break;
141 case 'q': query = TRUE; break;
142 case 'S': Show_Errors = TRUE; break;
143 case 's': pr_summary = TRUE; break;
144 case 'v': edit_files = TRUE; break;
145 case 'T': terse = TRUE; break;
147 *cp-- = 0; argv++; argc--;
149 suffixlist = argv[1];
152 case 'I': /*ignore file name*/
153 *cp-- = 0; argv++; argc--;
155 ignorename = argv[1];
163 fprintf(stderr, "%s: Only takes 0 or 1 arguments\n",
167 if ( (errorfile = fopen(argv[1], "r")) == NULL){
168 fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n",
169 processname, argv[1]);
173 if ( (queryfile = fopen(im_on, "r")) == NULL){
176 "%s: Can't open \"%s\" to query the user.\n",
181 if (signal(SIGINT, onintr) == SIG_IGN)
182 signal(SIGINT, SIG_IGN);
183 if (signal(SIGTERM, onintr) == SIG_IGN)
184 signal(SIGTERM, SIG_IGN);
185 getignored(ignorename);
186 eaterrors(&nerrors, &errors);
188 printerrors(TRUE, nerrors, errors);
189 qsort(errors, nerrors, sizeof(Eptr), errorsort);
191 printerrors(FALSE, nerrors, errors);
192 findfiles(nerrors, errors, &nfiles, &files);
193 #define P(msg, arg) fprintf(stdout, msg, arg)
196 P("%d Errors are unclassifiable.\n", nunknown);
198 P("%d Errors are classifiable, but totally discarded.\n",nignore);
200 P("%d Errors are synchronization errors.\n", nsyncerrors);
202 P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard);
204 P("%d Errors are nulled because they refer to specific functions.\n", nnulled);
206 P("%d Errors are not specific to any file.\n", nnonspec);
208 P("%d Errors are specific to a given file, but not to a line.\n", nthisfile);
210 P("%d Errors are true errors, and can be inserted into the files.\n", ntrue);
212 filenames(nfiles, files);
214 if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files)
215 forkvi(ed_argc, ed_argv);
225 : "Do you still want to edit the files you touched? ")){
234 * ed_agument's first argument is
235 * a vi/ex compatabile search argument
236 * to find the first occurance of ###
238 try("vi", argc, argv);
239 try("ex", argc, argv);
240 try("ed", argc-1, argv+1);
241 fprintf(stdout, "Can't find any editors.\n");
244 try(name, argc, argv)
250 wordvprint(stdout, argc, argv);
251 fprintf(stdout, "\n");
255 if (freopen(im_on, "r", stdin) == NULL)
257 if (freopen(im_on, "w", stdout) == NULL)
262 int errorsort(epp1, epp2)
269 * 1) synchronization, non specific, discarded errors first;
270 * 2) nulled and true errors last
271 * a) grouped by similar file names
272 * 1) grouped in ascending line number
274 ep1 = *epp1; ep2 = *epp2;
275 if (ep1 == 0 || ep2 == 0)
277 if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){
278 return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1);
280 if (NOTSORTABLE(ep1->error_e_class)) /* then both are */
281 return(ep1->error_no - ep2->error_no);
282 order = strcmp(ep1->error_text[0], ep2->error_text[0]);
284 return(ep1->error_line - ep2->error_line);