Merge branch 'master' into subsep

This commit is contained in:
onetrueawk 2019-01-21 14:17:57 -05:00 committed by GitHub
commit 10da937340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 25 deletions

10
b.c
View File

@ -823,7 +823,15 @@ int relex(void) /* lexical analyzer for reparse */
if (cc->cc_name != NULL && prestr[1 + cc->cc_namelen] == ':' && if (cc->cc_name != NULL && prestr[1 + cc->cc_namelen] == ':' &&
prestr[2 + cc->cc_namelen] == ']') { prestr[2 + cc->cc_namelen] == ']') {
prestr += cc->cc_namelen + 3; prestr += cc->cc_namelen + 3;
for (i = 0; i < NCHARS; i++) { /*
* BUG: We begin at 1, instead of 0, since we
* would otherwise prematurely terminate the
* string for classes like [[:cntrl:]]. This
* means that we can't match the NUL character,
* not without first adapting the entire
* program to track each string's length.
*/
for (i = 1; i < NCHARS; i++) {
if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2")) if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2"))
FATAL("out of space for reg expr %.10s...", lastre); FATAL("out of space for reg expr %.10s...", lastre);
if (cc->cc_func(i)) { if (cc->cc_func(i)) {

View File

@ -24,17 +24,25 @@ and also if CONVFMT changed.
7. unary-plus: Unary plus on a string constant returned the string. 7. unary-plus: Unary plus on a string constant returned the string.
Instead, it should convert the value to numeric and give that value. Instead, it should convert the value to numeric and give that value.
8. missing-precision: When using the format string "%*s", the precision 8. concat-assign-same: Concatenation previously evaluated both sides of the
expression before doing its work, which, since assign() evaluates to the cell
being assigned to, meant that expressions like "print (a = 1) (a = 2)" would
print "22" rather than "12".
9. missing-precision: When using the format string "%*s", the precision
argument was used without checking if it was present first. argument was used without checking if it was present first.
9. fmt-overflow: The buffer used for OFMT/CONVFMT conversions was written 10. missing-precision: When using the format string "%*s", the precision
argument was used without checking if it was present first.
11. fmt-overflow: The buffer used for OFMT/CONVFMT conversions was written
to with sprintf(), which meant that some conversions could write past the to with sprintf(), which meant that some conversions could write past the
end. end.
10. numeric-subsep, numeric-fs, numeric-output-seps, numerics-rs: If SUBSEP, 12. numeric-subsep, numeric-fs, numeric-output-seps, numerics-rs: If SUBSEP,
FS, RS, OFS, or ORS were set to a numeric value, then their string values FS, RS, OFS, or ORS were set to a numeric value, then their string values
wouldn't always be generated before being needed. wouldn't always be generated before being needed.
11. subsep-overflow: The length of SUBSEP needs to be rechecked after 13. subsep-overflow: The length of SUBSEP needs to be rechecked after
calling execute(), in case SUBSEP itself has been changed. calling execute(), in case SUBSEP itself has been changed.

View File

@ -0,0 +1,4 @@
BEGIN {
print (a = 1) (a = 2) (a = 3) (a = 4) (a = 5);
print (a = 1), (a = 2), (a = 3), (a = 4), (a = 5);
}

View File

@ -0,0 +1,2 @@
22345
1 2 3 4 5

View File

@ -0,0 +1,2 @@
12345
1 2 3 4 5

18
lex.c
View File

@ -198,6 +198,7 @@ int yylex(void)
yylval.i = c; yylval.i = c;
switch (c) { switch (c) {
case '\n': /* {EOL} */ case '\n': /* {EOL} */
lineno++;
RET(NL); RET(NL);
case '\r': /* assume \n is coming */ case '\r': /* assume \n is coming */
case ' ': /* {WS}+ */ case ' ': /* {WS}+ */
@ -213,6 +214,7 @@ int yylex(void)
case '\\': case '\\':
if (peek() == '\n') { if (peek() == '\n') {
input(); input();
lineno++;
} else if (peek() == '\r') { } else if (peek() == '\r') {
input(); input(); /* \n */ input(); input(); /* \n */
lineno++; lineno++;
@ -370,10 +372,11 @@ int string(void)
case '\n': case '\n':
case '\r': case '\r':
case 0: case 0:
*bp = '\0';
SYNTAX( "non-terminated string %.10s...", buf ); SYNTAX( "non-terminated string %.10s...", buf );
lineno++;
if (c == 0) /* hopeless */ if (c == 0) /* hopeless */
FATAL( "giving up" ); FATAL( "giving up" );
lineno++;
break; break;
case '\\': case '\\':
c = input(); c = input();
@ -515,6 +518,7 @@ int regexpr(void)
if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr")) if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr"))
FATAL("out of space for reg expr %.10s...", buf); FATAL("out of space for reg expr %.10s...", buf);
if (c == '\n') { if (c == '\n') {
*bp = '\0';
SYNTAX( "newline in regular expression %.10s...", buf ); SYNTAX( "newline in regular expression %.10s...", buf );
unput('\n'); unput('\n');
break; break;
@ -553,19 +557,19 @@ int input(void) /* get next lexical input character */
lexprog++; lexprog++;
} else /* awk -f ... */ } else /* awk -f ... */
c = pgetc(); c = pgetc();
if (c == '\n') if (c == EOF)
lineno++;
else if (c == EOF)
c = 0; c = 0;
if (ep >= ebuf + sizeof ebuf) if (ep >= ebuf + sizeof ebuf)
ep = ebuf; ep = ebuf;
return *ep++ = c; *ep = c;
if (c != 0) {
ep++;
}
return (c);
} }
void unput(int c) /* put lexical character back on input */ void unput(int c) /* put lexical character back on input */
{ {
if (c == '\n')
lineno--;
if (yysptr >= yysbuf + sizeof(yysbuf)) if (yysptr >= yysbuf + sizeof(yysbuf))
FATAL("pushed back too much: %.20s...", yysbuf); FATAL("pushed back too much: %.20s...", yysbuf);
*yysptr++ = c; *yysptr++ = c;

2
lib.c
View File

@ -59,7 +59,7 @@ void recinit(unsigned int n)
{ {
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 **) malloc((nfields+1) * sizeof(Cell *))) == NULL || (fldtab = (Cell **) malloc((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");
*fldtab[0] = dollar0; *fldtab[0] = dollar0;

2
main.c
View File

@ -88,7 +88,7 @@ int main(int argc, char *argv[])
exit(0); exit(0);
break; break;
} }
if (strncmp(argv[1], "--", 2) == 0) { /* explicit end of args */ if (strcmp(argv[1], "--") == 0) { /* explicit end of args */
argc--; argc--;
argv++; argv++;
break; break;

23
run.c
View File

@ -1181,25 +1181,26 @@ Cell *cat(Node **a, int q) /* a[0] cat a[1] */
{ {
Cell *x, *y, *z; Cell *x, *y, *z;
int n1, n2; int n1, n2;
char *s; char *s = NULL;
int ssz = 0;
x = execute(a[0]); x = execute(a[0]);
n1 = strlen(getsval(x));
adjbuf(&s, &ssz, n1 + 1, recsize, 0, "cat1");
(void) strncpy(s, x->sval, ssz);
y = execute(a[1]); y = execute(a[1]);
getsval(x); n2 = strlen(getsval(y));
getsval(y); adjbuf(&s, &ssz, n1 + n2 + 1, recsize, 0, "cat2");
n1 = strlen(x->sval); (void) strncpy(s + n1, y->sval, ssz - n1);
n2 = strlen(y->sval);
s = (char *) malloc(n1 + n2 + 1);
if (s == NULL)
FATAL("out of space concatenating %.15s... and %.15s...",
x->sval, y->sval);
strcpy(s, x->sval);
strcpy(s+n1, y->sval);
tempfree(x); tempfree(x);
tempfree(y); tempfree(y);
z = gettemp(); z = gettemp();
z->sval = s; z->sval = s;
z->tval = STR; z->tval = STR;
return(z); return(z);
} }