📄 mbregex.c
字号:
printf("/"); while (mcnt--) { print_mbc(EXTRACT_MBC_AND_INCR(p)); printf("-"); print_mbc(EXTRACT_MBC_AND_INCR(p)); } break; } case begline: printf("/begline"); break; case endline: printf("/endline"); break; case on_failure_jump: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/on_failure_jump//%d", mcnt); break; case dummy_failure_jump: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/dummy_failure_jump//%d", mcnt); break; case push_dummy_failure: printf("/push_dummy_failure"); break; case finalize_jump: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/finalize_jump//%d", mcnt); break; case maybe_finalize_jump: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/maybe_finalize_jump//%d", mcnt); break; case jump_past_alt: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/jump_past_alt//%d", mcnt); break; case jump: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/jump//%d", mcnt); break; case succeed_n: EXTRACT_NUMBER_AND_INCR(mcnt, p); EXTRACT_NUMBER_AND_INCR(mcnt2, p); printf("/succeed_n//%d//%d", mcnt, mcnt2); break; case jump_n: EXTRACT_NUMBER_AND_INCR(mcnt, p); EXTRACT_NUMBER_AND_INCR(mcnt2, p); printf("/jump_n//%d//%d", mcnt, mcnt2); break; case set_number_at: EXTRACT_NUMBER_AND_INCR(mcnt, p); EXTRACT_NUMBER_AND_INCR(mcnt2, p); printf("/set_number_at//%d//%d", mcnt, mcnt2); break; case try_next: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/try_next//%d", mcnt); break; case finalize_push: EXTRACT_NUMBER_AND_INCR(mcnt, p); printf("/finalize_push//%d", mcnt); break; case finalize_push_n: EXTRACT_NUMBER_AND_INCR(mcnt, p); EXTRACT_NUMBER_AND_INCR(mcnt2, p); printf("/finalize_push_n//%d//%d", mcnt, mcnt2); break; case wordbound: printf("/wordbound"); break; case notwordbound: printf("/notwordbound"); break; case wordbeg: printf("/wordbeg"); break; case wordend: printf("/wordend"); case wordchar: printf("/wordchar"); break; case notwordchar: printf("/notwordchar"); break; case begbuf: printf("/begbuf"); break; case endbuf: printf("/endbuf"); break; case endbuf2: printf("/endbuf2"); break; case begpos: printf("/begpos"); break; default: printf("?%d", *(p-1)); } } printf("/\n");}static voidprint_compiled_pattern(bufp) struct mbre_pattern_buffer *bufp;{ unsigned char *buffer = (unsigned char*)bufp->buffer; print_partial_compiled_pattern(buffer, buffer + bufp->used);}#endifstatic char*calculate_must_string(start, end) char *start; char *end;{ int mcnt; int max = 0; char *p = start; char *pend = end; char *must = 0; if (start == NULL) return 0; /* Loop over pattern commands. */ while (p < pend) { switch ((enum regexpcode)*p++) { case unused: break; case exactn: mcnt = *p; if (mcnt > max) { must = p; max = mcnt; } p += mcnt+1; break; case start_memory: case stop_memory: p += 2; break; case duplicate: p++; break; case casefold_on: case casefold_off: return 0; /* should not check must_string */ case pop_and_fail: case anychar: case anychar_repeat: case begline: case endline: case wordbound: case notwordbound: case wordbeg: case wordend: case wordchar: case notwordchar: case begbuf: case endbuf: case endbuf2: case begpos: case push_dummy_failure: case start_paren: case stop_paren: case option_set: break; case charset: case charset_not: mcnt = *p++; p += mcnt; mcnt = EXTRACT_UNSIGNED_AND_INCR(p); while (mcnt--) { p += 4; } break; case on_failure_jump: EXTRACT_NUMBER_AND_INCR(mcnt, p); if (mcnt > 0) p += mcnt; if ((enum regexpcode)p[-3] == jump) { p -= 2; EXTRACT_NUMBER_AND_INCR(mcnt, p); if (mcnt > 0) p += mcnt; } break; case dummy_failure_jump: case succeed_n: case try_next: case jump: EXTRACT_NUMBER_AND_INCR(mcnt, p); if (mcnt > 0) p += mcnt; break; case start_nowidth: case stop_nowidth: case stop_backtrack: case finalize_jump: case maybe_finalize_jump: case finalize_push: p += 2; break; case jump_n: case set_number_at: case finalize_push_n: p += 4; break; default: break; } } return must;}static unsigned intread_backslash(c) int c;{ switch (c) { case 'n': return '\n'; case 't': return '\t'; case 'r': return '\r'; case 'f': return '\f'; case 'v': return '\v'; case 'a': return '\007'; case 'b': return '\010'; case 'e': return '\033'; } return c;}static unsigned intread_special(p, pend, pp) const char *p, *pend, **pp;{ int c; PATFETCH_RAW(c); switch (c) { case 'M': PATFETCH_RAW(c); if (c != '-') return -1; PATFETCH_RAW(c); *pp = p; if (c == '\\') { return read_special(p, pend, pp) | 0x80; } else if (c == -1) return ~0; else { return ((c & 0xff) | 0x80); } case 'C': PATFETCH_RAW(c); if (c != '-') return ~0; case 'c': PATFETCH_RAW(c); *pp = p; if (c == '\\') { c = read_special(p, pend, pp); } else if (c == '?') return 0177; else if (c == -1) return ~0; return c & 0x9f; default: return read_backslash(c); } end_of_pattern: return ~0;}/* re_compile_pattern takes a regular-expression string and converts it into a buffer full of byte commands for matching. PATTERN is the address of the pattern string SIZE is the length of it. BUFP is a struct mbre_pattern_buffer * which points to the info on where to store the byte commands. This structure contains a char * which points to the actual space, which should have been obtained with malloc. re_compile_pattern may use realloc to grow the buffer space. The number of bytes of commands can be found out by looking in the `struct mbre_pattern_buffer' that bufp pointed to, after re_compile_pattern returns. */char *re_compile_pattern(pattern, size, bufp) const char *pattern; int size; struct mbre_pattern_buffer *bufp;{ register char *b = bufp->buffer; register const char *p = pattern; const char *nextp; const char *pend = pattern + size; register unsigned int c, c1=0; const char *p0; int numlen;#define ERROR_MSG_MAX_SIZE 200 static char error_msg[ERROR_MSG_MAX_SIZE+1]; /* Address of the count-byte of the most recently inserted `exactn' command. This makes it possible to tell whether a new exact-match character can be added to that command or requires a new `exactn' command. */ char *pending_exact = 0; /* Address of the place where a forward-jump should go to the end of the containing expression. Each alternative of an `or', except the last, ends with a forward-jump of this sort. */ char *fixup_alt_jump = 0; /* Address of start of the most recently finished expression. This tells postfix * where to find the start of its operand. */ char *laststart = 0; /* In processing a repeat, 1 means zero matches is allowed. */ char zero_times_ok; /* In processing a repeat, 1 means many matches is allowed. */ char many_times_ok; /* In processing a repeat, 1 means non-greedy matches. */ char greedy; /* Address of beginning of regexp, or inside of last (. */ char *begalt = b; /* Place in the uncompiled pattern (i.e., the {) to which to go back if the interval is invalid. */ const char *beg_interval; /* In processing an interval, at least this many matches must be made. */ int lower_bound; /* In processing an interval, at most this many matches can be made. */ int upper_bound; /* Stack of information saved by ( and restored by ). Five stack elements are pushed by each (: First, the value of b. Second, the value of fixup_alt_jump. Third, the value of begalt. Fourth, the value of regnum. Fifth, the type of the paren. */ int stacka[40]; int *stackb = stacka; int *stackp = stackb; int *stacke = stackb + 40; /* Counts ('s as they are encountered. Remembered for the matching ), where it becomes the register number to put in the stop_memory command. */ int regnum = 1; int range = 0; int had_mbchar = 0; int had_num_literal = 0; int had_char_class = 0; int options = bufp->options; int current_mbctype = bufp->mbctype; const unsigned char *re_mbctab = re_mbctab_get(current_mbctype); bufp->fastmap_accurate = 0; bufp->must = 0; bufp->must_skip = 0; bufp->stclass = 0; /* Initialize the syntax table. */ init_syntax_once(); if (bufp->allocated == 0) { bufp->allocated = INIT_BUF_SIZE; if (bufp->buffer) /* EXTEND_BUFFER loses when bufp->allocated is 0. */ bufp->buffer = (char*)xrealloc(bufp->buffer, INIT_BUF_SIZE); else /* Caller did not allocate a buffer. Do it for them. */ bufp->buffer = (char*)xmalloc(INIT_BUF_SIZE); if (!bufp->buffer) goto memory_exhausted; begalt = b = bufp->buffer; } while (p != pend) { PATFETCH(c); switch (c) { case '$': if (bufp->options & MBRE_OPTION_SINGLELINE) { BUFPUSH(endbuf); } else { p0 = p; /* When testing what follows the $, look past the \-constructs that don't consume anything. */ while (p0 != pend) { if (*p0 == '\\' && p0 + 1 != pend && (p0[1] == 'b' || p0[1] == 'B')) p0 += 2; else break; } BUFPUSH(endline); } break; case '^': if (bufp->options & MBRE_OPTION_SINGLELINE) BUFPUSH(begbuf); else BUFPUSH(begline); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -