121636Sdist /* 221636Sdist * Copyright (c) 1980 Regents of the University of California. 3*34664Sbostic * All rights reserved. 4*34664Sbostic * 5*34664Sbostic * Redistribution and use in source and binary forms are permitted 6*34664Sbostic * provided that this notice is preserved and that due credit is given 7*34664Sbostic * to the University of California at Berkeley. The name of the University 8*34664Sbostic * may not be used to endorse or promote products derived from this 9*34664Sbostic * software without specific prior written permission. This software 10*34664Sbostic * is provided ``as is'' without express or implied warranty. 1121636Sdist */ 1221636Sdist 1321636Sdist #ifndef lint 1421636Sdist char copyright[] = 1521636Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1621636Sdist All rights reserved.\n"; 17*34664Sbostic #endif /* not lint */ 1821636Sdist 19*34664Sbostic #ifndef lint 20*34664Sbostic static char sccsid[] = "@(#)main.c 5.2 (Berkeley) 06/06/88"; 21*34664Sbostic #endif /* not lint */ 22*34664Sbostic 231457Sroot #include <stdio.h> 241457Sroot #include <ctype.h> 251457Sroot #include <signal.h> 261457Sroot #include "error.h" 271457Sroot 281457Sroot int nerrors = 0; 295592Srrh Eptr er_head; 305592Srrh Eptr *errors; 311457Sroot 321457Sroot int nfiles = 0; 335592Srrh Eptr **files; /* array of pointers into errors*/ 341457Sroot int language = INCC; 351457Sroot 361457Sroot char *currentfilename = "????"; 371457Sroot char *processname; 3816564Sralph char im_on[] = "/dev/tty"; /* my tty name */ 391457Sroot 401457Sroot boolean query = FALSE; /* query the operator if touch files */ 411457Sroot boolean notouch = FALSE; /* don't touch ANY files */ 421457Sroot boolean piflag = FALSE; /* this is not pi */ 435592Srrh boolean terse = FALSE; /* Terse output */ 441457Sroot 451457Sroot char *suffixlist = ".*"; /* initially, can touch any file */ 461457Sroot 471457Sroot int errorsort(); 481457Sroot int onintr(); 491457Sroot /* 501457Sroot * error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile] 511457Sroot * 525592Srrh * -T: terse output 535592Srrh * 541457Sroot * -I: the following name, `ignorename' contains a list of 551457Sroot * function names that are not to be treated as hard errors. 561457Sroot * Default: ~/.errorsrc 571457Sroot * 581457Sroot * -n: don't touch ANY files! 591457Sroot * 601457Sroot * -q: The user is to be queried before touching each 611457Sroot * file; if not specified, all files with hard, non 621457Sroot * ignorable errors are touched (assuming they can be). 631457Sroot * 641457Sroot * -t: touch only files ending with the list of suffices, each 651457Sroot * suffix preceded by a dot. 661457Sroot * eg, -t .c.y.l 671457Sroot * will touch only files ending with .c, .y or .l 681457Sroot * 691457Sroot * -s: print a summary of the error's categories. 701457Sroot * 711457Sroot * -v: after touching all files, overlay vi(1), ex(1) or ed(1) 721457Sroot * on top of error, entered in the first file with 731457Sroot * an error in it, with the appropriate editor 741457Sroot * set up to use the "next" command to get the other 751457Sroot * files containing errors. 761457Sroot * 771457Sroot * -p: (obsolete: for older versions of pi without bug 781457Sroot * fix regarding printing out the name of the main file 791457Sroot * with an error in it) 801457Sroot * Take the following argument and use it as the name of 811457Sroot * the pascal source file, suffix .p 821457Sroot * 831457Sroot * -E: show the errors in sorted order; intended for 841457Sroot * debugging. 851457Sroot * 861457Sroot * -S: show the errors in unsorted order 871457Sroot * (as they come from the error file) 881457Sroot * 891457Sroot * infile: The error messages come from this file. 901457Sroot * Default: stdin 911457Sroot */ 921457Sroot main(argc, argv) 931457Sroot int argc; 941457Sroot char *argv[]; 951457Sroot { 961457Sroot char *cp; 971457Sroot char *ignorename = 0; 981457Sroot int ed_argc; 991457Sroot char **ed_argv; /*return from touchfiles*/ 1001457Sroot boolean show_errors = FALSE; 1011457Sroot boolean Show_Errors = FALSE; 1021457Sroot boolean pr_summary = FALSE; 1031457Sroot boolean edit_files = FALSE; 1041457Sroot 1051457Sroot processname = argv[0]; 1061457Sroot 1071457Sroot errorfile = stdin; 1085592Srrh if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){ 1095592Srrh for (cp = argv[1] + 1; *cp; cp++) switch(*cp){ 1105592Srrh default: 1115592Srrh fprintf(stderr, "%s: -%c: Unknown flag\n", 1125592Srrh processname, *cp); 1135592Srrh break; 1145592Srrh 1155592Srrh case 'n': notouch = TRUE; break; 1165592Srrh case 'q': query = TRUE; break; 1175592Srrh case 'S': Show_Errors = TRUE; break; 1185592Srrh case 's': pr_summary = TRUE; break; 1195592Srrh case 'v': edit_files = TRUE; break; 1205592Srrh case 'T': terse = TRUE; break; 1215592Srrh case 't': 1225592Srrh *cp-- = 0; argv++; argc--; 1235592Srrh if (argc > 1){ 1245592Srrh suffixlist = argv[1]; 1255592Srrh } 1265592Srrh break; 1275592Srrh case 'I': /*ignore file name*/ 1285592Srrh *cp-- = 0; argv++; argc--; 1295592Srrh if (argc > 1) 1305592Srrh ignorename = argv[1]; 1315592Srrh break; 1325592Srrh } 1335592Srrh } 1341457Sroot if (notouch) 1351457Sroot suffixlist = 0; 1361457Sroot if (argc > 1){ 1371457Sroot if (argc > 3){ 1381457Sroot fprintf(stderr, "%s: Only takes 0 or 1 arguments\n", 1391457Sroot processname); 1401457Sroot exit(3); 1411457Sroot } 1421457Sroot if ( (errorfile = fopen(argv[1], "r")) == NULL){ 1431457Sroot fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n", 1441457Sroot processname, argv[1]); 1451457Sroot exit(4); 1461457Sroot } 1471457Sroot } 1481457Sroot if ( (queryfile = fopen(im_on, "r")) == NULL){ 14916564Sralph if (query){ 15016564Sralph fprintf(stderr, 15116564Sralph "%s: Can't open \"%s\" to query the user.\n", 15216564Sralph processname, im_on); 15316564Sralph exit(9); 15416564Sralph } 1551457Sroot } 1561457Sroot if (signal(SIGINT, onintr) == SIG_IGN) 1571457Sroot signal(SIGINT, SIG_IGN); 1581457Sroot if (signal(SIGTERM, onintr) == SIG_IGN) 1591457Sroot signal(SIGTERM, SIG_IGN); 1601457Sroot getignored(ignorename); 1611457Sroot eaterrors(&nerrors, &errors); 1621457Sroot if (Show_Errors) 1631457Sroot printerrors(TRUE, nerrors, errors); 1645592Srrh qsort(errors, nerrors, sizeof(Eptr), errorsort); 1651457Sroot if (show_errors) 1661457Sroot printerrors(FALSE, nerrors, errors); 1671457Sroot findfiles(nerrors, errors, &nfiles, &files); 1681457Sroot #define P(msg, arg) fprintf(stdout, msg, arg) 1691457Sroot if (pr_summary){ 1701457Sroot if (nunknown) 1711457Sroot P("%d Errors are unclassifiable.\n", nunknown); 1721457Sroot if (nignore) 1731457Sroot P("%d Errors are classifiable, but totally discarded.\n",nignore); 1741457Sroot if (nsyncerrors) 1751457Sroot P("%d Errors are synchronization errors.\n", nsyncerrors); 1761457Sroot if (nignore) 1771457Sroot P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard); 1781457Sroot if (nnulled) 1791457Sroot P("%d Errors are nulled because they refer to specific functions.\n", nnulled); 1801457Sroot if (nnonspec) 1811457Sroot P("%d Errors are not specific to any file.\n", nnonspec); 1821457Sroot if (nthisfile) 1831457Sroot P("%d Errors are specific to a given file, but not to a line.\n", nthisfile); 1841457Sroot if (ntrue) 1851457Sroot P("%d Errors are true errors, and can be inserted into the files.\n", ntrue); 1861457Sroot } 1871457Sroot filenames(nfiles, files); 1881457Sroot fflush(stdout); 1895592Srrh if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files) 1905592Srrh forkvi(ed_argc, ed_argv); 1915592Srrh } 1925592Srrh 1935592Srrh forkvi(argc, argv) 1945592Srrh int argc; 1955592Srrh char **argv; 1965592Srrh { 1975592Srrh if (query){ 1985592Srrh switch(inquire(terse 1995592Srrh ? "Edit? " 2005592Srrh : "Do you still want to edit the files you touched? ")){ 2015592Srrh case Q_NO: 2025592Srrh case Q_no: 2035592Srrh return; 2045592Srrh default: 2055592Srrh break; 2061457Sroot } 2071457Sroot } 2085592Srrh /* 2095592Srrh * ed_agument's first argument is 2105592Srrh * a vi/ex compatabile search argument 2115592Srrh * to find the first occurance of ### 2125592Srrh */ 2135592Srrh try("vi", argc, argv); 2145592Srrh try("ex", argc, argv); 2155592Srrh try("ed", argc-1, argv+1); 2165592Srrh fprintf(stdout, "Can't find any editors.\n"); 2171457Sroot } 2181457Sroot 2191457Sroot try(name, argc, argv) 2201457Sroot char *name; 2211457Sroot int argc; 2221457Sroot char **argv; 2231457Sroot { 2241457Sroot argv[0] = name; 2251457Sroot wordvprint(stdout, argc, argv); 2261457Sroot fprintf(stdout, "\n"); 2271457Sroot fflush(stderr); 2281457Sroot fflush(stdout); 2291457Sroot sleep(2); 2301457Sroot if (freopen(im_on, "r", stdin) == NULL) 2311457Sroot return; 2321457Sroot if (freopen(im_on, "w", stdout) == NULL) 2331457Sroot return; 2341457Sroot execvp(name, argv); 2351457Sroot } 2361457Sroot 2371457Sroot int errorsort(epp1, epp2) 2385592Srrh Eptr *epp1, *epp2; 2391457Sroot { 2405592Srrh reg Eptr ep1, ep2; 2415592Srrh int order; 2421457Sroot /* 2431457Sroot * Sort by: 2441457Sroot * 1) synchronization, non specific, discarded errors first; 2451457Sroot * 2) nulled and true errors last 2461457Sroot * a) grouped by similar file names 2471457Sroot * 1) grouped in ascending line number 2481457Sroot */ 2491457Sroot ep1 = *epp1; ep2 = *epp2; 2501457Sroot if (ep1 == 0 || ep2 == 0) 2511457Sroot return(0); 2521457Sroot if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){ 2531457Sroot return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1); 2541457Sroot } 2551457Sroot if (NOTSORTABLE(ep1->error_e_class)) /* then both are */ 2561457Sroot return(ep1->error_no - ep2->error_no); 2571457Sroot order = strcmp(ep1->error_text[0], ep2->error_text[0]); 2581457Sroot if (order == 0){ 2591457Sroot return(ep1->error_line - ep2->error_line); 2601457Sroot } 2611457Sroot return(order); 2621457Sroot } 263