1*13106Srrh static char *sccsid = "@(#)input.c 1.8 (Berkeley) 83/06/14"; 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(); 24*13106Srrh 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; 471456Sroot if ( 0 481456Sroot || (( 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*13106Srrh || (( 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; 1331456Sroot if (strcmp(wordv[2], "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*/ 2106610Srrh currentfilename = wordv[1]; 2116610Srrh language = INCC; 2126610Srrh return(C_TRUE); 2131456Sroot } 2141456Sroot return(C_UNKNOWN); 2151456Sroot } /* end of ccom */ 2162798Swnj /* 2172798Swnj * Do the error message from the Richie C Compiler for the PDP11, 2182798Swnj * which has this source: 2192798Swnj * 2202798Swnj * if (filename[0]) 2212798Swnj * fprintf(stderr, "%s:", filename); 2222798Swnj * fprintf(stderr, "%d: ", line); 2232798Swnj * 2242798Swnj */ 2252798Swnj Errorclass richieccom() 2262798Swnj { 2275592Srrh reg char *cp; 2285592Srrh reg char **nwordv; 2295592Srrh char *file; 2305592Srrh 2312798Swnj if (lastchar(wordv[1]) == ':'){ 2322798Swnj cp = wordv[1] + strlen(wordv[1]) - 1; 2332798Swnj while (isdigit(*--cp)) 2342798Swnj continue; 2352798Swnj if (*cp == ':'){ 2362798Swnj clob_last(wordv[1], '\0'); /* last : */ 2372798Swnj *cp = '\0'; /* first : */ 2382798Swnj file = wordv[1]; 2392798Swnj nwordv = wordvsplice(1, wordc, wordv+1); 2402798Swnj nwordv[0] = file; 2412798Swnj nwordv[1] = cp + 1; 2422798Swnj wordc += 1; 2432798Swnj wordv = nwordv - 1; 2442798Swnj language = INCC; 2452798Swnj currentfilename = wordv[1]; 2462798Swnj return(C_TRUE); 2472798Swnj } 2482798Swnj } 2492798Swnj return(C_UNKNOWN); 2502798Swnj } 2511456Sroot 2521456Sroot Errorclass lint0() 2531456Sroot { 2545592Srrh reg char **nwordv; 2555592Srrh char *line, *file; 2561456Sroot /* 2571456Sroot * Attempt a match for the new lint style normal compiler 2581456Sroot * error messages, of the form 2591456Sroot * 2601456Sroot * printf("%s(%d): %s\n", filename, linenumber, message); 2611456Sroot */ 2621456Sroot if (wordc >= 2){ 2631456Sroot if ( (lastchar(wordv[1]) == ':') 2641456Sroot && (next_lastchar(wordv[1]) == ')') 2651456Sroot ) { 2661456Sroot clob_last(wordv[1], '\0'); /* colon */ 2671456Sroot if (persperdexplode(wordv[1], &line, &file)){ 2681456Sroot nwordv = wordvsplice(1, wordc, wordv+1); 2691456Sroot nwordv[0] = file; /* file name */ 2701456Sroot nwordv[1] = line; /* line number */ 2711456Sroot wordc += 1; 2721456Sroot wordv = nwordv - 1; 2731456Sroot language = INLINT; 2741456Sroot return(C_TRUE); 2751456Sroot } 2761456Sroot wordv[1][strlen(wordv[1])] = ':'; 2771456Sroot } 2781456Sroot } 2791456Sroot return (C_UNKNOWN); 2801456Sroot } 2811456Sroot 2821456Sroot Errorclass lint1() 2831456Sroot { 2841456Sroot char *line1, *line2; 2851456Sroot char *file1, *file2; 2861456Sroot char **nwordv1, **nwordv2; 2871456Sroot 2881456Sroot /* 2891456Sroot * Now, attempt a match for the various errors that lint 2901456Sroot * can complain about. 2911456Sroot * 2921456Sroot * Look first for type 1 lint errors 2931456Sroot */ 29410829Ssam if (wordc > 1 && strcmp(wordv[wordc-1], "::") == 0){ 2951456Sroot /* 2961456Sroot * %.7s, arg. %d used inconsistently %s(%d) :: %s(%d) 2971456Sroot * %.7s value used inconsistently %s(%d) :: %s(%d) 2981456Sroot * %.7s multiply declared %s(%d) :: %s(%d) 2991456Sroot * %.7s value declared inconsistently %s(%d) :: %s(%d) 3001456Sroot * %.7s function value type must be declared before use %s(%d) :: %s(%d) 3011456Sroot */ 3021456Sroot language = INLINT; 30310829Ssam if (wordc > 2 30410829Ssam && (persperdexplode(wordv[wordc], &line2, &file2)) 3051456Sroot && (persperdexplode(wordv[wordc-2], &line1, &file1)) ){ 3061456Sroot nwordv1 = wordvsplice(2, wordc, wordv+1); 3071456Sroot nwordv2 = wordvsplice(2, wordc, wordv+1); 3081456Sroot nwordv1[0] = file1; nwordv1[1] = line1; 3091456Sroot erroradd(wordc+2, nwordv1, C_TRUE, C_DUPL); /* takes 0 based*/ 3101456Sroot nwordv2[0] = file2; nwordv2[1] = line2; 3111456Sroot wordc = wordc + 2; 3121456Sroot wordv = nwordv2 - 1; /* 1 based */ 3131456Sroot return(C_TRUE); 3141456Sroot } 3151456Sroot } 3161456Sroot return(C_UNKNOWN); 3171456Sroot } /* end of lint 1*/ 3181456Sroot 3191456Sroot Errorclass lint2() 3201456Sroot { 3211456Sroot char *file; 3221456Sroot char *line; 3231456Sroot char **nwordv; 3241456Sroot /* 3251456Sroot * Look for type 2 lint errors 3261456Sroot * 3271456Sroot * %.7s used( %s(%d) ), but not defined 3281456Sroot * %.7s defined( %s(%d) ), but never used 3291456Sroot * %.7s declared( %s(%d) ), but never used or defined 3301456Sroot * 3311456Sroot * bufp defined( "./metric.h"(10) ), but never used 3321456Sroot */ 3331456Sroot if ( (lastchar(wordv[2]) == '(' /* ')' */ ) 3341456Sroot && (strcmp(wordv[4], "),") == 0) ){ 3351456Sroot language = INLINT; 3361456Sroot if (persperdexplode(wordv[3], &line, &file)){ 3371456Sroot nwordv = wordvsplice(2, wordc, wordv+1); 3381456Sroot nwordv[0] = file; nwordv[1] = line; 3391456Sroot wordc = wordc + 2; 3401456Sroot wordv = nwordv - 1; /* 1 based */ 3411456Sroot return(C_TRUE); 3421456Sroot } 3431456Sroot } 3441456Sroot return(C_UNKNOWN); 3451456Sroot } /* end of lint 2*/ 3461456Sroot 3471456Sroot char *Lint31[4] = {"returns", "value", "which", "is"}; 3481456Sroot char *Lint32[6] = {"value", "is", "used,", "but", "none", "returned"}; 3491456Sroot Errorclass lint3() 3501456Sroot { 3511456Sroot if ( (wordvcmp(wordv+2, 4, Lint31) == 0) 3521456Sroot || (wordvcmp(wordv+2, 6, Lint32) == 0) ){ 3531456Sroot language = INLINT; 3541456Sroot return(C_NONSPEC); 3551456Sroot } 3561456Sroot return(C_UNKNOWN); 3571456Sroot } 3581456Sroot 3591456Sroot /* 3601456Sroot * Special word vectors for use by F77 recognition 3611456Sroot */ 3621456Sroot char *F77_fatal[3] = {"Compiler", "error", "line"}; 3631456Sroot char *F77_error[3] = {"Error", "on", "line"}; 3641456Sroot char *F77_warning[3] = {"Warning", "on", "line"}; 3651456Sroot f77() 3661456Sroot { 3671456Sroot char **nwordv; 3681456Sroot /* 3691456Sroot * look for f77 errors: 3701456Sroot * Error messages from /usr/src/cmd/f77/error.c, with 3711456Sroot * these printf formats: 3721456Sroot * 3731456Sroot * Compiler error line %d of %s: %s 3741456Sroot * Error on line %d of %s: %s 3751456Sroot * Warning on line %d of %s: %s 3761456Sroot */ 3771456Sroot if (wordc < 6) 3781456Sroot return(C_UNKNOWN); 3791456Sroot if ( (lastchar(wordv[6]) == ':') 3801456Sroot &&( 3811456Sroot (wordvcmp(wordv+1, 3, F77_fatal) == 0) 3821456Sroot || (wordvcmp(wordv+1, 3, F77_error) == 0) 3831456Sroot || (wordvcmp(wordv+1, 3, F77_warning) == 0) ) 3841456Sroot ){ 3851456Sroot language = INF77; 3861456Sroot nwordv = wordvsplice(2, wordc, wordv+1); 3871456Sroot nwordv[0] = wordv[6]; 3881456Sroot clob_last(nwordv[0],'\0'); 3891456Sroot nwordv[1] = wordv[4]; 3901456Sroot wordc += 2; 3911456Sroot wordv = nwordv - 1; /* 1 based */ 3921456Sroot return(C_TRUE); 3931456Sroot } 3941456Sroot return(C_UNKNOWN); 3951456Sroot } /* end of f77 */ 3961456Sroot 3971456Sroot char *Make_Croak[3] = {"***", "Error", "code"}; 3981456Sroot char *Make_NotRemade[5] = {"not", "remade", "because", "of", "errors"}; 3991456Sroot Errorclass make() 4001456Sroot { 4011456Sroot if (wordvcmp(wordv+1, 3, Make_Croak) == 0){ 4021456Sroot language = INMAKE; 4031456Sroot return(C_SYNC); 4041456Sroot } 4051456Sroot if (wordvcmp(wordv+2, 5, Make_NotRemade) == 0){ 4061456Sroot language = INMAKE; 4071456Sroot return(C_SYNC); 4081456Sroot } 4091456Sroot return(C_UNKNOWN); 4101456Sroot } 4111456Sroot Errorclass ri() 4121456Sroot { 4131456Sroot /* 4141456Sroot * Match an error message produced by ri; here is the 4151456Sroot * procedure yanked from the distributed version of ri 4161456Sroot * April 24, 1980. 4171456Sroot * 4181456Sroot * serror(str, x1, x2, x3) 4191456Sroot * char str[]; 4201456Sroot * char *x1, *x2, *x3; 4211456Sroot * { 4221456Sroot * extern int yylineno; 4231456Sroot * 4241456Sroot * putc('"', stdout); 4251456Sroot * fputs(srcfile, stdout); 4261456Sroot * putc('"', stdout); 4271456Sroot * fprintf(stdout, " %d: ", yylineno); 4281456Sroot * fprintf(stdout, str, x1, x2, x3); 4291456Sroot * fprintf(stdout, "\n"); 4301456Sroot * synerrs++; 4311456Sroot * } 4321456Sroot */ 4331456Sroot if ( (firstchar(wordv[1]) == '"') 4341456Sroot &&(lastchar(wordv[1]) == '"') 4351456Sroot &&(lastchar(wordv[2]) == ':') 4361456Sroot &&(isdigit(firstchar(wordv[2]))) ){ 4371456Sroot clob_last(wordv[1], '\0'); /* drop the last " */ 4381456Sroot wordv[1]++; /* skip over the first " */ 4391456Sroot clob_last(wordv[2], '\0'); 4401456Sroot language = INRI; 4411456Sroot return(C_TRUE); 4421456Sroot } 4431456Sroot return(C_UNKNOWN); 4441456Sroot } 4451456Sroot 4461456Sroot Errorclass catchall() 4471456Sroot { 4481456Sroot /* 4491456Sroot * Catches random things. 4501456Sroot */ 4511456Sroot language = INUNKNOWN; 4521456Sroot return(C_NONSPEC); 4531456Sroot } /* end of catch all*/ 454*13106Srrh 455*13106Srrh Errorclass troff() 456*13106Srrh { 457*13106Srrh /* 458*13106Srrh * troff source error message, from eqn, bib, tbl... 459*13106Srrh * Just like pcc ccom, except uses `' 460*13106Srrh */ 461*13106Srrh if ( (firstchar(wordv[1]) == '`') 462*13106Srrh && (lastchar(wordv[1]) == ',') 463*13106Srrh && (next_lastchar(wordv[1]) == '\'') 464*13106Srrh && (strcmp(wordv[2],"line") == 0) 465*13106Srrh && (isdigit(firstchar(wordv[3]))) 466*13106Srrh && (lastchar(wordv[3]) == ':') ){ 467*13106Srrh clob_last(wordv[1], '\0'); /* drop last , */ 468*13106Srrh clob_last(wordv[1], '\0'); /* drop last " */ 469*13106Srrh wordv[1]++; /* drop first " */ 470*13106Srrh clob_last(wordv[3], '\0'); /* drop : on line number */ 471*13106Srrh wordv[2] = wordv[1]; /* overwrite "line" */ 472*13106Srrh wordv++; /*compensate*/ 473*13106Srrh currentfilename = wordv[1]; 474*13106Srrh language = INTROFF; 475*13106Srrh return(C_TRUE); 476*13106Srrh } 477*13106Srrh return(C_UNKNOWN); 478*13106Srrh } 479