Lines Matching +full:non +full:- +full:pc

2  * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
5 * "THE BEER-WARE LICENSE" (Revision 42):
52 {"STARQ", 1, "o"}, /* Non-greedy STAR, "*?" */
53 {"PLUSQ", 1, "o"}, /* Non-greedy PLUS, "+?" */
56 {"NONSPACE", 0, ""}, /* Match non-space, "\S" */
78 * records the beginning of the matched substring (cap->ptr), CLOSE
79 * sets the length (cap->len) for respective capture_number.
89 * STARQ, PLUSQ are non-greedy versions of STAR and PLUS.
121 int i, j, ch, op, pc; in slre_dump() local
123 for (pc = 0; pc < r->code_size; pc++) { in slre_dump()
125 op = r->code[pc]; in slre_dump()
126 (void) fprintf(fp, "%3d %s ", pc, opcodes[op].name); in slre_dump()
131 (void) fprintf(fp, "%d ", r->code[pc + 1]); in slre_dump()
132 pc++; in slre_dump()
136 pc + r->code[pc + 1] - i); in slre_dump()
137 pc++; in slre_dump()
140 print_character_set(fp, r->data + in slre_dump()
141 r->code[pc + 1], r->code[pc + 2]); in slre_dump()
142 pc += 2; in slre_dump()
146 for (j = 0; j < r->code[pc + 2]; j++) { in slre_dump()
147 ch = r->data[r->code[pc + 1] + j]; in slre_dump()
156 pc += 2; in slre_dump()
166 set_jump_offset(struct slre *r, int pc, int offset) in set_jump_offset() argument
168 assert(offset < r->code_size); in set_jump_offset()
170 if (r->code_size - offset > 0xff) in set_jump_offset()
171 r->err_str = "Jump offset is too big"; in set_jump_offset()
173 r->code[pc] = (unsigned char) (r->code_size - offset); in set_jump_offset()
179 if (r->code_size >= (int) (sizeof(r->code) / sizeof(r->code[0]))) in emit()
180 r->err_str = "RE is too long (code overflow)"; in emit()
182 r->code[r->code_size++] = (unsigned char) code; in emit()
188 if (r->data_size >= (int) sizeof(r->data)) in store_char_in_data()
189 r->err_str = "RE is too long (data overflow)"; in store_char_in_data()
191 r->data[r->data_size++] = ch; in store_char_in_data()
197 int old_data_size = r->data_size; in exact()
204 emit(r, r->data_size - old_data_size); in exact()
235 res = (*re)[-1]; in get_escape_char()
245 int esc, old_data_size = r->data_size, op = ANYOF; in anyof()
258 emit(r, r->data_size - old_data_size); in anyof()
272 store_char_in_data(r, (*re)[-1]); in anyof()
276 r->err_str = "No closing ']' bracket"; in anyof()
283 memmove(r->code + begin + shift, r->code + begin, r->code_size - begin); in relocate()
284 r->code_size += shift; in relocate()
290 if (r->code[prev] == EXACT && r->code[prev + 2] > 1) { in quantifier()
291 r->code[prev + 2]--; in quantifier()
293 emit(r, r->code[prev + 1] + r->code[prev + 2]); in quantifier()
295 prev = r->code_size - 3; in quantifier()
298 r->code[prev] = op; in quantifier()
306 emit(r, r->data_size); in exact_one_char()
316 set_jump_offset(r, fixup, fixup - 2); in fixup_branch()
326 level = r->num_caps; in compile()
327 branch_start = last_op = r->code_size; in compile()
332 (*re)--; in compile()
343 last_op = r->code_size; in compile()
347 last_op = r->code_size; in compile()
351 last_op = r->code_size; in compile()
359 last_op = r->code_size; in compile()
360 cap_no = ++r->num_caps; in compile()
366 r->err_str = "No closing bracket"; in compile()
374 (*re)--; in compile()
377 r->err_str = "Unbalanced brackets"; in compile()
385 op = (*re)[-1] == '*' ? STAR : PLUS; in compile()
398 r->code[branch_start] = BRANCH; in compile()
401 r->code[fixup] = 0xff; in compile()
404 (*re)--; in compile()
405 last_op = r->code_size; in compile()
414 r->err_str = NULL; in slre_compile()
415 r->code_size = r->data_size = r->num_caps = r->anchored = 0; in slre_compile()
418 r->anchored++; in slre_compile()
426 if (r->code[2] == BRANCH) in slre_compile()
433 return (r->err_str == NULL ? 1 : 0); in slre_compile()
440 loop_greedy(const struct slre *r, int pc, const char *s, int len, int *ofs) in loop_greedy() argument
446 while (match(r, pc + 2, s, len, ofs, NULL)) { in loop_greedy()
448 if (match(r, pc + r->code[pc + 1], s, len, ofs, NULL)) in loop_greedy()
457 loop_non_greedy(const struct slre *r, int pc, const char *s, int len, int *ofs) in loop_non_greedy() argument
461 while (match(r, pc + 2, s, len, ofs, NULL)) { in loop_non_greedy()
463 if (match(r, pc + r->code[pc + 1], s, len, ofs, NULL)) in loop_non_greedy()
503 match(const struct slre *r, int pc, const char *s, int len, in match() argument
508 while (res && r->code[pc] != END) { in match()
510 assert(pc < r->code_size); in match()
511 assert(pc < (int) (sizeof(r->code) / sizeof(r->code[0]))); in match()
513 switch (r->code[pc]) { in match()
516 res = match(r, pc + 3, s, len, ofs, caps); in match()
519 res = match(r, pc + r->code[pc + 1], in match()
522 pc += r->code[pc + 2]; in match()
526 n = r->code[pc + 2]; /* String length */ in match()
527 if (n <= len - *ofs && !memcmp(s + *ofs, r->data + in match()
528 r->code[pc + 1], n)) { in match()
532 pc += 3; in match()
537 if (!match(r, pc + 2, s, len, ofs, caps)) in match()
539 pc += r->code[pc + 1]; in match()
543 loop_greedy(r, pc, s, len, ofs); in match()
544 pc += r->code[pc + 1]; in match()
548 loop_non_greedy(r, pc, s, len, ofs); in match()
549 pc += r->code[pc + 1]; in match()
552 res = match(r, pc + 2, s, len, ofs, caps); in match()
556 loop_greedy(r, pc, s, len, ofs); in match()
557 pc += r->code[pc + 1]; in match()
560 res = match(r, pc + 2, s, len, ofs, caps); in match()
564 loop_non_greedy(r, pc, s, len, ofs); in match()
565 pc += r->code[pc + 1]; in match()
573 pc++; in match()
582 pc++; in match()
590 pc++; in match()
598 pc++; in match()
603 res = is_any_of(r->data + r->code[pc + 1], in match()
604 r->code[pc + 2], s, ofs); in match()
605 pc += 3; in match()
610 res = is_any_but(r->data + r->code[pc + 1], in match()
611 r->code[pc + 2], s, ofs); in match()
612 pc += 3; in match()
616 pc++; in match()
620 pc++; in match()
624 caps[r->code[pc + 1]].ptr = s + *ofs; in match()
625 pc += 2; in match()
629 caps[r->code[pc + 1]].len = (s + *ofs) - in match()
630 caps[r->code[pc + 1]].ptr; in match()
631 pc += 2; in match()
634 pc++; in match()
637 printf("unknown cmd (%d) at %d\n", r->code[pc], pc); in match()
652 if (r->anchored) { in slre_match()
697 if ((len > 0) && (data[len-1] == '\n')) { in main()
698 data[len-1] = '\0'; in main()
699 --len; in main()
716 printf("----------------------------------------------------\n"); in main()