|
Lines 245-250
Link Here
|
| 245 |
g->categories = &g->catspace[-(CHAR_MIN)]; |
245 |
g->categories = &g->catspace[-(CHAR_MIN)]; |
| 246 |
(void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); |
246 |
(void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); |
| 247 |
g->backrefs = 0; |
247 |
g->backrefs = 0; |
|
|
248 |
(void) memset((void *)g->delta0, 0, 256 * sizeof(int)); |
| 248 |
|
249 |
|
| 249 |
/* do it */ |
250 |
/* do it */ |
| 250 |
EMIT(OEND, 0); |
251 |
EMIT(OEND, 0); |
|
Lines 1738-1743
Link Here
|
| 1738 |
} |
1739 |
} |
| 1739 |
assert(cp == g->must + g->mlen); |
1740 |
assert(cp == g->must + g->mlen); |
| 1740 |
*cp++ = '\0'; /* just on general principles */ |
1741 |
*cp++ = '\0'; /* just on general principles */ |
|
|
1742 |
gosper(g->must, g->delta0, g->cmap); |
| 1741 |
} |
1743 |
} |
| 1742 |
|
1744 |
|
| 1743 |
/* |
1745 |
/* |
|
Lines 1774-1777
Link Here
|
| 1774 |
if (plusnest != 0) |
1776 |
if (plusnest != 0) |
| 1775 |
g->iflags |= BAD; |
1777 |
g->iflags |= BAD; |
| 1776 |
return(maxnest); |
1778 |
return(maxnest); |
|
|
1779 |
} |
| 1780 |
|
| 1781 |
|
| 1782 |
#define NALT 7 /* tied to scanf() size in alternate() */ |
| 1783 |
|
| 1784 |
/* |
| 1785 |
* Compute "Boyer-Moore" delta table -- put skip distance in delta0[c] |
| 1786 |
*/ |
| 1787 |
void |
| 1788 |
gosper(pattern, delta0, cmap) |
| 1789 |
char *pattern; /* ... HAKMEM lives ... */ |
| 1790 |
int *delta0; /* Who/what is HAKMEM? */ |
| 1791 |
char *cmap; |
| 1792 |
{ |
| 1793 |
char *altpat[NALT]; |
| 1794 |
int altlen[NALT]; |
| 1795 |
register int j, altmin; |
| 1796 |
unsigned char c; |
| 1797 |
|
| 1798 |
/* Make one-string case look like simple alternatives case */ |
| 1799 |
altmin = altlen[0] = strlen(pattern); |
| 1800 |
altpat[0] = pattern; |
| 1801 |
|
| 1802 |
/* For chars that aren't in any string, skip by string length. */ |
| 1803 |
for (j = 0; j < 256; j++) { |
| 1804 |
delta0[j] = altmin; |
| 1805 |
cmap[j] = j; /* Sneak in initialization of cmap */ |
| 1806 |
} |
| 1807 |
|
| 1808 |
/* For chars in a string, skip distance from char to end of string. */ |
| 1809 |
/* (If char appears more than once, skip minimum distance.) */ |
| 1810 |
|
| 1811 |
delta0[0] = 0; |
| 1812 |
for (j = 0; j < altlen[0] - 1; j++) { |
| 1813 |
c = altpat[0][j]; |
| 1814 |
delta0[c] = MIN(delta0[c], altlen[0] - j - 1); |
| 1815 |
} |
| 1816 |
|
| 1817 |
/* For last char of each string, fall out of search loop. */ |
| 1818 |
c = altpat[0][altlen[0] - 1]; |
| 1819 |
delta0[c] = LARGE; |
| 1820 |
|
| 1777 |
} |
1821 |
} |