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

Defined functions

errorsort defined in line 228; used 2 times
forkvi defined in line 184; used 1 times
main defined in line 83; never used
try defined in line 210; used 3 times

Defined variables

copyright defined in line 8; never used
currentfilename defined in line 27; used 14 times
er_head defined in line 20; used 3 times
errors defined in line 21; used 20 times
files defined in line 24; used 44 times
im_on defined in line 29; used 4 times
nerrors defined in line 19; used 25 times
nfiles defined in line 23; used 24 times
notouch defined in line 32; used 2 times
piflag defined in line 33; never used
processname defined in line 28; used 19 times
query defined in line 31; used 8 times
sccsid defined in line 13; never used
suffixlist defined in line 36; used 2 times
terse defined in line 34; used 22 times

Defined macros

P defined in line 159; used 8 times
Last modified: 1985-05-31
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1694
Valid CSS Valid XHTML 1.0 Strict