Lines Matching +full:- +full:c
1 /*-
2 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3 * Copyright (c) 1992, 1993, 1994
33 * @(#)regcomp.c 8.5 (Berkeley) 3/20/94
60 char *end; /* end of string (-> NUL normally) */
67 # define NPAREN 10 /* we need to remember () 1-9 for back refs */
68 sopno pbegin[NPAREN]; /* -> ( ([0] unused) */
69 sopno pend[NPAREN]; /* -> ) ([0] unused) */
74 extern "C" {
77 /* === regcomp.c === */
109 static int isinsets(struct re_guts *g, int c);
135 #define PEEK() (*p->next)
136 #define PEEK2() (*(p->next+1))
137 #define MORE() (p->next < p->end)
138 #define MORE2() (p->next+1 < p->end)
139 #define SEE(c) (MORE() && PEEK() == (c)) argument
141 #define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) argument
143 #define NEXT() (p->next++)
144 #define NEXT2() (p->next += 2)
145 #define NEXTn(n) (p->next += (n))
146 #define GETNEXT() (*p->next++)
149 #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) argument
150 #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) argument
151 #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) argument
153 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
154 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
155 #define ASTERN(sop, pos) EMIT(sop, HERE()-pos)
156 #define HERE() (p->slen)
157 #define THERE() (p->slen - 1)
158 #define THERETHERE() (p->slen - 2)
159 #define DROP(n) (p->slen -= (n))
171 - regcomp - interface for parser and compilation
201 if (preg->re_endp < pattern) in regcomp()
203 len = preg->re_endp - pattern; in regcomp()
211 p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ in regcomp()
212 p->strip = (sop *)malloc(p->ssize * sizeof(sop)); in regcomp()
213 p->slen = 0; in regcomp()
214 if (p->strip == NULL) { in regcomp()
220 p->g = g; in regcomp()
221 p->next = (char *)pattern; /* convenience; we do not modify it */ in regcomp()
222 p->end = p->next + len; in regcomp()
223 p->error = 0; in regcomp()
224 p->ncsalloc = 0; in regcomp()
226 p->pbegin[i] = 0; in regcomp()
227 p->pend[i] = 0; in regcomp()
229 g->csetsize = NC; in regcomp()
230 g->sets = NULL; in regcomp()
231 g->setbits = NULL; in regcomp()
232 g->ncsets = 0; in regcomp()
233 g->cflags = cflags; in regcomp()
234 g->iflags = 0; in regcomp()
235 g->nbol = 0; in regcomp()
236 g->neol = 0; in regcomp()
237 g->must = NULL; in regcomp()
238 g->moffset = -1; in regcomp()
239 g->charjump = NULL; in regcomp()
240 g->matchjump = NULL; in regcomp()
241 g->mlen = 0; in regcomp()
242 g->nsub = 0; in regcomp()
243 g->ncategories = 1; /* category 0 is "everything else" */ in regcomp()
244 g->categories = &g->catspace[-(CHAR_MIN)]; in regcomp()
245 (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); in regcomp()
246 g->backrefs = 0; in regcomp()
250 g->firststate = THERE(); in regcomp()
258 g->laststate = THERE(); in regcomp()
264 /* only use Boyer-Moore algorithm if the pattern is bigger in regcomp()
267 if(g->mlen > 3) { in regcomp()
270 if(g->matchjump == NULL && g->charjump != NULL) { in regcomp()
271 free(g->charjump); in regcomp()
272 g->charjump = NULL; in regcomp()
275 g->nplus = pluscount(p, g); in regcomp()
276 g->magic = MAGIC2; in regcomp()
277 preg->re_nsub = g->nsub; in regcomp()
278 preg->re_g = g; in regcomp()
279 preg->re_magic = MAGIC1; in regcomp()
282 if (g->iflags&BAD) in regcomp()
287 if (p->error != 0) /* lose */ in regcomp()
289 return(p->error); in regcomp()
293 - p_ere - ERE parser top level, concatenation and alternation
300 char c; in p_ere() local
309 while (MORE() && (c = PEEK()) != '|' && c != stop) in p_ere()
329 if (!first) { /* tail-end fixups */ in p_ere()
338 - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
344 char c; in p_ere_exp() local
352 c = GETNEXT(); in p_ere_exp()
355 switch (c) { in p_ere_exp()
358 p->g->nsub++; in p_ere_exp()
359 subno = p->g->nsub; in p_ere_exp()
361 p->pbegin[subno] = HERE(); in p_ere_exp()
366 p->pend[subno] = HERE(); in p_ere_exp()
367 assert(p->pend[subno] != 0); in p_ere_exp()
377 * other 1003.2 regular-expression reviewers noticed it at in p_ere_exp()
386 p->g->iflags |= USEBOL; in p_ere_exp()
387 p->g->nbol++; in p_ere_exp()
392 p->g->iflags |= USEEOL; in p_ere_exp()
393 p->g->neol++; in p_ere_exp()
404 if (p->g->cflags®_NEWLINE) in p_ere_exp()
414 c = GETNEXT(); in p_ere_exp()
415 ordinary(p, c); in p_ere_exp()
421 ordinary(p, c); in p_ere_exp()
427 c = PEEK(); in p_ere_exp()
429 if (!( c == '*' || c == '+' || c == '?' || in p_ere_exp()
430 (c == '{' && MORE2() && isdigit((uch)PEEK2())) )) in p_ere_exp()
435 switch (c) { in p_ere_exp()
478 c = PEEK(); in p_ere_exp()
479 if (!( c == '*' || c == '+' || c == '?' || in p_ere_exp()
480 (c == '{' && MORE2() && isdigit((uch)PEEK2())) ) ) in p_ere_exp()
486 - p_str - string (no metacharacters) "parser"
498 - p_bre - BRE parser top level, anchoring and concatenation
520 p->g->iflags |= USEBOL; in p_bre()
521 p->g->nbol++; in p_bre()
530 p->g->iflags |= USEEOL; in p_bre()
531 p->g->neol++; in p_bre()
538 - p_simp_re - parse a simple RE, an atom possibly followed by a repetition
545 int c; in p_simp_re() local
556 c = GETNEXT(); in p_simp_re()
557 if (c == '\\') { in p_simp_re()
559 c = BACKSL | GETNEXT(); in p_simp_re()
561 switch (c) { in p_simp_re()
563 if (p->g->cflags®_NEWLINE) in p_simp_re()
575 p->g->nsub++; in p_simp_re()
576 subno = p->g->nsub; in p_simp_re()
578 p->pbegin[subno] = HERE(); in p_simp_re()
584 p->pend[subno] = HERE(); in p_simp_re()
585 assert(p->pend[subno] != 0); in p_simp_re()
590 case BACKSL|')': /* should not get here -- must be user */ in p_simp_re()
603 i = (c&~BACKSL) - '0'; in p_simp_re()
605 if (p->pend[i] != 0) { in p_simp_re()
606 assert(i <= p->g->nsub); in p_simp_re()
608 assert(p->pbegin[i] != 0); in p_simp_re()
609 assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); in p_simp_re()
610 assert(OP(p->strip[p->pend[i]]) == ORPAREN); in p_simp_re()
611 (void) dupl(p, p->pbegin[i]+1, p->pend[i]); in p_simp_re()
615 p->g->backrefs = 1; in p_simp_re()
621 ordinary(p, (char)c); in p_simp_re()
648 } else if (c == '$') /* $ (but not \$) ends it */ in p_simp_re()
655 - p_count - parse a repetition count
665 count = count*10 + (GETNEXT() - '0'); in p_count()
674 - p_bracket - parse a bracketed character list
686 /* Dept of Truly Sickening Special-Case Kludges */ in p_bracket()
687 if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) { in p_bracket()
692 if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) { in p_bracket()
698 if (p->error != 0) /* don't mess things up further */ in p_bracket()
705 else if (EAT('-')) in p_bracket()
706 CHadd(cs, '-'); in p_bracket()
707 while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) in p_bracket()
709 if (EAT('-')) in p_bracket()
710 CHadd(cs, '-'); in p_bracket()
713 if (p->g->cflags®_ICASE) { in p_bracket()
717 for (i = p->g->csetsize - 1; i >= 0; i--) in p_bracket()
723 if (cs->multis != NULL) in p_bracket()
729 for (i = p->g->csetsize - 1; i >= 0; i--) in p_bracket()
734 if (p->g->cflags®_NEWLINE) in p_bracket()
736 if (cs->multis != NULL) in p_bracket()
740 assert(cs->multis == NULL); /* xxx */ in p_bracket()
750 - p_b_term - parse one term of a bracketed character list
756 char c; in p_b_term() local
763 c = (MORE2()) ? PEEK2() : '\0'; in p_b_term()
765 case '-': in p_b_term()
770 c = '\0'; in p_b_term()
774 switch (c) { in p_b_term()
778 c = PEEK(); in p_b_term()
779 (void)REQUIRE(c != '-' && c != ']', REG_ECTYPE); in p_b_term()
787 c = PEEK(); in p_b_term()
788 (void)REQUIRE(c != '-' && c != ']', REG_ECOLLATE); in p_b_term()
796 if (SEE('-') && MORE2() && PEEK2() != ']') { in p_b_term()
799 if (EAT('-')) in p_b_term()
800 finish = '-'; in p_b_term()
827 - p_b_cclass - parse a character-class name and deal with it
833 int c; in p_b_cclass() local
834 char *sp = p->next; in p_b_cclass()
840 len = p->next - sp; in p_b_cclass()
841 for (cp = cclasses; cp->name != NULL; cp++) in p_b_cclass()
842 if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') in p_b_cclass()
844 if (cp->name == NULL) { in p_b_cclass()
850 switch (cp->fidx) { in p_b_cclass()
852 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
853 if (isalnum((uch)c)) in p_b_cclass()
854 CHadd(cs, c); in p_b_cclass()
857 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
858 if (isalpha((uch)c)) in p_b_cclass()
859 CHadd(cs, c); in p_b_cclass()
862 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
863 if (isblank((uch)c)) in p_b_cclass()
864 CHadd(cs, c); in p_b_cclass()
867 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
868 if (iscntrl((uch)c)) in p_b_cclass()
869 CHadd(cs, c); in p_b_cclass()
872 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
873 if (isdigit((uch)c)) in p_b_cclass()
874 CHadd(cs, c); in p_b_cclass()
877 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
878 if (isgraph((uch)c)) in p_b_cclass()
879 CHadd(cs, c); in p_b_cclass()
882 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
883 if (islower((uch)c)) in p_b_cclass()
884 CHadd(cs, c); in p_b_cclass()
887 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
888 if (isprint((uch)c)) in p_b_cclass()
889 CHadd(cs, c); in p_b_cclass()
892 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
893 if (ispunct((uch)c)) in p_b_cclass()
894 CHadd(cs, c); in p_b_cclass()
897 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
898 if (isspace((uch)c)) in p_b_cclass()
899 CHadd(cs, c); in p_b_cclass()
902 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
903 if (isupper((uch)c)) in p_b_cclass()
904 CHadd(cs, c); in p_b_cclass()
907 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in p_b_cclass()
908 if (isxdigit((uch)c)) in p_b_cclass()
909 CHadd(cs, c); in p_b_cclass()
913 for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) in p_b_cclass()
919 - p_b_eclass - parse an equivalence-class name and deal with it
927 char c; in p_b_eclass() local
929 c = p_b_coll_elem(p, '='); in p_b_eclass()
930 CHadd(cs, c); in p_b_eclass()
934 - p_b_symbol - parse a character or [..]ed multicharacter collating symbol
953 - p_b_coll_elem - parse a collating-element name and look it up
960 char *sp = p->next; in p_b_coll_elem()
970 len = p->next - sp; in p_b_coll_elem()
971 for (cp = cnames; cp->name != NULL; cp++) in p_b_coll_elem()
972 if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') in p_b_coll_elem()
973 return(cp->code); /* known name */ in p_b_coll_elem()
981 - othercase - return the case counterpart of an alphabetic
998 - bothcases - emit a dualcase version of a two-case character
1006 char *oldnext = p->next; in bothcases()
1007 char *oldend = p->end; in bothcases()
1012 p->next = bracket; in bothcases()
1013 p->end = bracket+2; in bothcases()
1018 assert(p->next == bracket+2); in bothcases()
1019 p->next = oldnext; in bothcases()
1020 p->end = oldend; in bothcases()
1024 - ordinary - emit an ordinary character
1030 cat_t *cap = p->g->categories; in ordinary()
1032 if ((p->g->cflags®_ICASE) && isalpha((uch)ch) && othercase(ch) != ch) in ordinary()
1037 cap[ch] = p->g->ncategories++; in ordinary()
1042 - nonnewline - emit REG_NEWLINE version of OANY
1050 char *oldnext = p->next; in nonnewline()
1051 char *oldend = p->end; in nonnewline()
1054 p->next = bracket; in nonnewline()
1055 p->end = bracket+3; in nonnewline()
1061 assert(p->next == bracket+3); in nonnewline()
1062 p->next = oldnext; in nonnewline()
1063 p->end = oldend; in nonnewline()
1067 - repeat - generate code for a bounded repetition, recursively if needed
1083 if (p->error != 0) /* head off possible runaway recursion */ in repeat()
1090 DROP(finish-start); /* drop the operand */ in repeat()
1107 case REP(1, N): /* as x?x{1,n-1} */ in repeat()
1117 repeat(p, copy, 1, to-1); in repeat()
1123 case REP(N, N): /* as xx{m-1,n-1} */ in repeat()
1125 repeat(p, copy, from-1, to-1); in repeat()
1127 case REP(N, INF): /* as xx{n-1,INF} */ in repeat()
1129 repeat(p, copy, from-1, to); in repeat()
1138 - seterr - set an error condition
1144 if (p->error == 0) /* keep earliest error condition */ in seterr()
1145 p->error = e; in seterr()
1146 free(p->g->sets); in seterr()
1147 free(p->g->setbits); in seterr()
1148 p->g->sets = NULL; in seterr()
1149 p->g->setbits = NULL; in seterr()
1150 p->next = nuls; /* try to bring things to a halt */ in seterr()
1151 p->end = nuls; in seterr()
1152 return(0); /* make the return value well-defined */ in seterr()
1156 - allocset - allocate a set of characters for []
1162 int no = p->g->ncsets++; in allocset()
1166 size_t css = (size_t)p->g->csetsize; in allocset()
1170 if (no >= p->ncsalloc) { /* need another column of space */ in allocset()
1171 p->ncsalloc += CHAR_BIT; in allocset()
1172 nc = p->ncsalloc; in allocset()
1176 cs = realloc(p->g->sets, nc * sizeof(cset)); in allocset()
1181 p->g->sets = cs; in allocset()
1183 setbits = realloc(p->g->setbits, nbytes); in allocset()
1188 p->g->setbits = setbits; in allocset()
1193 (void) memset(setbits + (nbytes - css), 0, css); in allocset()
1196 cs = &p->g->sets[no]; in allocset()
1197 cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); in allocset()
1198 cs->mask = 1 << ((no) % CHAR_BIT); in allocset()
1199 cs->hash = 0; in allocset()
1200 cs->smultis = 0; in allocset()
1201 cs->multis = NULL; in allocset()
1207 - freeset - free a now-unused set
1214 cset *top = &p->g->sets[p->g->ncsets]; in freeset()
1215 size_t css = (size_t)p->g->csetsize; in freeset()
1219 if (cs == top-1) /* recover only the easy case */ in freeset()
1220 p->g->ncsets--; in freeset()
1224 - freezeset - final processing on a set of characters
1230 * is done using addition rather than xor -- all ASCII [aA] sets xor to
1236 short h = cs->hash; in freezeset()
1238 cset *top = &p->g->sets[p->g->ncsets]; in freezeset()
1240 size_t css = (size_t)p->g->csetsize; in freezeset()
1243 for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) in freezeset()
1244 if (cs2->hash == h && cs2 != cs) { in freezeset()
1258 return((int)(cs - p->g->sets)); in freezeset()
1262 - firstch - return first character in a set (which must have at least one)
1269 size_t css = (size_t)p->g->csetsize; in firstch()
1279 - nch - number of characters in a set
1286 size_t css = (size_t)p->g->csetsize; in nch()
1297 - mcadd - add a collating element to a cset
1304 size_t oldend = cs->smultis; in mcadd()
1306 cs->smultis += strlen(cp) + 1; in mcadd()
1307 if (cs->multis == NULL) in mcadd()
1308 cs->multis = malloc(cs->smultis); in mcadd()
1310 cs->multis = reallocf(cs->multis, cs->smultis); in mcadd()
1311 if (cs->multis == NULL) { in mcadd()
1316 (void) strcpy(cs->multis + oldend - 1, cp); in mcadd()
1317 cs->multis[cs->smultis - 1] = '\0'; in mcadd()
1321 - mcsub - subtract a collating element from a cset
1332 cs->smultis - (fp + len + 1 - cs->multis)); in mcsub()
1333 cs->smultis -= len; in mcsub()
1335 if (cs->smultis == 0) { in mcsub()
1336 free(cs->multis); in mcsub()
1337 cs->multis = NULL; in mcsub()
1341 cs->multis = reallocf(cs->multis, cs->smultis); in mcsub()
1342 assert(cs->multis != NULL); in mcsub()
1346 - mcin - is a collating element in a cset?
1356 - mcfind - find a collating element in a cset
1364 if (cs->multis == NULL) in mcfind()
1366 for (p = cs->multis; *p != '\0'; p += strlen(p) + 1) in mcfind()
1374 - mcinvert - invert the list of collating elements in a cset
1385 assert(cs->multis == NULL); /* xxx */ in mcinvert()
1389 - mccase - add case counterparts of the list of collating elements in a cset
1400 assert(cs->multis == NULL); /* xxx */ in mccase()
1404 - isinsets - is this character in any sets?
1405 == static int isinsets(struct re_guts *g, int c);
1408 isinsets(struct re_guts *g, int c) in isinsets() argument
1412 int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; in isinsets()
1413 unsigned uc = (uch)c; in isinsets()
1415 for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) in isinsets()
1422 - samesets - are these two characters in exactly the same sets?
1430 int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; in samesets()
1434 for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) in samesets()
1441 - categorize - sort out character categories
1447 cat_t *cats = g->categories; in categorize()
1448 int c; in categorize() local
1453 if (p->error != 0) in categorize()
1456 for (c = CHAR_MIN; c <= CHAR_MAX; c++) in categorize()
1457 if (cats[c] == 0 && isinsets(g, c)) { in categorize()
1458 cat = g->ncategories++; in categorize()
1459 cats[c] = cat; in categorize()
1460 for (c2 = c+1; c2 <= CHAR_MAX; c2++) in categorize()
1461 if (cats[c2] == 0 && samesets(g, c, c2)) in categorize()
1467 - dupl - emit a duplicate of a bunch of sops
1476 sopno len = finish - start; in dupl()
1481 enlarge(p, p->ssize + len); /* this many unexpected additions */ in dupl()
1482 assert(p->ssize >= p->slen + len); in dupl()
1483 (void) memcpy((char *)(p->strip + p->slen), in dupl()
1484 (char *)(p->strip + start), (size_t)len*sizeof(sop)); in dupl()
1485 p->slen += len; in dupl()
1490 - doemit - emit a strip operator
1494 * hard-case backup, but it's just too big and messy unless there are
1501 if (p->error != 0) in doemit()
1508 if (p->slen >= p->ssize) in doemit()
1509 enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */ in doemit()
1510 assert(p->slen < p->ssize); in doemit()
1513 p->strip[p->slen++] = SOP(op, opnd); in doemit()
1517 - doinsert - insert a sop into the strip
1528 if (p->error != 0) in doinsert()
1534 s = p->strip[sn]; in doinsert()
1539 if (p->pbegin[i] >= pos) { in doinsert()
1540 p->pbegin[i]++; in doinsert()
1542 if (p->pend[i] >= pos) { in doinsert()
1543 p->pend[i]++; in doinsert()
1547 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos], in doinsert()
1548 (HERE()-pos-1)*sizeof(sop)); in doinsert()
1549 p->strip[pos] = s; in doinsert()
1553 - dofwd - complete a forward reference
1560 if (p->error != 0) in dofwd()
1564 p->strip[pos] = OP(p->strip[pos]) | value; in dofwd()
1568 - enlarge - enlarge the strip
1576 if (p->ssize >= size) in enlarge()
1579 sp = (sop *)realloc(p->strip, size*sizeof(sop)); in enlarge()
1584 p->strip = sp; in enlarge()
1585 p->ssize = size; in enlarge()
1589 - stripsnug - compact the strip
1595 g->nstates = p->slen; in stripsnug()
1596 g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); in stripsnug()
1597 if (g->strip == NULL) { in stripsnug()
1599 g->strip = p->strip; in stripsnug()
1604 - findmust - fill in must and mlen with longest mandatory literal string
1627 if (p->error != 0) in findmust()
1632 for (cs = 0; cs < g->ncsets; cs++) in findmust()
1633 if (g->sets[cs].multis != NULL) in findmust()
1639 g->moffset = 0; in findmust()
1640 scan = g->strip + 1; in findmust()
1646 newstart = scan - 1; in findmust()
1656 scan--; in findmust()
1663 g->iflags |= BAD; in findmust()
1675 if (newlen > g->mlen) { /* ends one */ in findmust()
1677 g->mlen = newlen; in findmust()
1678 if (offset > -1) { in findmust()
1679 g->moffset += offset; in findmust()
1682 g->moffset = offset; in findmust()
1684 if (offset > -1) in findmust()
1690 if (newlen > g->mlen) { /* ends one */ in findmust()
1692 g->mlen = newlen; in findmust()
1693 if (offset > -1) { in findmust()
1694 g->moffset += offset; in findmust()
1697 g->moffset = offset; in findmust()
1699 if (offset > -1) in findmust()
1702 if (offset > -1) in findmust()
1708 if (newlen > g->mlen) { /* ends one */ in findmust()
1710 g->mlen = newlen; in findmust()
1711 if (offset > -1) { in findmust()
1712 g->moffset += offset; in findmust()
1715 g->moffset = offset; in findmust()
1717 if (offset > -1) in findmust()
1720 if (offset > -1) in findmust()
1724 * it, make offset = -1. in findmust()
1727 offset = -1; in findmust()
1731 * to calculate the offset -- so we give up; in findmust()
1735 if (newlen > g->mlen) { /* ends one */ in findmust()
1737 g->mlen = newlen; in findmust()
1738 if (offset > -1) in findmust()
1739 g->moffset += offset; in findmust()
1741 g->moffset = offset; in findmust()
1743 offset = -1; in findmust()
1749 if (g->mlen == 0 || !start) { /* there isn't one */ in findmust()
1750 g->moffset = -1; in findmust()
1755 g->must = malloc((size_t)g->mlen + 1); in findmust()
1756 if (g->must == NULL) { /* argh; just forget it */ in findmust()
1757 g->mlen = 0; in findmust()
1758 g->moffset = -1; in findmust()
1761 cp = g->must; in findmust()
1763 for (i = g->mlen; i > 0; i--) { in findmust()
1766 assert(cp < g->must + g->mlen); in findmust()
1769 assert(cp == g->must + g->mlen); in findmust()
1774 - altoffset - choose biggest offset among multiple choices
1788 if (offset == -1) in altoffset()
1789 return -1; in altoffset()
1804 if (try == -1) in altoffset()
1805 return -1; in altoffset()
1806 scan--; in altoffset()
1812 return -1; in altoffset()
1821 return -1; in altoffset()
1833 try = -1; in altoffset()
1836 if (try == -1) in altoffset()
1837 return -1; in altoffset()
1848 - computejumps - compute char jumps for BM scan
1851 * This algorithm assumes g->must exists and is has size greater than
1865 if (p->error != 0) in computejumps()
1868 g->charjump = (int*) malloc(NC * sizeof(int)); in computejumps()
1869 if (g->charjump == NULL) /* Not a fatal error */ in computejumps()
1876 g->charjump[ch] = g->mlen; in computejumps()
1883 for (mindex = 0; mindex < g->mlen; mindex++) in computejumps()
1884 g->charjump[(unsigned char) g->must[mindex]] = g->mlen - mindex - 1; in computejumps()
1888 #pragma GCC diagnostic ignored "-Wpragmas"
1889 #pragma GCC diagnostic ignored "-Wunknown-warning-option"
1890 #pragma GCC diagnostic ignored "-Wanalyzer-out-of-bounds"
1894 - computematchjumps - compute match jumps for BM scan
1897 * This algorithm assumes g->must exists and is has size greater than
1902 * on the already-matched suffix.
1903 * Notice that all values here are minus (g->mlen-1), because of the way
1914 * of k+1...k+mlen-i-1 in computematchjumps()
1918 if (p->error != 0) in computematchjumps()
1921 pmatches = (int*) calloc(g->mlen + 1, sizeof(unsigned int)); in computematchjumps()
1923 g->matchjump = NULL; in computematchjumps()
1927 g->matchjump = (int*) calloc(g->mlen, sizeof(unsigned int)); in computematchjumps()
1928 if (g->matchjump == NULL) { /* Not a fatal error */ in computematchjumps()
1934 for (mindex = 0; mindex < g->mlen; mindex++) in computematchjumps()
1935 g->matchjump[mindex] = 2*g->mlen - mindex - 1; in computematchjumps()
1938 for (mindex = g->mlen - 1, suffix = g->mlen; mindex >= 0; in computematchjumps()
1939 mindex--, suffix--) { in computematchjumps()
1948 while (suffix < g->mlen in computematchjumps()
1949 && g->must[mindex] != g->must[suffix]) { in computematchjumps()
1950 g->matchjump[suffix] = MIN(g->matchjump[suffix], in computematchjumps()
1951 g->mlen - mindex - 1); in computematchjumps()
1961 g->matchjump[mindex] = MIN(g->matchjump[mindex], in computematchjumps()
1962 g->mlen + suffix - mindex); in computematchjumps()
1965 while (suffix < g->mlen) { in computematchjumps()
1966 while (suffix <= ssuffix && suffix < g->mlen) { in computematchjumps()
1967 g->matchjump[suffix] = MIN(g->matchjump[suffix], in computematchjumps()
1968 g->mlen + ssuffix - suffix); in computematchjumps()
1971 if (suffix < g->mlen) in computematchjumps()
1979 - pluscount - count + nesting
1990 if (p->error != 0) in pluscount()
1993 scan = g->strip + 1; in pluscount()
2003 plusnest--; in pluscount()
2008 g->iflags |= BAD; in pluscount()