aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorAshley Hewson <a.hewson@gmail.com>2014-02-23 16:23:53 +0000
committerAshley Hewson <a.hewson@gmail.com>2014-02-23 16:23:53 +0000
commitb0abcda487d4f1bc7eb3f6a1edc878e576124451 (patch)
treeaaa0ffe6dff75594f13f47b02e10e5aa25efa68e /src/main.c
parentcebac0fc59cda330b8e26a2bab2bd2c1fb09df13 (diff)
parent19296296dbdbbb23538cb58b3ec0b0c6f5036bb1 (diff)
downloadrneovim-b0abcda487d4f1bc7eb3f6a1edc878e576124451.tar.gz
rneovim-b0abcda487d4f1bc7eb3f6a1edc878e576124451.tar.bz2
rneovim-b0abcda487d4f1bc7eb3f6a1edc878e576124451.zip
Merge pull request #54 from mitchellwrosen/master
Clean up main.c:parse_command_name
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/main.c b/src/main.c
index 8eb0a605b3..d073fbe9a9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -70,6 +70,8 @@ static int get_number_arg __ARGS((char_u *p, int *idx, int def));
static void init_locale __ARGS((void));
# endif
static void parse_command_name __ARGS((mparm_T *parmp));
+static bool parse_char_i __ARGS((char_u **input, char val));
+static bool parse_string __ARGS((char_u **input, char* val, int len));
static void command_line_scan __ARGS((mparm_T *parmp));
static void init_params __ARGS((mparm_T *parmp, int argc, char **argv));
static void init_startuptime __ARGS((mparm_T *parmp));
@@ -91,7 +93,7 @@ static void main_start_gui __ARGS((void));
# if defined(HAS_SWAP_EXISTS_ACTION)
static void check_swap_exists_action __ARGS((void));
# endif
-#endif
+#endif /* NO_VIM_MAIN */
/*
@@ -899,39 +901,33 @@ static void parse_command_name(parmp)
set_vim_var_string(VV_PROGNAME, initstr, -1);
- if (TOLOWER_ASC(initstr[0]) == 'r') {
+ if (STRNICMP(initstr, "editor", 6) == 0)
+ return;
+
+ if (parse_char_i(&initstr, 'r'))
restricted = TRUE;
- ++initstr;
- }
- /* Use evim mode for "evim" and "egvim", not for "editor". */
- if (TOLOWER_ASC(initstr[0]) == 'e'
- && (TOLOWER_ASC(initstr[1]) == 'v'
- || TOLOWER_ASC(initstr[1]) == 'g')) {
+ if (parse_char_i(&initstr, 'e'))
parmp->evim_mode = TRUE;
- ++initstr;
- }
/* "gvim" starts the GUI. Also accept "Gvim" for MS-Windows. */
- if (TOLOWER_ASC(initstr[0]) == 'g') {
+ if (parse_char_i(&initstr, 'g'))
main_start_gui();
- }
- if (STRNICMP(initstr, "view", 4) == 0) {
+ if (parse_string(&initstr, "view", 4)) {
readonlymode = TRUE;
curbuf->b_p_ro = TRUE;
p_uc = 10000; /* don't update very often */
- initstr += 4;
- } else if (STRNICMP(initstr, "vim", 3) == 0)
- initstr += 3;
+ } else {
+ parse_string(&initstr, "vim", 3); /* consume "vim" if it's there */
+ }
/* Catch "[r][g]vimdiff" and "[r][g]viewdiff". */
- if (STRICMP(initstr, "diff") == 0) {
+ if (parse_string(&initstr, "diff", 4))
parmp->diff_mode = TRUE;
- }
- if (STRNICMP(initstr, "ex", 2) == 0) {
- if (STRNICMP(initstr + 2, "im", 2) == 0)
+ if (parse_string(&initstr, "ex", 2)) {
+ if (parse_string(&initstr, "im", 2))
exmode_active = EXMODE_VIM;
else
exmode_active = EXMODE_NORMAL;
@@ -939,6 +935,29 @@ static void parse_command_name(parmp)
}
}
+static bool parse_char_i(input, val)
+ char_u **input;
+ char val;
+{
+ if (TOLOWER_ASC(**input) == val) {
+ *input += 1; /* or (*input)++ WITH parens */
+ return true;
+ }
+ return false;
+}
+
+static bool parse_string(input, val, len)
+ char_u **input;
+ char *val;
+ int len;
+{
+ if (STRNICMP(*input, val, len) == 0) {
+ *input += len;
+ return true;
+ }
+ return false;
+}
+
/*
* Scan the command line arguments.
*/
@@ -2062,7 +2081,7 @@ static void main_start_gui() {
mch_exit(2);
}
-#endif /* NO_VIM_MAIN */
+#endif /* NO_VIM_MAIN */
/*
* Get an environment variable, and execute it as Ex commands.