version 1.38, 2020/06/26 15:50:06 |
version 1.39, 2020/06/26 15:57:39 |
|
|
firsttime = false; |
firsttime = false; |
initgetrec(); |
initgetrec(); |
} |
} |
DPRINTF( ("RS=<%s>, FS=<%s>, ARGC=%g, FILENAME=%s\n", |
DPRINTF("RS=<%s>, FS=<%s>, ARGC=%g, FILENAME=%s\n", |
*RS, *FS, *ARGC, *FILENAME) ); |
*RS, *FS, *ARGC, *FILENAME); |
if (isrecord) { |
if (isrecord) { |
donefld = false; |
donefld = false; |
donerec = true; |
donerec = true; |
|
|
saveb0 = buf[0]; |
saveb0 = buf[0]; |
buf[0] = 0; |
buf[0] = 0; |
while (argno < *ARGC || infile == stdin) { |
while (argno < *ARGC || infile == stdin) { |
DPRINTF( ("argno=%d, file=|%s|\n", argno, file) ); |
DPRINTF("argno=%d, file=|%s|\n", argno, file); |
if (infile == NULL) { /* have to open a new file */ |
if (infile == NULL) { /* have to open a new file */ |
file = getargv(argno); |
file = getargv(argno); |
if (file == NULL || *file == '\0') { /* deleted or zapped */ |
if (file == NULL || *file == '\0') { /* deleted or zapped */ |
|
|
continue; |
continue; |
} |
} |
*FILENAME = file; |
*FILENAME = file; |
DPRINTF( ("opening file %s\n", file) ); |
DPRINTF("opening file %s\n", file); |
if (*file == '-' && *(file+1) == '\0') |
if (*file == '-' && *(file+1) == '\0') |
infile = stdin; |
infile = stdin; |
else if ((infile = fopen(file, "r")) == NULL) |
else if ((infile = fopen(file, "r")) == NULL) |
|
|
*pbuf = buf; |
*pbuf = buf; |
*pbufsize = bufsize; |
*pbufsize = bufsize; |
isrec = *buf || !feof(inf); |
isrec = *buf || !feof(inf); |
DPRINTF( ("readrec saw <%s>, returns %d\n", buf, isrec) ); |
DPRINTF("readrec saw <%s>, returns %d\n", buf, isrec); |
return isrec; |
return isrec; |
} |
} |
|
|
|
|
return NULL; |
return NULL; |
x = setsymtab(temp, "", 0.0, STR, ARGVtab); |
x = setsymtab(temp, "", 0.0, STR, ARGVtab); |
s = getsval(x); |
s = getsval(x); |
DPRINTF( ("getargv(%d) returns |%s|\n", n, s) ); |
DPRINTF("getargv(%d) returns |%s|\n", n, s); |
return s; |
return s; |
} |
} |
|
|
|
|
q->fval = atof(q->sval); |
q->fval = atof(q->sval); |
q->tval |= NUM; |
q->tval |= NUM; |
} |
} |
DPRINTF( ("command line set %s to |%s|\n", s, p) ); |
DPRINTF("command line set %s to |%s|\n", s, p); |
} |
} |
|
|
|
|
|
|
if (*rec == '\0') |
if (*rec == '\0') |
return 0; |
return 0; |
pfa = makedfa(fs, 1); |
pfa = makedfa(fs, 1); |
DPRINTF( ("into refldbld, rec = <%s>, pat = <%s>\n", rec, fs) ); |
DPRINTF("into refldbld, rec = <%s>, pat = <%s>\n", rec, fs); |
tempstat = pfa->initstat; |
tempstat = pfa->initstat; |
for (i = 1; ; i++) { |
for (i = 1; ; i++) { |
const size_t fss_rem = fields + fieldssize + 1 - fr; |
const size_t fss_rem = fields + fieldssize + 1 - fr; |
|
|
xfree(fldtab[i]->sval); |
xfree(fldtab[i]->sval); |
fldtab[i]->tval = FLD | STR | DONTFREE; |
fldtab[i]->tval = FLD | STR | DONTFREE; |
fldtab[i]->sval = fr; |
fldtab[i]->sval = fr; |
DPRINTF( ("refldbld: i=%d\n", i) ); |
DPRINTF("refldbld: i=%d\n", i); |
if (nematch(pfa, rec)) { |
if (nematch(pfa, rec)) { |
const size_t reclen = patbeg - rec; |
const size_t reclen = patbeg - rec; |
pfa->initstat = 2; /* horrible coupling to b.c */ |
pfa->initstat = 2; /* horrible coupling to b.c */ |
DPRINTF( ("match %s (%d chars)\n", patbeg, patlen) ); |
DPRINTF("match %s (%d chars)\n", patbeg, patlen); |
if (reclen >= fss_rem) |
if (reclen >= fss_rem) |
FATAL("out of space for fields in refldbld"); |
FATAL("out of space for fields in refldbld"); |
memcpy(fr, rec, reclen); |
memcpy(fr, rec, reclen); |
|
|
*fr++ = '\0'; |
*fr++ = '\0'; |
rec = patbeg + patlen; |
rec = patbeg + patlen; |
} else { |
} else { |
DPRINTF( ("no match %s\n", rec) ); |
DPRINTF("no match %s\n", rec); |
if (strlcpy(fr, rec, fss_rem) >= fss_rem) |
if (strlcpy(fr, rec, fss_rem) >= fss_rem) |
FATAL("out of space for fields in refldbld"); |
FATAL("out of space for fields in refldbld"); |
pfa->initstat = tempstat; |
pfa->initstat = tempstat; |
|
|
if (!adjbuf(&record, &recsize, 2+r-record, recsize, &r, "recbld 3")) |
if (!adjbuf(&record, &recsize, 2+r-record, recsize, &r, "recbld 3")) |
FATAL("built giant record `%.30s...'", record); |
FATAL("built giant record `%.30s...'", record); |
*r = '\0'; |
*r = '\0'; |
DPRINTF( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) ); |
DPRINTF("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]); |
|
|
if (freeable(fldtab[0])) |
if (freeable(fldtab[0])) |
xfree(fldtab[0]->sval); |
xfree(fldtab[0]->sval); |
fldtab[0]->tval = REC | STR | DONTFREE; |
fldtab[0]->tval = REC | STR | DONTFREE; |
fldtab[0]->sval = record; |
fldtab[0]->sval = record; |
|
|
DPRINTF( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) ); |
DPRINTF("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]); |
DPRINTF( ("recbld = |%s|\n", record) ); |
DPRINTF("recbld = |%s|\n", record); |
donerec = true; |
donerec = true; |
} |
} |
|
|