1*5592Srrh static char *sccsid = "@(#)main.c 1.3 (Berkeley) 01/22/82"; 21457Sroot #include <stdio.h> 31457Sroot #include <ctype.h> 41457Sroot #include <signal.h> 51457Sroot #include "error.h" 61457Sroot 71457Sroot int nerrors = 0; 8*5592Srrh Eptr er_head; 9*5592Srrh Eptr *errors; 101457Sroot 111457Sroot int nfiles = 0; 12*5592Srrh Eptr **files; /* array of pointers into errors*/ 131457Sroot int language = INCC; 141457Sroot 151457Sroot char *currentfilename = "????"; 161457Sroot char *processname; 171457Sroot char *im_on; /* my tty name */ 181457Sroot 191457Sroot boolean query = FALSE; /* query the operator if touch files */ 201457Sroot boolean notouch = FALSE; /* don't touch ANY files */ 211457Sroot boolean piflag = FALSE; /* this is not pi */ 22*5592Srrh boolean terse = FALSE; /* Terse output */ 231457Sroot 241457Sroot char *suffixlist = ".*"; /* initially, can touch any file */ 251457Sroot 261457Sroot int errorsort(); 271457Sroot int onintr(); 281457Sroot /* 291457Sroot * error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile] 301457Sroot * 31*5592Srrh * -T: terse output 32*5592Srrh * 331457Sroot * -I: the following name, `ignorename' contains a list of 341457Sroot * function names that are not to be treated as hard errors. 351457Sroot * Default: ~/.errorsrc 361457Sroot * 371457Sroot * -n: don't touch ANY files! 381457Sroot * 391457Sroot * -q: The user is to be queried before touching each 401457Sroot * file; if not specified, all files with hard, non 411457Sroot * ignorable errors are touched (assuming they can be). 421457Sroot * 431457Sroot * -t: touch only files ending with the list of suffices, each 441457Sroot * suffix preceded by a dot. 451457Sroot * eg, -t .c.y.l 461457Sroot * will touch only files ending with .c, .y or .l 471457Sroot * 481457Sroot * -s: print a summary of the error's categories. 491457Sroot * 501457Sroot * -v: after touching all files, overlay vi(1), ex(1) or ed(1) 511457Sroot * on top of error, entered in the first file with 521457Sroot * an error in it, with the appropriate editor 531457Sroot * set up to use the "next" command to get the other 541457Sroot * files containing errors. 551457Sroot * 561457Sroot * -p: (obsolete: for older versions of pi without bug 571457Sroot * fix regarding printing out the name of the main file 581457Sroot * with an error in it) 591457Sroot * Take the following argument and use it as the name of 601457Sroot * the pascal source file, suffix .p 611457Sroot * 621457Sroot * -E: show the errors in sorted order; intended for 631457Sroot * debugging. 641457Sroot * 651457Sroot * -S: show the errors in unsorted order 661457Sroot * (as they come from the error file) 671457Sroot * 681457Sroot * infile: The error messages come from this file. 691457Sroot * Default: stdin 701457Sroot */ 711457Sroot main(argc, argv) 721457Sroot int argc; 731457Sroot char *argv[]; 741457Sroot { 751457Sroot char *cp; 761457Sroot char *ignorename = 0; 771457Sroot int ed_argc; 781457Sroot char **ed_argv; /*return from touchfiles*/ 791457Sroot boolean show_errors = FALSE; 801457Sroot boolean Show_Errors = FALSE; 811457Sroot boolean pr_summary = FALSE; 821457Sroot boolean edit_files = FALSE; 831457Sroot 841457Sroot processname = argv[0]; 851457Sroot 861457Sroot errorfile = stdin; 87*5592Srrh if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){ 88*5592Srrh for (cp = argv[1] + 1; *cp; cp++) switch(*cp){ 89*5592Srrh default: 90*5592Srrh fprintf(stderr, "%s: -%c: Unknown flag\n", 91*5592Srrh processname, *cp); 92*5592Srrh break; 93*5592Srrh 94*5592Srrh case 'n': notouch = TRUE; break; 95*5592Srrh case 'q': query = TRUE; break; 96*5592Srrh case 'S': Show_Errors = TRUE; break; 97*5592Srrh case 's': pr_summary = TRUE; break; 98*5592Srrh case 'v': edit_files = TRUE; break; 99*5592Srrh case 'T': terse = TRUE; break; 1001457Sroot #ifndef ERNIE 101*5592Srrh case 'p': 102*5592Srrh *cp-- = 0; argv++; argc--; 103*5592Srrh if (argc > 1){ 104*5592Srrh currentfilename = argv[1]; 105*5592Srrh piflag = TRUE; 106*5592Srrh } 107*5592Srrh break; 1081457Sroot #endif 109*5592Srrh case 't': 110*5592Srrh *cp-- = 0; argv++; argc--; 111*5592Srrh if (argc > 1){ 112*5592Srrh suffixlist = argv[1]; 113*5592Srrh } 114*5592Srrh break; 115*5592Srrh case 'I': /*ignore file name*/ 116*5592Srrh *cp-- = 0; argv++; argc--; 117*5592Srrh if (argc > 1) 118*5592Srrh ignorename = argv[1]; 119*5592Srrh break; 120*5592Srrh } 121*5592Srrh } 1221457Sroot if (notouch) 1231457Sroot suffixlist = 0; 1241457Sroot if (argc > 1){ 1251457Sroot if (argc > 3){ 1261457Sroot fprintf(stderr, "%s: Only takes 0 or 1 arguments\n", 1271457Sroot processname); 1281457Sroot exit(3); 1291457Sroot } 1301457Sroot if ( (errorfile = fopen(argv[1], "r")) == NULL){ 1311457Sroot fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n", 1321457Sroot processname, argv[1]); 1331457Sroot exit(4); 1341457Sroot } 1351457Sroot } 1361461Sroot im_on = "/dev/tty"; 1371457Sroot if ( (queryfile = fopen(im_on, "r")) == NULL){ 1381457Sroot fprintf(stderr,"%s: Can't open \"%s\" to query the user.\n", 1391457Sroot processname, im_on); 1401457Sroot exit(9); 1411457Sroot } 1421457Sroot if (signal(SIGINT, onintr) == SIG_IGN) 1431457Sroot signal(SIGINT, SIG_IGN); 1441457Sroot if (signal(SIGTERM, onintr) == SIG_IGN) 1451457Sroot signal(SIGTERM, SIG_IGN); 1461457Sroot getignored(ignorename); 1471457Sroot eaterrors(&nerrors, &errors); 1481457Sroot if (Show_Errors) 1491457Sroot printerrors(TRUE, nerrors, errors); 150*5592Srrh qsort(errors, nerrors, sizeof(Eptr), errorsort); 1511457Sroot if (show_errors) 1521457Sroot printerrors(FALSE, nerrors, errors); 1531457Sroot findfiles(nerrors, errors, &nfiles, &files); 1541457Sroot #define P(msg, arg) fprintf(stdout, msg, arg) 1551457Sroot if (pr_summary){ 1561457Sroot if (nunknown) 1571457Sroot P("%d Errors are unclassifiable.\n", nunknown); 1581457Sroot if (nignore) 1591457Sroot P("%d Errors are classifiable, but totally discarded.\n",nignore); 1601457Sroot if (nsyncerrors) 1611457Sroot P("%d Errors are synchronization errors.\n", nsyncerrors); 1621457Sroot if (nignore) 1631457Sroot P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard); 1641457Sroot if (nnulled) 1651457Sroot P("%d Errors are nulled because they refer to specific functions.\n", nnulled); 1661457Sroot if (nnonspec) 1671457Sroot P("%d Errors are not specific to any file.\n", nnonspec); 1681457Sroot if (nthisfile) 1691457Sroot P("%d Errors are specific to a given file, but not to a line.\n", nthisfile); 1701457Sroot if (ntrue) 1711457Sroot P("%d Errors are true errors, and can be inserted into the files.\n", ntrue); 1721457Sroot } 1731457Sroot filenames(nfiles, files); 1741457Sroot fflush(stdout); 175*5592Srrh if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files) 176*5592Srrh forkvi(ed_argc, ed_argv); 177*5592Srrh } 178*5592Srrh 179*5592Srrh forkvi(argc, argv) 180*5592Srrh int argc; 181*5592Srrh char **argv; 182*5592Srrh { 183*5592Srrh if (query){ 184*5592Srrh switch(inquire(terse 185*5592Srrh ? "Edit? " 186*5592Srrh : "Do you still want to edit the files you touched? ")){ 187*5592Srrh case Q_NO: 188*5592Srrh case Q_no: 189*5592Srrh return; 190*5592Srrh default: 191*5592Srrh break; 1921457Sroot } 1931457Sroot } 194*5592Srrh /* 195*5592Srrh * ed_agument's first argument is 196*5592Srrh * a vi/ex compatabile search argument 197*5592Srrh * to find the first occurance of ### 198*5592Srrh */ 199*5592Srrh try("vi", argc, argv); 200*5592Srrh try("ex", argc, argv); 201*5592Srrh try("ed", argc-1, argv+1); 202*5592Srrh fprintf(stdout, "Can't find any editors.\n"); 2031457Sroot } 2041457Sroot 2051457Sroot try(name, argc, argv) 2061457Sroot char *name; 2071457Sroot int argc; 2081457Sroot char **argv; 2091457Sroot { 2101457Sroot argv[0] = name; 2111457Sroot wordvprint(stdout, argc, argv); 2121457Sroot fprintf(stdout, "\n"); 2131457Sroot fflush(stderr); 2141457Sroot fflush(stdout); 2151457Sroot sleep(2); 2161457Sroot if (freopen(im_on, "r", stdin) == NULL) 2171457Sroot return; 2181457Sroot if (freopen(im_on, "w", stdout) == NULL) 2191457Sroot return; 2201457Sroot execvp(name, argv); 2211457Sroot } 2221457Sroot 2231457Sroot int errorsort(epp1, epp2) 224*5592Srrh Eptr *epp1, *epp2; 2251457Sroot { 226*5592Srrh reg Eptr ep1, ep2; 227*5592Srrh int order; 2281457Sroot /* 2291457Sroot * Sort by: 2301457Sroot * 1) synchronization, non specific, discarded errors first; 2311457Sroot * 2) nulled and true errors last 2321457Sroot * a) grouped by similar file names 2331457Sroot * 1) grouped in ascending line number 2341457Sroot */ 2351457Sroot ep1 = *epp1; ep2 = *epp2; 2361457Sroot if (ep1 == 0 || ep2 == 0) 2371457Sroot return(0); 2381457Sroot if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){ 2391457Sroot return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1); 2401457Sroot } 2411457Sroot if (NOTSORTABLE(ep1->error_e_class)) /* then both are */ 2421457Sroot return(ep1->error_no - ep2->error_no); 2431457Sroot order = strcmp(ep1->error_text[0], ep2->error_text[0]); 2441457Sroot if (order == 0){ 2451457Sroot return(ep1->error_line - ep2->error_line); 2461457Sroot } 2471457Sroot return(order); 2481457Sroot } 249