1: static  char *sccsid = "@(#)errormain.c	1.4 (Berkeley) 5/4/82";
   2: #include <sys/types.h>
   3: #include <stdio.h>
   4: #include <ctype.h>
   5: #include <signal.h>
   6: #include "error.h"
   7: 
   8: int nerrors = 0;
   9: Eptr    er_head;
  10: Eptr    *errors;
  11: 
  12: int nfiles = 0;
  13: Eptr    **files;    /* array of pointers into errors*/
  14: int language = INCC;
  15: 
  16: char    *currentfilename = "????";
  17: char    *processname;
  18: char    *im_on;         /* my tty name */
  19: 
  20: boolean query = FALSE;      /* query the operator if touch files */
  21: boolean notouch = FALSE;    /* don't touch ANY files */
  22: boolean piflag  = FALSE;    /* this is not pi */
  23: boolean terse   = FALSE;    /* Terse output */
  24: 
  25: char    *suffixlist = ".*"; /* initially, can touch any file */
  26: 
  27: int errorsort();
  28: int onintr();
  29: /*
  30:  *	error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile]
  31:  *
  32:  *	-T:	terse output
  33:  *
  34:  *	-I:	the following name, `ignorename' contains a list of
  35:  *		function names that are not to be treated as hard errors.
  36:  *		Default: ~/.errorsrc
  37:  *
  38:  *	-n:	don't touch ANY files!
  39:  *
  40:  *	-q:	The user is to be queried before touching each
  41:  *		file; if not specified, all files with hard, non
  42:  *		ignorable errors are touched (assuming they can be).
  43:  *
  44:  *	-t:	touch only files ending with the list of suffices, each
  45:  *		suffix preceded by a dot.
  46:  *		eg, -t .c.y.l
  47:  *		will touch only files ending with .c, .y or .l
  48:  *
  49:  *	-s:	print a summary of the error's categories.
  50:  *
  51:  *	-v:	after touching all files, overlay vi(1), ex(1) or ed(1)
  52:  *		on top of error, entered in the first file with
  53:  *		an error in it, with the appropriate editor
  54:  *		set up to use the "next" command to get the other
  55:  *		files containing errors.
  56:  *
  57:  *	-p:	(obsolete: for older versions of pi without bug
  58:  *		fix regarding printing out the name of the main file
  59:  *		with an error in it)
  60:  *		Take the following argument and use it as the name of
  61:  *		the pascal source file, suffix .p
  62:  *
  63:  *	-E:	show the errors in sorted order; intended for
  64:  *		debugging.
  65:  *
  66:  *	-S:	show the errors in unsorted order
  67:  *		(as they come from the error file)
  68:  *
  69:  *	infile:	The error messages come from this file.
  70:  *		Default: stdin
  71:  */
  72: main(argc, argv)
  73:     int argc;
  74:     char    *argv[];
  75: {
  76:     char    *cp;
  77:     char    *ignorename = 0;
  78:     int ed_argc;
  79:     char    **ed_argv;      /*return from touchfiles*/
  80:     boolean show_errors = FALSE;
  81:     boolean Show_Errors = FALSE;
  82:     boolean pr_summary = FALSE;
  83:     boolean edit_files = FALSE;
  84: 
  85:     processname = argv[0];
  86: 
  87:     errorfile = stdin;
  88:     if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){
  89:         for (cp = argv[1] + 1; *cp; cp++) switch(*cp){
  90:         default:
  91:             fprintf(stderr, "%s: -%c: Unknown flag\n",
  92:                 processname, *cp);
  93:             break;
  94: 
  95:         case 'n':   notouch = TRUE; break;
  96:         case 'q':   query = TRUE;   break;
  97:         case 'S':   Show_Errors = TRUE; break;
  98:         case 's':   pr_summary = TRUE;  break;
  99:         case 'v':   edit_files = TRUE;  break;
 100:         case 'T':   terse = TRUE;   break;
 101:         case 't':
 102:             *cp-- = 0; argv++; argc--;
 103:             if (argc > 1){
 104:                 suffixlist = argv[1];
 105:             }
 106:             break;
 107:         case 'I':   /*ignore file name*/
 108:             *cp-- = 0; argv++; argc--;
 109:             if (argc > 1)
 110:                 ignorename = argv[1];
 111:             break;
 112:         }
 113:     }
 114:     if (notouch)
 115:         suffixlist = 0;
 116:     if (argc > 1){
 117:         if (argc > 3){
 118:             fprintf(stderr, "%s: Only takes 0 or 1 arguments\n",
 119:                 processname);
 120:             exit(3);
 121:         }
 122:         if ( (errorfile = fopen(argv[1], "r")) == NULL){
 123:             fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n",
 124:                 processname, argv[1]);
 125:             exit(4);
 126:         }
 127:     }
 128:     im_on = "/dev/tty";
 129:     if ( (queryfile = fopen(im_on, "r")) == NULL){
 130:         fprintf(stderr,"%s: Can't open \"%s\" to query the user.\n",
 131:             processname, im_on);
 132:         exit(9);
 133:     }
 134:     if (signal(SIGINT, onintr) == SIG_IGN)
 135:         signal(SIGINT, SIG_IGN);
 136:     if (signal(SIGTERM, onintr) == SIG_IGN)
 137:         signal(SIGTERM, SIG_IGN);
 138:     getignored(ignorename);
 139:     eaterrors(&nerrors, &errors);
 140:     if (Show_Errors)
 141:         printerrors(TRUE, nerrors, errors);
 142:     qsort(errors, nerrors, sizeof(Eptr), errorsort);
 143:     if (show_errors)
 144:         printerrors(FALSE, nerrors, errors);
 145:     findfiles(nerrors, errors, &nfiles, &files);
 146: #define P(msg, arg) fprintf(stdout, msg, arg)
 147:     if (pr_summary){
 148:         if (nunknown)
 149:           P("%d Errors are unclassifiable.\n", nunknown);
 150:         if (nignore)
 151:           P("%d Errors are classifiable, but totally discarded.\n",nignore);
 152:         if (nsyncerrors)
 153:           P("%d Errors are synchronization errors.\n", nsyncerrors);
 154:         if (nignore)
 155:           P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard);
 156:         if (nnulled)
 157:           P("%d Errors are nulled because they refer to specific functions.\n", nnulled);
 158:         if (nnonspec)
 159:           P("%d Errors are not specific to any file.\n", nnonspec);
 160:         if (nthisfile)
 161:           P("%d Errors are specific to a given file, but not to a line.\n", nthisfile);
 162:         if (ntrue)
 163:           P("%d Errors are true errors, and can be inserted into the files.\n", ntrue);
 164:     }
 165:     filenames(nfiles, files);
 166:     fflush(stdout);
 167:     if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files)
 168:         forkvi(ed_argc, ed_argv);
 169: }
 170: 
 171: forkvi(argc, argv)
 172:     int argc;
 173:     char    **argv;
 174: {
 175:     if (query){
 176:         switch(inquire(terse
 177:             ? "Edit? "
 178:             : "Do you still want to edit the files you touched? ")){
 179:         case Q_NO:
 180:         case Q_no:
 181:             return;
 182:         default:
 183:             break;
 184:         }
 185:     }
 186:     /*
 187: 	 *	ed_agument's first argument is
 188: 	 *	a vi/ex compatabile search argument
 189: 	 *	to find the first occurance of ###
 190: 	 */
 191:     try("vi", argc, argv);
 192:     try("ex", argc, argv);
 193:     try("ed", argc-1, argv+1);
 194:     fprintf(stdout, "Can't find any editors.\n");
 195: }
 196: 
 197: try(name, argc, argv)
 198:     char    *name;
 199:     int argc;
 200:     char    **argv;
 201: {
 202:     argv[0] = name;
 203:     wordvprint(stdout, argc, argv);
 204:     fprintf(stdout, "\n");
 205:     fflush(stderr);
 206:     fflush(stdout);
 207:     sleep(2);
 208:     if (freopen(im_on, "r", stdin) == NULL)
 209:         return;
 210:     if (freopen(im_on, "w", stdout) == NULL)
 211:         return;
 212:     execvp(name, argv);
 213: }
 214: 
 215: int errorsort(epp1, epp2)
 216:         Eptr    *epp1, *epp2;
 217: {
 218:     reg Eptr    ep1, ep2;
 219:         int order;
 220:     /*
 221: 	 *	Sort by:
 222: 	 *	1)	synchronization, non specific, discarded errors first;
 223: 	 *	2)	nulled and true errors last
 224: 	 *		a)	grouped by similar file names
 225: 	 *			1)	grouped in ascending line number
 226: 	 */
 227:     ep1 = *epp1; ep2 = *epp2;
 228:     if (ep1 == 0 || ep2 == 0)
 229:         return(0);
 230:     if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){
 231:         return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1);
 232:     }
 233:     if (NOTSORTABLE(ep1->error_e_class))    /* then both are */
 234:         return(ep1->error_no - ep2->error_no);
 235:     order = strcmp(ep1->error_text[0], ep2->error_text[0]);
 236:     if (order == 0){
 237:         return(ep1->error_line - ep2->error_line);
 238:     }
 239:     return(order);
 240: }

Defined functions

errorsort defined in line 215; used 2 times
forkvi defined in line 171; used 1 times
main defined in line 72; never used
try defined in line 197; used 3 times

Defined variables

currentfilename defined in line 16; used 12 times
er_head defined in line 9; used 3 times
errors defined in line 10; used 20 times
files defined in line 13; used 44 times
im_on defined in line 18; used 5 times
language defined in line 14; used 31 times
nerrors defined in line 8; used 25 times
nfiles defined in line 12; used 24 times
notouch defined in line 21; used 2 times
piflag defined in line 22; never used
processname defined in line 17; used 19 times
query defined in line 20; used 6 times
sccsid defined in line 1; never used
suffixlist defined in line 25; used 2 times
terse defined in line 23; used 22 times

Defined macros

P defined in line 146; used 8 times
Last modified: 1983-06-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1138
Valid CSS Valid XHTML 1.0 Strict