Patch from awk maintainer (Dmitry Zakhrov) to fix bugs 642, 663, and 667.

This commit is contained in:
Rob Landley 2006-02-14 16:05:32 +00:00
parent 5ba53c05fc
commit 46e351d478

View File

@ -948,7 +948,7 @@ static uint32_t next_token(uint32_t expected)
*(p-1) = '\0'; *(p-1) = '\0';
tc = TC_VARIABLE; tc = TC_VARIABLE;
/* also consume whitespace between functionname and bracket */ /* also consume whitespace between functionname and bracket */
skip_spaces(&p); if (! (expected & TC_VARIABLE)) skip_spaces(&p);
if (*p == '(') { if (*p == '(') {
tc = TC_FUNCTION; tc = TC_FUNCTION;
} else { } else {
@ -1656,6 +1656,7 @@ static int awk_getline(rstream *rsm, var *v)
} }
} else if (c != '\0') { } else if (c != '\0') {
s = strchr(b+pp, c); s = strchr(b+pp, c);
if (! s) s = memchr(b+pp, '\0', p - pp);
if (s) { if (s) {
so = eo = s-b; so = eo = s-b;
eo++; eo++;
@ -2614,7 +2615,7 @@ static rstream *next_input_file(void)
extern int awk_main(int argc, char **argv) extern int awk_main(int argc, char **argv)
{ {
char *s, *s1; char *s, *s1;
int i, j, c; int i, j, c, flen;
var *v; var *v;
static var tv; static var tv;
char **envp; char **envp;
@ -2682,10 +2683,17 @@ keep_going:
F = afopen(programname = optarg, "r"); F = afopen(programname = optarg, "r");
s = NULL; s = NULL;
/* one byte is reserved for some trick in next_token */ /* one byte is reserved for some trick in next_token */
if (fseek(F, 0, SEEK_END) == 0) {
flen = ftell(F);
s = (char *)xmalloc(flen+4);
fseek(F, 0, SEEK_SET);
i = 1 + fread(s+1, 1, flen, F);
} else {
for (i=j=1; j>0; i+=j) { for (i=j=1; j>0; i+=j) {
s = (char *)xrealloc(s, i+4096); s = (char *)xrealloc(s, i+4096);
j = fread(s+i, 1, 4094, F); j = fread(s+i, 1, 4094, F);
} }
}
s[i] = '\0'; s[i] = '\0';
fclose(F); fclose(F);
parse_program(s+1); parse_program(s+1);