1*16460Sedward static char *sccsid = "@(#)input.c 1.9 (Berkeley) 84/05/08"; 21456Sroot #include <stdio.h> 31456Sroot #include <ctype.h> 41456Sroot #include "error.h" 51456Sroot 61456Sroot int wordc; /* how long the current error message is */ 71456Sroot char **wordv; /* the actual error message */ 81456Sroot 91456Sroot int nerrors; 101456Sroot int language; 111456Sroot 121456Sroot Errorclass onelong(); 131456Sroot Errorclass cpp(); 142798Swnj Errorclass pccccom(); /* Portable C Compiler C Compiler */ 152798Swnj Errorclass richieccom(); /* Richie Compiler for 11 */ 161456Sroot Errorclass lint0(); 171456Sroot Errorclass lint1(); 181456Sroot Errorclass lint2(); 191456Sroot Errorclass lint3(); 201456Sroot Errorclass make(); 211456Sroot Errorclass f77(); 221456Sroot Errorclass pi(); 231456Sroot Errorclass ri(); 2413106Srrh Errorclass troff(); 251456Sroot /* 261456Sroot * Eat all of the lines in the input file, attempting to categorize 271456Sroot * them by their various flavors 281456Sroot */ 291456Sroot static char inbuffer[BUFSIZ]; 301456Sroot 311456Sroot eaterrors(r_errorc, r_errorv) 321456Sroot int *r_errorc; 335592Srrh Eptr **r_errorv; 341456Sroot { 351456Sroot extern boolean piflag; 361456Sroot Errorclass errorclass = C_SYNC; 371456Sroot 381456Sroot for (;;){ 391456Sroot if (fgets(inbuffer, BUFSIZ, errorfile) == NULL) 401456Sroot break; 411456Sroot wordvbuild(inbuffer, &wordc, &wordv); 421456Sroot /* 431456Sroot * for convience, convert wordv to be 1 based, instead 441456Sroot * of 0 based. 451456Sroot */ 461456Sroot wordv -= 1; 47*16460Sedward if ( wordc > 0 && 48*16460Sedward ((( errorclass = onelong() ) != C_UNKNOWN) 491456Sroot || (( errorclass = cpp() ) != C_UNKNOWN) 502798Swnj || (( errorclass = pccccom() ) != C_UNKNOWN) 512798Swnj || (( errorclass = richieccom() ) != C_UNKNOWN) 521456Sroot || (( errorclass = lint0() ) != C_UNKNOWN) 531456Sroot || (( errorclass = lint1() ) != C_UNKNOWN) 541456Sroot || (( errorclass = lint2() ) != C_UNKNOWN) 551456Sroot || (( errorclass = lint3() ) != C_UNKNOWN) 561456Sroot || (( errorclass = make() ) != C_UNKNOWN) 571456Sroot || (( errorclass = f77() ) != C_UNKNOWN) 581456Sroot || ((errorclass = pi() ) != C_UNKNOWN) 591456Sroot || (( errorclass = ri() )!= C_UNKNOWN) 60*16460Sedward || (( errorclass = troff() )!= C_UNKNOWN)) 611456Sroot ) ; 621456Sroot else 631456Sroot errorclass = catchall(); 641456Sroot if (wordc) 651456Sroot erroradd(wordc, wordv+1, errorclass, C_UNKNOWN); 661456Sroot } 671456Sroot #ifdef FULLDEBUG 681456Sroot printf("%d errorentrys\n", nerrors); 691456Sroot #endif 701456Sroot arrayify(r_errorc, r_errorv, er_head); 711456Sroot } 721456Sroot 731456Sroot /* 741456Sroot * create a new error entry, given a zero based array and count 751456Sroot */ 761456Sroot erroradd(errorlength, errorv, errorclass, errorsubclass) 771456Sroot int errorlength; 781456Sroot char **errorv; 791456Sroot Errorclass errorclass; 801456Sroot Errorclass errorsubclass; 811456Sroot { 825592Srrh reg Eptr newerror; 835592Srrh reg char *cp; 841456Sroot 851456Sroot if (errorclass == C_TRUE){ 861456Sroot /* check canonicalization of the second argument*/ 871456Sroot for(cp = errorv[1]; *cp && isdigit(*cp); cp++) 881456Sroot continue; 891456Sroot errorclass = (*cp == '\0') ? C_TRUE : C_NONSPEC; 901456Sroot #ifdef FULLDEBUG 911456Sroot if (errorclass != C_TRUE) 921456Sroot printf("The 2nd word, \"%s\" is not a number.\n", 931456Sroot errorv[1]); 941456Sroot #endif 951456Sroot } 961456Sroot if (errorlength > 0){ 975592Srrh newerror = (Eptr)Calloc(1, sizeof(Edesc)); 981456Sroot newerror->error_language = language; /* language is global */ 991456Sroot newerror->error_text = errorv; 1001456Sroot newerror->error_lgtext = errorlength; 1011456Sroot if (errorclass == C_TRUE) 1021456Sroot newerror->error_line = atoi(errorv[1]); 1031456Sroot newerror->error_e_class = errorclass; 1041456Sroot newerror->error_s_class = errorsubclass; 1051456Sroot switch(newerror->error_e_class = discardit(newerror)){ 1061456Sroot case C_SYNC: nsyncerrors++; break; 1071456Sroot case C_DISCARD: ndiscard++; break; 1081456Sroot case C_NULLED: nnulled++; break; 1091456Sroot case C_NONSPEC: nnonspec++; break; 1101456Sroot case C_THISFILE: nthisfile++; break; 1111456Sroot case C_TRUE: ntrue++; break; 1121456Sroot case C_UNKNOWN: nunknown++; break; 1131456Sroot case C_IGNORE: nignore++; break; 1141456Sroot } 1151456Sroot newerror->error_next = er_head; 1161456Sroot er_head = newerror; 1171456Sroot newerror->error_no = nerrors++; 1181456Sroot } /* length > 0 */ 1191456Sroot } 1201456Sroot 1211456Sroot Errorclass onelong() 1221456Sroot { 1231456Sroot char **nwordv; 1241456Sroot if ( (wordc == 1) && (language != INLD) ){ 1251456Sroot /* 1261456Sroot * We have either: 1271456Sroot * a) file name from cc 1281456Sroot * b) Assembler telling world that it is complaining 1291456Sroot * c) Noise from make ("Stop.") 1301456Sroot * c) Random noise 1311456Sroot */ 1321456Sroot wordc = 0; 133*16460Sedward if (strcmp(wordv[1], "Stop.") == 0){ 1341456Sroot language = INMAKE; return(C_SYNC); 1351456Sroot } 1361456Sroot if (strcmp(wordv[1], "Assembler:") == 0){ 1371456Sroot /* assembler always alerts us to what happened*/ 1381456Sroot language = INAS; return(C_SYNC); 1391456Sroot } else 1401456Sroot if (strcmp(wordv[1], "Undefined:") == 0){ 1411456Sroot /* loader complains about unknown symbols*/ 1421456Sroot language = INLD; return(C_SYNC); 1431456Sroot } 1441456Sroot if (lastchar(wordv[1]) == ':'){ 1451456Sroot /* cc tells us what file we are in */ 1461456Sroot currentfilename = wordv[1]; 1475592Srrh (void)substitute(currentfilename, ':', '\0'); 1481456Sroot language = INCC; return(C_SYNC); 1491456Sroot } 1501456Sroot } else 1511456Sroot if ( (wordc == 1) && (language == INLD) ){ 1521456Sroot nwordv = (char **)Calloc(4, sizeof(char *)); 1531456Sroot nwordv[0] = "ld:"; 1541456Sroot nwordv[1] = wordv[1]; 1551456Sroot nwordv[2] = "is"; 1561456Sroot nwordv[3] = "undefined."; 1571456Sroot wordc = 4; 1581456Sroot wordv = nwordv - 1; 1591456Sroot return(C_NONSPEC); 1601456Sroot } else 1611456Sroot if (wordc == 1){ 1621456Sroot return(C_SYNC); 1631456Sroot } 1641456Sroot return(C_UNKNOWN); 1651456Sroot } /* end of one long */ 1661456Sroot 1671456Sroot Errorclass cpp() 1681456Sroot { 1691456Sroot /* 1701456Sroot * Now attempt a cpp error message match 1711456Sroot * Examples: 1721456Sroot * ./morse.h: 23: undefined control 1731456Sroot * morsesend.c: 229: MAGNIBBL: argument mismatch 1741456Sroot * morsesend.c: 237: MAGNIBBL: argument mismatch 1751456Sroot * test1.c: 6: undefined control 1761456Sroot */ 1771456Sroot if ( (language != INLD) /* loader errors have almost same fmt*/ 1781456Sroot && (lastchar(wordv[1]) == ':') 1791456Sroot && (isdigit(firstchar(wordv[2]))) 1801456Sroot && (lastchar(wordv[2]) == ':') ){ 1811456Sroot language = INCPP; 1821456Sroot clob_last(wordv[1], '\0'); 1831456Sroot clob_last(wordv[2], '\0'); 1841456Sroot return(C_TRUE); 1851456Sroot } 1861456Sroot return(C_UNKNOWN); 1871456Sroot } /*end of cpp*/ 1881456Sroot 1892798Swnj Errorclass pccccom() 1901456Sroot { 1911456Sroot /* 1921456Sroot * Now attempt a ccom error message match: 1931456Sroot * Examples: 1941456Sroot * "morsesend.c", line 237: operands of & have incompatible types 1951456Sroot * "test.c", line 7: warning: old-fashioned initialization: use = 1961456Sroot * "subdir.d/foo2.h", line 1: illegal initialization 1971456Sroot */ 1981456Sroot if ( (firstchar(wordv[1]) == '"') 1991456Sroot && (lastchar(wordv[1]) == ',') 2001456Sroot && (next_lastchar(wordv[1]) == '"') 2011456Sroot && (strcmp(wordv[2],"line") == 0) 2021456Sroot && (isdigit(firstchar(wordv[3]))) 2031456Sroot && (lastchar(wordv[3]) == ':') ){ 2041456Sroot clob_last(wordv[1], '\0'); /* drop last , */ 2051456Sroot clob_last(wordv[1], '\0'); /* drop last " */ 2061456Sroot wordv[1]++; /* drop first " */ 2071456Sroot clob_last(wordv[3], '\0'); /* drop : on line number */ 2081456Sroot wordv[2] = wordv[1]; /* overwrite "line" */ 2091456Sroot wordv++; /*compensate*/ 210*16460Sedward wordc--; 2116610Srrh currentfilename = wordv[1]; 2126610Srrh language = INCC; 2136610Srrh return(C_TRUE); 2141456Sroot } 2151456Sroot return(C_UNKNOWN); 2161456Sroot } /* end of ccom */ 2172798Swnj /* 2182798Swnj * Do the error message from the Richie C Compiler for the PDP11, 2192798Swnj * which has this source: 2202798Swnj * 2212798Swnj * if (filename[0]) 2222798Swnj * fprintf(stderr, "%s:", filename); 2232798Swnj * fprintf(stderr, "%d: ", line); 2242798Swnj * 2252798Swnj */ 2262798Swnj Errorclass richieccom() 2272798Swnj { 2285592Srrh reg char *cp; 2295592Srrh reg char **nwordv; 2305592Srrh char *file; 2315592Srrh 2322798Swnj if (lastchar(wordv[1]) == ':'){ 2332798Swnj cp = wordv[1] + strlen(wordv[1]) - 1; 2342798Swnj while (isdigit(*--cp)) 2352798Swnj continue; 2362798Swnj if (*cp == ':'){ 2372798Swnj clob_last(wordv[1], '\0'); /* last : */ 2382798Swnj *cp = '\0'; /* first : */ 2392798Swnj file = wordv[1]; 2402798Swnj nwordv = wordvsplice(1, wordc, wordv+1); 2412798Swnj nwordv[0] = file; 2422798Swnj nwordv[1] = cp + 1; 2432798Swnj wordc += 1; 2442798Swnj wordv = nwordv - 1; 2452798Swnj language = INCC; 2462798Swnj currentfilename = wordv[1]; 2472798Swnj return(C_TRUE); 2482798Swnj } 2492798Swnj } 2502798Swnj return(C_UNKNOWN); 2512798Swnj } 2521456Sroot 2531456Sroot Errorclass lint0() 2541456Sroot { 2555592Srrh reg char **nwordv; 2565592Srrh char *line, *file; 2571456Sroot /* 2581456Sroot * Attempt a match for the new lint style normal compiler 2591456Sroot * error messages, of the form 2601456Sroot * 2611456Sroot * printf("%s(%d): %s\n", filename, linenumber, message); 2621456Sroot */ 2631456Sroot if (wordc >= 2){ 2641456Sroot if ( (lastchar(wordv[1]) == ':') 2651456Sroot && (next_lastchar(wordv[1]) == ')') 2661456Sroot ) { 2671456Sroot clob_last(wordv[1], '\0'); /* colon */ 2681456Sroot if (persperdexplode(wordv[1], &line, &file)){ 2691456Sroot nwordv = wordvsplice(1, wordc, wordv+1); 2701456Sroot nwordv[0] = file; /* file name */ 2711456Sroot nwordv[1] = line; /* line number */ 2721456Sroot wordc += 1; 2731456Sroot wordv = nwordv - 1; 2741456Sroot language = INLINT; 2751456Sroot return(C_TRUE); 2761456Sroot } 2771456Sroot wordv[1][strlen(wordv[1])] = ':'; 2781456Sroot } 2791456Sroot } 2801456Sroot return (C_UNKNOWN); 2811456Sroot } 2821456Sroot 2831456Sroot Errorclass lint1() 2841456Sroot { 2851456Sroot char *line1, *line2; 2861456Sroot char *file1, *file2; 2871456Sroot char **nwordv1, **nwordv2; 2881456Sroot 2891456Sroot /* 2901456Sroot * Now, attempt a match for the various errors that lint 2911456Sroot * can complain about. 2921456Sroot * 2931456Sroot * Look first for type 1 lint errors 2941456Sroot */ 29510829Ssam if (wordc > 1 && strcmp(wordv[wordc-1], "::") == 0){ 2961456Sroot /* 2971456Sroot * %.7s, arg. %d used inconsistently %s(%d) :: %s(%d) 2981456Sroot * %.7s value used inconsistently %s(%d) :: %s(%d) 2991456Sroot * %.7s multiply declared %s(%d) :: %s(%d) 3001456Sroot * %.7s value declared inconsistently %s(%d) :: %s(%d) 3011456Sroot * %.7s function value type must be declared before use %s(%d) :: %s(%d) 3021456Sroot */ 3031456Sroot language = INLINT; 30410829Ssam if (wordc > 2 30510829Ssam && (persperdexplode(wordv[wordc], &line2, &file2)) 3061456Sroot && (persperdexplode(wordv[wordc-2], &line1, &file1)) ){ 3071456Sroot nwordv1 = wordvsplice(2, wordc, wordv+1); 3081456Sroot nwordv2 = wordvsplice(2, wordc, wordv+1); 3091456Sroot nwordv1[0] = file1; nwordv1[1] = line1; 3101456Sroot erroradd(wordc+2, nwordv1, C_TRUE, C_DUPL); /* takes 0 based*/ 3111456Sroot nwordv2[0] = file2; nwordv2[1] = line2; 3121456Sroot wordc = wordc + 2; 3131456Sroot wordv = nwordv2 - 1; /* 1 based */ 3141456Sroot return(C_TRUE); 3151456Sroot } 3161456Sroot } 3171456Sroot return(C_UNKNOWN); 3181456Sroot } /* end of lint 1*/ 3191456Sroot 3201456Sroot Errorclass lint2() 3211456Sroot { 3221456Sroot char *file; 3231456Sroot char *line; 3241456Sroot char **nwordv; 3251456Sroot /* 3261456Sroot * Look for type 2 lint errors 3271456Sroot * 3281456Sroot * %.7s used( %s(%d) ), but not defined 3291456Sroot * %.7s defined( %s(%d) ), but never used 3301456Sroot * %.7s declared( %s(%d) ), but never used or defined 3311456Sroot * 3321456Sroot * bufp defined( "./metric.h"(10) ), but never used 3331456Sroot */ 3341456Sroot if ( (lastchar(wordv[2]) == '(' /* ')' */ ) 3351456Sroot && (strcmp(wordv[4], "),") == 0) ){ 3361456Sroot language = INLINT; 3371456Sroot if (persperdexplode(wordv[3], &line, &file)){ 3381456Sroot nwordv = wordvsplice(2, wordc, wordv+1); 3391456Sroot nwordv[0] = file; nwordv[1] = line; 3401456Sroot wordc = wordc + 2; 3411456Sroot wordv = nwordv - 1; /* 1 based */ 3421456Sroot return(C_TRUE); 3431456Sroot } 3441456Sroot } 3451456Sroot return(C_UNKNOWN); 3461456Sroot } /* end of lint 2*/ 3471456Sroot 3481456Sroot char *Lint31[4] = {"returns", "value", "which", "is"}; 3491456Sroot char *Lint32[6] = {"value", "is", "used,", "but", "none", "returned"}; 3501456Sroot Errorclass lint3() 3511456Sroot { 3521456Sroot if ( (wordvcmp(wordv+2, 4, Lint31) == 0) 3531456Sroot || (wordvcmp(wordv+2, 6, Lint32) == 0) ){ 3541456Sroot language = INLINT; 3551456Sroot return(C_NONSPEC); 3561456Sroot } 3571456Sroot return(C_UNKNOWN); 3581456Sroot } 3591456Sroot 3601456Sroot /* 3611456Sroot * Special word vectors for use by F77 recognition 3621456Sroot */ 3631456Sroot char *F77_fatal[3] = {"Compiler", "error", "line"}; 3641456Sroot char *F77_error[3] = {"Error", "on", "line"}; 3651456Sroot char *F77_warning[3] = {"Warning", "on", "line"}; 3661456Sroot f77() 3671456Sroot { 3681456Sroot char **nwordv; 3691456Sroot /* 3701456Sroot * look for f77 errors: 3711456Sroot * Error messages from /usr/src/cmd/f77/error.c, with 3721456Sroot * these printf formats: 3731456Sroot * 3741456Sroot * Compiler error line %d of %s: %s 3751456Sroot * Error on line %d of %s: %s 3761456Sroot * Warning on line %d of %s: %s 3771456Sroot */ 3781456Sroot if (wordc < 6) 3791456Sroot return(C_UNKNOWN); 3801456Sroot if ( (lastchar(wordv[6]) == ':') 3811456Sroot &&( 3821456Sroot (wordvcmp(wordv+1, 3, F77_fatal) == 0) 3831456Sroot || (wordvcmp(wordv+1, 3, F77_error) == 0) 3841456Sroot || (wordvcmp(wordv+1, 3, F77_warning) == 0) ) 3851456Sroot ){ 3861456Sroot language = INF77; 3871456Sroot nwordv = wordvsplice(2, wordc, wordv+1); 3881456Sroot nwordv[0] = wordv[6]; 3891456Sroot clob_last(nwordv[0],'\0'); 3901456Sroot nwordv[1] = wordv[4]; 3911456Sroot wordc += 2; 3921456Sroot wordv = nwordv - 1; /* 1 based */ 3931456Sroot return(C_TRUE); 3941456Sroot } 3951456Sroot return(C_UNKNOWN); 3961456Sroot } /* end of f77 */ 3971456Sroot 3981456Sroot char *Make_Croak[3] = {"***", "Error", "code"}; 3991456Sroot char *Make_NotRemade[5] = {"not", "remade", "because", "of", "errors"}; 4001456Sroot Errorclass make() 4011456Sroot { 4021456Sroot if (wordvcmp(wordv+1, 3, Make_Croak) == 0){ 4031456Sroot language = INMAKE; 4041456Sroot return(C_SYNC); 4051456Sroot } 4061456Sroot if (wordvcmp(wordv+2, 5, Make_NotRemade) == 0){ 4071456Sroot language = INMAKE; 4081456Sroot return(C_SYNC); 4091456Sroot } 4101456Sroot return(C_UNKNOWN); 4111456Sroot } 4121456Sroot Errorclass ri() 4131456Sroot { 4141456Sroot /* 4151456Sroot * Match an error message produced by ri; here is the 4161456Sroot * procedure yanked from the distributed version of ri 4171456Sroot * April 24, 1980. 4181456Sroot * 4191456Sroot * serror(str, x1, x2, x3) 4201456Sroot * char str[]; 4211456Sroot * char *x1, *x2, *x3; 4221456Sroot * { 4231456Sroot * extern int yylineno; 4241456Sroot * 4251456Sroot * putc('"', stdout); 4261456Sroot * fputs(srcfile, stdout); 4271456Sroot * putc('"', stdout); 4281456Sroot * fprintf(stdout, " %d: ", yylineno); 4291456Sroot * fprintf(stdout, str, x1, x2, x3); 4301456Sroot * fprintf(stdout, "\n"); 4311456Sroot * synerrs++; 4321456Sroot * } 4331456Sroot */ 4341456Sroot if ( (firstchar(wordv[1]) == '"') 4351456Sroot &&(lastchar(wordv[1]) == '"') 4361456Sroot &&(lastchar(wordv[2]) == ':') 4371456Sroot &&(isdigit(firstchar(wordv[2]))) ){ 4381456Sroot clob_last(wordv[1], '\0'); /* drop the last " */ 4391456Sroot wordv[1]++; /* skip over the first " */ 4401456Sroot clob_last(wordv[2], '\0'); 4411456Sroot language = INRI; 4421456Sroot return(C_TRUE); 4431456Sroot } 4441456Sroot return(C_UNKNOWN); 4451456Sroot } 4461456Sroot 4471456Sroot Errorclass catchall() 4481456Sroot { 4491456Sroot /* 4501456Sroot * Catches random things. 4511456Sroot */ 4521456Sroot language = INUNKNOWN; 4531456Sroot return(C_NONSPEC); 4541456Sroot } /* end of catch all*/ 45513106Srrh 45613106Srrh Errorclass troff() 45713106Srrh { 45813106Srrh /* 45913106Srrh * troff source error message, from eqn, bib, tbl... 46013106Srrh * Just like pcc ccom, except uses `' 46113106Srrh */ 46213106Srrh if ( (firstchar(wordv[1]) == '`') 46313106Srrh && (lastchar(wordv[1]) == ',') 46413106Srrh && (next_lastchar(wordv[1]) == '\'') 46513106Srrh && (strcmp(wordv[2],"line") == 0) 46613106Srrh && (isdigit(firstchar(wordv[3]))) 46713106Srrh && (lastchar(wordv[3]) == ':') ){ 46813106Srrh clob_last(wordv[1], '\0'); /* drop last , */ 46913106Srrh clob_last(wordv[1], '\0'); /* drop last " */ 47013106Srrh wordv[1]++; /* drop first " */ 47113106Srrh clob_last(wordv[3], '\0'); /* drop : on line number */ 47213106Srrh wordv[2] = wordv[1]; /* overwrite "line" */ 47313106Srrh wordv++; /*compensate*/ 47413106Srrh currentfilename = wordv[1]; 47513106Srrh language = INTROFF; 47613106Srrh return(C_TRUE); 47713106Srrh } 47813106Srrh return(C_UNKNOWN); 47913106Srrh } 480