#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: input.c,v 1.5 1997/10/18 14:44:32 lukem Exp $");
#endif
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
int wordc;
char **wordv;
Errorclass catchall __P((void));
Errorclass cpp __P((void));
Errorclass f77 __P((void));
Errorclass lint0 __P((void));
Errorclass lint1 __P((void));
Errorclass lint2 __P((void));
Errorclass lint3 __P((void));
Errorclass make __P((void));
Errorclass mod2 __P((void));
Errorclass onelong __P((void));
Errorclass pccccom __P((void));
Errorclass pi __P((void));
Errorclass ri __P((void));
Errorclass richieccom __P((void));
Errorclass troff __P((void));
void
eaterrors(r_errorc, r_errorv)
int *r_errorc;
Eptr **r_errorv;
{
Errorclass errorclass = C_SYNC;
char *line;
char *inbuffer;
size_t inbuflen;
for (;;){
if ((inbuffer = fgetln(errorfile, &inbuflen)) == NULL)
break;
line = Calloc(inbuflen + 1, sizeof(char));
memcpy(line, inbuffer, inbuflen);
line[inbuflen] = '\0';
wordvbuild(line, &wordc, &wordv);
wordv -= 1;
if ( wordc > 0 &&
((( errorclass = onelong() ) != C_UNKNOWN)
|| (( errorclass = cpp() ) != C_UNKNOWN)
|| (( errorclass = pccccom() ) != C_UNKNOWN)
|| (( errorclass = richieccom() ) != C_UNKNOWN)
|| (( errorclass = lint0() ) != C_UNKNOWN)
|| (( errorclass = lint1() ) != C_UNKNOWN)
|| (( errorclass = lint2() ) != C_UNKNOWN)
|| (( errorclass = lint3() ) != C_UNKNOWN)
|| (( errorclass = make() ) != C_UNKNOWN)
|| (( errorclass = f77() ) != C_UNKNOWN)
|| ((errorclass = pi() ) != C_UNKNOWN)
|| (( errorclass = ri() )!= C_UNKNOWN)
|| (( errorclass = mod2() )!= C_UNKNOWN)
|| (( errorclass = troff() )!= C_UNKNOWN))
) ;
else
errorclass = catchall();
if (wordc)
erroradd(wordc, wordv+1, errorclass, C_UNKNOWN);
}
#ifdef FULLDEBUG
printf("%d errorentrys\n", nerrors);
#endif
arrayify(r_errorc, r_errorv, er_head);
}
void
erroradd(errorlength, errorv, errorclass, errorsubclass)
int errorlength;
char **errorv;
Errorclass errorclass;
Errorclass errorsubclass;
{
Eptr newerror;
char *cp;
if (errorclass == C_TRUE){
for(cp = errorv[1]; *cp && isdigit(*cp); cp++)
continue;
errorclass = (*cp == '\0') ? C_TRUE : C_NONSPEC;
#ifdef FULLDEBUG
if (errorclass != C_TRUE)
printf("The 2nd word, \"%s\" is not a number.\n",
errorv[1]);
#endif
}
if (errorlength > 0){
newerror = (Eptr)Calloc(1, sizeof(Edesc));
newerror->error_language = language;
newerror->error_text = errorv;
newerror->error_lgtext = errorlength;
if (errorclass == C_TRUE)
newerror->error_line = atoi(errorv[1]);
newerror->error_e_class = errorclass;
newerror->error_s_class = errorsubclass;
switch(newerror->error_e_class = discardit(newerror)){
case C_SYNC: nsyncerrors++; break;
case C_DISCARD: ndiscard++; break;
case C_NULLED: nnulled++; break;
case C_NONSPEC: nnonspec++; break;
case C_THISFILE: nthisfile++; break;
case C_TRUE: ntrue++; break;
case C_UNKNOWN: nunknown++; break;
case C_IGNORE: nignore++; break;
}
newerror->error_next = er_head;
er_head = newerror;
newerror->error_no = nerrors++;
}
}
Errorclass
onelong()
{
char **nwordv;
if ( (wordc == 1) && (language != INLD) ){
wordc = 0;
if (strcmp(wordv[1], "Stop.") == 0){
language = INMAKE; return(C_SYNC);
}
if (strcmp(wordv[1], "Assembler:") == 0){
language = INAS; return(C_SYNC);
} else
if (strcmp(wordv[1], "Undefined:") == 0){
language = INLD; return(C_SYNC);
}
if (lastchar(wordv[1]) == ':'){
currentfilename = wordv[1];
(void)substitute(currentfilename, ':', '\0');
language = INCC; return(C_SYNC);
}
} else
if ( (wordc == 1) && (language == INLD) ){
nwordv = (char **)Calloc(4, sizeof(char *));
nwordv[0] = "ld:";
nwordv[1] = wordv[1];
nwordv[2] = "is";
nwordv[3] = "undefined.";
wordc = 4;
wordv = nwordv - 1;
return(C_NONSPEC);
} else
if (wordc == 1){
return(C_SYNC);
}
return(C_UNKNOWN);
}
Errorclass
cpp()
{
if ( (language != INLD)
&& (lastchar(wordv[1]) == ':')
&& (isdigit(firstchar(wordv[2])))
&& (lastchar(wordv[2]) == ':') ){
language = INCPP;
clob_last(wordv[1], '\0');
clob_last(wordv[2], '\0');
return(C_TRUE);
}
return(C_UNKNOWN);
}
Errorclass
pccccom()
{
if ( (firstchar(wordv[1]) == '"')
&& (lastchar(wordv[1]) == ',')
&& (next_lastchar(wordv[1]) == '"')
&& (strcmp(wordv[2],"line") == 0)
&& (isdigit(firstchar(wordv[3])))
&& (lastchar(wordv[3]) == ':') ){
clob_last(wordv[1], '\0');
clob_last(wordv[1], '\0');
wordv[1]++;
clob_last(wordv[3], '\0');
wordv[2] = wordv[1];
wordv++;
wordc--;
currentfilename = wordv[1];
language = INCC;
return(C_TRUE);
}
return(C_UNKNOWN);
}
Errorclass
richieccom()
{
char *cp;
char **nwordv;
char *file;
if (lastchar(wordv[1]) == ':'){
cp = wordv[1] + strlen(wordv[1]) - 1;
while (isdigit(*--cp))
continue;
if (*cp == ':'){
clob_last(wordv[1], '\0');
*cp = '\0';
file = wordv[1];
nwordv = wordvsplice(1, wordc, wordv+1);
nwordv[0] = file;
nwordv[1] = cp + 1;
wordc += 1;
wordv = nwordv - 1;
language = INCC;
currentfilename = wordv[1];
return(C_TRUE);
}
}
return(C_UNKNOWN);
}
Errorclass
lint0()
{
char **nwordv;
char *line, *file;
if (wordc >= 2){
if ( (lastchar(wordv[1]) == ':')
&& (next_lastchar(wordv[1]) == ')')
) {
clob_last(wordv[1], '\0');
if (persperdexplode(wordv[1], &line, &file)){
nwordv = wordvsplice(1, wordc, wordv+1);
nwordv[0] = file;
nwordv[1] = line;
wordc += 1;
wordv = nwordv - 1;
language = INLINT;
return(C_TRUE);
}
wordv[1][strlen(wordv[1])] = ':';
}
}
return (C_UNKNOWN);
}
Errorclass
lint1()
{
char *line1, *line2;
char *file1, *file2;
char **nwordv1, **nwordv2;
if (wordc > 1 && strcmp(wordv[wordc-1], "::") == 0){
language = INLINT;
if (wordc > 2
&& (persperdexplode(wordv[wordc], &line2, &file2))
&& (persperdexplode(wordv[wordc-2], &line1, &file1)) ){
nwordv1 = wordvsplice(2, wordc, wordv+1);
nwordv2 = wordvsplice(2, wordc, wordv+1);
nwordv1[0] = file1; nwordv1[1] = line1;
erroradd(wordc+2, nwordv1, C_TRUE, C_DUPL);
nwordv2[0] = file2; nwordv2[1] = line2;
wordc = wordc + 2;
wordv = nwordv2 - 1;
return(C_TRUE);
}
}
return(C_UNKNOWN);
}
Errorclass
lint2()
{
char *file;
char *line;
char **nwordv;
if ( (lastchar(wordv[2]) == '(' )
&& (strcmp(wordv[4], "),") == 0) ){
language = INLINT;
if (persperdexplode(wordv[3], &line, &file)){
nwordv = wordvsplice(2, wordc, wordv+1);
nwordv[0] = file; nwordv[1] = line;
wordc = wordc + 2;
wordv = nwordv - 1;
return(C_TRUE);
}
}
return(C_UNKNOWN);
}
char *Lint31[4] = {"returns", "value", "which", "is"};
char *Lint32[6] = {"value", "is", "used,", "but", "none", "returned"};
Errorclass
lint3()
{
if ( (wordvcmp(wordv+2, 4, Lint31) == 0)
|| (wordvcmp(wordv+2, 6, Lint32) == 0) ){
language = INLINT;
return(C_NONSPEC);
}
return(C_UNKNOWN);
}
char *F77_fatal[3] = {"Compiler", "error", "line"};
char *F77_error[3] = {"Error", "on", "line"};
char *F77_warning[3] = {"Warning", "on", "line"};
char *F77_no_ass[3] = {"Error.","No","assembly."};
Errorclass
f77()
{
char **nwordv;
if (wordc == 3 && wordvcmp(wordv+1, 3, F77_no_ass) == 0) {
wordc = 0;
return(C_SYNC);
}
if (wordc < 6)
return(C_UNKNOWN);
if ( (lastchar(wordv[6]) == ':')
&&(
(wordvcmp(wordv+1, 3, F77_fatal) == 0)
|| (wordvcmp(wordv+1, 3, F77_error) == 0)
|| (wordvcmp(wordv+1, 3, F77_warning) == 0) )
){
language = INF77;
nwordv = wordvsplice(2, wordc, wordv+1);
nwordv[0] = wordv[6];
clob_last(nwordv[0],'\0');
nwordv[1] = wordv[4];
wordc += 2;
wordv = nwordv - 1;
return(C_TRUE);
}
return(C_UNKNOWN);
}
char *Make_Croak[3] = {"***", "Error", "code"};
char *Make_NotRemade[5] = {"not", "remade", "because", "of", "errors"};
Errorclass
make()
{
if (wordvcmp(wordv+1, 3, Make_Croak) == 0){
language = INMAKE;
return(C_SYNC);
}
if (wordvcmp(wordv+2, 5, Make_NotRemade) == 0){
language = INMAKE;
return(C_SYNC);
}
return(C_UNKNOWN);
}
Errorclass
ri()
{
if ( (firstchar(wordv[1]) == '"')
&&(lastchar(wordv[1]) == '"')
&&(lastchar(wordv[2]) == ':')
&&(isdigit(firstchar(wordv[2]))) ){
clob_last(wordv[1], '\0');
wordv[1]++;
clob_last(wordv[2], '\0');
language = INRI;
return(C_TRUE);
}
return(C_UNKNOWN);
}
Errorclass
catchall()
{
language = INUNKNOWN;
return(C_NONSPEC);
}
Errorclass
troff()
{
if ( (firstchar(wordv[1]) == '`')
&& (lastchar(wordv[1]) == ',')
&& (next_lastchar(wordv[1]) == '\'')
&& (strcmp(wordv[2],"line") == 0)
&& (isdigit(firstchar(wordv[3])))
&& (lastchar(wordv[3]) == ':') ){
clob_last(wordv[1], '\0');
clob_last(wordv[1], '\0');
wordv[1]++;
clob_last(wordv[3], '\0');
wordv[2] = wordv[1];
wordv++;
currentfilename = wordv[1];
language = INTROFF;
return(C_TRUE);
}
return(C_UNKNOWN);
}
Errorclass
mod2()
{
if ( ( (strcmp(wordv[1], "!!!") == 0)
||(strcmp(wordv[1], "File") == 0))
&& (lastchar(wordv[2]) == ',')
&& (strcmp(wordv[3], "line") == 0)
&& (isdigit(firstchar(wordv[4])))
&& (lastchar(wordv[4]) == ':')
){
clob_last(wordv[2], '\0');
clob_last(wordv[4], '\0');
wordv[3] = wordv[2];
wordv += 2;
wordc -= 2;
currentfilename = wordv[1];
language = INMOD2;
return(C_TRUE);
}
return(C_UNKNOWN);
}