1*1461Sroot static char *sccsid = "@(#)main.c 1.2 (Berkeley) 10/16/80"; 21457Sroot #include <stdio.h> 31457Sroot #include <ctype.h> 41457Sroot #include <signal.h> 51457Sroot #include "error.h" 61457Sroot 71457Sroot int nerrors = 0; 81457Sroot struct error_desc *er_head; 91457Sroot struct error_desc **errors; 101457Sroot 111457Sroot int nfiles = 0; 121457Sroot struct error_desc ***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 */ 221457Sroot 231457Sroot char *suffixlist = ".*"; /* initially, can touch any file */ 241457Sroot 251457Sroot int errorsort(); 261457Sroot int onintr(); 271457Sroot /* 281457Sroot * error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile] 291457Sroot * 301457Sroot * -I: the following name, `ignorename' contains a list of 311457Sroot * function names that are not to be treated as hard errors. 321457Sroot * Default: ~/.errorsrc 331457Sroot * 341457Sroot * -n: don't touch ANY files! 351457Sroot * 361457Sroot * -q: The user is to be queried before touching each 371457Sroot * file; if not specified, all files with hard, non 381457Sroot * ignorable errors are touched (assuming they can be). 391457Sroot * 401457Sroot * -t: touch only files ending with the list of suffices, each 411457Sroot * suffix preceded by a dot. 421457Sroot * eg, -t .c.y.l 431457Sroot * will touch only files ending with .c, .y or .l 441457Sroot * 451457Sroot * -s: print a summary of the error's categories. 461457Sroot * 471457Sroot * -v: after touching all files, overlay vi(1), ex(1) or ed(1) 481457Sroot * on top of error, entered in the first file with 491457Sroot * an error in it, with the appropriate editor 501457Sroot * set up to use the "next" command to get the other 511457Sroot * files containing errors. 521457Sroot * 531457Sroot * -p: (obsolete: for older versions of pi without bug 541457Sroot * fix regarding printing out the name of the main file 551457Sroot * with an error in it) 561457Sroot * Take the following argument and use it as the name of 571457Sroot * the pascal source file, suffix .p 581457Sroot * 591457Sroot * -E: show the errors in sorted order; intended for 601457Sroot * debugging. 611457Sroot * 621457Sroot * -S: show the errors in unsorted order 631457Sroot * (as they come from the error file) 641457Sroot * 651457Sroot * infile: The error messages come from this file. 661457Sroot * Default: stdin 671457Sroot */ 681457Sroot main(argc, argv) 691457Sroot int argc; 701457Sroot char *argv[]; 711457Sroot { 721457Sroot char *cp; 731457Sroot char *ignorename = 0; 741457Sroot int ed_argc; 751457Sroot char **ed_argv; /*return from touchfiles*/ 761457Sroot boolean show_errors = FALSE; 771457Sroot boolean Show_Errors = FALSE; 781457Sroot boolean pr_summary = FALSE; 791457Sroot boolean edit_files = FALSE; 801457Sroot 811457Sroot processname = argv[0]; 821457Sroot 831457Sroot errorfile = stdin; 841457Sroot if (argc > 1){ 851457Sroot for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){ 861457Sroot for (cp = argv[1] + 1; *cp; cp++){ 871457Sroot switch(*cp){ 881457Sroot default: 891457Sroot fprintf(stderr, "%s: -%c: Unknown flag\n", 901457Sroot processname, *cp); 911457Sroot break; 921457Sroot case 'n': /* no touch */ 931457Sroot notouch = TRUE; 941457Sroot break; 951457Sroot case 'q': /* query */ 961457Sroot query = TRUE; 971457Sroot break; 981457Sroot case 'S': 991457Sroot Show_Errors = TRUE; 1001457Sroot break; 1011457Sroot case 's': /* show summary */ 1021457Sroot pr_summary = TRUE; 1031457Sroot break; 1041457Sroot case 'v': /* edit files */ 1051457Sroot edit_files = TRUE; 1061457Sroot break; 1071457Sroot #ifndef ERNIE 1081457Sroot case 'p': 1091457Sroot *cp-- = 0; argv++; argc--; 1101457Sroot if (argc > 1){ 1111457Sroot currentfilename=argv[1]; 1121457Sroot piflag = TRUE; 1131457Sroot } 1141457Sroot break; 1151457Sroot #endif 1161457Sroot case 't': 1171457Sroot *cp-- = 0; argv++; argc--; 1181457Sroot if (argc > 1){ 1191457Sroot suffixlist = argv[1]; 1201457Sroot } 1211457Sroot break; 1221457Sroot case 'I': /*ignore file name*/ 1231457Sroot *cp-- = 0; argv++; argc--; 1241457Sroot if (argc > 1) 1251457Sroot ignorename = argv[1]; 1261457Sroot break; 1271457Sroot } /*end of the argument switch*/ 1281457Sroot } /*end of loop to consume characters after '-'*/ 1291457Sroot } 1301457Sroot } /* end of being at least one argument */ 1311457Sroot if (notouch) 1321457Sroot suffixlist = 0; 1331457Sroot if (argc > 1){ 1341457Sroot if (argc > 3){ 1351457Sroot fprintf(stderr, "%s: Only takes 0 or 1 arguments\n", 1361457Sroot processname); 1371457Sroot exit(3); 1381457Sroot } 1391457Sroot if ( (errorfile = fopen(argv[1], "r")) == NULL){ 1401457Sroot fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n", 1411457Sroot processname, argv[1]); 1421457Sroot exit(4); 1431457Sroot } 1441457Sroot } 145*1461Sroot im_on = "/dev/tty"; 1461457Sroot if ( (queryfile = fopen(im_on, "r")) == NULL){ 1471457Sroot fprintf(stderr,"%s: Can't open \"%s\" to query the user.\n", 1481457Sroot processname, im_on); 1491457Sroot exit(9); 1501457Sroot } 1511457Sroot if (signal(SIGINT, onintr) == SIG_IGN) 1521457Sroot signal(SIGINT, SIG_IGN); 1531457Sroot if (signal(SIGTERM, onintr) == SIG_IGN) 1541457Sroot signal(SIGTERM, SIG_IGN); 1551457Sroot getignored(ignorename); 1561457Sroot eaterrors(&nerrors, &errors); 1571457Sroot if (Show_Errors) 1581457Sroot printerrors(TRUE, nerrors, errors); 1591457Sroot qsort(errors, nerrors, sizeof (struct error_desc *), errorsort); 1601457Sroot if (show_errors) 1611457Sroot printerrors(FALSE, nerrors, errors); 1621457Sroot findfiles(nerrors, errors, &nfiles, &files); 1631457Sroot #define P(msg, arg) fprintf(stdout, msg, arg) 1641457Sroot if (pr_summary){ 1651457Sroot if (nunknown) 1661457Sroot P("%d Errors are unclassifiable.\n", nunknown); 1671457Sroot if (nignore) 1681457Sroot P("%d Errors are classifiable, but totally discarded.\n",nignore); 1691457Sroot if (nsyncerrors) 1701457Sroot P("%d Errors are synchronization errors.\n", nsyncerrors); 1711457Sroot if (nignore) 1721457Sroot P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard); 1731457Sroot if (nnulled) 1741457Sroot P("%d Errors are nulled because they refer to specific functions.\n", nnulled); 1751457Sroot if (nnonspec) 1761457Sroot P("%d Errors are not specific to any file.\n", nnonspec); 1771457Sroot if (nthisfile) 1781457Sroot P("%d Errors are specific to a given file, but not to a line.\n", nthisfile); 1791457Sroot if (ntrue) 1801457Sroot P("%d Errors are true errors, and can be inserted into the files.\n", ntrue); 1811457Sroot } 1821457Sroot filenames(nfiles, files); 1831457Sroot fflush(stdout); 1841457Sroot if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files){ 1851457Sroot if (!query || 1861457Sroot inquire("Do you still want to edit the files you touched? ")){ 1871457Sroot /* 1881457Sroot * ed_agument's first argument is 1891457Sroot * a vi/ex compatabile search argument 1901457Sroot * to find the first occurance of ### 1911457Sroot */ 1921457Sroot try("vi", ed_argc, ed_argv); 1931457Sroot try("ex", ed_argc, ed_argv); 1941457Sroot try("ed", ed_argc-1, ed_argv+1); 1951457Sroot fprintf(stdout, "Can't find any editors.\n"); 1961457Sroot } 1971457Sroot } 1981457Sroot } 1991457Sroot 2001457Sroot try(name, argc, argv) 2011457Sroot char *name; 2021457Sroot int argc; 2031457Sroot char **argv; 2041457Sroot { 2051457Sroot argv[0] = name; 2061457Sroot wordvprint(stdout, argc, argv); 2071457Sroot fprintf(stdout, "\n"); 2081457Sroot fflush(stderr); 2091457Sroot fflush(stdout); 2101457Sroot sleep(2); 2111457Sroot if (freopen(im_on, "r", stdin) == NULL) 2121457Sroot return; 2131457Sroot if (freopen(im_on, "w", stdout) == NULL) 2141457Sroot return; 2151457Sroot execvp(name, argv); 2161457Sroot } 2171457Sroot 2181457Sroot int errorsort(epp1, epp2) 2191457Sroot struct error_desc **epp1, **epp2; 2201457Sroot { 2211457Sroot register struct error_desc *ep1, *ep2; 2221457Sroot int order; 2231457Sroot /* 2241457Sroot * Sort by: 2251457Sroot * 1) synchronization, non specific, discarded errors first; 2261457Sroot * 2) nulled and true errors last 2271457Sroot * a) grouped by similar file names 2281457Sroot * 1) grouped in ascending line number 2291457Sroot */ 2301457Sroot ep1 = *epp1; ep2 = *epp2; 2311457Sroot if (ep1 == 0 || ep2 == 0) 2321457Sroot return(0); 2331457Sroot if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){ 2341457Sroot return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1); 2351457Sroot } 2361457Sroot if (NOTSORTABLE(ep1->error_e_class)) /* then both are */ 2371457Sroot return(ep1->error_no - ep2->error_no); 2381457Sroot order = strcmp(ep1->error_text[0], ep2->error_text[0]); 2391457Sroot if (order == 0){ 2401457Sroot return(ep1->error_line - ep2->error_line); 2411457Sroot } 2421457Sroot return(order); 2431457Sroot } 244