Lines Matching +full:cs +full:- +full:number
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
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) */
91 int ncsalloc; /* number of csets allocated */
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()
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®_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()
602 } else /* single number with comma */ in p_ere_exp()
604 } else /* just a single number */ in p_ere_exp()
627 - p_str - string (no metacharacters) "parser"
640 * parsing, return the number of delimiters that we ate.
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()
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
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®_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()
979 } else /* single number with comma */ in p_simp_re()
981 } else /* just a single number */ 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®_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®_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®_ICASE)
1178 cs->icase = 1;
1182 cs->invert = 1;
1185 p_b_cclass_named(p, cs, "alnum");
1186 CHadd(p, cs, '_');
1189 cs->invert = 1;
1192 p_b_cclass_named(p, cs, "space");
1198 EMIT(OANYOF, (int)(cs - p->g->sets));
1203 - p_b_cclass - parse a character-class name and deal with it
1204 == static void p_b_cclass(struct parse *p, cset *cs);
1207 p_b_cclass(struct parse *p, cset *cs) argument
1209 const char *sp = p->next;
1215 len = p->next - sp;
1216 if (len >= sizeof(clname) - 1) {
1223 p_b_cclass_named(p, cs, clname);
1226 - p_b_cclass_named - deal with a named character class
1227 == static void p_b_cclass_named(struct parse *p, cset *cs, const char []);
1230 p_b_cclass_named(struct parse *p, cset *cs, const char clname[]) { argument
1237 CHaddtype(p, cs, wct);
1241 - p_b_eclass - parse an equivalence-class name and deal with it
1242 == static void p_b_eclass(struct parse *p, cset *cs);
1247 p_b_eclass(struct parse *p, cset *cs) argument
1252 CHadd(p, cs, c);
1256 - p_b_symbol - parse a character or [..]ed multicharacter collating symbol
1275 - p_b_coll_elem - parse a collating-element name and look it up
1282 const char *sp = p->next;
1294 len = p->next - sp;
1295 for (cp = cnames; cp->name != NULL; cp++)
1296 if (strncmp(cp->name, sp, len) == 0 && strlen(cp->name) == len)
1297 return(cp->code); /* known name */
1301 else if (clen == (size_t)-1 || clen == (size_t)-2)
1309 - may_escape - determine whether 'ch' is escape-able in the current context
1316 if ((p->pflags & PFLAG_LEGACY_ESC) != 0)
1327 * IEEE 1003.1-2008. Some extensions (notably, some GNU extensions) take
1336 if (!(p->g->cflags®_EXTENDED))
1358 - othercase - return the case counterpart of an alphabetic
1374 - bothcases - emit a dualcase version of a two-case character
1382 const char *oldnext = p->next;
1383 const char *oldend = p->end;
1389 p->next = bracket;
1392 assert(n != (size_t)-1);
1395 p->end = bracket+n+1;
1397 assert(p->next == p->end);
1398 p->next = oldnext;
1399 p->end = oldend;
1403 - ordinary - emit an ordinary character
1409 cset *cs; local
1411 if ((p->g->cflags®_ICASE) && iswalpha(ch) && othercase(ch) != ch)
1420 if ((cs = allocset(p)) == NULL)
1422 CHadd(p, cs, ch);
1423 EMIT(OANYOF, (int)(cs - p->g->sets));
1428 - nonnewline - emit REG_NEWLINE version of OANY
1436 const char *oldnext = p->next;
1437 const char *oldend = p->end;
1440 p->next = bracket;
1441 p->end = bracket+3;
1447 assert(p->next == bracket+3);
1448 p->next = oldnext;
1449 p->end = oldend;
1453 - repeat - generate code for a bounded repetition, recursively if needed
1459 int from, /* repeated from this number */
1460 int to) /* to this number of times (maybe INFINITY) */
1469 if (p->error != 0) /* head off possible runaway recursion */
1476 DROP(finish-start); /* drop the operand */
1493 case REP(1, N): /* as x?x{1,n-1} */
1503 repeat(p, copy, 1, to-1);
1509 case REP(N, N): /* as xx{m-1,n-1} */
1511 repeat(p, copy, from-1, to-1);
1513 case REP(N, INF): /* as xx{n-1,INF} */
1515 repeat(p, copy, from-1, to);
1524 - wgetnext - helper function for WGETNEXT() macro. Gets the next wide
1525 - character from the parse struct, signals a REG_ILLSEQ error if the
1526 - character can't be converted. Returns the number of bytes consumed.
1536 n = mbrtowc(&wc, p->next, p->end - p->next, &mbs);
1537 if (n == (size_t)-1 || n == (size_t)-2) {
1543 p->next += n;
1548 - seterr - set an error condition
1554 if (p->error == 0) /* keep earliest error condition */
1555 p->error = e;
1556 p->next = nuls; /* try to bring things to a halt */
1557 p->end = nuls;
1558 return(0); /* make the return value well-defined */
1562 - allocset - allocate a set of characters for []
1568 cset *cs, *ncs; local
1570 ncs = reallocarray(p->g->sets, p->g->ncsets + 1, sizeof(*ncs));
1575 p->g->sets = ncs;
1576 cs = &p->g->sets[p->g->ncsets++];
1577 memset(cs, 0, sizeof(*cs));
1579 return(cs);
1583 - freeset - free a now-unused set
1584 == static void freeset(struct parse *p, cset *cs);
1587 freeset(struct parse *p, cset *cs) argument
1589 cset *top = &p->g->sets[p->g->ncsets];
1591 free(cs->wides);
1592 free(cs->ranges);
1593 free(cs->types);
1594 memset(cs, 0, sizeof(*cs));
1595 if (cs == top-1) /* recover only the easy case */
1596 p->g->ncsets--;
1600 - singleton - Determine whether a set contains only one character,
1601 - returning it if so, otherwise returning OUT.
1604 singleton(cset *cs) argument
1609 if (cs->nranges != 0 || cs->ntypes != 0 || cs->icase != 0)
1612 if (cs->nwides > 1)
1615 /* Count the number of characters present in the bitmap */
1617 if (CHIN(cs, i)) {
1626 if (cs->nwides == 0)
1631 if (cs->nwides == 1)
1632 return (cs->wides[0]);
1638 - CHadd - add character to character set.
1641 CHadd(struct parse *p, cset *cs, wint_t ch) argument
1646 cs->bmp[ch >> 3] |= 1 << (ch & 7);
1648 newwides = reallocarray(cs->wides, cs->nwides + 1,
1649 sizeof(*cs->wides));
1654 cs->wides = newwides;
1655 cs->wides[cs->nwides++] = ch;
1657 if (cs->icase) {
1659 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1661 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1666 - CHaddrange - add all characters in the range [min,max] to a character set.
1669 CHaddrange(struct parse *p, cset *cs, wint_t min, wint_t max) argument
1674 CHadd(p, cs, min);
1677 newranges = reallocarray(cs->ranges, cs->nranges + 1,
1678 sizeof(*cs->ranges));
1683 cs->ranges = newranges;
1684 cs->ranges[cs->nranges].min = min;
1685 cs->ranges[cs->nranges].max = max;
1686 cs->nranges++;
1690 - CHaddtype - add all characters of a certain type to a character set.
1693 CHaddtype(struct parse *p, cset *cs, wctype_t wct) argument
1700 CHadd(p, cs, i);
1701 newtypes = reallocarray(cs->types, cs->ntypes + 1,
1702 sizeof(*cs->types));
1707 cs->types = newtypes;
1708 cs->types[cs->ntypes++] = wct;
1712 - dupl - emit a duplicate of a bunch of sops
1721 sopno len = finish - start;
1726 if (!enlarge(p, p->ssize + len)) /* this many unexpected additions */
1728 (void) memcpy((char *)(p->strip + p->slen),
1729 (char *)(p->strip + start), (size_t)len*sizeof(sop));
1730 p->slen += len;
1735 - doemit - emit a strip operator
1739 * hard-case backup, but it's just too big and messy unless there are
1746 if (p->error != 0)
1753 if (p->slen >= p->ssize)
1754 if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */
1758 p->strip[p->slen++] = SOP(op, opnd);
1762 - doinsert - insert a sop into the strip
1773 if (p->error != 0)
1779 s = p->strip[sn];
1784 if (p->pbegin[i] >= pos) {
1785 p->pbegin[i]++;
1787 if (p->pend[i] >= pos) {
1788 p->pend[i]++;
1792 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
1793 (HERE()-pos-1)*sizeof(sop));
1794 p->strip[pos] = s;
1798 - dofwd - complete a forward reference
1805 if (p->error != 0)
1809 p->strip[pos] = OP(p->strip[pos]) | value;
1813 - enlarge - enlarge the strip
1821 if (p->ssize >= size)
1824 sp = reallocarray(p->strip, size, sizeof(sop));
1829 p->strip = sp;
1830 p->ssize = size;
1835 - stripsnug - compact the strip
1841 g->nstates = p->slen;
1842 g->strip = reallocarray((char *)p->strip, p->slen, sizeof(sop));
1843 if (g->strip == NULL) {
1845 g->strip = p->strip;
1850 - findmust - fill in must and mlen with longest mandatory literal string
1874 if (p->error != 0)
1880 * UTF-8 (see RFC 3629).
1883 strcmp(_CurrentRuneLocale->__encoding, "UTF-8") != 0)
1889 g->moffset = 0;
1890 scan = g->strip + 1;
1897 newstart = scan - 1;
1900 if (clen == (size_t)-1)
1911 scan--;
1918 g->iflags |= BAD;
1934 if (newlen > (sopno)g->mlen) { /* ends one */
1936 g->mlen = newlen;
1937 if (offset > -1) {
1938 g->moffset += offset;
1941 g->moffset = offset;
1943 if (offset > -1)
1949 if (newlen > (sopno)g->mlen) { /* ends one */
1951 g->mlen = newlen;
1952 if (offset > -1) {
1953 g->moffset += offset;
1956 g->moffset = offset;
1958 if (offset > -1)
1961 if (offset > -1)
1967 if (newlen > (sopno)g->mlen) { /* ends one */
1969 g->mlen = newlen;
1970 if (offset > -1) {
1971 g->moffset += offset;
1974 g->moffset = offset;
1976 if (offset > -1)
1979 if (offset > -1)
1986 * to calculate the offset -- so we give up;
1990 if (newlen > (sopno)g->mlen) { /* ends one */
1992 g->mlen = newlen;
1993 if (offset > -1)
1994 g->moffset += offset;
1996 g->moffset = offset;
1998 offset = -1;
2004 if (g->mlen == 0) { /* there isn't one */
2005 g->moffset = -1;
2010 g->must = malloc((size_t)g->mlen + 1);
2011 if (g->must == NULL) { /* argh; just forget it */
2012 g->mlen = 0;
2013 g->moffset = -1;
2016 cp = g->must;
2019 while (cp < g->must + g->mlen) {
2023 assert(clen != (size_t)-1);
2026 assert(cp == g->must + g->mlen);
2031 - altoffset - choose biggest offset among multiple choices
2045 if (offset == -1)
2046 return -1;
2061 if (try == -1)
2062 return -1;
2063 scan--;
2069 return -1;
2089 try = -1;
2092 if (try == -1)
2093 return -1;
2104 - computejumps - compute char jumps for BM scan
2107 * This algorithm assumes g->must exists and is has size greater than
2111 * A char jump is the number of characters one needs to jump based on
2121 if (p->error != 0)
2124 g->charjump = (int *)malloc((NC_MAX + 1) * sizeof(int));
2125 if (g->charjump == NULL) /* Not a fatal error */
2128 g->charjump = &g->charjump[-(CHAR_MIN)];
2131 * is equal to the number of characters in the pattern.
2134 g->charjump[ch] = g->mlen;
2141 for (mindex = 0; mindex < g->mlen; mindex++)
2142 g->charjump[(int)g->must[mindex]] = g->mlen - mindex - 1;
2146 - computematchjumps - compute match jumps for BM scan
2149 * This algorithm assumes g->must exists and is has size greater than
2153 * A match jump is the number of characters one needs to advance based
2154 * on the already-matched suffix.
2155 * Notice that all values here are minus (g->mlen-1), because of the way
2166 * of k+1...k+mlen-i-1
2170 if (p->error != 0)
2173 pmatches = (int*) malloc(g->mlen * sizeof(int));
2175 g->matchjump = NULL;
2179 g->matchjump = (int*) malloc(g->mlen * sizeof(int));
2180 if (g->matchjump == NULL) { /* Not a fatal error */
2186 for (mindex = 0; mindex < g->mlen; mindex++)
2187 g->matchjump[mindex] = 2*g->mlen - mindex - 1;
2190 for (mindex = g->mlen - 1, suffix = g->mlen; mindex >= 0;
2191 mindex--, suffix--) {
2200 while (suffix < g->mlen
2201 && g->must[mindex] != g->must[suffix]) {
2202 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2203 g->mlen - mindex - 1);
2213 g->matchjump[mindex] = MIN(g->matchjump[mindex],
2214 g->mlen + suffix - mindex);
2217 while (suffix < g->mlen) {
2218 while (suffix <= ssuffix && suffix < g->mlen) {
2219 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2220 g->mlen + ssuffix - suffix);
2223 if (suffix < g->mlen)
2231 - pluscount - count + nesting
2242 if (p->error != 0)
2245 scan = g->strip + 1;
2255 plusnest--;
2260 g->iflags |= BAD;