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