From 70a82653363ef22fd000b0af14656251deed3448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 7 Nov 2015 09:10:09 +0100 Subject: vis: prefix enum VisOperator values with VIS_ --- main.c | 40 +++++++++++++++++----------------- vis-core.h | 4 ++-- vis-modes.c | 4 ++-- vis-operators.c | 67 +++++++++++++++++++++++---------------------------------- vis.c | 38 ++++++++++++++++---------------- vis.h | 36 +++++++++++++++---------------- 6 files changed, 88 insertions(+), 101 deletions(-) diff --git a/main.c b/main.c index 21cc04e..e44f3e5 100644 --- a/main.c +++ b/main.c @@ -663,42 +663,42 @@ static KeyAction vis_action[] = { [VIS_ACTION_OPERATOR_CHANGE] = { "vis-operator-change", "Change operator", - operator, { .i = OP_CHANGE } + operator, { .i = VIS_OP_CHANGE } }, [VIS_ACTION_OPERATOR_DELETE] = { "vis-operator-delete", "Delete operator", - operator, { .i = OP_DELETE } + operator, { .i = VIS_OP_DELETE } }, [VIS_ACTION_OPERATOR_YANK] = { "vis-operator-yank", "Yank operator", - operator, { .i = OP_YANK } + operator, { .i = VIS_OP_YANK } }, [VIS_ACTION_OPERATOR_SHIFT_LEFT] = { "vis-operator-shift-left", "Shift left operator", - operator, { .i = OP_SHIFT_LEFT } + operator, { .i = VIS_OP_SHIFT_LEFT } }, [VIS_ACTION_OPERATOR_SHIFT_RIGHT] = { "vis-operator-shift-right", "Shift right operator", - operator, { .i = OP_SHIFT_RIGHT } + operator, { .i = VIS_OP_SHIFT_RIGHT } }, [VIS_ACTION_OPERATOR_CASE_LOWER] = { "vis-operator-case-lower", "Lowercase operator", - operator, { .i = OP_CASE_LOWER } + operator, { .i = VIS_OP_CASE_LOWER } }, [VIS_ACTION_OPERATOR_CASE_UPPER] = { "vis-operator-case-upper", "Uppercase operator", - operator, { .i = OP_CASE_UPPER } + operator, { .i = VIS_OP_CASE_UPPER } }, [VIS_ACTION_OPERATOR_CASE_SWAP] = { "vis-operator-case-swap", "Swap case operator", - operator, { .i = OP_CASE_SWAP } + operator, { .i = VIS_OP_CASE_SWAP } }, [VIS_ACTION_COUNT] = { "vis-count", @@ -768,7 +768,7 @@ static KeyAction vis_action[] = { [VIS_ACTION_JOIN_LINES] = { "join-lines", "Join selected lines", - operator, { .i = OP_JOIN } + operator, { .i = VIS_OP_JOIN } }, [VIS_ACTION_PROMPT_SHOW] = { "prompt-show", @@ -833,22 +833,22 @@ static KeyAction vis_action[] = { [VIS_ACTION_PUT_AFTER] = { "put-after", "Put text after the cursor", - operator, { .i = OP_PUT_AFTER } + operator, { .i = VIS_OP_PUT_AFTER } }, [VIS_ACTION_PUT_BEFORE] = { "put-before", "Put text before the cursor", - operator, { .i = OP_PUT_BEFORE } + operator, { .i = VIS_OP_PUT_BEFORE } }, [VIS_ACTION_PUT_AFTER_END] = { "put-after-end", "Put text after the cursor, place cursor after new text", - operator, { .i = OP_PUT_AFTER_END } + operator, { .i = VIS_OP_PUT_AFTER_END } }, [VIS_ACTION_PUT_BEFORE_END] = { "put-before-end", "Put text before the cursor, place cursor after new text", - operator, { .i = OP_PUT_BEFORE_END } + operator, { .i = VIS_OP_PUT_BEFORE_END } }, [VIS_ACTION_CURSOR_SELECT_WORD] = { "cursors-select-word", @@ -868,12 +868,12 @@ static KeyAction vis_action[] = { [VIS_ACTION_CURSORS_NEW_LINES_BEGIN] = { "cursors-new-lines-begin", "Create a new cursor at the start of every line covered by selection", - operator, { .i = OP_CURSOR_SOL } + operator, { .i = VIS_OP_CURSOR_SOL } }, [VIS_ACTION_CURSORS_NEW_LINES_END] = { "cursors-new-lines-end", "Create a new cursor at the end of every line covered by selection", - operator, { .i = OP_CURSOR_EOL } + operator, { .i = VIS_OP_CURSOR_EOL } }, [VIS_ACTION_CURSORS_NEW_MATCH_NEXT] = { "cursors-new-match-next", @@ -1201,7 +1201,7 @@ static const char *replace(Vis *vis, const char *keys, const Arg *arg) { char key[len+1]; memcpy(key, keys, len); key[len] = '\0'; - vis_operator(vis, OP_REPLACE); + vis_operator(vis, VIS_OP_REPLACE); vis_motion(vis, MOVE_NOP); vis_keys_inject(vis, next, key); vis_keys_inject(vis, next+len, ""); @@ -1361,7 +1361,7 @@ static const char *later(Vis *vis, const char *keys, const Arg *arg) { } static const char *delete(Vis *vis, const char *keys, const Arg *arg) { - vis_operator(vis, OP_DELETE); + vis_operator(vis, VIS_OP_DELETE); vis_motion(vis, arg->i); return keys; } @@ -1515,7 +1515,7 @@ static const char *window(Vis *vis, const char *keys, const Arg *arg) { } static const char *openline(Vis *vis, const char *keys, const Arg *arg) { - vis_operator(vis, OP_INSERT); + vis_operator(vis, VIS_OP_INSERT); if (arg->i > 0) { vis_motion(vis, MOVE_LINE_END); vis_keys_inject(vis, keys, ""); @@ -1530,7 +1530,7 @@ static const char *join(Vis *vis, const char *keys, const Arg *arg) { int count = vis_count_get(vis); if (count) vis_count_set(vis, count-1); - vis_operator(vis, OP_JOIN); + vis_operator(vis, VIS_OP_JOIN); vis_motion(vis, arg->i); return keys; } @@ -1541,7 +1541,7 @@ static const char *switchmode(Vis *vis, const char *keys, const Arg *arg) { } static const char *insertmode(Vis *vis, const char *keys, const Arg *arg) { - vis_operator(vis, OP_INSERT); + vis_operator(vis, VIS_OP_INSERT); vis_motion(vis, arg->i); return keys; } diff --git a/vis-core.h b/vis-core.h index 4321a80..bb330ce 100644 --- a/vis-core.h +++ b/vis-core.h @@ -161,7 +161,7 @@ extern Mode vis_modes[VIS_MODE_LAST]; extern Movement moves[MOVE_INVALID]; -extern Operator ops[OP_INVALID]; +extern Operator ops[VIS_OP_INVALID]; const char *expandtab(Vis *vis); @@ -173,4 +173,4 @@ void action_reset(Action*); void mode_set(Vis *vis, Mode *new_mode); Mode *mode_get(Vis *vis, enum VisMode mode); -#endif \ No newline at end of file +#endif diff --git a/vis-modes.c b/vis-modes.c index b53aeb7..42c9d8a 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -114,7 +114,7 @@ static void vis_mode_insert_enter(Vis *vis, Mode *old) { macro_operator_record(vis); action_reset(&vis->action_prev); vis->action_prev.macro = vis->macro_operator; - vis->action_prev.op = &ops[OP_INSERT]; + vis->action_prev.op = &ops[VIS_OP_INSERT]; } } @@ -138,7 +138,7 @@ static void vis_mode_replace_enter(Vis *vis, Mode *old) { macro_operator_record(vis); action_reset(&vis->action_prev); vis->action_prev.macro = vis->macro_operator; - vis->action_prev.op = &ops[OP_REPLACE]; + vis->action_prev.op = &ops[VIS_OP_REPLACE]; } } diff --git a/vis-operators.c b/vis-operators.c index b7201cb..0923ef6 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -6,33 +6,6 @@ #include "text-util.h" #include "util.h" -/** operators */ -static size_t op_change(Vis*, Text*, OperatorContext *c); -static size_t op_yank(Vis*, Text*, OperatorContext *c); -static size_t op_put(Vis*, Text*, OperatorContext *c); -static size_t op_delete(Vis*, Text*, OperatorContext *c); -static size_t op_shift_right(Vis*, Text*, OperatorContext *c); -static size_t op_shift_left(Vis*, Text*, OperatorContext *c); -static size_t op_case_change(Vis*, Text*, OperatorContext *c); -static size_t op_join(Vis*, Text*, OperatorContext *c); -static size_t op_insert(Vis*, Text*, OperatorContext *c); -static size_t op_replace(Vis*, Text*, OperatorContext *c); -static size_t op_cursor(Vis*, Text*, OperatorContext *c); - -Operator ops[] = { - [OP_DELETE] = { op_delete }, - [OP_CHANGE] = { op_change }, - [OP_YANK] = { op_yank }, - [OP_PUT_AFTER] = { op_put }, - [OP_SHIFT_RIGHT] = { op_shift_right }, - [OP_SHIFT_LEFT] = { op_shift_left }, - [OP_CASE_SWAP] = { op_case_change }, - [OP_JOIN] = { op_join }, - [OP_INSERT] = { op_insert }, - [OP_REPLACE] = { op_replace }, - [OP_CURSOR_SOL] = { op_cursor }, -}; - static size_t op_delete(Vis *vis, Text *txt, OperatorContext *c) { c->reg->linewise = c->linewise; register_put(c->reg, txt, &c->range); @@ -58,15 +31,15 @@ static size_t op_yank(Vis *vis, Text *txt, OperatorContext *c) { static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) { size_t pos = c->pos; switch (c->arg->i) { - case OP_PUT_AFTER: - case OP_PUT_AFTER_END: + case VIS_OP_PUT_AFTER: + case VIS_OP_PUT_AFTER_END: if (c->reg->linewise) pos = text_line_next(txt, pos); else pos = text_char_next(txt, pos); break; - case OP_PUT_BEFORE: - case OP_PUT_BEFORE_END: + case VIS_OP_PUT_BEFORE: + case VIS_OP_PUT_BEFORE_END: if (c->reg->linewise) pos = text_line_begin(txt, pos); break; @@ -79,21 +52,21 @@ static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) { if (c->reg->linewise) { switch (c->arg->i) { - case OP_PUT_BEFORE_END: - case OP_PUT_AFTER_END: + case VIS_OP_PUT_BEFORE_END: + case VIS_OP_PUT_AFTER_END: pos = text_line_start(txt, pos); break; - case OP_PUT_AFTER: + case VIS_OP_PUT_AFTER: pos = text_line_start(txt, text_line_next(txt, c->pos)); break; - case OP_PUT_BEFORE: + case VIS_OP_PUT_BEFORE: pos = text_line_start(txt, c->pos); break; } } else { switch (c->arg->i) { - case OP_PUT_AFTER: - case OP_PUT_BEFORE: + case VIS_OP_PUT_AFTER: + case VIS_OP_PUT_BEFORE: pos = text_char_prev(txt, pos); break; } @@ -157,9 +130,9 @@ static size_t op_case_change(Vis *vis, Text *txt, OperatorContext *c) { for (char *cur = buf; rem > 0; cur++, rem--) { int ch = (unsigned char)*cur; if (isascii(ch)) { - if (c->arg->i == OP_CASE_SWAP) + if (c->arg->i == VIS_OP_CASE_SWAP) *cur = islower(ch) ? toupper(ch) : tolower(ch); - else if (c->arg->i == OP_CASE_UPPER) + else if (c->arg->i == VIS_OP_CASE_UPPER) *cur = toupper(ch); else *cur = tolower(ch); @@ -179,7 +152,7 @@ static size_t op_cursor(Vis *vis, Text *txt, OperatorContext *c) { Cursor *cursor = view_cursors_new(view); if (cursor) { size_t pos; - if (c->arg->i == OP_CURSOR_EOL) + if (c->arg->i == VIS_OP_CURSOR_EOL) pos = text_line_finish(txt, line); else pos = text_line_start(txt, line); @@ -224,3 +197,17 @@ static size_t op_replace(Vis *vis, Text *txt, OperatorContext *c) { macro_operator_record(vis); return c->newpos != EPOS ? c->newpos : c->pos; } + +Operator ops[] = { + [VIS_OP_DELETE] = { op_delete }, + [VIS_OP_CHANGE] = { op_change }, + [VIS_OP_YANK] = { op_yank }, + [VIS_OP_PUT_AFTER] = { op_put }, + [VIS_OP_SHIFT_RIGHT] = { op_shift_right }, + [VIS_OP_SHIFT_LEFT] = { op_shift_left }, + [VIS_OP_CASE_SWAP] = { op_case_change }, + [VIS_OP_JOIN] = { op_join }, + [VIS_OP_INSERT] = { op_insert }, + [VIS_OP_REPLACE] = { op_replace }, + [VIS_OP_CURSOR_SOL] = { op_cursor }, +}; diff --git a/vis.c b/vis.c index be8f727..4a376a5 100644 --- a/vis.c +++ b/vis.c @@ -638,9 +638,9 @@ static void action_do(Vis *vis, Action *a) { /* operator implementations must not change the mode, * they might get called multiple times (once for every cursor) */ - if (a->op == &ops[OP_INSERT] || a->op == &ops[OP_CHANGE]) + if (a->op == &ops[VIS_OP_INSERT] || a->op == &ops[VIS_OP_CHANGE]) vis_mode_switch(vis, VIS_MODE_INSERT); - else if (a->op == &ops[OP_REPLACE]) + else if (a->op == &ops[VIS_OP_REPLACE]) vis_mode_switch(vis, VIS_MODE_REPLACE); else if (vis->mode == &vis_modes[VIS_MODE_OPERATOR]) mode_set(vis, vis->mode_prev); @@ -964,23 +964,23 @@ int vis_run(Vis *vis, int argc, char *argv[]) { bool vis_operator(Vis *vis, enum VisOperator id) { switch (id) { - case OP_CASE_LOWER: - case OP_CASE_UPPER: - case OP_CASE_SWAP: + case VIS_OP_CASE_LOWER: + case VIS_OP_CASE_UPPER: + case VIS_OP_CASE_SWAP: vis->action.arg.i = id; - id = OP_CASE_SWAP; + id = VIS_OP_CASE_SWAP; break; - case OP_CURSOR_SOL: - case OP_CURSOR_EOL: + case VIS_OP_CURSOR_SOL: + case VIS_OP_CURSOR_EOL: vis->action.arg.i = id; - id = OP_CURSOR_SOL; + id = VIS_OP_CURSOR_SOL; break; - case OP_PUT_AFTER: - case OP_PUT_AFTER_END: - case OP_PUT_BEFORE: - case OP_PUT_BEFORE_END: + case VIS_OP_PUT_AFTER: + case VIS_OP_PUT_AFTER_END: + case VIS_OP_PUT_BEFORE: + case VIS_OP_PUT_BEFORE_END: vis->action.arg.i = id; - id = OP_PUT_AFTER; + id = VIS_OP_PUT_AFTER; break; default: break; @@ -1006,7 +1006,7 @@ bool vis_operator(Vis *vis, enum VisOperator id) { } /* put is not a real operator, does not need a range to operate on */ - if (id == OP_PUT_AFTER) + if (id == VIS_OP_PUT_AFTER) vis_motion(vis, MOVE_NOP); return true; @@ -1022,11 +1022,11 @@ bool vis_motion(Vis *vis, enum VisMotion motion, ...) { switch (motion) { case MOVE_WORD_START_NEXT: - if (vis->action.op == &ops[OP_CHANGE]) + if (vis->action.op == &ops[VIS_OP_CHANGE]) motion = MOVE_WORD_END_NEXT; break; case MOVE_LONGWORD_START_NEXT: - if (vis->action.op == &ops[OP_CHANGE]) + if (vis->action.op == &ops[VIS_OP_CHANGE]) motion = MOVE_LONGWORD_END_NEXT; break; case MOVE_SEARCH_FORWARD: @@ -1183,7 +1183,7 @@ void vis_repeat(Vis *vis) { vis->action_prev.count = count; count = vis->action_prev.count; /* for some operators count should be applied only to the macro not the motion */ - if (vis->action_prev.op == &ops[OP_INSERT] || vis->action_prev.op == &ops[OP_REPLACE]) + if (vis->action_prev.op == &ops[VIS_OP_INSERT] || vis->action_prev.op == &ops[VIS_OP_REPLACE]) vis->action_prev.count = 1; action_do(vis, &vis->action_prev); vis->action_prev.count = count; @@ -1191,7 +1191,7 @@ void vis_repeat(Vis *vis) { Mode *mode = vis->mode; Action action_prev = vis->action_prev; count = action_prev.count; - if (count < 1 || action_prev.op == &ops[OP_CHANGE]) + if (count < 1 || action_prev.op == &ops[VIS_OP_CHANGE]) count = 1; for (int i = 0; i < count; i++) { mode_set(vis, mode); diff --git a/vis.h b/vis.h index 01c1358..2e84f0e 100644 --- a/vis.h +++ b/vis.h @@ -149,25 +149,25 @@ const char *vis_mode_status(Vis*); bool vis_action_register(Vis*, KeyAction*); enum VisOperator { - OP_DELETE, - OP_CHANGE, - OP_YANK, - OP_PUT_AFTER, - OP_SHIFT_RIGHT, - OP_SHIFT_LEFT, - OP_JOIN, - OP_INSERT, - OP_REPLACE, - OP_CURSOR_SOL, - OP_CASE_SWAP, - OP_INVALID, /* denotes the end of the "real" operators */ + VIS_OP_DELETE, + VIS_OP_CHANGE, + VIS_OP_YANK, + VIS_OP_PUT_AFTER, + VIS_OP_SHIFT_RIGHT, + VIS_OP_SHIFT_LEFT, + VIS_OP_JOIN, + VIS_OP_INSERT, + VIS_OP_REPLACE, + VIS_OP_CURSOR_SOL, + VIS_OP_CASE_SWAP, + VIS_OP_INVALID, /* denotes the end of the "real" operators */ /* pseudo operators: keep them at the end to save space in array definition */ - OP_CASE_LOWER, - OP_CASE_UPPER, - OP_CURSOR_EOL, - OP_PUT_AFTER_END, - OP_PUT_BEFORE, - OP_PUT_BEFORE_END, + VIS_OP_CASE_LOWER, + VIS_OP_CASE_UPPER, + VIS_OP_CURSOR_EOL, + VIS_OP_PUT_AFTER_END, + VIS_OP_PUT_BEFORE, + VIS_OP_PUT_BEFORE_END, }; /* set operator to execute, has immediate effect if -- cgit v1.2.3