summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/awk
diff options
context:
space:
mode:
authorjtc <jtc@NetBSD.org>1993-07-02 23:58:28 +0000
committerjtc <jtc@NetBSD.org>1993-07-02 23:58:28 +0000
commit28968b044aed074b683139b0fa4f6ce5685344bb (patch)
tree295ab3eaa25f740c0819d9b53b2920d8c384cea1 /gnu/usr.bin/awk
parent669fd11072a4a6a9e66212e70dc7ed34ba1d8b8a (diff)
Updated to mawk 1.1.4
Diffstat (limited to 'gnu/usr.bin/awk')
-rw-r--r--gnu/usr.bin/awk/rexp/rexp.c8
-rw-r--r--gnu/usr.bin/awk/rexp/rexp.h8
-rw-r--r--gnu/usr.bin/awk/rexp/rexp0.c113
-rw-r--r--gnu/usr.bin/awk/rexp/rexp1.c8
-rw-r--r--gnu/usr.bin/awk/rexp/rexp2.c68
-rw-r--r--gnu/usr.bin/awk/rexp/rexp3.c25
-rw-r--r--gnu/usr.bin/awk/rexp/rexpdb.c8
7 files changed, 146 insertions, 92 deletions
diff --git a/gnu/usr.bin/awk/rexp/rexp.c b/gnu/usr.bin/awk/rexp/rexp.c
index a4ad537ce62..99fd1249db9 100644
--- a/gnu/usr.bin/awk/rexp/rexp.c
+++ b/gnu/usr.bin/awk/rexp/rexp.c
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: rexp.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:28 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 3.4 91/08/13 09:09:59 brennan
+ * Revision 3.4 1991/08/13 09:09:59 brennan
* VERSION .9994
- *
+ *
* Revision 3.3 91/08/04 15:45:03 brennan
* no longer attempt to recover mem on failed REcompile
* Its not worth the effort
diff --git a/gnu/usr.bin/awk/rexp/rexp.h b/gnu/usr.bin/awk/rexp/rexp.h
index 92d3ff3e5b1..aa42639631b 100644
--- a/gnu/usr.bin/awk/rexp/rexp.h
+++ b/gnu/usr.bin/awk/rexp/rexp.h
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: rexp.h,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:32 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 3.6 92/01/21 17:31:45 brennan
+ * Revision 3.6 1992/01/21 17:31:45 brennan
* moved ison() macro out of rexp[23].c
- *
+ *
* Revision 3.5 91/10/29 10:53:55 brennan
* SIZE_T
*
diff --git a/gnu/usr.bin/awk/rexp/rexp0.c b/gnu/usr.bin/awk/rexp/rexp0.c
index 63493c1c110..ffe0fe132e6 100644
--- a/gnu/usr.bin/awk/rexp/rexp0.c
+++ b/gnu/usr.bin/awk/rexp/rexp0.c
@@ -11,9 +11,17 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: rexp0.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:35 jtc
+/*Updated to mawk 1.1.4
/*
+ * Revision 3.8 1992/04/21 20:22:38 brennan
+ * 1.1 patch2
+ * [c1-c2] now works if c2 is an escaped character
+ *
+ * Revision 3.7 1992/03/24 09:33:12 brennan
+ * 1.1 patch2
+ * When backing up in do_str, check if last character was escaped
+ *
* Revision 3.6 92/01/21 17:32:51 brennan
* added some casts so that character classes work with signed chars
*
@@ -188,16 +196,22 @@ int RE_lex( mp )
return prev ;
}
+/*
+ collect a run of characters into a string
+ machine
+*/
+
static int do_str( c, pp, mp)
int c ; /* the first character */
char **pp ; /* where to put the re_char pointer on exit */
MACHINE *mp ; /* where to put the string machine */
{ register char *p , *s ;
- char *str ;
- unsigned len ;
+ char *p_entry ;
+ char *str ; /* collect it here */
+ unsigned len ; /* length collected */
- p = *pp ;
+ p = p_entry = *pp ;
s = str = RE_malloc( re_len ) ;
*s++ = c ; len = 1 ;
@@ -221,7 +235,20 @@ static int do_str( c, pp, mp)
out:
/* if len > 1 and we failed on a ? + or * , need to back up */
if ( len > 1 && (*p == '*' || *p == '+' || *p == '?' ) )
- { len-- ; p-- ; s-- ; }
+ { len-- ; p-- ; s-- ;
+
+ /* if the last character was escaped, back up one more */
+ {
+ int cnt = 0 ;
+ char *bp = p-1 ;
+
+ while ( bp >= p_entry && *bp == '\\' )
+ {
+ cnt++ ; bp-- ;
+ }
+ if ( cnt & 1 ) p-- ;
+ }
+ }
*s = 0 ;
*pp = p ;
@@ -234,14 +261,16 @@ out:
BUILD A CHARACTER CLASS
*---------------------------*/
-#define on( b, x) ( (b)[((unsigned char)(x))>>3] |= ( 1 << ((x)&7) ))
+#define on( b, x) ((b)[(x)>>3] |= ( 1 << ((x)&7) ))
static void PROTO(block_on, (BV,int,int) ) ;
static void block_on( b, x, y)
- BV b ; int x, y ;
-{ int lo = (x&0xff) >> 3 ;
- int hi = (y&0xff) >> 3 ;
+ BV b ;
+ int x, y ;
+ /* caller makes sure x<=y and x>0 y>0 */
+{ int lo = x >> 3 ;
+ int hi = y >> 3 ;
int i, j, bit ;
if ( lo == hi )
@@ -269,7 +298,7 @@ static int do_class( start, mp)
int cnt ;
int comp_flag ;
- p = (*start) + 1 ;
+ p = t = (*start) + 1 ;
if ( *p == ']' || *p == '^' && *(p+1) == ']' )
RE_error_trap(-E3) ;
while ( 1 ) /* find the back of the class */
@@ -282,41 +311,69 @@ static int do_class( start, mp)
p = q+1 ;
}
/* q now pts at the back of the class */
- p = (*start) + 1 ;
+ p = t ;
*start = q + 1 ;
bvp = (BV *) RE_malloc( sizeof(BV) ) ;
(void) memset( bvp, 0, SIZE_T(sizeof(BV)) ) ;
- comp_flag = *p == '^' ? (p++ , 1) : 0 ;
+ if ( *p == '^' ) { comp_flag = 1 ; p++ ; }
+ else comp_flag = 0 ;
+
prev = -1 ; /* indicates - cannot be part of a range */
while ( p < q )
{
switch( *p )
- { case '\\' :
- t = ++p ;
+ {
+ case '\\' :
+
+ t = p+1 ;
prev = escape(&t) ;
on(*bvp, prev) ;
p = t ;
- continue ;
+ break ;
case '-' :
- if ( prev == -1 || p+1 == q || prev > *(unsigned char*)(p+1) )
- { prev = '-' ; on(*bvp, '-') ; }
- else
- { p++ ;
- block_on(*bvp, prev, *p) ;
- prev = -1 ;
- }
- break ;
+ if ( prev == -1 || p+1 == q )
+ {
+ prev = '-' ;
+ on(*bvp,'-') ;
+ p++ ;
+ }
+ else
+ {
+ int c ;
+ char *mark = ++p ;
+
+ if ( *p != '\\' ) c = *(unsigned char *) p++ ;
+ else
+ {
+ t = p+1 ;
+ c = escape(&t) ;
+ p = t ;
+ }
+
+ if ( prev <= c )
+ {
+ block_on(*bvp, prev, c) ;
+ prev = -1 ;
+ }
+ else /* back up */
+ {
+ p = mark ;
+ prev = '-' ;
+ on(*bvp,'-') ;
+ }
+ }
+ break ;
+
default :
- prev = *(unsigned char*)p ;
- on(*bvp, *p) ;
+ prev = *(unsigned char*)p++ ;
+ on(*bvp, prev) ;
break ;
}
- p++ ;
}
if ( comp_flag )
@@ -457,5 +514,5 @@ static int escape(start_p)
}
/* anything else \c -> c */
*start_p = p ;
- return p[-1] ;
+ return *(unsigned char*)(p-1) ;
}
diff --git a/gnu/usr.bin/awk/rexp/rexp1.c b/gnu/usr.bin/awk/rexp/rexp1.c
index 1f3e3a78621..58c770d1b4a 100644
--- a/gnu/usr.bin/awk/rexp/rexp1.c
+++ b/gnu/usr.bin/awk/rexp/rexp1.c
@@ -11,12 +11,12 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: rexp1.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:36 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 3.4 92/02/20 16:08:12 brennan
+ * Revision 3.4 1992/02/20 16:08:12 brennan
* change new_TWO() to work around sun acc bug
- *
+ *
* Revision 3.3 91/10/29 10:54:01 brennan
* SIZE_T
*
diff --git a/gnu/usr.bin/awk/rexp/rexp2.c b/gnu/usr.bin/awk/rexp/rexp2.c
index 38272514cff..f15cf557351 100644
--- a/gnu/usr.bin/awk/rexp/rexp2.c
+++ b/gnu/usr.bin/awk/rexp/rexp2.c
@@ -11,9 +11,14 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: rexp2.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:38 jtc
+/*Updated to mawk 1.1.4
/*
+ * Revision 3.8 1992/12/24 00:36:44 mike
+ * fixed major bozo for LMDOS when growing stack
+ * fixed potential LMDOS bozo with M_STR+U_ON+END_ON
+ * fixed minor bug in M_CLASS+U_ON+END_ON
+ *
* Revision 3.7 92/01/21 17:33:15 brennan
* added some casts so that character classes work with signed chars
*
@@ -54,9 +59,9 @@ the GNU General Public License, version 2, 1991.
#define STACKGROWTH 16
-/* statics */
+#ifdef DEBUG
static RT_STATE *PROTO(slow_push,(RT_STATE *,STATE*,char*,int));
-
+#endif
RT_STATE *RE_run_stack_base;
@@ -66,16 +71,14 @@ RT_STATE *RE_run_stack_limit ;
This hack fixes it without rewriting the whole thing, 5/31/91 */
RT_STATE *RE_run_stack_empty ;
-/* for statistics and debug */
-static RT_STATE *stack_max ;
-
void RE_run_stack_init()
-{ if ( !RE_run_stack_base )
+{
+ if ( !RE_run_stack_base )
{
RE_run_stack_base = (RT_STATE *)
RE_malloc(sizeof(RT_STATE) * STACKGROWTH ) ;
RE_run_stack_limit = RE_run_stack_base + STACKGROWTH ;
- RE_run_stack_empty = stack_max = RE_run_stack_base-1 ;
+ RE_run_stack_empty = RE_run_stack_base-1 ;
}
}
@@ -86,7 +89,9 @@ void RE_run_stack_init()
*/
RT_STATE *RE_new_run_stack()
-{ int newsize = (RE_run_stack_limit - RE_run_stack_base) + STACKGROWTH ;
+{
+ int oldsize = RE_run_stack_limit - RE_run_stack_base ;
+ int newsize = oldsize + STACKGROWTH ;
#ifdef LMDOS /* large model DOS */
/* have to worry about overflow on multiplication (ugh) */
@@ -94,18 +99,8 @@ RT_STATE *RE_new_run_stack()
else
#endif
-#ifdef __TURBOC__
-/* turbo C's realloc() screws up when running out of mem */
- { RT_STATE *temp = (RT_STATE*)malloc(SIZE_T(newsize*sizeof(RT_STATE))) ;
- if ( temp ) (void)memcpy(temp,RE_run_stack_base,
- SIZE_T((newsize-STACKGROWTH)*sizeof(RT_STATE))) ;
- free(RE_run_stack_base) ;
- RE_run_stack_base = temp ;
- }
-#else /* normal case */
RE_run_stack_base = (RT_STATE *) realloc( RE_run_stack_base ,
SIZE_T(newsize * sizeof(RT_STATE)) ) ;
-#endif
if ( ! RE_run_stack_base )
{ fprintf(stderr, "out of memory for RE run time stack\n") ;
@@ -117,36 +112,30 @@ RT_STATE *RE_new_run_stack()
RE_run_stack_limit = RE_run_stack_base + newsize ;
RE_run_stack_empty = RE_run_stack_base - 1 ;
- return stack_max = RE_run_stack_base + newsize - STACKGROWTH ;
+
+ /* return the new stackp */
+ return RE_run_stack_base + oldsize ;
}
+#ifdef DEBUG
static RT_STATE *slow_push(sp, m, s, u)
RT_STATE *sp ;
STATE *m ;
char *s ;
int u ;
{
- if ( sp > stack_max )
- if ( (stack_max = sp) == RE_run_stack_limit )
- sp = RE_new_run_stack() ;
-
+ if ( sp == RE_run_stack_limit ) sp = RE_new_run_stack() ;
sp->m = m ; sp->s = s ; sp->u = u ;
return sp ;
}
-
-#ifdef DEBUG
-void print_max_stack(f)
- FILE *f ;
-{ fprintf(f, "stack_max = %d\n", stack_max-RE_run_stack_base+1) ; }
#endif
#ifdef DEBUG
#define push(mx,sx,ux) stackp = slow_push(++stackp, mx, sx, ux)
#else
#define push(mx,sx,ux) if (++stackp == RE_run_stack_limit)\
- stackp = slow_push(stackp,mx,sx,ux) ;\
- else\
- { stackp->m=mx;stackp->s=sx;stackp->u=ux;}
+ stackp = RE_new_run_stack() ;\
+ stackp->m=(mx);stackp->s=(sx);stackp->u=(ux)
#endif
@@ -163,12 +152,12 @@ int REtest( str, machine)
register RT_STATE *stackp ;
int u_flag ;
char *str_end ;
- char *ts ; /*convenient temps */
+ int t ; /*convenient temps */
STATE *tm ;
/* handle the easy case quickly */
if ( (m+1)->type == M_ACCEPT && m->type == M_STR )
- return (int ) str_str(s, m->data.str, m->len) ;
+ return str_str(s, m->data.str, m->len) != (char *) 0 ;
else
{ u_flag = U_ON ; str_end = (char *) 0 ;
stackp = RE_run_stack_empty ;
@@ -204,8 +193,9 @@ reswitch :
case M_STR + U_ON + END_ON :
if ( !str_end ) str_end = s + strlen(s) ;
- ts = str_end - m->len ;
- if (ts < s || memcmp(ts,m->data.str,SIZE_T(m->len+1))) goto refill ;
+ t = (str_end - s) - m->len ;
+ if (t < 0 || memcmp(s+t,m->data.str,SIZE_T(m->len)))
+ goto refill ;
s = str_end ; m++ ; u_flag = U_OFF ;
goto reswitch ;
@@ -218,7 +208,6 @@ reswitch :
if ( s[1] || !ison(*m->data.bvp,s[0]) ) goto refill ;
s++ ; m++ ;
goto reswitch ;
-
case M_CLASS + U_ON + END_OFF :
while ( !ison(*m->data.bvp,s[0]) )
if ( s[0] == 0 ) goto refill ;
@@ -230,7 +219,8 @@ reswitch :
case M_CLASS + U_ON + END_ON :
if ( ! str_end ) str_end = s + strlen(s) ;
- if ( ! ison(*m->data.bvp, str_end[-1]) ) goto refill ;
+ if ( s[0] == 0 || ! ison(*m->data.bvp, str_end[-1]) )
+ goto refill ;
s = str_end ; m++ ; u_flag = U_OFF ;
goto reswitch ;
diff --git a/gnu/usr.bin/awk/rexp/rexp3.c b/gnu/usr.bin/awk/rexp/rexp3.c
index 2703a0d266d..d3857c0fc48 100644
--- a/gnu/usr.bin/awk/rexp/rexp3.c
+++ b/gnu/usr.bin/awk/rexp/rexp3.c
@@ -11,12 +11,16 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*$Log: rexp3.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:39 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 3.5 92/01/21 17:33:20 brennan
+ * Revision 3.6 1992/12/24 00:44:53 mike
+ * fixed potential LMDOS bozo with M_STR+U_ON+END_ON
+ * fixed minor bug in M_CLASS+U_ON+END_ON
+ *
+ * Revision 3.5 1992/01/21 17:33:20 brennan
* added some casts so that character classes work with signed chars
- *
+ *
* Revision 3.4 91/10/29 10:54:09 brennan
* SIZE_T
*
@@ -49,7 +53,8 @@ RT_STATE *RE_new_run_stack() ;
#define push(mx,sx,ssx,ux) if (++stackp == RE_run_stack_limit)\
stackp = RE_new_run_stack() ;\
- stackp->m=mx;stackp->s=sx;stackp->ss=ssx;stackp->u=ux;
+ stackp->m=(mx);stackp->s=(sx);stackp->ss=(ssx);\
+ stackp->u=(ux)
#define CASE_UANY(x) case x + U_OFF : case x + U_ON
@@ -65,7 +70,7 @@ char *REmatch(str, machine, lenp)
register char *s = str ;
char *ss ;
register RT_STATE *stackp ;
- int u_flag ;
+ int u_flag, t ;
char *str_end, *ts ;
/* state of current best match stored here */
@@ -132,8 +137,9 @@ reswitch :
case M_STR + U_ON + END_ON :
if ( !str_end ) str_end = s + strlen(s) ;
- ts = str_end - m->len ;
- if (ts < s || memcmp(ts,m->data.str,SIZE_T(m->len+1))) goto refill ;
+ t = (str_end - s) - m->len ;
+ if (t < 0 || memcmp(ts=s+t,m->data.str,SIZE_T(m->len)))
+ goto refill ;
if ( !ss )
if ( cb_ss && ts > cb_ss ) goto refill ;
else ss = ts ;
@@ -171,7 +177,8 @@ reswitch :
case M_CLASS + U_ON + END_ON :
if ( ! str_end ) str_end = s + strlen(s) ;
- if ( ! ison(*m->data.bvp, str_end[-1]) ) goto refill ;
+ if ( s[0] == 0 || ! ison(*m->data.bvp, str_end[-1]) )
+ goto refill ;
if ( !ss )
if ( cb_ss && str_end-1 > cb_ss ) goto refill ;
else ss = str_end-1 ;
diff --git a/gnu/usr.bin/awk/rexp/rexpdb.c b/gnu/usr.bin/awk/rexp/rexpdb.c
index 490fd679dc1..f61d78d6311 100644
--- a/gnu/usr.bin/awk/rexp/rexpdb.c
+++ b/gnu/usr.bin/awk/rexp/rexpdb.c
@@ -12,12 +12,12 @@ the GNU General Public License, version 2, 1991.
/*$Log: rexpdb.c,v $
-/*Revision 1.1.1.1 1993/03/21 09:45:37 cgd
-/*initial import of 386bsd-0.1 sources
+/*Revision 1.2 1993/07/02 23:58:40 jtc
+/*Updated to mawk 1.1.4
/*
- * Revision 3.2 91/08/13 09:10:09 brennan
+ * Revision 3.2 1991/08/13 09:10:09 brennan
* VERSION .9994
- *
+ *
* Revision 3.1 91/06/07 10:33:30 brennan
* VERSION 0.995
*