aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FIXES5
-rw-r--r--awkgram.y8
-rw-r--r--main.c2
-rw-r--r--proto.h1
-rw-r--r--tran.c16
5 files changed, 30 insertions, 2 deletions
diff --git a/FIXES b/FIXES
index afd76da..9ec29c0 100644
--- a/FIXES
+++ b/FIXES
@@ -25,12 +25,17 @@ THIS SOFTWARE.
This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987.
+July 28, 2019:
+ Import grammar optimization from NetBSD: Two string constants
+ concatenated together get turned into a single string.
+
July 26, 2019:
Support POSIX-specified C-style escape sequences "\a" (alarm)
and "\v" (vertical tab) in command line arguments and regular
expressions, further to the support for them in strings added on
Apr 9, 1989. These now no longer match as literal "a" and "v"
characters (as they don't on other awk implementations).
+ Thanks to Martijn Dekker.
July 17, 2019:
Pull in a number of code cleanups and minor fixes from
diff --git a/awkgram.y b/awkgram.y
index fd0f40e..c5356d7 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -71,6 +71,7 @@ Node *arglist = 0; /* list of args for current function */
%type <i> do st
%type <i> pst opt_pst lbrace rbrace rparen comma nl opt_nl and bor
%type <i> subop print
+%type <cp> string
%right ASGNOP
%right '?'
@@ -348,6 +349,11 @@ subop:
SUB | GSUB
;
+string:
+ STRING
+ | string STRING { $$ = catstr($1, $2); }
+ ;
+
term:
term '/' ASGNOP term { $$ = op2(DIVEQ, $1, $4); }
| term '+' term { $$ = op2(ADD, $1, $3); }
@@ -394,7 +400,7 @@ term:
| SPLIT '(' pattern comma varname ')'
{ $$ = op4(SPLIT, $3, makearr($5), NIL, (Node*)STRING); } /* default */
| SPRINTF '(' patlist ')' { $$ = op1($1, $3); }
- | STRING { $$ = celltonode($1, CCON); }
+ | string { $$ = celltonode($1, CCON); }
| subop '(' reg_expr comma pattern ')'
{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, rectonode()); }
| subop '(' pattern comma pattern ')'
diff --git a/main.c b/main.c
index e19a1b4..a910bc9 100644
--- a/main.c
+++ b/main.c
@@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/
-const char *version = "version 20190726";
+const char *version = "version 20190728";
#define DEBUG
#include <stdio.h>
diff --git a/proto.h b/proto.h
index e44370d..add45fb 100644
--- a/proto.h
+++ b/proto.h
@@ -111,6 +111,7 @@ extern char *getsval(Cell *);
extern char *getpssval(Cell *); /* for print */
extern char *tostring(const char *);
extern char *qstring(const char *, int);
+extern Cell *catstr(Cell *, Cell *);
extern void recinit(unsigned int);
extern void initgetrec(void);
diff --git a/tran.c b/tran.c
index 5356b63..134b54e 100644
--- a/tran.c
+++ b/tran.c
@@ -516,6 +516,22 @@ char *tostring(const char *s) /* make a copy of string s */
return(p);
}
+Cell *catstr(Cell *a, Cell *b) /* concatenate a and b */
+{
+ Cell *c;
+ char *p;
+ char *sa = getsval(a);
+ char *sb = getsval(b);
+ size_t l = strlen(sa) + strlen(sb) + 1;
+ p = malloc(l);
+ if (p == NULL)
+ FATAL("out of space concatenating %s and %s", sa, sb);
+ snprintf(p, l, "%s%s", sa, sb);
+ c = setsymtab(p, p, 0.0, CON|STR|DONTFREE, symtab);
+ free(p);
+ return c;
+}
+
char *qstring(const char *is, int delim) /* collect string up to next delim */
{
const char *os = is;