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