use malloc, made more robust against errors in line directives

This commit is contained in:
ceriel 1987-08-04 19:30:14 +00:00
parent bcb04a1a76
commit 3c6a9b2b96

View file

@ -94,7 +94,7 @@ int atoi();
void exit(); void exit();
void sleep(); void sleep();
void execv(); void execv();
char *sbrk(); char *malloc();
int chdir(); int chdir();
int fork(); int fork();
int wait(); int wait();
@ -397,7 +397,7 @@ int list(p,q) char *p,*q; {
return(0); return(0);
} }
if (index == 0) { if (index == 0) {
index = (int *) sbrk(MAXERNO * sizeof index[0]); index = (int *) malloc(MAXERNO * sizeof index[0]);
fillindex(); fillindex();
} }
if ((inpfil = fopen(p,"r")) == NULL) if ((inpfil = fopen(p,"r")) == NULL)
@ -457,10 +457,10 @@ int nextline(printing) {
listlino++; listlino++;
ch = getc(inpfil); ch = getc(inpfil);
if (ch == '#') { while (ch == '#') {
if (lineline(printing) == 0) if (lineline(printing) == 1)
fatal("bad line directive");
return(1); return(1);
ch = getc(inpfil);
} }
listrela++; listrela++;
if (listfnam == source) if (listfnam == source)
@ -482,35 +482,61 @@ lineline(printing) {
register ch; register ch;
register char *p,*q; register char *p,*q;
static char line[100]; static char line[100];
int ln;
p = line; p = line;
while ((ch = getc(inpfil)) != '\n') { while ((ch = getc(inpfil)) != '\n') {
if (ch == EOF || p == &line[100-1]) if (ch == EOF || p == &line[100-1]) {
*p = 0;
listlino++;
listrela++;
if (listfnam == source)
listorig++;
if (printing) {
printf("%5d\t#%s", listorig, p);
putchar(ch);
}
while (ch != EOF && ch != '\n') {
ch = getc(inpfil);
if (ch != EOF && printing) putchar(ch);
}
return(0); return(0);
}
*p++ = ch; *p++ = ch;
} }
*p = '\0'; p = line; *p = '\0'; p = line;
if (printing) ln = atoi(p)-1;
printf("\t#%s\n",p); if (ln >= 0) {
if ((listrela = atoi(p)-1) < 0) while ((ch = *p++) != '"' && ch != '\0')
return(0); ;
while ((ch = *p++) != '"') if (ch == '"') {
if (ch == '\0')
return(0);
q = p; q = p;
while (ch = *p++) { while (ch = *p++) {
if (ch == '"') { if (ch == '"') {
*--p = '\0'; *--p = '\0';
listrela = ln;
if ( source ) { if ( source ) {
listfnam = strcmp(q,source)==0 ? source : q; listfnam = strcmp(q,source)==0 ? source : q;
return(1);
} }
else {
source=q ; listfnam=q ; source=q ; listfnam=q ;
}
listlino++;
if (printing)
printf("\t#%s\n",p);
return 1 ; return 1 ;
} }
if (ch == '/') if (ch == '/')
q = p; q = p;
} }
}
}
listlino++;
listrela++;
if (listfnam == source)
listorig++;
if (printing)
printf("%5d\t#%s\n",listorig, p);
return(0); return(0);
} }