static int parse_posix_basic(struct ParseCtx *ctx, const char *re) { int err = 0; unsigned c; int glevel = 0; loop: if (err) return err; c = *re++; switch (c) { case 0: return (glevel == 0) ? 0 : REG_EPAREN; case '*': if (ctx->last_elem && ctx->last_elem->type != OP_BOL) err = op_count_simple(ctx, 0, MAX_COUNT); else err = op_char(ctx, '*'); break; case '.': err = op_simple(ctx, OP_ANY); break; case '[': err = op_class(ctx, &re); break; case '^': if (!ctx->last_elem) err = op_simple(ctx, OP_BOL); else err = op_char(ctx, c); break; case '$': if (!*re || (re[0] == '\\' && re[1] == ')')) err = op_simple(ctx, OP_EOL); else err = op_char(ctx, c); break; case '\\': goto escaped; default: err = op_char(ctx, c); } goto loop; escaped: c = *re++; switch (c) { case 0: return REG_EESCAPE; case '(': glevel++; err = op_gstart(ctx); break; case ')': glevel--; if (glevel < 0) return REG_EPAREN; err = op_gend(ctx); break; case '{': err = op_count_full(ctx, &re); break; case '.': case '^': case '$': case '*': case '[': case ']': case '\\': err = op_char(ctx, c); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': err = op_bref(ctx, c); break; case '|': err = STRICT ? REG_BADPAT : op_or(ctx); break; default: err = parse_relaxed_escapes(ctx, c); } goto loop; }
qw_op_t qw_edit_op(qw_edit_t *e, qw_event_t *ev) { qw_op_t r = QW_OP_NOP; qw_core_t *c = ev->c; switch (ev->o) { case QW_OP_LEFT: op_left(e); break; case QW_OP_RIGHT: op_right(e); break; case QW_OP_UP: op_up(e, ev->f); break; case QW_OP_DOWN: op_down(e, ev->f); break; case QW_OP_PGUP: op_pgup(e, ev->f); break; case QW_OP_PGDN: op_pgdn(e, ev->f); break; case QW_OP_BOL: op_bol(e); break; case QW_OP_EOL: op_eol(e); break; case QW_OP_BOR: op_bor(e, ev->f); break; case QW_OP_EOR: op_eor(e, ev->f); break; case QW_OP_BOF: op_bof(e); break; case QW_OP_EOF: op_eof(e); break; case QW_OP_CHAR: op_char(e, ev->w); break; case QW_OP_DEL: op_del(e); break; case QW_OP_BACKSPACE: op_backspace(e); break; case QW_OP_NEWLINE: op_char(e, L'\n'); break; case QW_OP_TAB: op_tab(e, ev->f, c); break; case QW_OP_HARD_TAB: op_char(e, L'\t'); break; case QW_OP_DEL_ROW: op_del_row(e, ev->f); break; case QW_OP_UNDO: op_undo(e); break; case QW_OP_MARK: op_mark(e); break; case QW_OP_UNMARK: op_unmark(e); break; case QW_OP_COPY: op_copy(e, c); op_unmark(e); break; case QW_OP_PASTE: op_paste(e, c); break; case QW_OP_CUT: op_cut(e, c); break; case QW_OP_SAVE: op_save(e); break; case QW_OP_SHOW_CODES: ev->f->l = L" \xb6"[!!(ev->f->l == L' ')]; break; case QW_OP_SEARCH: op_search(e, c); break; case QW_OP_CLOSE: r = QW_OP_DESTROY; break; case QW_OP_DESTROY: r = QW_OP_DESTROY; break; case QW_OP_NOP: case QW_OP_COUNT: break; } return r; }
static int parse_posix_ext(struct ParseCtx *ctx, const char *re) { int err = 0; unsigned c; int glevel = 0; loop: if (err) return err; c = *re++; switch (c) { case 0: return (glevel == 0) ? 0 : REG_EPAREN; case '(': glevel++; err = op_gstart(ctx); break; case ')': if (glevel > 0) { glevel--; err = op_gend(ctx); } else { err = op_char(ctx, c); /* POSIX bug */ } break; case '|': err = op_or(ctx); break; case '*': err = op_count_simple(ctx, 0, MAX_COUNT); break; case '?': err = op_count_simple(ctx, 0, 1); break; case '+': err = op_count_simple(ctx, 1, MAX_COUNT); break; case '[': err = op_class(ctx, &re); break; case '{': err = op_count_full(ctx, &re); break; case '.': err = op_simple(ctx, OP_ANY); break; case '^': err = op_simple(ctx, OP_BOL); break; case '$': err = op_simple(ctx, OP_EOL); break; case '\\': goto escaped; default: err = op_char(ctx, c); } goto loop; escaped: c = *re++; if (c == 0) err = REG_EESCAPE; else if (c >= '0' && c <= '9') err = STRICT ? REG_BADPAT : op_bref(ctx, c); else if (isalpha(c)) err = parse_relaxed_escapes(ctx, c); else err = op_char(ctx, c); goto loop; }