Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/historical/nawk/dist Apply all our changes includin...
details: https://anonhg.NetBSD.org/src/rev/41bd73c70ea5
branches: trunk
changeset: 757356:41bd73c70ea5
user: christos <christos%NetBSD.org@localhost>
date: Thu Aug 26 14:55:19 2010 +0000
description:
Apply all our changes including newer fixes to WARNS?=4
diffstat:
external/historical/nawk/dist/awk.h | 18 +-
external/historical/nawk/dist/awkgram.y | 22 +-
external/historical/nawk/dist/b.c | 293 ++++++++--------
external/historical/nawk/dist/lex.c | 44 +-
external/historical/nawk/dist/lib.c | 168 ++++++---
external/historical/nawk/dist/main.c | 73 +++-
external/historical/nawk/dist/makefile | 4 +-
external/historical/nawk/dist/maketab.c | 30 +-
external/historical/nawk/dist/parse.c | 31 +-
external/historical/nawk/dist/proctab.c | 206 ++++++-----
external/historical/nawk/dist/proto.h | 26 +-
external/historical/nawk/dist/run.c | 547 +++++++++++++++++++++++--------
external/historical/nawk/dist/tran.c | 44 +-
13 files changed, 1002 insertions(+), 504 deletions(-)
diffs (truncated from 3018 to 300 lines):
diff -r 1854ad037c80 -r 41bd73c70ea5 external/historical/nawk/dist/awk.h
--- a/external/historical/nawk/dist/awk.h Thu Aug 26 14:53:14 2010 +0000
+++ b/external/historical/nawk/dist/awk.h Thu Aug 26 14:55:19 2010 +0000
@@ -48,6 +48,7 @@
#define RECSIZE (8 * 1024) /* sets limit on records, fields, etc., etc. */
extern int recsize; /* size of current record, orig RECSIZE */
+extern char EMPTY[];
extern char **FS;
extern char **RS;
extern char **ORS;
@@ -61,16 +62,15 @@
extern Awkfloat *RSTART;
extern Awkfloat *RLENGTH;
-extern char *record; /* points to $0 */
+extern uschar *record; /* points to $0 */
extern int lineno; /* line number in awk program */
extern int errorflag; /* 1 if error has occurred */
extern int donefld; /* 1 if record broken into fields */
extern int donerec; /* 1 if record is valid (no fld has changed */
-extern char inputFS[]; /* FS at time of input, for field splitting */
extern int dbg;
-extern char *patbeg; /* beginning of pattern matched */
+extern uschar *patbeg; /* beginning of pattern matched */
extern int patlen; /* length of pattern matched. set in b.c */
/* Cell: all information about a variable or constant */
@@ -126,6 +126,8 @@
#define FTOUPPER 12
#define FTOLOWER 13
#define FFLUSH 14
+#define FSYSTIME 15
+#define FSTRFTIME 16
/* Node: parse tree is made of nodes, with Cell's at bottom */
@@ -203,8 +205,6 @@
#define NCHARS (256+3) /* 256 handles 8-bit chars; 128 does 7-bit */
/* watch out in match(), etc. */
-#define NSTATES 32
-
typedef struct rrow {
long ltype; /* long avoids pointer warnings on 64-bit */
union {
@@ -216,16 +216,16 @@
} rrow;
typedef struct fa {
- uschar gototab[NSTATES][NCHARS];
- uschar out[NSTATES];
+ unsigned int **gototab;
+ uschar *out;
uschar *restr;
- int *posns[NSTATES];
+ int **posns;
+ int state_count;
int anchor;
int use;
int initstat;
int curstat;
int accept;
- int reset;
struct rrow re[1]; /* variable: actual size set by calling malloc */
} fa;
diff -r 1854ad037c80 -r 41bd73c70ea5 external/historical/nawk/dist/awkgram.y
--- a/external/historical/nawk/dist/awkgram.y Thu Aug 26 14:53:14 2010 +0000
+++ b/external/historical/nawk/dist/awkgram.y Thu Aug 26 14:55:19 2010 +0000
@@ -23,6 +23,10 @@
****************************************************************/
%{
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <stdio.h>
#include <string.h>
#include "awk.h"
@@ -80,7 +84,7 @@
%left GETLINE
%nonassoc APPEND EQ GE GT LE LT NE MATCHOP IN '|'
%left ARG BLTIN BREAK CALL CLOSE CONTINUE DELETE DO EXIT FOR FUNC
-%left GSUB IF INDEX LSUBSTR MATCHFCN NEXT NUMBER
+%left GENSUB GSUB IF INDEX LSUBSTR MATCHFCN NEXT NUMBER
%left PRINT PRINTF RETURN SPLIT SPRINTF STRING SUB SUBSTR
%left REGEXPR VAR VARNF IVAR WHILE '('
%left CAT
@@ -369,6 +373,22 @@
| INCR var { $$ = op1(PREINCR, $2); }
| var DECR { $$ = op1(POSTDECR, $1); }
| var INCR { $$ = op1(POSTINCR, $1); }
+ | GENSUB '(' reg_expr comma pattern comma pattern ')'
+ { $$ = op5(GENSUB, NIL, (Node*)makedfa($3, 1), $5, $7, rectonode()); }
+ | GENSUB '(' pattern comma pattern comma pattern ')'
+ { if (constnode($3))
+ $$ = op5(GENSUB, NIL, (Node *)makedfa(strnode($3), 1), $5, $7, rectonode());
+ else
+ $$ = op5(GENSUB, (Node *)1, $3, $5, $7, rectonode());
+ }
+ | GENSUB '(' reg_expr comma pattern comma pattern comma pattern ')'
+ { $$ = op5(GENSUB, NIL, (Node*)makedfa($3, 1), $5, $7, $9); }
+ | GENSUB '(' pattern comma pattern comma pattern comma pattern ')'
+ { if (constnode($3))
+ $$ = op5(GENSUB, NIL, (Node *)makedfa(strnode($3),1), $5,$7,$9);
+ else
+ $$ = op5(GENSUB, (Node *)1, $3, $5, $7, $9);
+ }
| GETLINE var LT term { $$ = op3(GETLINE, $2, itonp($3), $4); }
| GETLINE LT term { $$ = op3(GETLINE, NIL, itonp($2), $3); }
| GETLINE var { $$ = op3(GETLINE, $2, NIL, NIL); }
diff -r 1854ad037c80 -r 41bd73c70ea5 external/historical/nawk/dist/b.c
--- a/external/historical/nawk/dist/b.c Thu Aug 26 14:53:14 2010 +0000
+++ b/external/historical/nawk/dist/b.c Thu Aug 26 14:55:19 2010 +0000
@@ -24,14 +24,19 @@
/* lasciate ogne speranza, voi ch'intrate. */
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#define DEBUG
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <assert.h>
#include "awk.h"
-#include "ytab.h"
+#include "awkgram.h"
#define HAT (NCHARS+2) /* matches ^ in regular expr */
/* NCHARS is 2**n */
@@ -62,33 +67,80 @@
int rtok; /* next token in current re */
int rlxval;
-static uschar *rlxstr;
-static uschar *prestr; /* current position in current re */
-static uschar *lastre; /* origin of last re */
+static const uschar *rlxstr;
+static const uschar *prestr; /* current position in current re */
+static const uschar *lastre; /* origin of last re */
static int setcnt;
static int poscnt;
-char *patbeg;
+uschar *patbeg;
int patlen;
-#define NFA 20 /* cache this many dynamic fa's */
+#define NFA 128 /* cache this many dynamic fa's */
fa *fatab[NFA];
int nfatab = 0; /* entries in fatab */
+static void
+resizesetvec(const char *msg)
+{
+ if (maxsetvec == 0)
+ maxsetvec = MAXLIN;
+ else
+ maxsetvec *= 4;
+ setvec = realloc(setvec, maxsetvec * sizeof(*setvec));
+ tmpset = realloc(tmpset, maxsetvec * sizeof(*tmpset));
+ if (setvec == 0 || tmpset == 0)
+ overflo(msg);
+}
+
+static void
+resize_state(fa *f, int state)
+{
+ void *p;
+ int i, new_count;
+
+ if (++state < f->state_count)
+ return;
+
+ new_count = state + 10; /* needs to be tuned */
+
+ p = realloc(f->gototab, new_count * sizeof(f->gototab[0]));
+ if (p == NULL)
+ goto out;
+ f->gototab = p;
+
+ p = realloc(f->out, new_count * sizeof(f->out[0]));
+ if (p == NULL)
+ goto out;
+ f->out = p;
+
+ p = realloc(f->posns, new_count * sizeof(f->posns[0]));
+ if (p == NULL)
+ goto out;
+ f->posns = p;
+
+ for (i = f->state_count; i < new_count; ++i) {
+ f->gototab[i] = calloc(1, NCHARS * sizeof (**f->gototab));
+ if (f->gototab[i] == NULL)
+ goto out;
+ f->out[i] = 0;
+ f->posns[i] = NULL;
+ }
+ f->state_count = new_count;
+ return;
+out:
+ overflo("out of memory in resize_state");
+}
+
fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */
{
int i, use, nuse;
fa *pfa;
static int now = 1;
- if (setvec == 0) { /* first time through any RE */
- maxsetvec = MAXLIN;
- setvec = (int *) malloc(maxsetvec * sizeof(int));
- tmpset = (int *) malloc(maxsetvec * sizeof(int));
- if (setvec == 0 || tmpset == 0)
- overflo("out of space initializing makedfa");
- }
+ if (setvec == 0) /* first time through any RE */
+ resizesetvec("out of space initializing makedfa");
if (compile_time) /* a constant for sure */
return mkdfa(s, anchor);
@@ -132,14 +184,15 @@
poscnt = 0;
penter(p1); /* enter parent pointers and leaf indices */
- if ((f = (fa *) calloc(1, sizeof(fa) + poscnt*sizeof(rrow))) == NULL)
+ if ((f = calloc(1, sizeof(*f) + poscnt*sizeof(rrow))) == NULL)
overflo("out of space for fa");
f->accept = poscnt-1; /* penter has computed number of positions in re */
cfoll(f, p1); /* set up follow sets */
freetr(p1);
- if ((f->posns[0] = (int *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL)
+ resize_state(f, 1);
+ if ((f->posns[0] = calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL)
overflo("out of space in makedfa");
- if ((f->posns[1] = (int *) calloc(1, sizeof(int))) == NULL)
+ if ((f->posns[1] = calloc(1, sizeof(int))) == NULL)
overflo("out of space in makedfa");
*f->posns[1] = 0;
f->initstat = makeinit(f, anchor);
@@ -152,12 +205,12 @@
{
int i, k;
+ resize_state(f, 2);
f->curstat = 2;
f->out[2] = 0;
- f->reset = 0;
k = *(f->re[0].lfollow);
xfree(f->posns[2]);
- if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL)
+ if ((f->posns[2] = calloc(1, (k+1)*sizeof(int))) == NULL)
overflo("out of space in makeinit");
for (i=0; i <= k; i++) {
(f->posns[2])[i] = (f->re[0].lfollow)[i];
@@ -174,8 +227,10 @@
}
f->out[0] = f->out[2];
- if (f->curstat != 2)
+ if (f->curstat != 2) {
+ resize_state(f, f->curstat);
--(*f->posns[f->curstat]);
+ }
}
return f->curstat;
}
@@ -231,13 +286,13 @@
/* in the parsing of regular expressions, metacharacters like . have */
/* to be seen literally; \056 is not a metacharacter. */
-int hexstr(char **pp) /* find and eval hex string at pp, return new p */
+int hexstr(const uschar **pp) /* find and eval hex string at pp, return new p */
{ /* only pick up one 8-bit byte (2 chars) */
- uschar *p;
+ const uschar *p;
int n = 0;
int i;
- for (i = 0, p = (uschar *) *pp; i < 2 && isxdigit(*p); i++, p++) {
+ for (i = 0, p = *pp; i < 2 && isxdigit(*p); i++, p++) {
if (isdigit(*p))
n = 16 * n + *p - '0';
else if (*p >= 'a' && *p <= 'f')
@@ -245,16 +300,16 @@
else if (*p >= 'A' && *p <= 'F')
n = 16 * n + *p - 'A' + 10;
}
- *pp = (char *) p;
Home |
Main Index |
Thread Index |
Old Index