Lines Matching +full:cs +full:- +full:out

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * Branching context, used to keep track of branch state for all of the branch-
66 * also for whether we're in a sub-expression or not.
85 const char *end; /* end of string (-> NUL normally) */
93 # define NPAREN 10 /* we need to remember () 1-9 for back refs */
94 sopno pbegin[NPAREN]; /* -> ( ([0] unused) */
95 sopno pend[NPAREN]; /* -> ) ([0] unused) */
98 int pflags; /* other parsing flags -- legacy escapes? */
126 static void p_b_term(struct parse *p, cset *cs);
128 static void p_b_cclass(struct parse *p, cset *cs);
129 static void p_b_cclass_named(struct parse *p, cset *cs, const char[]);
130 static void p_b_eclass(struct parse *p, cset *cs);
141 static void freeset(struct parse *p, cset *cs);
142 static void CHadd(struct parse *p, cset *cs, wint_t ch);
143 static void CHaddrange(struct parse *p, cset *cs, wint_t min, wint_t max);
144 static void CHaddtype(struct parse *p, cset *cs, wctype_t wct);
145 static wint_t singleton(cset *cs);
170 #define PEEK() (*p->next)
171 #define PEEK2() (*(p->next+1))
172 #define MORE() (p->end - p->next > 0)
173 #define MORE2() (p->end - p->next > 1)
176 #define SEESPEC(a) (p->bre ? SEETWO('\\', a) : SEE(a))
179 #define EATSPEC(a) (p->bre ? EATTWO('\\', a) : EAT(a))
180 #define NEXT() (p->next++)
181 #define NEXT2() (p->next += 2)
182 #define NEXTn(n) (p->next += (n))
183 #define GETNEXT() (*p->next++)
191 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
192 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
193 #define ASTERN(sop, pos) EMIT(sop, HERE()-pos)
194 #define HERE() (p->slen)
195 #define THERE() (p->slen - 1)
196 #define THERETHERE() (p->slen - 2)
197 #define DROP(n) (p->slen -= (n))
224 if (preg->re_endp < pattern) in regcomp_internal()
226 len = preg->re_endp - pattern; in regcomp_internal()
235 * Limit the pattern space to avoid a 32-bit overflow on buffer in regcomp_internal()
237 * so make the real limit based on a 31-bit overflow. in regcomp_internal()
239 * Likely not applicable on 64-bit systems but handle the case in regcomp_internal()
243 maxlen = ((size_t)-1 >> 1) / sizeof(sop) * 2 / 3; in regcomp_internal()
248 p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ in regcomp_internal()
249 assert(p->ssize >= len); in regcomp_internal()
251 p->strip = (sop *)malloc(p->ssize * sizeof(sop)); in regcomp_internal()
252 p->slen = 0; in regcomp_internal()
253 if (p->strip == NULL) { in regcomp_internal()
259 p->g = g; in regcomp_internal()
260 p->next = pattern; /* convenience; we do not modify it */ in regcomp_internal()
261 p->end = p->next + len; in regcomp_internal()
262 p->error = 0; in regcomp_internal()
263 p->ncsalloc = 0; in regcomp_internal()
264 p->pflags = pflags; in regcomp_internal()
266 p->pbegin[i] = 0; in regcomp_internal()
267 p->pend[i] = 0; in regcomp_internal()
271 p->gnuext = false; in regcomp_internal()
272 p->allowbranch = (cflags & REG_EXTENDED) != 0; in regcomp_internal()
274 p->gnuext = p->allowbranch = true; in regcomp_internal()
276 p->gnuext = false; in regcomp_internal()
277 p->allowbranch = (cflags & REG_EXTENDED) != 0; in regcomp_internal()
280 p->bre = false; in regcomp_internal()
281 p->parse_expr = p_ere_exp; in regcomp_internal()
282 p->pre_parse = NULL; in regcomp_internal()
283 p->post_parse = NULL; in regcomp_internal()
285 p->bre = true; in regcomp_internal()
286 p->parse_expr = p_simp_re; in regcomp_internal()
287 p->pre_parse = p_bre_pre_parse; in regcomp_internal()
288 p->post_parse = p_bre_post_parse; in regcomp_internal()
290 g->sets = NULL; in regcomp_internal()
291 g->ncsets = 0; in regcomp_internal()
292 g->cflags = cflags; in regcomp_internal()
293 g->iflags = 0; in regcomp_internal()
294 g->nbol = 0; in regcomp_internal()
295 g->neol = 0; in regcomp_internal()
296 g->must = NULL; in regcomp_internal()
297 g->moffset = -1; in regcomp_internal()
298 g->charjump = NULL; in regcomp_internal()
299 g->matchjump = NULL; in regcomp_internal()
300 g->mlen = 0; in regcomp_internal()
301 g->nsub = 0; in regcomp_internal()
302 g->backrefs = 0; in regcomp_internal()
306 g->firststate = THERE(); in regcomp_internal()
310 p_re(p, OUT, OUT); in regcomp_internal()
312 g->laststate = THERE(); in regcomp_internal()
317 /* only use Boyer-Moore algorithm if the pattern is bigger in regcomp_internal()
320 if(g->mlen > 3) { in regcomp_internal()
323 if(g->matchjump == NULL && g->charjump != NULL) { in regcomp_internal()
324 free(&g->charjump[CHAR_MIN]); in regcomp_internal()
325 g->charjump = NULL; in regcomp_internal()
328 g->nplus = pluscount(p, g); in regcomp_internal()
329 g->magic = MAGIC2; in regcomp_internal()
330 preg->re_nsub = g->nsub; in regcomp_internal()
331 preg->re_g = g; in regcomp_internal()
332 preg->re_magic = MAGIC1; in regcomp_internal()
335 if (g->iflags&BAD) in regcomp_internal()
340 if (p->error != 0) /* lose */ in regcomp_internal()
342 return(p->error); in regcomp_internal()
346 - regcomp - interface for parser and compilation
383 - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op,
384 - return whether we should terminate or not
413 p->g->nsub++; in p_ere_exp()
414 subno = p->g->nsub; in p_ere_exp()
416 p->pbegin[subno] = HERE(); in p_ere_exp()
421 p->pend[subno] = HERE(); in p_ere_exp()
422 assert(p->pend[subno] != 0); in p_ere_exp()
432 * other 1003.2 regular-expression reviewers noticed it at in p_ere_exp()
441 p->g->iflags |= USEBOL; in p_ere_exp()
442 p->g->nbol++; in p_ere_exp()
447 p->g->iflags |= USEEOL; in p_ere_exp()
448 p->g->neol++; in p_ere_exp()
462 if (p->g->cflags&REG_NEWLINE) in p_ere_exp()
474 if (p->gnuext) { in p_ere_exp()
504 i = wc - '0'; in p_ere_exp()
506 if (p->pend[i] != 0) { in p_ere_exp()
507 assert(i <= p->g->nsub); in p_ere_exp()
509 assert(p->pbegin[i] != 0); in p_ere_exp()
510 assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); in p_ere_exp()
511 assert(OP(p->strip[p->pend[i]]) == ORPAREN); in p_ere_exp()
512 (void) dupl(p, p->pbegin[i]+1, p->pend[i]); in p_ere_exp()
516 p->g->backrefs = 1; in p_ere_exp()
547 if (p->error != 0) in p_ere_exp()
549 p->next--; in p_ere_exp()
627 - p_str - string (no metacharacters) "parser"
655 * Insert necessary branch book-keeping operations. This emits a
662 if (bc->nbranch == 0) { in p_branch_ins_offset()
663 INSERT(OCH_, bc->start); /* offset is wrong */ in p_branch_ins_offset()
664 bc->fwd = bc->start; in p_branch_ins_offset()
665 bc->back = bc->start; in p_branch_ins_offset()
668 ASTERN(OOR1, bc->back); in p_branch_ins_offset()
669 bc->back = THERE(); in p_branch_ins_offset()
670 AHEAD(bc->fwd); /* fix previous offset */ in p_branch_ins_offset()
671 bc->fwd = HERE(); in p_branch_ins_offset()
673 ++bc->nbranch; in p_branch_ins_offset()
685 if (bc->nbranch > 0) { in p_branch_fix_tail()
686 AHEAD(bc->fwd); in p_branch_fix_tail()
687 ASTERN(O_CH, bc->back); in p_branch_fix_tail()
709 * delimiters until we either run out of pattern or need to parse more pattern.
719 else if ((ate > 1 || (bc->outer && !MORE())) && !p_branch_empty(p, bc)) in p_branch_do()
743 p->g->iflags |= USEBOL; in p_bre_pre_parse()
744 p->g->nbol++; in p_bre_pre_parse()
753 if (bc->terminate) { in p_bre_post_parse()
756 p->g->iflags |= USEEOL; in p_bre_post_parse()
757 p->g->neol++; in p_bre_post_parse()
762 - p_re - Top level parser, concatenation and BRE anchoring
764 * Giving end1 as OUT essentially eliminates the end1/end2 check.
778 if (end1 == OUT && end2 == OUT) in p_re()
782 #define SEEEND() (!p->bre ? SEE(end1) : SEETWO(end1, end2)) in p_re()
787 if (p->pre_parse != NULL) in p_re()
788 p->pre_parse(p, &bc); in p_re()
789 while (MORE() && (!p->allowbranch || !SEESPEC('|')) && !SEEEND()) { in p_re()
790 bc.terminate = p->parse_expr(p, &bc); in p_re()
793 if (p->post_parse != NULL) in p_re()
794 p->post_parse(p, &bc); in p_re()
795 (void) REQUIRE(p->gnuext || HERE() != bc.start, REG_EMPTY); in p_re()
800 if (!p->allowbranch) in p_re()
813 if (p->allowbranch) in p_re()
819 - p_simp_re - parse a simple RE, an atom possibly followed by a repetition
846 if (p->gnuext) { in p_simp_re()
876 if (p->g->cflags&REG_NEWLINE) in p_simp_re()
894 p->g->nsub++; in p_simp_re()
895 subno = p->g->nsub; in p_simp_re()
897 p->pbegin[subno] = HERE(); in p_simp_re()
903 p->pend[subno] = HERE(); in p_simp_re()
904 assert(p->pend[subno] != 0); in p_simp_re()
909 case BACKSL|')': /* should not get here -- must be user */ in p_simp_re()
924 i = (c&~BACKSL) - '0'; in p_simp_re()
926 if (p->pend[i] != 0) { in p_simp_re()
927 assert(i <= p->g->nsub); in p_simp_re()
929 assert(p->pbegin[i] != 0); in p_simp_re()
930 assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); in p_simp_re()
931 assert(OP(p->strip[p->pend[i]]) == ORPAREN); in p_simp_re()
932 (void) dupl(p, p->pbegin[i]+1, p->pend[i]); in p_simp_re()
936 p->g->backrefs = 1; in p_simp_re()
941 * a (sub-)expression, counts as a bad repetition operator if it in p_simp_re()
944 (void)REQUIRE(bc->nchain == 0, REG_BADRPT); in p_simp_re()
947 if (p->error != 0) in p_simp_re()
949 p->next--; in p_simp_re()
966 } else if (p->gnuext && EATTWO('\\', '?')) { in p_simp_re()
969 } else if (p->gnuext && EATTWO('\\', '+')) { in p_simp_re()
997 - p_count - parse a repetition count
1007 count = count*10 + ((uch)GETNEXT() - '0'); in p_count()
1016 - p_bracket - parse a bracketed character list
1022 cset *cs; in p_bracket() local
1025 /* Dept of Truly Sickening Special-Case Kludges */ in p_bracket()
1026 if (p->end - p->next > 5) { in p_bracket()
1027 if (strncmp(p->next, "[:<:]]", 6) == 0) { in p_bracket()
1032 if (strncmp(p->next, "[:>:]]", 6) == 0) { in p_bracket()
1039 if ((cs = allocset(p)) == NULL) in p_bracket()
1042 if (p->g->cflags&REG_ICASE) in p_bracket()
1043 cs->icase = 1; in p_bracket()
1045 cs->invert = 1; in p_bracket()
1047 CHadd(p, cs, ']'); in p_bracket()
1048 else if (EAT('-')) in p_bracket()
1049 CHadd(p, cs, '-'); in p_bracket()
1050 while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) in p_bracket()
1051 p_b_term(p, cs); in p_bracket()
1052 if (EAT('-')) in p_bracket()
1053 CHadd(p, cs, '-'); in p_bracket()
1056 if (p->error != 0) /* don't mess things up further */ in p_bracket()
1059 if (cs->invert && p->g->cflags&REG_NEWLINE) in p_bracket()
1060 cs->bmp['\n' >> 3] |= 1 << ('\n' & 7); in p_bracket()
1062 if ((ch = singleton(cs)) != OUT) { /* optimize singleton sets */ in p_bracket()
1064 freeset(p, cs); in p_bracket()
1066 EMIT(OANYOF, (int)(cs - p->g->sets)); in p_bracket()
1087 - p_b_term - parse one term of a bracketed character list
1088 == static void p_b_term(struct parse *p, cset *cs);
1091 p_b_term(struct parse *p, cset *cs) argument
1098 (struct xlocale_collate*)__get_locale()->components[XLC_COLLATE];
1105 case '-':
1118 (void)REQUIRE(c != '-' && c != ']', REG_ECTYPE);
1119 p_b_cclass(p, cs);
1127 (void)REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
1128 p_b_eclass(p, cs);
1134 if (SEE('-') && MORE2() && PEEK2() != ']') {
1137 if (EAT('-'))
1138 finish = '-';
1144 CHadd(p, cs, start);
1147 if (table->__collate_load_error || MB_CUR_MAX > 1) {
1152 CHaddrange(p, cs, start, finish);
1158 CHadd(p, cs, i);
1167 - p_b_pseudoclass - parse a pseudo-class (\w, \W, \s, \S)
1172 cset *cs; local
1174 if ((cs = allocset(p)) == NULL)
1177 if (p->g->cflags&REG_ICASE)
1178 cs->icase = 1;
1182 cs->invert = 1;
1185 p_b_cclass_named(p, cs, "alnum");
1188 cs->invert = 1;
1191 p_b_cclass_named(p, cs, "space");
1197 EMIT(OANYOF, (int)(cs - p->g->sets));
1202 - p_b_cclass - parse a character-class name and deal with it
1203 == static void p_b_cclass(struct parse *p, cset *cs);
1206 p_b_cclass(struct parse *p, cset *cs) argument
1208 const char *sp = p->next;
1214 len = p->next - sp;
1215 if (len >= sizeof(clname) - 1) {
1222 p_b_cclass_named(p, cs, clname);
1225 - p_b_cclass_named - deal with a named character class
1226 == static void p_b_cclass_named(struct parse *p, cset *cs, const char []);
1229 p_b_cclass_named(struct parse *p, cset *cs, const char clname[]) { argument
1236 CHaddtype(p, cs, wct);
1240 - p_b_eclass - parse an equivalence-class name and deal with it
1241 == static void p_b_eclass(struct parse *p, cset *cs);
1246 p_b_eclass(struct parse *p, cset *cs) argument
1251 CHadd(p, cs, c);
1255 - p_b_symbol - parse a character or [..]ed multicharacter collating symbol
1274 - p_b_coll_elem - parse a collating-element name and look it up
1281 const char *sp = p->next;
1293 len = p->next - sp;
1294 for (cp = cnames; cp->name != NULL; cp++)
1295 if (strncmp(cp->name, sp, len) == 0 && strlen(cp->name) == len)
1296 return(cp->code); /* known name */
1300 else if (clen == (size_t)-1 || clen == (size_t)-2)
1308 - may_escape - determine whether 'ch' is escape-able in the current context
1315 if ((p->pflags & PFLAG_LEGACY_ESC) != 0)
1326 * IEEE 1003.1-2008. Some extensions (notably, some GNU extensions) take
1335 if (!(p->g->cflags&REG_EXTENDED))
1357 - othercase - return the case counterpart of an alphabetic
1373 - bothcases - emit a dualcase version of a two-case character
1381 const char *oldnext = p->next;
1382 const char *oldend = p->end;
1388 p->next = bracket;
1391 assert(n != (size_t)-1);
1394 p->end = bracket+n+1;
1396 assert(p->next == p->end);
1397 p->next = oldnext;
1398 p->end = oldend;
1402 - ordinary - emit an ordinary character
1408 cset *cs; local
1410 if ((p->g->cflags&REG_ICASE) && iswalpha(ch) && othercase(ch) != ch)
1419 if ((cs = allocset(p)) == NULL)
1421 CHadd(p, cs, ch);
1422 EMIT(OANYOF, (int)(cs - p->g->sets));
1427 - nonnewline - emit REG_NEWLINE version of OANY
1435 const char *oldnext = p->next;
1436 const char *oldend = p->end;
1439 p->next = bracket;
1440 p->end = bracket+3;
1446 assert(p->next == bracket+3);
1447 p->next = oldnext;
1448 p->end = oldend;
1452 - repeat - generate code for a bounded repetition, recursively if needed
1468 if (p->error != 0) /* head off possible runaway recursion */
1475 DROP(finish-start); /* drop the operand */
1492 case REP(1, N): /* as x?x{1,n-1} */
1502 repeat(p, copy, 1, to-1);
1508 case REP(N, N): /* as xx{m-1,n-1} */
1510 repeat(p, copy, from-1, to-1);
1512 case REP(N, INF): /* as xx{n-1,INF} */
1514 repeat(p, copy, from-1, to);
1523 - wgetnext - helper function for WGETNEXT() macro. Gets the next wide
1524 - character from the parse struct, signals a REG_ILLSEQ error if the
1525 - character can't be converted. Returns the number of bytes consumed.
1535 n = mbrtowc(&wc, p->next, p->end - p->next, &mbs);
1536 if (n == (size_t)-1 || n == (size_t)-2) {
1542 p->next += n;
1547 - seterr - set an error condition
1553 if (p->error == 0) /* keep earliest error condition */
1554 p->error = e;
1555 p->next = nuls; /* try to bring things to a halt */
1556 p->end = nuls;
1557 return(0); /* make the return value well-defined */
1561 - allocset - allocate a set of characters for []
1567 cset *cs, *ncs; local
1569 ncs = reallocarray(p->g->sets, p->g->ncsets + 1, sizeof(*ncs));
1574 p->g->sets = ncs;
1575 cs = &p->g->sets[p->g->ncsets++];
1576 memset(cs, 0, sizeof(*cs));
1578 return(cs);
1582 - freeset - free a now-unused set
1583 == static void freeset(struct parse *p, cset *cs);
1586 freeset(struct parse *p, cset *cs) argument
1588 cset *top = &p->g->sets[p->g->ncsets];
1590 free(cs->wides);
1591 free(cs->ranges);
1592 free(cs->types);
1593 memset(cs, 0, sizeof(*cs));
1594 if (cs == top-1) /* recover only the easy case */
1595 p->g->ncsets--;
1599 - singleton - Determine whether a set contains only one character,
1600 - returning it if so, otherwise returning OUT.
1603 singleton(cset *cs) argument
1608 if (cs->nranges != 0 || cs->ntypes != 0 || cs->icase != 0)
1609 return (OUT);
1611 if (cs->nwides > 1)
1612 return (OUT);
1616 if (CHIN(cs, i)) {
1622 return (OUT);
1625 if (cs->nwides == 0)
1628 return (OUT);
1630 if (cs->nwides == 1)
1631 return (cs->wides[0]);
1633 return (OUT);
1637 - CHadd - add character to character set.
1640 CHadd(struct parse *p, cset *cs, wint_t ch) argument
1645 cs->bmp[ch >> 3] |= 1 << (ch & 7);
1647 newwides = reallocarray(cs->wides, cs->nwides + 1,
1648 sizeof(*cs->wides));
1653 cs->wides = newwides;
1654 cs->wides[cs->nwides++] = ch;
1656 if (cs->icase) {
1658 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1660 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1665 - CHaddrange - add all characters in the range [min,max] to a character set.
1668 CHaddrange(struct parse *p, cset *cs, wint_t min, wint_t max) argument
1673 CHadd(p, cs, min);
1676 newranges = reallocarray(cs->ranges, cs->nranges + 1,
1677 sizeof(*cs->ranges));
1682 cs->ranges = newranges;
1683 cs->ranges[cs->nranges].min = min;
1684 cs->ranges[cs->nranges].max = max;
1685 cs->nranges++;
1689 - CHaddtype - add all characters of a certain type to a character set.
1692 CHaddtype(struct parse *p, cset *cs, wctype_t wct) argument
1699 CHadd(p, cs, i);
1700 newtypes = reallocarray(cs->types, cs->ntypes + 1,
1701 sizeof(*cs->types));
1706 cs->types = newtypes;
1707 cs->types[cs->ntypes++] = wct;
1711 - dupl - emit a duplicate of a bunch of sops
1720 sopno len = finish - start;
1725 if (!enlarge(p, p->ssize + len)) /* this many unexpected additions */
1727 (void) memcpy((char *)(p->strip + p->slen),
1728 (char *)(p->strip + start), (size_t)len*sizeof(sop));
1729 p->slen += len;
1734 - doemit - emit a strip operator
1738 * hard-case backup, but it's just too big and messy unless there are
1745 if (p->error != 0)
1752 if (p->slen >= p->ssize)
1753 if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */
1757 p->strip[p->slen++] = SOP(op, opnd);
1761 - doinsert - insert a sop into the strip
1772 if (p->error != 0)
1778 s = p->strip[sn];
1783 if (p->pbegin[i] >= pos) {
1784 p->pbegin[i]++;
1786 if (p->pend[i] >= pos) {
1787 p->pend[i]++;
1791 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
1792 (HERE()-pos-1)*sizeof(sop));
1793 p->strip[pos] = s;
1797 - dofwd - complete a forward reference
1804 if (p->error != 0)
1808 p->strip[pos] = OP(p->strip[pos]) | value;
1812 - enlarge - enlarge the strip
1820 if (p->ssize >= size)
1823 sp = reallocarray(p->strip, size, sizeof(sop));
1828 p->strip = sp;
1829 p->ssize = size;
1834 - stripsnug - compact the strip
1840 g->nstates = p->slen;
1841 g->strip = reallocarray((char *)p->strip, p->slen, sizeof(sop));
1842 if (g->strip == NULL) {
1844 g->strip = p->strip;
1849 - findmust - fill in must and mlen with longest mandatory literal string
1873 if (p->error != 0)
1879 * UTF-8 (see RFC 3629).
1882 strcmp(_CurrentRuneLocale->__encoding, "UTF-8") != 0)
1888 g->moffset = 0;
1889 scan = g->strip + 1;
1896 newstart = scan - 1;
1899 if (clen == (size_t)-1)
1910 scan--;
1917 g->iflags |= BAD;
1933 if (newlen > (sopno)g->mlen) { /* ends one */
1935 g->mlen = newlen;
1936 if (offset > -1) {
1937 g->moffset += offset;
1940 g->moffset = offset;
1942 if (offset > -1)
1948 if (newlen > (sopno)g->mlen) { /* ends one */
1950 g->mlen = newlen;
1951 if (offset > -1) {
1952 g->moffset += offset;
1955 g->moffset = offset;
1957 if (offset > -1)
1960 if (offset > -1)
1966 if (newlen > (sopno)g->mlen) { /* ends one */
1968 g->mlen = newlen;
1969 if (offset > -1) {
1970 g->moffset += offset;
1973 g->moffset = offset;
1975 if (offset > -1)
1978 if (offset > -1)
1985 * to calculate the offset -- so we give up;
1989 if (newlen > (sopno)g->mlen) { /* ends one */
1991 g->mlen = newlen;
1992 if (offset > -1)
1993 g->moffset += offset;
1995 g->moffset = offset;
1997 offset = -1;
2003 if (g->mlen == 0) { /* there isn't one */
2004 g->moffset = -1;
2009 g->must = malloc((size_t)g->mlen + 1);
2010 if (g->must == NULL) { /* argh; just forget it */
2011 g->mlen = 0;
2012 g->moffset = -1;
2015 cp = g->must;
2018 while (cp < g->must + g->mlen) {
2022 assert(clen != (size_t)-1);
2025 assert(cp == g->must + g->mlen);
2030 - altoffset - choose biggest offset among multiple choices
2044 if (offset == -1)
2045 return -1;
2060 if (try == -1)
2061 return -1;
2062 scan--;
2068 return -1;
2088 try = -1;
2091 if (try == -1)
2092 return -1;
2103 - computejumps - compute char jumps for BM scan
2106 * This algorithm assumes g->must exists and is has size greater than
2120 if (p->error != 0)
2123 g->charjump = (int *)malloc((NC_MAX + 1) * sizeof(int));
2124 if (g->charjump == NULL) /* Not a fatal error */
2127 g->charjump = &g->charjump[-(CHAR_MIN)];
2133 g->charjump[ch] = g->mlen;
2140 for (mindex = 0; mindex < g->mlen; mindex++)
2141 g->charjump[(int)g->must[mindex]] = g->mlen - mindex - 1;
2145 - computematchjumps - compute match jumps for BM scan
2148 * This algorithm assumes g->must exists and is has size greater than
2153 * on the already-matched suffix.
2154 * Notice that all values here are minus (g->mlen-1), because of the way
2165 * of k+1...k+mlen-i-1
2169 if (p->error != 0)
2172 pmatches = (int*) malloc(g->mlen * sizeof(int));
2174 g->matchjump = NULL;
2178 g->matchjump = (int*) malloc(g->mlen * sizeof(int));
2179 if (g->matchjump == NULL) { /* Not a fatal error */
2185 for (mindex = 0; mindex < g->mlen; mindex++)
2186 g->matchjump[mindex] = 2*g->mlen - mindex - 1;
2189 for (mindex = g->mlen - 1, suffix = g->mlen; mindex >= 0;
2190 mindex--, suffix--) {
2199 while (suffix < g->mlen
2200 && g->must[mindex] != g->must[suffix]) {
2201 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2202 g->mlen - mindex - 1);
2212 g->matchjump[mindex] = MIN(g->matchjump[mindex],
2213 g->mlen + suffix - mindex);
2216 while (suffix < g->mlen) {
2217 while (suffix <= ssuffix && suffix < g->mlen) {
2218 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2219 g->mlen + ssuffix - suffix);
2222 if (suffix < g->mlen)
2230 - pluscount - count + nesting
2241 if (p->error != 0)
2244 scan = g->strip + 1;
2254 plusnest--;
2259 g->iflags |= BAD;