home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume18
/
gnugrep1.3.pch
/
cvt1.2to1.3
Wrap
Text File
|
1989-03-12
|
47KB
|
1,565 lines
diff -rcN grep-1.2/Makefile grep-1.3/Makefile
*** grep-1.2/Makefile Thu Oct 13 22:11:28 1988
--- grep-1.3/Makefile Tue Feb 28 23:37:13 1989
***************
*** 5,27 ****
# Add -DUSG for System V.
CFLAGS = -O
# You may add getopt.o if your C library lacks getopt(); note that
# 4.3BSD getopt() is said to be somewhat broken.
# Add alloca.o if your machine does not support alloca().
! OBJS = grep.o dfa.o regex.o
all: regress
! regress: grep
cd tests; sh regress.sh
! grep: $(OBJS)
! $(CC) $(CFLAGS) -o grep $(OBJS)
! rm -f egrep
! ln grep egrep
clean:
! rm -f grep egrep *.o core tests/core tests/tmp.script
! dfa.o grep.o: dfa.h
! grep.o regex.o: regex.h
--- 5,40 ----
# Add -DUSG for System V.
CFLAGS = -O
+ #
# You may add getopt.o if your C library lacks getopt(); note that
# 4.3BSD getopt() is said to be somewhat broken.
+ #
# Add alloca.o if your machine does not support alloca().
! #
! OBJS = dfa.o regex.o
! GOBJ = grep.o
! EOBJ = egrep.o
+ # Space provided for machine dependent libraries.
+ LIBS =
+
all: regress
! regress: egrep grep
cd tests; sh regress.sh
! egrep: $(OBJS) $(EOBJ)
! $(CC) $(CFLAGS) -o egrep $(OBJS) $(EOBJ) $(LIBS)
!
! egrep.o: grep.c
! $(CC) $(CFLAGS) -DEGREP -c grep.c
! mv grep.o egrep.o
!
! grep: $(OBJS) $(GOBJ)
! $(CC) $(CFLAGS) -o grep $(OBJS) $(GOBJ) $(LIBS)
clean:
! rm -f grep egrep *.o core tests/core tests/tmp.script tests/khadafy.out
! dfa.o egrep.o grep.o: dfa.h
! egrep.o grep.o regex.o: regex.h
diff -rcN grep-1.2/README grep-1.3/README
*** grep-1.2/README Tue Dec 13 11:04:21 1988
--- grep-1.3/README Wed Mar 1 21:43:59 1989
***************
*** 1,4 ****
! This README documents GNU e?grep version 1.2.
Changes needed to the makefile under various perversions of Unix are
described therein.
--- 1,4 ----
! This README documents GNU e?grep version 1.3.
Changes needed to the makefile under various perversions of Unix are
described therein.
diff -rcN grep-1.2/README.sunos4 grep-1.3/README.sunos4
*** grep-1.2/README.sunos4 Wed Dec 31 18:00:00 1969
--- grep-1.3/README.sunos4 Tue Feb 28 22:35:10 1989
***************
*** 0 ****
--- 1,96 ----
+ Date: Fri, 24 Feb 89 15:36:40 -0600
+ To: mike@wheaties.ai.mit.edu
+ From: Dave Cohrs <dave@cs.wisc.edu>
+ Subject: bug + fix in gnu grep 1.2 (from prep.ai.mit.edu)
+
+ I tried installing the GNU grep 1.2 on a Sun4 running 4.0.1 and
+ "Spencer test #36" failed. After some experimenting, I found and
+ fixed the bug. Well, actually, the bug in the the C compiler, but
+ I managed a workaround.
+
+ Description:
+
+ The Sun4 4.0.1 C compiler with -O doesn't generate the correct for
+ statements of the form
+ if("string")
+ x;
+ else
+ y;
+ To be exact, "y;" gets executed, while "x;" should. This causes the
+ #define FETCH() to fail for test #36.
+
+ Fix:
+
+ In an #ifdef sparc in dfa.c, I made two versions of FETCH, FETCH0() and
+ the regular FETCH(). The former takes only one argument, the latter
+ expects its 2nd argument to contain a non-nil string. This removes
+ the need to test the constant strings, and the compiler bug isn't
+ exercised. I then changed the one instance of FETCH() with a nil
+ second argument to be FETCH0() instead.
+
+ dave cohrs
+
+ ===================================================================
+ RCS file: RCS/dfa.c,v
+ retrieving revision 1.1
+ diff -c -r1.1 dfa.c
+ *** /tmp/,RCSt1a05930 Fri Feb 24 15:32:33 1989
+ --- dfa.c Fri Feb 24 15:23:34 1989
+ ***************
+ *** 285,293 ****
+ --- 285,315 ----
+ is turned off). */
+
+ /* Note that characters become unsigned here. */
+ + #ifdef sparc
+ + /*
+ + * Sun4 4.0.1 C compiler can't compare constant strings correctly.
+ + * e.g. if("test") { x; } else { y; }
+ + * the compiler will not generate code to execute { x; }, but
+ + * executes { y; } instead.
+ + */
+ + #define FETCH0(c) \
+ + { \
+ + if (! lexleft) \
+ + return _END; \
+ + (c) = (unsigned char) *lexptr++; \
+ + --lexleft; \
+ + }
+ #define FETCH(c, eoferr) \
+ { \
+ if (! lexleft) \
+ + regerror(eoferr); \
+ + (c) = (unsigned char) *lexptr++; \
+ + --lexleft; \
+ + }
+ + #else
+ + #define FETCH(c, eoferr) \
+ + { \
+ + if (! lexleft) \
+ if (eoferr) \
+ regerror(eoferr); \
+ else \
+ ***************
+ *** 295,300 ****
+ --- 317,323 ----
+ (c) = (unsigned char) *lexptr++; \
+ --lexleft; \
+ }
+ + #endif sparc
+
+ static _token
+ lex()
+ ***************
+ *** 303,309 ****
+ --- 326,336 ----
+ int invert;
+ _charset cset;
+
+ + #ifdef sparc
+ + FETCH0(c);
+ + #else
+ FETCH(c, (char *) 0);
+ + #endif sparc
+ switch (c)
+ {
+ case '^':
diff -rcN grep-1.2/dfa.c grep-1.3/dfa.c
*** grep-1.2/dfa.c Thu Oct 13 22:11:29 1988
--- grep-1.3/dfa.c Tue Feb 28 18:46:35 1989
***************
*** 105,110 ****
--- 105,112 ----
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
+ #include <stdio.h>
+ #include <assert.h>
#include <ctype.h>
#include "dfa.h"
***************
*** 135,140 ****
--- 137,143 ----
{
ptr_t r = malloc(n);
+ assert(n != 0);
if (r)
return r;
else
***************
*** 148,153 ****
--- 151,157 ----
{
ptr_t r = realloc(p, n);
+ assert(n != 0);
if (r)
return r;
else
***************
*** 1122,1128 ****
{
copy(&r->follows[i], &merged);
epsclosure(&merged, r);
! REALLOC(r->follows[i].elems, _position, merged.nelem);
copy(&merged, &r->follows[i]);
}
--- 1126,1133 ----
{
copy(&r->follows[i], &merged);
epsclosure(&merged, r);
! if (r->follows[i].nelem < merged.nelem)
! REALLOC(r->follows[i].elems, _position, merged.nelem);
copy(&merged, &r->follows[i]);
}
***************
*** 1719,1742 ****
Having found the postfix representation of the regular expression,
try to find a long sequence of characters that must appear in any line
containing the r.e.
! Finding a "longest" sequence is beyond the scope of this bagatelle;
! we take the easy way out and hope for the best.
! We do a bottom-up calculation of several (possibly zero-length) sequences
! of characters that must appear in matches of r.e.'s represented by trees
! rooted at the nodes of the postfix representation:
sequences that must appear at the left of the match ("left")
sequences that must appear at the right of the match ("right")
! sequences that must appear somewhere in the match ("in")
sequences that must constitute the match ("is")
! When we get to the root of the tree, we use its calculated "in" sequence
! as our answer. The sequence we find is returned in r->must (where "r" is
! the single argument passed to "regmust"); the length of the sequence is
! returned in r->mustn.
The sequences calculated for the various types of node (in pseudo ANSI c)
are shown below. "p" is the operand of unary operators (and the left-hand
! operand of binary operators); "q" is the right-hand operand of binary operators.
"ZERO" means "a zero-length sequence" below.
Type left right is in
--- 1724,1749 ----
Having found the postfix representation of the regular expression,
try to find a long sequence of characters that must appear in any line
containing the r.e.
! Finding a "longest" sequence is beyond the scope here;
! we take an easy way out and hope for the best.
! (Take "(ab|a)b"--please.)
! We do a bottom-up calculation of sequences of characters that must appear
! in matches of r.e.'s represented by trees rooted at the nodes of the postfix
! representation:
sequences that must appear at the left of the match ("left")
sequences that must appear at the right of the match ("right")
! lists of sequences that must appear somewhere in the match ("in")
sequences that must constitute the match ("is")
! When we get to the root of the tree, we use one of the longest of its
! calculated "in" sequences as our answer. The sequence we find is returned in
! r->must (where "r" is the single argument passed to "regmust");
! the length of the sequence is returned in r->mustn.
The sequences calculated for the various types of node (in pseudo ANSI c)
are shown below. "p" is the operand of unary operators (and the left-hand
! operand of binary operators); "q" is the right-hand operand of binary operators
! .
"ZERO" means "a zero-length sequence" below.
Type left right is in
***************
*** 1749,1865 ****
QMARK ZERO ZERO ZERO ZERO
! PLUS p->left p->right ZERO ZERO
! CAT (p->is==ZERO)? (q->is==ZERO)? (p->is!=ZERO && longest of
! p->left : q->right : q->is!=ZERO) ? p->in, q->in, or
p->is##q->left p->right##q->is p->is##q->is : p->right##q->left
ZERO
! OR longest common longest common (do p->is and (do p->in and
! leading trailing q->is have same q->in have same
! (sub)sequence (sub)sequence length and length and
! of p->left of p->right content) ? content) ?
! and q->left and q->right p->is : NULL p->in : NULL
If there's anything else we recognize in the tree, all four sequences get set
to zero-length sequences. If there's something we don't recognize in the tree,
we just return a zero-length sequence.
! After the above calculations are performed, three additional steps are taken:
! 1. If there's a non-zero-length "is" sequence, it replaces the
! "left", "right", and "in" sequences.
! 2. If the "left" sequence is longer than the "in" sequence, it replaces
! the "in" sequence.
! 3. If the "right" sequence is longer than the "in" sequence, it replaces
! the "in" sequence.
!
! Possibilities:
! 1. Find the longest common (sub)sequence of p->in and q->in when doing
! an OR node's "in" sequence? Possibly effective, as in
! egrep 'pepsi|epsilon'
! but is it cheap and easy enough?
! 2. In replacing "in" sequences with "left" and "right" sequences, how
! should ties be broken?
! 3. Switch to allocated memory, rather than relying on a defined MUST_MAX?
*/
! #define TRUE 1
! #define FALSE 0
! typedef struct {
! int n;
! char p[MUST_MAX];
! } counted;
! #define initcounted(cp) ((cp)->n = 0)
!
! static void
! cntcpy(top, fromp)
! counted * top;
! counted * fromp;
! {
! register char * fp;
! register char * tp;
! register int n;
!
! fp = fromp->p;
! tp = top->p;
! n = fromp->n;
! top->n = n;
! while (n-- > 0)
! *tp++ = *fp++;
! }
!
! static void
! cntcat(top, fromp)
! counted * top;
! counted * fromp;
! {
! register char * fp;
! register char * tp;
! register int n;
!
! fp = fromp->p;
! tp = top->p + top->n;
! n = fromp->n;
! top->n += n;
! while (n-- > 0)
! *tp++ = *fp++;
! }
!
! static int
! cntsame(acp, bcp)
! counted * acp;
! counted * bcp;
{
register int i;
! if (acp->n != bcp->n)
! return FALSE;
! for (i = 0; i < acp->n; ++i)
! if (acp->p[i] != bcp->p[i])
! return FALSE;
! return TRUE;
}
typedef struct {
! counted left;
! counted right;
! counted in;
! counted is;
} must;
static void
! initmust(mp)
! must * mp;
{
! initcounted(&mp->left);
! initcounted(&mp->right);
! initcounted(&mp->in);
! initcounted(&mp->is);
}
static void
--- 1756,2022 ----
QMARK ZERO ZERO ZERO ZERO
! PLUS p->left p->right ZERO p->in
! CAT (p->is==ZERO)? (q->is==ZERO)? (p->is!=ZERO && p->in plus
! p->left : q->right : q->is!=ZERO) ? q->in plus
p->is##q->left p->right##q->is p->is##q->is : p->right##q->left
ZERO
! OR longest common longest common (do p->is and substrings common to
! leading trailing q->is have same p->in and q->in
! (sub)sequence (sub)sequence length and
! of p->left of p->right content) ?
! and q->left and q->right p->is : NULL
If there's anything else we recognize in the tree, all four sequences get set
to zero-length sequences. If there's something we don't recognize in the tree,
we just return a zero-length sequence.
! Break ties in favor of infrequent letters (choosing 'zzz' in preference to
! 'aaa')?
! And. . .is it here or someplace that we might ponder "optimizations" such as
! egrep 'psi|epsilon' -> egrep 'psi'
! egrep 'pepsi|epsilon' -> egrep 'epsi'
! (Yes, we now find "epsi" as a "string
! that must occur", but we might also
! simplify the *entire* r.e. being sought
! )
! grep '[c]' -> grep 'c'
! grep '(ab|a)b' -> grep 'ab'
! grep 'ab*' -> grep 'a'
! grep 'a*b' -> grep 'b'
! There are several issues:
! Is optimization easy (enough)?
!
! Does optimization actually accomplish anything,
! or is the automaton you get from "psi|epsilon" (for example)
! the same as the one you get from "psi" (for example)?
!
! Are optimizable r.e.'s likely to be used in real-life situations
! (something like 'ab*' is probably unlikely; something like is
! 'psi|epsilon' is likelier)?
*/
! static char *
! icatalloc(old, new)
! char * old;
! char * new;
! {
! register char * result;
! register int oldsize, newsize;
!
! newsize = (new == NULL) ? 0 : strlen(new);
! if (old == NULL)
! oldsize = 0;
! else if (newsize == 0)
! return old;
! else oldsize = strlen(old);
! if (old == NULL)
! result = (char *) malloc(newsize + 1);
! else result = (char *) realloc((void *) old, oldsize + newsize + 1);
! if (result != NULL && new != NULL)
! (void) strcpy(result + oldsize, new);
! return result;
! }
!
! static char *
! icpyalloc(string)
! const char * string;
! {
! return icatalloc((char *) NULL, string);
! }
!
! static char *
! istrstr(lookin, lookfor)
! char * lookin;
! register char * lookfor;
! {
! register char * cp;
! register int len;
! len = strlen(lookfor);
! for (cp = lookin; *cp != '\0'; ++cp)
! if (strncmp(cp, lookfor, len) == 0)
! return cp;
! return NULL;
! }
!
! static void
! ifree(cp)
! char * cp;
! {
! if (cp != NULL)
! free(cp);
! }
!
! static void
! freelist(cpp)
! register char ** cpp;
! {
! register int i;
!
! if (cpp == NULL)
! return;
! for (i = 0; cpp[i] != NULL; ++i) {
! free(cpp[i]);
! cpp[i] = NULL;
! }
! }
!
! static char **
! enlist(cpp, new, len)
! register char ** cpp;
! register char * new;
! {
! register int i, j;
!
! if (cpp == NULL)
! return NULL;
! if ((new = icpyalloc(new)) == NULL) {
! freelist(cpp);
! return NULL;
! }
! new[len] = '\0';
! /*
! ** Is there already something in the list that's new (or longer)?
! */
! for (i = 0; cpp[i] != NULL; ++i)
! if (istrstr(cpp[i], new) != NULL) {
! free(new);
! return cpp;
! }
! /*
! ** Eliminate any obsoleted strings.
! */
! j = 0;
! while (cpp[j] != NULL)
! if (istrstr(new, cpp[j]) == NULL)
! ++j;
! else {
! free(cpp[j]);
! if (--i == j)
! break;
! cpp[j] = cpp[i];
! }
! /*
! ** Add the new string.
! */
! cpp = (char **) realloc((char *) cpp, (i + 2) * sizeof *cpp);
! if (cpp == NULL)
! return NULL;
! cpp[i] = new;
! cpp[i + 1] = NULL;
! return cpp;
! }
!
! /*
! ** Given pointers to two strings,
! ** return a pointer to an allocated list of their distinct common substrings.
! ** Return NULL if something seems wild.
! */
! static char **
! comsubs(left, right)
! char * left;
! char * right;
! {
! register char ** cpp;
! register char * lcp;
! register char * rcp;
! register int i, len;
!
! if (left == NULL || right == NULL)
! return NULL;
! cpp = (char **) malloc(sizeof *cpp);
! if (cpp == NULL)
! return NULL;
! cpp[0] = NULL;
! for (lcp = left; *lcp != '\0'; ++lcp) {
! len = 0;
! rcp = strchr(right, *lcp);
! while (rcp != NULL) {
! for (i = 1; lcp[i] != '\0' && lcp[i] == rcp[i]; ++i)
! ;
! if (i > len)
! len = i;
! rcp = strchr(rcp + 1, *lcp);
! }
! if (len == 0)
! continue;
! if ((cpp = enlist(cpp, lcp, len)) == NULL)
! break;
! }
! return cpp;
! }
!
! static char **
! addlists(old, new)
! char ** old;
! char ** new;
{
register int i;
! if (old == NULL || new == NULL)
! return NULL;
! for (i = 0; new[i] != NULL; ++i) {
! old = enlist(old, new[i], strlen(new[i]));
! if (old == NULL)
! break;
! }
! return old;
}
+ /*
+ ** Given two lists of substrings,
+ ** return a new list giving substrings common to both.
+ */
+
+ static char **
+ inboth(left, right)
+ char ** left;
+ char ** right;
+ {
+ register char ** both;
+ register char ** temp;
+ register int lnum, rnum;
+
+ if (left == NULL || right == NULL)
+ return NULL;
+ both = (char **) malloc(sizeof *both);
+ if (both == NULL)
+ return NULL;
+ both[0] = NULL;
+ for (lnum = 0; left[lnum] != NULL; ++lnum) {
+ for (rnum = 0; right[rnum] != NULL; ++rnum) {
+ temp = comsubs(left[lnum], right[rnum]);
+ if (temp == NULL) {
+ freelist(both);
+ return NULL;
+ }
+ both = addlists(both, temp);
+ freelist(temp);
+ if (both == NULL)
+ return NULL;
+ }
+ }
+ return both;
+ }
typedef struct {
! char ** in;
! char * left;
! char * right;
! char * is;
} must;
static void
! resetmust(mp)
! register must * mp;
{
! mp->left[0] = mp->right[0] = mp->is[0] = '\0';
! freelist(mp->in);
}
static void
***************
*** 1866,1884 ****
regmust(r)
register struct regexp * r;
{
! must musts[MUST_MAX];
register must * mp;
! counted result;
register int ri;
register int i;
register _token t;
reg->mustn = 0;
reg->must[0] = '\0';
! if (reg->tindex > MUST_MAX)
return;
mp = musts;
! initcounted(&result);
for (ri = 0; ri < reg->tindex; ++ri) {
switch (t = reg->tokens[ri]) {
case _ALLBEGLINE:
--- 2023,2056 ----
regmust(r)
register struct regexp * r;
{
! register must * musts;
register must * mp;
! register char * result;
register int ri;
register int i;
register _token t;
+ static must must0;
reg->mustn = 0;
reg->must[0] = '\0';
! musts = (must *) malloc((reg->tindex + 1) * sizeof *musts);
! if (musts == NULL)
return;
mp = musts;
! for (i = 0; i <= reg->tindex; ++i)
! mp[i] = must0;
! for (i = 0; i <= reg->tindex; ++i) {
! mp[i].in = (char **) malloc(sizeof *mp[i].in);
! mp[i].left = malloc(2);
! mp[i].right = malloc(2);
! mp[i].is = malloc(2);
! if (mp[i].in == NULL || mp[i].left == NULL ||
! mp[i].right == NULL || mp[i].is == NULL)
! goto done;
! mp[i].left[0] = mp[i].right[0] = mp[i].is[0] = '\0';
! mp[i].in[0] = NULL;
! }
! result = "";
for (ri = 0; ri < reg->tindex; ++ri) {
switch (t = reg->tokens[ri]) {
case _ALLBEGLINE:
***************
*** 1894,1900 ****
case _LIMWORD:
case _NOTLIMWORD:
case _BACKREF:
! initmust(mp);
break;
case _STAR:
case _QMARK:
--- 2066,2072 ----
case _LIMWORD:
case _NOTLIMWORD:
case _BACKREF:
! resetmust(mp);
break;
case _STAR:
case _QMARK:
***************
*** 1901,1945 ****
if (mp <= musts)
goto done; /* "cannot happen" */
--mp;
! initmust(mp);
break;
case _OR:
if (mp < &musts[2])
goto done; /* "cannot happen" */
{
! register must * lmp;
! register must * rmp;
! register int j, n;
rmp = --mp;
lmp = --mp;
/* Guaranteed to be. Unlikely, but. . . */
! if (!cntsame(&lmp->is, &rmp->is))
! initcounted(&lmp->is);
/* Left side--easy */
! n = lmp->left.n;
! if (n > rmp->left.n)
! n = rmp->left.n;
! for (i = 0; i < n; ++i)
! if (lmp->left.p[i] != rmp->left.p[i])
! break;
! lmp->left.n = i;
/* Right side */
! n = lmp->right.n;
! if (n > rmp->right.n)
! n = rmp->right.n;
for (i = 0; i < n; ++i)
! if (lmp->right.p[lmp->right.n-i-1] !=
! rmp->right.p[rmp->right.n-i-1])
break;
for (j = 0; j < i; ++j)
! lmp->right.p[j] =
! lmp->right.p[(lmp->right.n -
! i) + j];
! lmp->right.n = i;
! /* Includes. Unlikely, but. . . */
! if (!cntsame(&lmp->in, &rmp->in))
! initcounted(&lmp->in);
}
break;
case _PLUS:
--- 2073,2120 ----
if (mp <= musts)
goto done; /* "cannot happen" */
--mp;
! resetmust(mp);
break;
case _OR:
if (mp < &musts[2])
goto done; /* "cannot happen" */
{
! register char ** new;
! register must * lmp;
! register must * rmp;
! register int j, ln, rn, n;
rmp = --mp;
lmp = --mp;
/* Guaranteed to be. Unlikely, but. . . */
! if (strcmp(lmp->is, rmp->is) != 0)
! lmp->is[0] = '\0';
/* Left side--easy */
! i = 0;
! while (lmp->left[i] != '\0' &&
! lmp->left[i] == rmp->left[i])
! ++i;
! lmp->left[i] = '\0';
/* Right side */
! ln = strlen(lmp->right);
! rn = strlen(rmp->right);
! n = ln;
! if (n > rn)
! n = rn;
for (i = 0; i < n; ++i)
! if (lmp->right[ln - i - 1] !=
! rmp->right[rn - i - 1])
break;
for (j = 0; j < i; ++j)
! lmp->right[j] =
! lmp->right[(ln - i) + j];
! lmp->right[j] = '\0';
! new = inboth(lmp->in, rmp->in);
! if (new == NULL)
! goto done;
! freelist(lmp->in);
! free((char *) lmp->in);
! lmp->in = new;
}
break;
case _PLUS:
***************
*** 1946,2001 ****
if (mp <= musts)
goto done; /* "cannot happen" */
--mp;
! initcounted(&mp->is);
break;
case _END:
if (mp != &musts[1])
goto done; /* "cannot happen" */
! result = musts[0].in;
goto done;
case _CAT:
if (mp < &musts[2])
goto done; /* "cannot happen" */
{
! must * lmp;
! must * rmp;
! must new;
! must * nmp;
! int a, b, c;
rmp = --mp;
lmp = --mp;
! nmp = &new;
! initmust(nmp);
/* Left-hand */
! cntcat(&nmp->left, &lmp->left);
! if (lmp->is.n != 0)
! cntcat(&nmp->left, &rmp->left);
/* Right-hand */
! if (rmp->is.n != 0)
! cntcat(&nmp->right, &lmp->right);
! cntcat(&nmp->right, &rmp->right);
/* Guaranteed to be */
! if (lmp->is.n != 0 && rmp->is.n != 0) {
! cntcat(&nmp->is, &lmp->is);
! cntcat(&nmp->is, &rmp->is);
}
- /* Interior */
- a = lmp->in.n;
- b = rmp->in.n;
- c = lmp->right.n + rmp->left.n;
- if (a == 0 && b == 0 && c == 0) {
- /* nothing */
- ;
- } else if (c > a && c > b) {
- cntcat(&nmp->in, &lmp->right);
- cntcat(&nmp->in, &rmp->left);
- } else if (a > b) {
- cntcat(&nmp->in, &lmp->in);
- } else {
- cntcat(&nmp->in, &rmp->in);
- }
- *mp = new;
}
break;
default:
--- 2121,2187 ----
if (mp <= musts)
goto done; /* "cannot happen" */
--mp;
! mp->is[0] = '\0';
break;
case _END:
if (mp != &musts[1])
goto done; /* "cannot happen" */
! for (i = 0; musts[0].in[i] != NULL; ++i)
! if (strlen(musts[0].in[i]) > strlen(result))
! result = musts[0].in[i];
goto done;
case _CAT:
if (mp < &musts[2])
goto done; /* "cannot happen" */
{
! register must * lmp;
! register must * rmp;
rmp = --mp;
lmp = --mp;
! /*
! ** In. Everything in left, plus everything in
! ** right, plus catenation of
! ** left's right and right's left.
! */
! lmp->in = addlists(lmp->in, rmp->in);
! if (lmp->in == NULL)
! goto done;
! if (lmp->right[0] != '\0' &&
! rmp->left[0] != '\0') {
! register char * tp;
!
! tp = icpyalloc(lmp->right);
! if (tp == NULL)
! goto done;
! tp = icatalloc(tp, rmp->left);
! if (tp == NULL)
! goto done;
! lmp->in = enlist(lmp->in, tp,
! strlen(tp));
! free(tp);
! if (lmp->in == NULL)
! goto done;
! }
/* Left-hand */
! if (lmp->is[0] != '\0') {
! lmp->left = icatalloc(lmp->left,
! rmp->left);
! if (lmp->left == NULL)
! goto done;
! }
/* Right-hand */
! if (rmp->is[0] == '\0')
! lmp->right[0] = '\0';
! lmp->right = icatalloc(lmp->right, rmp->right);
! if (lmp->right == NULL)
! goto done;
/* Guaranteed to be */
! if (lmp->is[0] != '\0' && rmp->is[0] != '\0') {
! lmp->is = icatalloc(lmp->is, rmp->is);
! if (lmp->is == NULL)
! goto done;
}
}
break;
default:
***************
*** 2002,2036 ****
if (t < _END) {
/* "cannot happen" */
goto done;
} else if (t >= _SET) {
/* easy enough */
! initmust(mp);
} else {
/* plain character */
! mp->left.p[0] = mp->right.p[0] =
! mp->in.p[0] = mp->is.p[0] = t;
! mp->left.n = mp->right.n =
! mp->in.n = mp->is.n = 1;
! break;
}
break;
}
- /*
- ** "Additional steps"
- */
- if (mp->is.n > 0) {
- cntcpy(&mp->left, &mp->is);
- cntcpy(&mp->right, &mp->is);
- cntcpy(&mp->in, &mp->is);
- }
- if (mp->left.n > mp->in.n)
- cntcpy(&mp->in, &mp->left);
- if (mp->right.n > mp->in.n)
- cntcpy(&mp->in, &mp->right);
++mp;
}
done:
! reg->mustn = result.n;
! for (i = 0; i < result.n; ++i)
! reg->must[i] = result.p[i];
}
--- 2188,2223 ----
if (t < _END) {
/* "cannot happen" */
goto done;
+ } else if (t == '\0') {
+ /* not on *my* shift */
+ goto done;
} else if (t >= _SET) {
/* easy enough */
! resetmust(mp);
} else {
/* plain character */
! resetmust(mp);
! mp->is[0] = mp->left[0] = mp->right[0] = t;
! mp->is[1] = mp->left[1] = mp->right[1] = '\0';
! mp->in = enlist(mp->in, mp->is, 1);
! if (mp->in == NULL)
! goto done;
}
break;
}
++mp;
}
done:
! (void) strncpy(reg->must, result, MUST_MAX - 1);
! reg->must[MUST_MAX - 1] = '\0';
! reg->mustn = strlen(reg->must);
! mp = musts;
! for (i = 0; i <= reg->tindex; ++i) {
! freelist(mp[i].in);
! ifree((char *) mp[i].in);
! ifree(mp[i].left);
! ifree(mp[i].right);
! ifree(mp[i].is);
! }
! free((char *) mp);
}
diff -rcN grep-1.2/dfa.h grep-1.3/dfa.h
*** grep-1.2/dfa.h Thu Oct 13 22:11:29 1988
--- grep-1.3/dfa.h Tue Feb 28 21:53:15 1989
***************
*** 103,108 ****
--- 103,117 ----
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
+
+ #ifdef USG
+ #include <string.h>
+ extern char *index();
+ #else
+ #include <strings.h>
+ extern char *strchr(), *strrchr(), *memcpy();
+ #endif
+
#ifdef __STDC__
/* Missing include files for GNU C. */
***************
*** 113,124 ****
extern void *realloc(void *, size_t);
extern void free(void *);
- #ifndef USG
- extern char *strchr(), *strrchr(), *memcpy();
- #else
- extern char *index();
- #endif
-
extern char *bcopy(), *bzero();
#ifdef SOMEDAY
--- 122,127 ----
***************
*** 136,147 ****
extern char *calloc(), *malloc(), *realloc();
extern void free();
- #ifndef USG
- extern char *strchr(), *strrchr(), *memcpy();
- #else
- extern char *index();
- #endif
-
extern char *bcopy(), *bzero();
#define ISALNUM(c) (isascii(c) && isalnum(c))
--- 139,144 ----
***************
*** 380,387 ****
a constraint. */
typedef struct
{
! unsigned index:24, /* Index into the parse array. */
! constraint:8; /* Constraint for matching this position. */
} _position;
/* Sets of positions are stored as arrays. */
--- 377,384 ----
a constraint. */
typedef struct
{
! unsigned index; /* Index into the parse array. */
! unsigned constraint; /* Constraint for matching this position. */
} _position;
/* Sets of positions are stored as arrays. */
***************
*** 398,407 ****
{
int hash; /* Hash of the positions of this state. */
_position_set elems; /* Positions this state could match. */
! unsigned newline:1, /* True if previous state matched newline. */
! letter:1, /* True if previous state matched a letter. */
! backref:1, /* True if this state matches a \<digit>. */
! constraint:8; /* Constraint for this state to accept. */
int first_end; /* Token value of the first _END in elems. */
} _dfa_state;
--- 395,404 ----
{
int hash; /* Hash of the positions of this state. */
_position_set elems; /* Positions this state could match. */
! char newline; /* True if previous state matched newline. */
! char letter; /* True if previous state matched a letter. */
! char backref; /* True if this state matches a \<digit>. */
! unsigned char constraint; /* Constraint for this state to accept. */
int first_end; /* Token value of the first _END in elems. */
} _dfa_state;
diff -rcN grep-1.2/getopt.c grep-1.3/getopt.c
*** grep-1.2/getopt.c Sun Dec 11 10:37:36 1988
--- grep-1.3/getopt.c Tue Feb 28 17:44:55 1989
***************
*** 406,412 ****
if (opterr != 0)
fprintf (stderr, "%s: no argument for `-%c' option\n",
argv[0], c);
! optarg = 0;
}
else
/* We already incremented `optind' once;
--- 406,412 ----
if (opterr != 0)
fprintf (stderr, "%s: no argument for `-%c' option\n",
argv[0], c);
! c = '?';
}
else
/* We already incremented `optind' once;
diff -rcN grep-1.2/grep.c grep-1.3/grep.c
*** grep-1.2/grep.c Tue Dec 13 10:54:54 1988
--- grep-1.3/grep.c Tue Feb 28 23:05:53 1989
***************
*** 368,376 ****
/* If a potential backreference is indicated, try it out with
a backtracking matcher to make sure the line is a match. */
if (try_backref && re_search(®ex, matching_line,
! next_line - matching_line,
0,
! next_line - matching_line,
NULL) < 0)
{
resume = next_line;
--- 368,376 ----
/* If a potential backreference is indicated, try it out with
a backtracking matcher to make sure the line is a match. */
if (try_backref && re_search(®ex, matching_line,
! next_line - matching_line - 1,
0,
! next_line - matching_line - 1,
NULL) < 0)
{
resume = next_line;
***************
*** 542,548 ****
exit(ERROR);
}
! static char version[] = "GNU e?grep, version 1.2";
main(argc, argv)
int argc;
--- 542,548 ----
exit(ERROR);
}
! static char version[] = "GNU e?grep, version 1.3";
main(argc, argv)
int argc;
***************
*** 679,695 ****
break;
}
! /* Set the syntax depending on arg 0 and whether to ignore case. */
! if (*prog == 'e')
! {
! regsyntax(RE_SYNTAX_EGREP, ignore_case);
! re_set_syntax(RE_SYNTAX_EGREP);
! }
! else
! {
! regsyntax(RE_SYNTAX_GREP, ignore_case);
! re_set_syntax(RE_SYNTAX_GREP);
! }
/* Compile the regexp according to all the options. */
if (regexp_file)
--- 679,692 ----
break;
}
! /* Set the syntax depending on whether we are EGREP or not. */
! #ifdef EGREP
! regsyntax(RE_SYNTAX_EGREP, ignore_case);
! re_set_syntax(RE_SYNTAX_EGREP);
! #else
! regsyntax(RE_SYNTAX_GREP, ignore_case);
! re_set_syntax(RE_SYNTAX_GREP);
! #endif
/* Compile the regexp according to all the options. */
if (regexp_file)
***************
*** 712,717 ****
--- 709,715 ----
if (i == len)
the_regexp = realloc(the_regexp, len *= 2);
}
+ fclose(fp);
/* Nuke the concluding newline so we won't match the empty string. */
if (i > 0 && the_regexp[i - 1] == '\n')
--i;
diff -rcN grep-1.2/grep.man grep-1.3/grep.man
*** grep-1.2/grep.man Tue Dec 13 11:46:46 1988
--- grep-1.3/grep.man Tue Feb 28 21:42:46 1989
***************
*** 6,21 ****
.B grep
[
.B \-CVbchilnsvwx
! ]
! [
! .B \-\c
! .I num
! ]
! [
.B \-AB
.I num
! ]
! [ [
.B \-e
]
.I expr
--- 6,17 ----
.B grep
[
.B \-CVbchilnsvwx
! ] [
! .BI \- num
! ] [
.B \-AB
.I num
! ] [ [
.B \-e
]
.I expr
***************
*** 254,260 ****
the aforementioned BMG search for a large class of regexps.
.PP
Richard Stallman wrote the backtracking regexp matcher that is
! used for \\fIdigit\fP backreferences, as well as the getopt that
is provided for 4.2BSD sites. The backtracking matcher was
originally written for GNU Emacs.
.PP
--- 250,256 ----
the aforementioned BMG search for a large class of regexps.
.PP
Richard Stallman wrote the backtracking regexp matcher that is
! used for \\\fIdigit\fP backreferences, as well as the getopt that
is provided for 4.2BSD sites. The backtracking matcher was
originally written for GNU Emacs.
.PP
diff -rcN grep-1.2/regex.c grep-1.3/regex.c
*** grep-1.2/regex.c Sun Oct 16 14:55:19 1988
--- grep-1.3/regex.c Tue Feb 28 17:44:59 1989
***************
*** 1,106 ****
! /* Extended regular expression matching and search.
! Copyright (C) 1985 Free Software Foundation, Inc.
! NO WARRANTY
- BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
- NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
- WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
- RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
- WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
- AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
- DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
- CORRECTION.
! IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
! STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
! WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
! LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
! OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
! USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
! DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
! A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
! PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
! DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
!
! GENERAL PUBLIC LICENSE TO COPY
!
! 1. You may copy and distribute verbatim copies of this source file
! as you receive it, in any medium, provided that you conspicuously and
! appropriately publish on each copy a valid copyright notice "Copyright
! (C) 1985 Free Software Foundation, Inc."; and include following the
! copyright notice a verbatim copy of the above disclaimer of warranty
! and of this License. You may charge a distribution fee for the
! physical act of transferring a copy.
!
! 2. You may modify your copy or copies of this source file or
! any portion of it, and copy and distribute such modifications under
! the terms of Paragraph 1 above, provided that you also do the following:
!
! a) cause the modified files to carry prominent notices stating
! that you changed the files and the date of any change; and
!
! b) cause the whole of any work that you distribute or publish,
! that in whole or in part contains or is a derivative of this
! program or any part thereof, to be licensed at no charge to all
! third parties on terms identical to those contained in this
! License Agreement (except that you may choose to grant more extensive
! warranty protection to some or all third parties, at your option).
!
! c) You may charge a distribution fee for the physical act of
! transferring a copy, and you may at your option offer warranty
! protection in exchange for a fee.
!
! Mere aggregation of another unrelated program with this program (or its
! derivative) on a volume of a storage or distribution medium does not bring
! the other program under the scope of these terms.
!
! 3. You may copy and distribute this program (or a portion or derivative
! of it, under Paragraph 2) in object code or executable form under the terms
! of Paragraphs 1 and 2 above provided that you also do one of the following:
!
! a) accompany it with the complete corresponding machine-readable
! source code, which must be distributed under the terms of
! Paragraphs 1 and 2 above; or,
!
! b) accompany it with a written offer, valid for at least three
! years, to give any third party free (except for a nominal
! shipping charge) a complete machine-readable copy of the
! corresponding source code, to be distributed under the terms of
! Paragraphs 1 and 2 above; or,
!
! c) accompany it with the information you received as to where the
! corresponding source code may be obtained. (This alternative is
! allowed only for noncommercial distribution and only if you
! received the program in object code or executable form alone.)
!
! For an executable file, complete source code means all the source code for
! all modules it contains; but, as a special exception, it need not include
! source code for modules which are standard libraries that accompany the
! operating system on which the executable file runs.
!
! 4. You may not copy, sublicense, distribute or transfer this program
! except as expressly provided under this License Agreement. Any attempt
! otherwise to copy, sublicense, distribute or transfer this program is void and
! your rights to use the program under this License agreement shall be
! automatically terminated. However, parties who have received computer
! software programs from you with this License Agreement will not have
! their licenses terminated so long as such parties remain in full compliance.
!
! 5. If you wish to incorporate parts of this program into other free
! programs whose distribution conditions are different, write to the Free
! Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
! worked out a simple rule that can be stated here, but we will often permit
! this. We will be guided by the two goals of preserving the free status of
! all derivatives of our free software and of promoting the sharing and reuse of
! software.
!
!
! In other words, you are welcome to use, share and improve this program.
! You are forbidden to forbid anyone else to use, share and improve
! what you give them. Help stamp out software-hoarding! */
/* To test, compile with -Dtest.
--- 1,24 ----
! /* Extended regular expression matching and search library.
! Copyright (C) 1985, 1989 Free Software Foundation, Inc.
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 1, or (at your option)
! any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program; if not, write to the Free Software
! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
! In other words, you are welcome to use, share and improve this program.
! You are forbidden to forbid anyone else to use, share and improve
! what you give them. Help stamp out software-hoarding! */
/* To test, compile with -Dtest.
diff -rcN grep-1.2/regex.h grep-1.3/regex.h
*** grep-1.2/regex.h Sat Aug 13 13:15:10 1988
--- grep-1.3/regex.h Tue Feb 28 17:44:59 1989
***************
*** 1,106 ****
/* Definitions for data structures callers pass the regex library.
! Copyright (C) 1985 Free Software Foundation, Inc.
! NO WARRANTY
- BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
- NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
- WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
- RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
- WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
- BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY
- AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
- DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
- CORRECTION.
! IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
! STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
! WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
! LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
! OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
! USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
! DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
! A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
! PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
! DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
!
! GENERAL PUBLIC LICENSE TO COPY
!
! 1. You may copy and distribute verbatim copies of this source file
! as you receive it, in any medium, provided that you conspicuously and
! appropriately publish on each copy a valid copyright notice "Copyright
! (C) 1985 Free Software Foundation, Inc."; and include following the
! copyright notice a verbatim copy of the above disclaimer of warranty
! and of this License. You may charge a distribution fee for the
! physical act of transferring a copy.
!
! 2. You may modify your copy or copies of this source file or
! any portion of it, and copy and distribute such modifications under
! the terms of Paragraph 1 above, provided that you also do the following:
!
! a) cause the modified files to carry prominent notices stating
! that you changed the files and the date of any change; and
!
! b) cause the whole of any work that you distribute or publish,
! that in whole or in part contains or is a derivative of this
! program or any part thereof, to be licensed at no charge to all
! third parties on terms identical to those contained in this
! License Agreement (except that you may choose to grant more extensive
! warranty protection to some or all third parties, at your option).
!
! c) You may charge a distribution fee for the physical act of
! transferring a copy, and you may at your option offer warranty
! protection in exchange for a fee.
!
! Mere aggregation of another unrelated program with this program (or its
! derivative) on a volume of a storage or distribution medium does not bring
! the other program under the scope of these terms.
!
! 3. You may copy and distribute this program (or a portion or derivative
! of it, under Paragraph 2) in object code or executable form under the terms
! of Paragraphs 1 and 2 above provided that you also do one of the following:
!
! a) accompany it with the complete corresponding machine-readable
! source code, which must be distributed under the terms of
! Paragraphs 1 and 2 above; or,
!
! b) accompany it with a written offer, valid for at least three
! years, to give any third party free (except for a nominal
! shipping charge) a complete machine-readable copy of the
! corresponding source code, to be distributed under the terms of
! Paragraphs 1 and 2 above; or,
!
! c) accompany it with the information you received as to where the
! corresponding source code may be obtained. (This alternative is
! allowed only for noncommercial distribution and only if you
! received the program in object code or executable form alone.)
!
! For an executable file, complete source code means all the source code for
! all modules it contains; but, as a special exception, it need not include
! source code for modules which are standard libraries that accompany the
! operating system on which the executable file runs.
!
! 4. You may not copy, sublicense, distribute or transfer this program
! except as expressly provided under this License Agreement. Any attempt
! otherwise to copy, sublicense, distribute or transfer this program is void and
! your rights to use the program under this License agreement shall be
! automatically terminated. However, parties who have received computer
! software programs from you with this License Agreement will not have
! their licenses terminated so long as such parties remain in full compliance.
!
! 5. If you wish to incorporate parts of this program into other free
! programs whose distribution conditions are different, write to the Free
! Software Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not yet
! worked out a simple rule that can be stated here, but we will often permit
! this. We will be guided by the two goals of preserving the free status of
! all derivatives of our free software and of promoting the sharing and reuse of
! software.
!
!
! In other words, you are welcome to use, share and improve this program.
! You are forbidden to forbid anyone else to use, share and improve
! what you give them. Help stamp out software-hoarding! */
/* Define number of parens for which we record the beginnings and ends.
--- 1,24 ----
/* Definitions for data structures callers pass the regex library.
! Copyright (C) 1985, 1989 Free Software Foundation, Inc.
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 1, or (at your option)
! any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program; if not, write to the Free Software
! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
! In other words, you are welcome to use, share and improve this program.
! You are forbidden to forbid anyone else to use, share and improve
! what you give them. Help stamp out software-hoarding! */
/* Define number of parens for which we record the beginnings and ends.