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