121636Sdist /* 221636Sdist * Copyright (c) 1980 Regents of the University of California. 334664Sbostic * All rights reserved. 434664Sbostic * 534664Sbostic * Redistribution and use in source and binary forms are permitted 6*34874Sbostic * provided that the above copyright notice and this paragraph are 7*34874Sbostic * duplicated in all such forms and that any documentation, 8*34874Sbostic * advertising materials, and other materials related to such 9*34874Sbostic * distribution and use acknowledge that the software was developed 10*34874Sbostic * by the University of California, Berkeley. The name of the 11*34874Sbostic * University may not be used to endorse or promote products derived 12*34874Sbostic * from this software without specific prior written permission. 13*34874Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34874Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34874Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1621636Sdist */ 1721636Sdist 1821636Sdist #ifndef lint 1921636Sdist char copyright[] = 2021636Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 2121636Sdist All rights reserved.\n"; 2234664Sbostic #endif /* not lint */ 2321636Sdist 2434664Sbostic #ifndef lint 25*34874Sbostic static char sccsid[] = "@(#)main.c 5.3 (Berkeley) 06/29/88"; 2634664Sbostic #endif /* not lint */ 2734664Sbostic 281457Sroot #include <stdio.h> 291457Sroot #include <ctype.h> 301457Sroot #include <signal.h> 311457Sroot #include "error.h" 321457Sroot 331457Sroot int nerrors = 0; 345592Srrh Eptr er_head; 355592Srrh Eptr *errors; 361457Sroot 371457Sroot int nfiles = 0; 385592Srrh Eptr **files; /* array of pointers into errors*/ 391457Sroot int language = INCC; 401457Sroot 411457Sroot char *currentfilename = "????"; 421457Sroot char *processname; 4316564Sralph char im_on[] = "/dev/tty"; /* my tty name */ 441457Sroot 451457Sroot boolean query = FALSE; /* query the operator if touch files */ 461457Sroot boolean notouch = FALSE; /* don't touch ANY files */ 471457Sroot boolean piflag = FALSE; /* this is not pi */ 485592Srrh boolean terse = FALSE; /* Terse output */ 491457Sroot 501457Sroot char *suffixlist = ".*"; /* initially, can touch any file */ 511457Sroot 521457Sroot int errorsort(); 531457Sroot int onintr(); 541457Sroot /* 551457Sroot * error [-I ignorename] [-n] [-q] [-t suffixlist] [-s] [-v] [infile] 561457Sroot * 575592Srrh * -T: terse output 585592Srrh * 591457Sroot * -I: the following name, `ignorename' contains a list of 601457Sroot * function names that are not to be treated as hard errors. 611457Sroot * Default: ~/.errorsrc 621457Sroot * 631457Sroot * -n: don't touch ANY files! 641457Sroot * 651457Sroot * -q: The user is to be queried before touching each 661457Sroot * file; if not specified, all files with hard, non 671457Sroot * ignorable errors are touched (assuming they can be). 681457Sroot * 691457Sroot * -t: touch only files ending with the list of suffices, each 701457Sroot * suffix preceded by a dot. 711457Sroot * eg, -t .c.y.l 721457Sroot * will touch only files ending with .c, .y or .l 731457Sroot * 741457Sroot * -s: print a summary of the error's categories. 751457Sroot * 761457Sroot * -v: after touching all files, overlay vi(1), ex(1) or ed(1) 771457Sroot * on top of error, entered in the first file with 781457Sroot * an error in it, with the appropriate editor 791457Sroot * set up to use the "next" command to get the other 801457Sroot * files containing errors. 811457Sroot * 821457Sroot * -p: (obsolete: for older versions of pi without bug 831457Sroot * fix regarding printing out the name of the main file 841457Sroot * with an error in it) 851457Sroot * Take the following argument and use it as the name of 861457Sroot * the pascal source file, suffix .p 871457Sroot * 881457Sroot * -E: show the errors in sorted order; intended for 891457Sroot * debugging. 901457Sroot * 911457Sroot * -S: show the errors in unsorted order 921457Sroot * (as they come from the error file) 931457Sroot * 941457Sroot * infile: The error messages come from this file. 951457Sroot * Default: stdin 961457Sroot */ 971457Sroot main(argc, argv) 981457Sroot int argc; 991457Sroot char *argv[]; 1001457Sroot { 1011457Sroot char *cp; 1021457Sroot char *ignorename = 0; 1031457Sroot int ed_argc; 1041457Sroot char **ed_argv; /*return from touchfiles*/ 1051457Sroot boolean show_errors = FALSE; 1061457Sroot boolean Show_Errors = FALSE; 1071457Sroot boolean pr_summary = FALSE; 1081457Sroot boolean edit_files = FALSE; 1091457Sroot 1101457Sroot processname = argv[0]; 1111457Sroot 1121457Sroot errorfile = stdin; 1135592Srrh if (argc > 1) for(; (argc > 1) && (argv[1][0] == '-'); argc--, argv++){ 1145592Srrh for (cp = argv[1] + 1; *cp; cp++) switch(*cp){ 1155592Srrh default: 1165592Srrh fprintf(stderr, "%s: -%c: Unknown flag\n", 1175592Srrh processname, *cp); 1185592Srrh break; 1195592Srrh 1205592Srrh case 'n': notouch = TRUE; break; 1215592Srrh case 'q': query = TRUE; break; 1225592Srrh case 'S': Show_Errors = TRUE; break; 1235592Srrh case 's': pr_summary = TRUE; break; 1245592Srrh case 'v': edit_files = TRUE; break; 1255592Srrh case 'T': terse = TRUE; break; 1265592Srrh case 't': 1275592Srrh *cp-- = 0; argv++; argc--; 1285592Srrh if (argc > 1){ 1295592Srrh suffixlist = argv[1]; 1305592Srrh } 1315592Srrh break; 1325592Srrh case 'I': /*ignore file name*/ 1335592Srrh *cp-- = 0; argv++; argc--; 1345592Srrh if (argc > 1) 1355592Srrh ignorename = argv[1]; 1365592Srrh break; 1375592Srrh } 1385592Srrh } 1391457Sroot if (notouch) 1401457Sroot suffixlist = 0; 1411457Sroot if (argc > 1){ 1421457Sroot if (argc > 3){ 1431457Sroot fprintf(stderr, "%s: Only takes 0 or 1 arguments\n", 1441457Sroot processname); 1451457Sroot exit(3); 1461457Sroot } 1471457Sroot if ( (errorfile = fopen(argv[1], "r")) == NULL){ 1481457Sroot fprintf(stderr, "%s: %s: No such file or directory for reading errors.\n", 1491457Sroot processname, argv[1]); 1501457Sroot exit(4); 1511457Sroot } 1521457Sroot } 1531457Sroot if ( (queryfile = fopen(im_on, "r")) == NULL){ 15416564Sralph if (query){ 15516564Sralph fprintf(stderr, 15616564Sralph "%s: Can't open \"%s\" to query the user.\n", 15716564Sralph processname, im_on); 15816564Sralph exit(9); 15916564Sralph } 1601457Sroot } 1611457Sroot if (signal(SIGINT, onintr) == SIG_IGN) 1621457Sroot signal(SIGINT, SIG_IGN); 1631457Sroot if (signal(SIGTERM, onintr) == SIG_IGN) 1641457Sroot signal(SIGTERM, SIG_IGN); 1651457Sroot getignored(ignorename); 1661457Sroot eaterrors(&nerrors, &errors); 1671457Sroot if (Show_Errors) 1681457Sroot printerrors(TRUE, nerrors, errors); 1695592Srrh qsort(errors, nerrors, sizeof(Eptr), errorsort); 1701457Sroot if (show_errors) 1711457Sroot printerrors(FALSE, nerrors, errors); 1721457Sroot findfiles(nerrors, errors, &nfiles, &files); 1731457Sroot #define P(msg, arg) fprintf(stdout, msg, arg) 1741457Sroot if (pr_summary){ 1751457Sroot if (nunknown) 1761457Sroot P("%d Errors are unclassifiable.\n", nunknown); 1771457Sroot if (nignore) 1781457Sroot P("%d Errors are classifiable, but totally discarded.\n",nignore); 1791457Sroot if (nsyncerrors) 1801457Sroot P("%d Errors are synchronization errors.\n", nsyncerrors); 1811457Sroot if (nignore) 1821457Sroot P("%d Errors are discarded because they refer to sacrosinct files.\n", ndiscard); 1831457Sroot if (nnulled) 1841457Sroot P("%d Errors are nulled because they refer to specific functions.\n", nnulled); 1851457Sroot if (nnonspec) 1861457Sroot P("%d Errors are not specific to any file.\n", nnonspec); 1871457Sroot if (nthisfile) 1881457Sroot P("%d Errors are specific to a given file, but not to a line.\n", nthisfile); 1891457Sroot if (ntrue) 1901457Sroot P("%d Errors are true errors, and can be inserted into the files.\n", ntrue); 1911457Sroot } 1921457Sroot filenames(nfiles, files); 1931457Sroot fflush(stdout); 1945592Srrh if (touchfiles(nfiles, files, &ed_argc, &ed_argv) && edit_files) 1955592Srrh forkvi(ed_argc, ed_argv); 1965592Srrh } 1975592Srrh 1985592Srrh forkvi(argc, argv) 1995592Srrh int argc; 2005592Srrh char **argv; 2015592Srrh { 2025592Srrh if (query){ 2035592Srrh switch(inquire(terse 2045592Srrh ? "Edit? " 2055592Srrh : "Do you still want to edit the files you touched? ")){ 2065592Srrh case Q_NO: 2075592Srrh case Q_no: 2085592Srrh return; 2095592Srrh default: 2105592Srrh break; 2111457Sroot } 2121457Sroot } 2135592Srrh /* 2145592Srrh * ed_agument's first argument is 2155592Srrh * a vi/ex compatabile search argument 2165592Srrh * to find the first occurance of ### 2175592Srrh */ 2185592Srrh try("vi", argc, argv); 2195592Srrh try("ex", argc, argv); 2205592Srrh try("ed", argc-1, argv+1); 2215592Srrh fprintf(stdout, "Can't find any editors.\n"); 2221457Sroot } 2231457Sroot 2241457Sroot try(name, argc, argv) 2251457Sroot char *name; 2261457Sroot int argc; 2271457Sroot char **argv; 2281457Sroot { 2291457Sroot argv[0] = name; 2301457Sroot wordvprint(stdout, argc, argv); 2311457Sroot fprintf(stdout, "\n"); 2321457Sroot fflush(stderr); 2331457Sroot fflush(stdout); 2341457Sroot sleep(2); 2351457Sroot if (freopen(im_on, "r", stdin) == NULL) 2361457Sroot return; 2371457Sroot if (freopen(im_on, "w", stdout) == NULL) 2381457Sroot return; 2391457Sroot execvp(name, argv); 2401457Sroot } 2411457Sroot 2421457Sroot int errorsort(epp1, epp2) 2435592Srrh Eptr *epp1, *epp2; 2441457Sroot { 2455592Srrh reg Eptr ep1, ep2; 2465592Srrh int order; 2471457Sroot /* 2481457Sroot * Sort by: 2491457Sroot * 1) synchronization, non specific, discarded errors first; 2501457Sroot * 2) nulled and true errors last 2511457Sroot * a) grouped by similar file names 2521457Sroot * 1) grouped in ascending line number 2531457Sroot */ 2541457Sroot ep1 = *epp1; ep2 = *epp2; 2551457Sroot if (ep1 == 0 || ep2 == 0) 2561457Sroot return(0); 2571457Sroot if ( (NOTSORTABLE(ep1->error_e_class)) ^ (NOTSORTABLE(ep2->error_e_class))){ 2581457Sroot return(NOTSORTABLE(ep1->error_e_class) ? -1 : 1); 2591457Sroot } 2601457Sroot if (NOTSORTABLE(ep1->error_e_class)) /* then both are */ 2611457Sroot return(ep1->error_no - ep2->error_no); 2621457Sroot order = strcmp(ep1->error_text[0], ep2->error_text[0]); 2631457Sroot if (order == 0){ 2641457Sroot return(ep1->error_line - ep2->error_line); 2651457Sroot } 2661457Sroot return(order); 2671457Sroot } 268