1*21636Sdist /* 2*21636Sdist * Copyright (c) 1980 Regents of the University of California. 3*21636Sdist * All rights reserved. The Berkeley software License Agreement 4*21636Sdist * specifies the terms and conditions for redistribution. 5*21636Sdist */ 6*21636Sdist 7*21636Sdist #ifndef lint 8*21636Sdist char copyright[] = 9*21636Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 10*21636Sdist All rights reserved.\n"; 11*21636Sdist #endif not lint 12*21636Sdist 13*21636Sdist static char *sccsid = "@(#)main.c 5.1 (Berkeley) 05/31/85"; 141457Sroot #include <stdio.h> 151457Sroot #include <ctype.h> 161457Sroot #include <signal.h> 171457Sroot #include "error.h" 181457Sroot 191457Sroot int nerrors = 0; 205592Srrh Eptr er_head; 215592Srrh Eptr *errors; 221457Sroot 231457Sroot int nfiles = 0; 245592Srrh Eptr **files; /* array of pointers into errors*/ 251457Sroot int language = INCC; 261457Sroot 271457Sroot char *currentfilename = "????"; 281457Sroot char *processname; 2916564Sralph char im_on[] = "/dev/tty"; /* my tty name */ 301457Sroot 311457Sroot boolean query = FALSE; /* query the operator if touch files */ 321457Sroot boolean notouch = FALSE; /* don't touch ANY files */ 331457Sroot boolean piflag = FALSE; /* this is not pi */ 345592Srrh boolean terse = FALSE; /* Terse output */ 351457Sroot 361457Sroot char *suffixlist = ".*"; /* initially, can touch any file */ 371457Sroot 381457Sroot int errorsort(); 391457Sroot int onintr(); 401457Sroot /* 411457Sroot * error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile] 421457Sroot * 435592Srrh * -T: terse output 445592Srrh * 451457Sroot * -I: the following name, `ignorename' contains a list of 461457Sroot * function names that are not to be treated as hard errors. 471457Sroot * Default: ~/.errorsrc 481457Sroot * 491457Sroot * -n: don't touch ANY files! 501457Sroot * 511457Sroot * -q: The user is to be queried before touching each 521457Sroot * file; if not specified, all files with hard, non 531457Sroot * ignorable errors are touched (assuming they can be). 541457Sroot * 551457Sroot * -t: touch only files ending with the list of suffices, each 561457Sroot * suffix preceded by a dot. 571457Sroot * eg, -t .c.y.l 581457Sroot * will touch only files ending with .c, .y or .l 591457Sroot * 601457Sroot * -s: print a summary of the error's categories. 611457Sroot * 621457Sroot * -v: after touching all files, overlay vi(1), ex(1) or ed(1) 631457Sroot * on top of error, entered in the first file with 641457Sroot * an error in it, with the appropriate editor 651457Sroot * set up to use the "next" command to get the other 661457Sroot * files containing errors. 671457Sroot * 681457Sroot * -p: (obsolete: for older versions of pi without bug 691457Sroot * fix regarding printing out the name of the main file 701457Sroot * with an error in it) 711457Sroot * Take the following argument and use it as the name of 721457Sroot * the pascal source file, suffix .p 731457Sroot * 741457Sroot * -E: show the errors in sorted order; intended for 751457Sroot * debugging. 761457Sroot * 771457Sroot * -S: show the errors in unsorted order 781457Sroot * (as they come from the error file) 791457Sroot * 801457Sroot * infile: The error messages come from this file. 811457Sroot * Default: stdin 821457Sroot */ 831457Sroot main(argc, argv) 841457Sroot int argc; 851457Sroot char *argv[]; 861457Sroot { 871457Sroot char *cp; 881457Sroot char *ignorename = 0; 891457Sroot int ed_argc; 901457Sroot char **ed_argv; /*return from touchfiles*/ 911457Sroot boolean show_errors = FALSE; 921457Sroot boolean Show_Errors = FALSE; 931457Sroot boolean pr_summary = FALSE; 941457Sroot boolean edit_files = FALSE; 951457Sroot 961457Sroot processname = argv[0]; 971457Sroot 981457Sroot errorfile = stdin; 995592Srrh if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){ 1005592Srrh for (cp = argv[1] + 1; *cp; cp++) switch(*cp){ 1015592Srrh default: 1025592Srrh fprintf(stderr, "%s: -%c: Unknown flag\n", 1035592Srrh processname, *cp); 1045592Srrh break; 1055592Srrh 1065592Srrh case 'n': notouch = TRUE; break; 1075592Srrh case 'q': query = TRUE; break; 1085592Srrh case 'S': Show_Errors = TRUE; break; 1095592Srrh case 's': pr_summary = TRUE; break; 1105592Srrh case 'v': edit_files = TRUE; break; 1115592Srrh case 'T': terse = TRUE; break; 1125592Srrh case 't': 1135592Srrh *cp-- = 0; argv++; argc--; 1145592Srrh if (argc > 1){ 1155592Srrh suffixlist = argv[1]; 1165592Srrh } 1175592Srrh break; 1185592Srrh case 'I': /*ignore file name*/ 1195592Srrh *cp-- = 0; argv++; argc--; 1205592Srrh if (argc > 1) 1215592Srrh ignorename = argv[1]; 1225592Srrh break; 1235592Srrh } 1245592Srrh } 1251457Sroot if (notouch) 1261457Sroot suffixlist = 0; 1271457Sroot if (argc > 1){ 1281457Sroot if (argc > 3){ 1291457Sroot fprintf(stderr, "%s: Only takes 0 or 1 arguments\n", 1301457Sroot processname); 1311457Sroot exit(3); 1321457Sroot } 1331457Sroot if ( (errorfile = fopen(argv[1], "r")) == NULL){ 1341457Sroot fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n", 1351457Sroot processname, argv[1]); 1361457Sroot exit(4); 1371457Sroot } 1381457Sroot } 1391457Sroot if ( (queryfile = fopen(im_on, "r")) == NULL){ 14016564Sralph if (query){ 14116564Sralph fprintf(stderr, 14216564Sralph "%s: Can't open \"%s\" to query the user.\n", 14316564Sralph processname, im_on); 14416564Sralph exit(9); 14516564Sralph } 1461457Sroot } 1471457Sroot if (signal(SIGINT, onintr) == SIG_IGN) 1481457Sroot signal(SIGINT, SIG_IGN); 1491457Sroot if (signal(SIGTERM, onintr) == SIG_IGN) 1501457Sroot signal(SIGTERM, SIG_IGN); 1511457Sroot getignored(ignorename); 1521457Sroot eaterrors(&nerrors, &errors); 1531457Sroot if (Show_Errors) 1541457Sroot printerrors(TRUE, nerrors, errors); 1555592Srrh qsort(errors, nerrors, sizeof(Eptr), errorsort); 1561457Sroot if (show_errors) 1571457Sroot printerrors(FALSE, nerrors, errors); 1581457Sroot findfiles(nerrors, errors, &nfiles, &files); 1591457Sroot #define P(msg, arg) fprintf(stdout, msg, arg) 1601457Sroot if (pr_summary){ 1611457Sroot if (nunknown) 1621457Sroot P("%d Errors are unclassifiable.\n", nunknown); 1631457Sroot if (nignore) 1641457Sroot P("%d Errors are classifiable, but totally discarded.\n",nignore); 1651457Sroot if (nsyncerrors) 1661457Sroot P("%d Errors are synchronization errors.\n", nsyncerrors); 1671457Sroot if (nignore) 1681457Sroot P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard); 1691457Sroot if (nnulled) 1701457Sroot P("%d Errors are nulled because they refer to specific functions.\n", nnulled); 1711457Sroot if (nnonspec) 1721457Sroot P("%d Errors are not specific to any file.\n", nnonspec); 1731457Sroot if (nthisfile) 1741457Sroot P("%d Errors are specific to a given file, but not to a line.\n", nthisfile); 1751457Sroot if (ntrue) 1761457Sroot P("%d Errors are true errors, and can be inserted into the files.\n", ntrue); 1771457Sroot } 1781457Sroot filenames(nfiles, files); 1791457Sroot fflush(stdout); 1805592Srrh if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files) 1815592Srrh forkvi(ed_argc, ed_argv); 1825592Srrh } 1835592Srrh 1845592Srrh forkvi(argc, argv) 1855592Srrh int argc; 1865592Srrh char **argv; 1875592Srrh { 1885592Srrh if (query){ 1895592Srrh switch(inquire(terse 1905592Srrh ? "Edit? " 1915592Srrh : "Do you still want to edit the files you touched? ")){ 1925592Srrh case Q_NO: 1935592Srrh case Q_no: 1945592Srrh return; 1955592Srrh default: 1965592Srrh break; 1971457Sroot } 1981457Sroot } 1995592Srrh /* 2005592Srrh * ed_agument's first argument is 2015592Srrh * a vi/ex compatabile search argument 2025592Srrh * to find the first occurance of ### 2035592Srrh */ 2045592Srrh try("vi", argc, argv); 2055592Srrh try("ex", argc, argv); 2065592Srrh try("ed", argc-1, argv+1); 2075592Srrh fprintf(stdout, "Can't find any editors.\n"); 2081457Sroot } 2091457Sroot 2101457Sroot try(name, argc, argv) 2111457Sroot char *name; 2121457Sroot int argc; 2131457Sroot char **argv; 2141457Sroot { 2151457Sroot argv[0] = name; 2161457Sroot wordvprint(stdout, argc, argv); 2171457Sroot fprintf(stdout, "\n"); 2181457Sroot fflush(stderr); 2191457Sroot fflush(stdout); 2201457Sroot sleep(2); 2211457Sroot if (freopen(im_on, "r", stdin) == NULL) 2221457Sroot return; 2231457Sroot if (freopen(im_on, "w", stdout) == NULL) 2241457Sroot return; 2251457Sroot execvp(name, argv); 2261457Sroot } 2271457Sroot 2281457Sroot int errorsort(epp1, epp2) 2295592Srrh Eptr *epp1, *epp2; 2301457Sroot { 2315592Srrh reg Eptr ep1, ep2; 2325592Srrh int order; 2331457Sroot /* 2341457Sroot * Sort by: 2351457Sroot * 1) synchronization, non specific, discarded errors first; 2361457Sroot * 2) nulled and true errors last 2371457Sroot * a) grouped by similar file names 2381457Sroot * 1) grouped in ascending line number 2391457Sroot */ 2401457Sroot ep1 = *epp1; ep2 = *epp2; 2411457Sroot if (ep1 == 0 || ep2 == 0) 2421457Sroot return(0); 2431457Sroot if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){ 2441457Sroot return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1); 2451457Sroot } 2461457Sroot if (NOTSORTABLE(ep1->error_e_class)) /* then both are */ 2471457Sroot return(ep1->error_no - ep2->error_no); 2481457Sroot order = strcmp(ep1->error_text[0], ep2->error_text[0]); 2491457Sroot if (order == 0){ 2501457Sroot return(ep1->error_line - ep2->error_line); 2511457Sroot } 2521457Sroot return(order); 2531457Sroot } 254