version 1.26, 2020/06/10 21:00:01 |
version 1.27, 2020/06/10 21:01:32 |
|
|
{ |
{ |
if ( (record = (char *) malloc(n)) == NULL |
if ( (record = (char *) malloc(n)) == NULL |
|| (fields = (char *) malloc(n+1)) == NULL |
|| (fields = (char *) malloc(n+1)) == NULL |
|| (fldtab = (Cell **) calloc(nfields+1, sizeof(Cell *))) == NULL |
|| (fldtab = (Cell **) calloc(nfields+2, sizeof(Cell *))) == NULL |
|| (fldtab[0] = (Cell *) malloc(sizeof(Cell))) == NULL ) |
|| (fldtab[0] = (Cell *) malloc(sizeof(Cell))) == NULL ) |
FATAL("out of space for $0 and fields"); |
FATAL("out of space for $0 and fields"); |
*record = '\0'; |
*record = '\0'; |
|
|
int sep, c; |
int sep, c; |
char *rr, *buf = *pbuf; |
char *rr, *buf = *pbuf; |
int bufsize = *pbufsize; |
int bufsize = *pbufsize; |
|
char *rs = getsval(rsloc); |
|
|
if (strlen(*FS) >= sizeof(inputFS)) |
if (strlen(getsval(fsloc)) >= sizeof (inputFS)) |
FATAL("field separator %.10s... is too long", *FS); |
FATAL("field separator %.10s... is too long", *FS); |
/*fflush(stdout); avoids some buffering problem but makes it 25% slower*/ |
/*fflush(stdout); avoids some buffering problem but makes it 25% slower*/ |
strlcpy(inputFS, *FS, sizeof inputFS); /* for subsequent field splitting */ |
strlcpy(inputFS, *FS, sizeof inputFS); /* for subsequent field splitting */ |
if ((sep = **RS) == 0) { |
if ((sep = *rs) == 0) { |
sep = '\n'; |
sep = '\n'; |
while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ |
while ((c=getc(inf)) == '\n' && c != EOF) /* skip leading \n's */ |
; |
; |
|
|
FATAL("input record `%.30s...' too long", buf); |
FATAL("input record `%.30s...' too long", buf); |
*rr++ = c; |
*rr++ = c; |
} |
} |
if (**RS == sep || c == EOF) |
if (*rs == sep || c == EOF) |
break; |
break; |
if ((c = getc(inf)) == '\n' || c == EOF) /* 2 in a row */ |
if ((c = getc(inf)) == '\n' || c == EOF) /* 2 in a row */ |
break; |
break; |
|
|
} |
} |
fr = fields; |
fr = fields; |
i = 0; /* number of fields accumulated here */ |
i = 0; /* number of fields accumulated here */ |
|
if (strlen(getsval(fsloc)) >= sizeof (inputFS)) |
|
FATAL("field separator %.10s... is too long", *FS); |
strlcpy(inputFS, *FS, sizeof(inputFS)); |
strlcpy(inputFS, *FS, sizeof(inputFS)); |
if (strlen(inputFS) > 1) { /* it's a regular expression */ |
if (strlen(inputFS) > 1) { /* it's a regular expression */ |
i = refldbld(r, inputFS); |
i = refldbld(r, inputFS); |
|
|
|
|
void setlastfld(int n) /* set lastfld cleaning fldtab cells if necessary */ |
void setlastfld(int n) /* set lastfld cleaning fldtab cells if necessary */ |
{ |
{ |
|
if (n < 0) |
|
FATAL("cannot set NF to a negative value"); |
if (n > nfields) |
if (n > nfields) |
growfldtab(n); |
growfldtab(n); |
|
|
|
|
{ |
{ |
int i; |
int i; |
char *r, *p; |
char *r, *p; |
|
char *sep = getsval(ofsloc); |
|
|
if (donerec == 1) |
if (donerec == 1) |
return; |
return; |
|
|
while ((*r = *p++) != 0) |
while ((*r = *p++) != 0) |
r++; |
r++; |
if (i < *NF) { |
if (i < *NF) { |
if (!adjbuf(&record, &recsize, 2+strlen(*OFS)+r-record, recsize, &r, "recbld 2")) |
if (!adjbuf(&record, &recsize, 2+strlen(sep)+r-record, recsize, &r, "recbld 2")) |
FATAL("created $0 `%.30s...' too long", record); |
FATAL("created $0 `%.30s...' too long", record); |
for (p = *OFS; (*r = *p++) != 0; ) |
for (p = sep; (*r = *p++) != 0; ) |
r++; |
r++; |
} |
} |
} |
} |