To: vim_dev@googlegroups.com Subject: Patch 7.4.2051 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2051 Problem: No proper testing of trunc_string(). Solution: Add a unittest for message.c. Files: src/Makefile, src/message.c, src/message_test.c, src/main.c, src/proto/main.pro, src/structs.h *** ../vim-7.4.2050/src/Makefile 2016-07-15 21:24:41.197452549 +0200 --- src/Makefile 2016-07-16 19:38:45.643149532 +0200 *************** *** 1558,1566 **** JSON_TEST_TARGET = json_test$(EXEEXT) MEMFILE_TEST_SRC = memfile_test.c MEMFILE_TEST_TARGET = memfile_test$(EXEEXT) ! UNITTEST_SRC = $(JSON_TEST_SRC) $(MEMFILE_TEST_SRC) ! UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(MEMFILE_TEST_TARGET) # All sources, also the ones that are not configured ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC) --- 1558,1568 ---- JSON_TEST_TARGET = json_test$(EXEEXT) MEMFILE_TEST_SRC = memfile_test.c MEMFILE_TEST_TARGET = memfile_test$(EXEEXT) + MESSAGE_TEST_SRC = message_test.c + MESSAGE_TEST_TARGET = message_test$(EXEEXT) ! UNITTEST_SRC = $(JSON_TEST_SRC) $(MEMFILE_TEST_SRC) $(MESSAGE_TEST_SRC) ! UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(MEMFILE_TEST_TARGET) $(MESSAGE_TEST_TARGET) # All sources, also the ones that are not configured ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC) *************** *** 1604,1610 **** objects/mark.o \ objects/memline.o \ objects/menu.o \ - objects/message.o \ objects/misc1.o \ objects/misc2.o \ objects/move.o \ --- 1606,1611 ---- *************** *** 1642,1660 **** $(CHANNEL_OBJ) \ $(WSDEBUG_OBJ) OBJ = $(OBJ_COMMON) \ objects/json.o \ objects/main.o \ ! objects/memfile.o JSON_TEST_OBJ = $(OBJ_COMMON) \ ! objects/json_test.o \ ! objects/memfile.o MEMFILE_TEST_OBJ = $(OBJ_COMMON) \ objects/json.o \ objects/memfile_test.o PRO_AUTO = \ arabic.pro \ blowfish.pro \ --- 1643,1670 ---- $(CHANNEL_OBJ) \ $(WSDEBUG_OBJ) + # The files included by tests are not in OBJ_COMMON. OBJ = $(OBJ_COMMON) \ objects/json.o \ objects/main.o \ ! objects/memfile.o \ ! objects/message.o JSON_TEST_OBJ = $(OBJ_COMMON) \ ! objects/memfile.o \ ! objects/message.o \ ! objects/json_test.o MEMFILE_TEST_OBJ = $(OBJ_COMMON) \ objects/json.o \ + objects/message.o \ objects/memfile_test.o + MESSAGE_TEST_OBJ = $(OBJ_COMMON) \ + objects/json.o \ + objects/memfile.o \ + objects/message_test.o + PRO_AUTO = \ arabic.pro \ blowfish.pro \ *************** *** 1970,1975 **** --- 1980,1988 ---- run_memfile_test: $(MEMFILE_TEST_TARGET) ./$(MEMFILE_TEST_TARGET) + run_message_test: $(MESSAGE_TEST_TARGET) + ./$(MESSAGE_TEST_TARGET) + # Run individual OLD style test, assuming that Vim was already compiled. test1 \ test_autocmd_option \ *************** *** 2123,2128 **** --- 2136,2148 ---- MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \ sh $(srcdir)/link.sh + $(MESSAGE_TEST_TARGET): auto/config.mk objects $(MESSAGE_TEST_OBJ) + $(CCC) version.c -o objects/version.o + @LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \ + -o $(MESSAGE_TEST_TARGET) $(MESSAGE_TEST_OBJ) $(ALL_LIBS)" \ + MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \ + sh $(srcdir)/link.sh + # install targets install: $(GUI_INSTALL) *************** *** 2941,2946 **** --- 2961,2969 ---- objects/message.o: message.c $(CCC) -o $@ message.c + objects/message_test.o: message_test.c + $(CCC) -o $@ message_test.c + objects/misc1.o: misc1.c $(CCC) -o $@ misc1.c *************** *** 3426,3431 **** --- 3449,3458 ---- os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \ structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h \ ex_cmds.h proto.h globals.h farsi.h arabic.h memfile.c + objects/message_test.o: message_test.c main.c vim.h auto/config.h feature.h \ + os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \ + structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h \ + ex_cmds.h proto.h globals.h farsi.h arabic.h message.c objects/hangulin.o: hangulin.c vim.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \ regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h proto.h \ *** ../vim-7.4.2050/src/message.c 2016-07-16 16:54:18.334699590 +0200 --- src/message.c 2016-07-16 19:36:06.884780592 +0200 *************** *** 260,266 **** return; } n = ptr2cells(s + e); ! if (len + n >= half) break; len += n; buf[e] = s[e]; --- 260,266 ---- return; } n = ptr2cells(s + e); ! if (len + n > half) break; len += n; buf[e] = s[e]; *** ../vim-7.4.2050/src/message_test.c 2016-07-16 19:48:58.148876983 +0200 --- src/message_test.c 2016-07-16 19:42:32.532819726 +0200 *************** *** 0 **** --- 1,77 ---- + /* vi:set ts=8 sts=4 sw=4: + * + * VIM - Vi IMproved by Bram Moolenaar + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + + /* + * message_test.c: Unittests for message.c + */ + + #undef NDEBUG + #include + + /* Must include main.c because it contains much more than just main() */ + #define NO_VIM_MAIN + #include "main.c" + + /* This file has to be included because some of the tested functions are + * static. */ + #include "message.c" + + /* + * Test trunc_string(). + */ + static void + test_trunc_string(void) + { + char_u buf[40]; + + /* in place */ + STRCPY(buf, "text"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "text") == 0); + + STRCPY(buf, "a short text"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "a short text") == 0); + + STRCPY(buf, "a text tha just fits"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "a text tha just fits") == 0); + + STRCPY(buf, "a text that nott fits"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "a text t...nott fits") == 0); + + /* copy from string to buf */ + trunc_string((char_u *)"text", buf, 20, 40); + assert(STRCMP(buf, "text") == 0); + + trunc_string((char_u *)"a short text", buf, 20, 40); + assert(STRCMP(buf, "a short text") == 0); + + trunc_string((char_u *)"a text tha just fits", buf, 20, 40); + assert(STRCMP(buf, "a text tha just fits") == 0); + + trunc_string((char_u *)"a text that nott fits", buf, 20, 40); + assert(STRCMP(buf, "a text t...nott fits") == 0); + } + + int + main(int argc, char **argv) + { + mparm_T params; + + vim_memset(¶ms, 0, sizeof(params)); + params.argc = argc; + params.argv = argv; + common_init(¶ms); + init_chartab(); + + test_trunc_string(); + return 0; + } *** ../vim-7.4.2050/src/main.c 2016-07-16 14:46:51.127240626 +0200 --- src/main.c 2016-07-16 19:31:47.879443174 +0200 *************** *** 23,92 **** # include "iscygpty.h" #endif - /* Maximum number of commands from + or -c arguments. */ - #define MAX_ARG_CMDS 10 - - /* values for "window_layout" */ - #define WIN_HOR 1 /* "-o" horizontally split windows */ - #define WIN_VER 2 /* "-O" vertically split windows */ - #define WIN_TABS 3 /* "-p" windows on tab pages */ - - /* Struct for various parameters passed between main() and other functions. */ - typedef struct - { - int argc; - char **argv; - - int evim_mode; /* started as "evim" */ - char_u *use_vimrc; /* vimrc from -u argument */ - - int n_commands; /* no. of commands from + or -c */ - char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c arg. */ - char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */ - int n_pre_commands; /* no. of commands from --cmd */ - char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd argument */ - - int edit_type; /* type of editing to do */ - char_u *tagname; /* tag from -t argument */ - #ifdef FEAT_QUICKFIX - char_u *use_ef; /* 'errorfile' from -q argument */ - #endif - - int want_full_screen; - int stdout_isatty; /* is stdout a terminal? */ - int not_a_term; /* no warning for missing term? */ - char_u *term; /* specified terminal name */ - #ifdef FEAT_CRYPT - int ask_for_key; /* -x argument */ - #endif - int no_swap_file; /* "-n" argument used */ - #ifdef FEAT_EVAL - int use_debug_break_level; - #endif - #ifdef FEAT_WINDOWS - int window_count; /* number of windows to use */ - int window_layout; /* 0, WIN_HOR, WIN_VER or WIN_TABS */ - #endif - - #ifdef FEAT_CLIENTSERVER - int serverArg; /* TRUE when argument for a server */ - char_u *serverName_arg; /* cmdline arg for server name */ - char_u *serverStr; /* remote server command */ - char_u *serverStrEnc; /* encoding of serverStr */ - char_u *servername; /* allocated name for our server */ - #endif - #if !defined(UNIX) - # define EXPAND_FILENAMES - int literal; /* don't expand file names */ - #endif - #ifdef MSWIN - int full_path; /* file name argument was full path */ - #endif - #ifdef FEAT_DIFF - int diff_mode; /* start with 'diff' set */ - #endif - } mparm_T; - /* Values for edit_type. */ #define EDIT_NONE 0 /* no edit type yet */ #define EDIT_FILE 1 /* file name argument[s] given, use argument list */ --- 23,28 ---- *************** *** 98,112 **** static int file_owned(char *fname); #endif static void mainerr(int, char_u *); #ifndef NO_VIM_MAIN static void main_msg(char *s); static void usage(void); static int get_number_arg(char_u *p, int *idx, int def); - # if defined(HAVE_LOCALE_H) || defined(X_LOCALE) - static void init_locale(void); - # endif static void parse_command_name(mparm_T *parmp); - static void early_arg_scan(mparm_T *parmp); static void command_line_scan(mparm_T *parmp); static void check_tty(mparm_T *parmp); static void read_stdin(void); --- 34,48 ---- static int file_owned(char *fname); #endif static void mainerr(int, char_u *); + # if defined(HAVE_LOCALE_H) || defined(X_LOCALE) + static void init_locale(void); + # endif + static void early_arg_scan(mparm_T *parmp); #ifndef NO_VIM_MAIN static void main_msg(char *s); static void usage(void); static int get_number_arg(char_u *p, int *idx, int def); static void parse_command_name(mparm_T *parmp); static void command_line_scan(mparm_T *parmp); static void check_tty(mparm_T *parmp); static void read_stdin(void); *************** *** 231,350 **** #endif starttime = time(NULL); ! #ifdef FEAT_MBYTE ! (void)mb_init(); /* init mb_bytelen_tab[] to ones */ ! #endif ! #ifdef FEAT_EVAL ! eval_init(); /* init global variables */ ! #endif ! ! #ifdef __QNXNTO__ ! qnx_init(); /* PhAttach() for clipboard, (and gui) */ ! #endif ! ! #ifdef MAC_OS_CLASSIC ! /* Prepare for possibly starting GUI sometime */ ! /* Macintosh needs this before any memory is allocated. */ ! gui_prepare(¶ms.argc, params.argv); ! TIME_MSG("GUI prepared"); ! #endif ! ! /* Init the table of Normal mode commands. */ ! init_normal_cmds(); ! ! #if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC) ! make_version(); /* Construct the long version string. */ ! #endif ! ! /* ! * Allocate space for the generic buffers (needed for set_init_1() and ! * EMSG2()). ! */ ! if ((IObuff = alloc(IOSIZE)) == NULL ! || (NameBuff = alloc(MAXPATHL)) == NULL) ! mch_exit(0); ! TIME_MSG("Allocated generic buffers"); ! ! #ifdef NBDEBUG ! /* Wait a moment for debugging NetBeans. Must be after allocating ! * NameBuff. */ ! nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); ! nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); ! TIME_MSG("NetBeans debug wait"); ! #endif ! ! #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) ! /* ! * Setup to use the current locale (for ctype() and many other things). ! * NOTE: Translated messages with encodings other than latin1 will not ! * work until set_init_1() has been called! ! */ ! init_locale(); ! TIME_MSG("locale set"); ! #endif ! ! #ifdef FEAT_GUI ! gui.dofork = TRUE; /* default is to use fork() */ ! #endif ! ! /* ! * Do a first scan of the arguments in "argv[]": ! * -display or --display ! * --server... ! * --socketid ! * --windowid ! */ ! early_arg_scan(¶ms); ! ! #ifdef FEAT_SUN_WORKSHOP ! findYourself(params.argv[0]); ! #endif ! #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC) ! /* Prepare for possibly starting GUI sometime */ ! gui_prepare(¶ms.argc, params.argv); ! TIME_MSG("GUI prepared"); ! #endif ! ! #ifdef FEAT_CLIPBOARD ! clip_init(FALSE); /* Initialise clipboard stuff */ ! TIME_MSG("clipboard setup"); ! #endif ! ! /* ! * Check if we have an interactive window. ! * On the Amiga: If there is no window, we open one with a newcli command ! * (needed for :! to * work). mch_check_win() will also handle the -d or ! * -dev argument. ! */ ! params.stdout_isatty = (mch_check_win(params.argc, params.argv) != FAIL); ! TIME_MSG("window checked"); ! ! /* ! * Allocate the first window and buffer. ! * Can't do anything without it, exit when it fails. ! */ ! if (win_alloc_first() == FAIL) ! mch_exit(0); ! ! init_yank(); /* init yank buffers */ ! ! alist_init(&global_alist); /* Init the argument list to empty. */ ! global_alist.id = 0; ! ! /* ! * Set the default values for the options. ! * NOTE: Non-latin1 translated messages are working only after this, ! * because this is where "has_mbyte" will be set, which is used by ! * msg_outtrans_len_attr(). ! * First find out the home directory, needed to expand "~" in options. ! */ ! init_homedir(); /* find real value of $HOME */ ! set_init_1(); ! TIME_MSG("inits 1"); ! ! #ifdef FEAT_EVAL ! set_lang_var(); /* set v:lang and v:ctype */ ! #endif #ifdef FEAT_CLIENTSERVER /* --- 167,173 ---- #endif starttime = time(NULL); ! common_init(¶ms); #ifdef FEAT_CLIENTSERVER /* *************** *** 1056,1061 **** --- 879,1007 ---- #endif /* PROTO */ /* + * Initialisation shared by main() and some tests. + */ + void + common_init(mparm_T *params) + { + + #ifdef FEAT_MBYTE + (void)mb_init(); /* init mb_bytelen_tab[] to ones */ + #endif + #ifdef FEAT_EVAL + eval_init(); /* init global variables */ + #endif + + #ifdef __QNXNTO__ + qnx_init(); /* PhAttach() for clipboard, (and gui) */ + #endif + + #ifdef MAC_OS_CLASSIC + /* Prepare for possibly starting GUI sometime */ + /* Macintosh needs this before any memory is allocated. */ + gui_prepare(¶ms->argc, params->argv); + TIME_MSG("GUI prepared"); + #endif + + /* Init the table of Normal mode commands. */ + init_normal_cmds(); + + #if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC) + make_version(); /* Construct the long version string. */ + #endif + + /* + * Allocate space for the generic buffers (needed for set_init_1() and + * EMSG2()). + */ + if ((IObuff = alloc(IOSIZE)) == NULL + || (NameBuff = alloc(MAXPATHL)) == NULL) + mch_exit(0); + TIME_MSG("Allocated generic buffers"); + + #ifdef NBDEBUG + /* Wait a moment for debugging NetBeans. Must be after allocating + * NameBuff. */ + nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); + nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); + TIME_MSG("NetBeans debug wait"); + #endif + + #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) + /* + * Setup to use the current locale (for ctype() and many other things). + * NOTE: Translated messages with encodings other than latin1 will not + * work until set_init_1() has been called! + */ + init_locale(); + TIME_MSG("locale set"); + #endif + + #ifdef FEAT_GUI + gui.dofork = TRUE; /* default is to use fork() */ + #endif + + /* + * Do a first scan of the arguments in "argv[]": + * -display or --display + * --server... + * --socketid + * --windowid + */ + early_arg_scan(params); + + #ifdef FEAT_SUN_WORKSHOP + findYourself(params->argv[0]); + #endif + #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC) + /* Prepare for possibly starting GUI sometime */ + gui_prepare(¶ms->argc, params->argv); + TIME_MSG("GUI prepared"); + #endif + + #ifdef FEAT_CLIPBOARD + clip_init(FALSE); /* Initialise clipboard stuff */ + TIME_MSG("clipboard setup"); + #endif + + /* + * Check if we have an interactive window. + * On the Amiga: If there is no window, we open one with a newcli command + * (needed for :! to * work). mch_check_win() will also handle the -d or + * -dev argument. + */ + params->stdout_isatty = (mch_check_win(params->argc, params->argv) != FAIL); + TIME_MSG("window checked"); + + /* + * Allocate the first window and buffer. + * Can't do anything without it, exit when it fails. + */ + if (win_alloc_first() == FAIL) + mch_exit(0); + + init_yank(); /* init yank buffers */ + + alist_init(&global_alist); /* Init the argument list to empty. */ + global_alist.id = 0; + + /* + * Set the default values for the options. + * NOTE: Non-latin1 translated messages are working only after this, + * because this is where "has_mbyte" will be set, which is used by + * msg_outtrans_len_attr(). + * First find out the home directory, needed to expand "~" in options. + */ + init_homedir(); /* find real value of $HOME */ + set_init_1(); + TIME_MSG("inits 1"); + + #ifdef FEAT_EVAL + set_lang_var(); /* set v:lang and v:ctype */ + #endif + } + + /* * Main loop: Execute Normal mode commands until exiting Vim. * Also used to handle commands in the command-line window, until the window * is closed. *************** *** 1547,1571 **** mch_exit(exitval); } - #ifndef NO_VIM_MAIN - /* - * Get a (optional) count for a Vim argument. - */ - static int - get_number_arg( - char_u *p, /* pointer to argument */ - int *idx, /* index in argument, is incremented */ - int def) /* default value */ - { - if (vim_isdigit(p[*idx])) - { - def = atoi((char *)&(p[*idx])); - while (vim_isdigit(p[*idx])) - *idx = *idx + 1; - } - return def; - } - #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) /* * Setup to use the current locale (for ctype() and many other things). --- 1493,1498 ---- *************** *** 1617,1716 **** #endif /* - * Check for: [r][e][g][vi|vim|view][diff][ex[im]] - * If the executable name starts with "r" we disable shell commands. - * If the next character is "e" we run in Easy mode. - * If the next character is "g" we run the GUI version. - * If the next characters are "view" we start in readonly mode. - * If the next characters are "diff" or "vimdiff" we start in diff mode. - * If the next characters are "ex" we start in Ex mode. If it's followed - * by "im" use improved Ex mode. - */ - static void - parse_command_name(mparm_T *parmp) - { - char_u *initstr; - - initstr = gettail((char_u *)parmp->argv[0]); - - #ifdef MACOS_X_UNIX - /* An issue has been seen when launching Vim in such a way that - * $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the - * executable or a symbolic link of it. Until this issue is resolved - * we prohibit the GUI from being used. - */ - if (STRCMP(initstr, parmp->argv[0]) == 0) - disallow_gui = TRUE; - - /* TODO: On MacOS X default to gui if argv[0] ends in: - * /Vim.app/Contents/MacOS/Vim */ - #endif - - #ifdef FEAT_EVAL - set_vim_var_string(VV_PROGNAME, initstr, -1); - set_vim_var_string(VV_PROGPATH, (char_u *)parmp->argv[0], -1); - #endif - - if (TOLOWER_ASC(initstr[0]) == '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')) - { - #ifdef FEAT_GUI - gui.starting = TRUE; - #endif - parmp->evim_mode = TRUE; - ++initstr; - } - - /* "gvim" starts the GUI. Also accept "Gvim" for MS-Windows. */ - if (TOLOWER_ASC(initstr[0]) == 'g') - { - main_start_gui(); - #ifdef FEAT_GUI - ++initstr; - #endif - } - - if (STRNICMP(initstr, "view", 4) == 0) - { - 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; - - /* Catch "[r][g]vimdiff" and "[r][g]viewdiff". */ - if (STRICMP(initstr, "diff") == 0) - { - #ifdef FEAT_DIFF - parmp->diff_mode = TRUE; - #else - mch_errmsg(_("This Vim was not compiled with the diff feature.")); - mch_errmsg("\n"); - mch_exit(2); - #endif - } - - if (STRNICMP(initstr, "ex", 2) == 0) - { - if (STRNICMP(initstr + 2, "im", 2) == 0) - exmode_active = EXMODE_VIM; - else - exmode_active = EXMODE_NORMAL; - change_compatible(TRUE); /* set 'compatible' */ - } - } - - /* * Get the name of the display, before gui_prepare() removes it from * argv[]. Used for the xterm-clipboard display. * --- 1544,1549 ---- *************** *** 1804,1809 **** --- 1637,1755 ---- #endif } + #ifndef NO_VIM_MAIN + /* + * Get a (optional) count for a Vim argument. + */ + static int + get_number_arg( + char_u *p, /* pointer to argument */ + int *idx, /* index in argument, is incremented */ + int def) /* default value */ + { + if (vim_isdigit(p[*idx])) + { + def = atoi((char *)&(p[*idx])); + while (vim_isdigit(p[*idx])) + *idx = *idx + 1; + } + return def; + } + + /* + * Check for: [r][e][g][vi|vim|view][diff][ex[im]] + * If the executable name starts with "r" we disable shell commands. + * If the next character is "e" we run in Easy mode. + * If the next character is "g" we run the GUI version. + * If the next characters are "view" we start in readonly mode. + * If the next characters are "diff" or "vimdiff" we start in diff mode. + * If the next characters are "ex" we start in Ex mode. If it's followed + * by "im" use improved Ex mode. + */ + static void + parse_command_name(mparm_T *parmp) + { + char_u *initstr; + + initstr = gettail((char_u *)parmp->argv[0]); + + #ifdef MACOS_X_UNIX + /* An issue has been seen when launching Vim in such a way that + * $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the + * executable or a symbolic link of it. Until this issue is resolved + * we prohibit the GUI from being used. + */ + if (STRCMP(initstr, parmp->argv[0]) == 0) + disallow_gui = TRUE; + + /* TODO: On MacOS X default to gui if argv[0] ends in: + * /Vim.app/Contents/MacOS/Vim */ + #endif + + #ifdef FEAT_EVAL + set_vim_var_string(VV_PROGNAME, initstr, -1); + set_vim_var_string(VV_PROGPATH, (char_u *)parmp->argv[0], -1); + #endif + + if (TOLOWER_ASC(initstr[0]) == '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')) + { + #ifdef FEAT_GUI + gui.starting = TRUE; + #endif + parmp->evim_mode = TRUE; + ++initstr; + } + + /* "gvim" starts the GUI. Also accept "Gvim" for MS-Windows. */ + if (TOLOWER_ASC(initstr[0]) == 'g') + { + main_start_gui(); + #ifdef FEAT_GUI + ++initstr; + #endif + } + + if (STRNICMP(initstr, "view", 4) == 0) + { + 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; + + /* Catch "[r][g]vimdiff" and "[r][g]viewdiff". */ + if (STRICMP(initstr, "diff") == 0) + { + #ifdef FEAT_DIFF + parmp->diff_mode = TRUE; + #else + mch_errmsg(_("This Vim was not compiled with the diff feature.")); + mch_errmsg("\n"); + mch_exit(2); + #endif + } + + if (STRNICMP(initstr, "ex", 2) == 0) + { + if (STRNICMP(initstr + 2, "im", 2) == 0) + exmode_active = EXMODE_VIM; + else + exmode_active = EXMODE_NORMAL; + change_compatible(TRUE); /* set 'compatible' */ + } + } + /* * Scan the command line arguments. */ *** ../vim-7.4.2050/src/proto/main.pro 2016-07-02 20:27:29.953436359 +0200 --- src/proto/main.pro 2016-07-16 19:21:10.421962175 +0200 *************** *** 1,4 **** --- 1,5 ---- /* main.c */ + void common_init(mparm_T *params); void main_loop(int cmdwin, int noexmode); void getout_preserve_modified(int exitval); void getout(int exitval); *** ../vim-7.4.2050/src/structs.h 2016-07-14 22:09:35.091660920 +0200 --- src/structs.h 2016-07-16 19:24:14.184090176 +0200 *************** *** 3053,3055 **** --- 3053,3119 ---- partial_T *tr_partial; #endif }; + + /* Maximum number of commands from + or -c arguments. */ + #define MAX_ARG_CMDS 10 + + /* values for "window_layout" */ + #define WIN_HOR 1 /* "-o" horizontally split windows */ + #define WIN_VER 2 /* "-O" vertically split windows */ + #define WIN_TABS 3 /* "-p" windows on tab pages */ + + /* Struct for various parameters passed between main() and other functions. */ + typedef struct + { + int argc; + char **argv; + + int evim_mode; /* started as "evim" */ + char_u *use_vimrc; /* vimrc from -u argument */ + + int n_commands; /* no. of commands from + or -c */ + char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c arg. */ + char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */ + int n_pre_commands; /* no. of commands from --cmd */ + char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd argument */ + + int edit_type; /* type of editing to do */ + char_u *tagname; /* tag from -t argument */ + #ifdef FEAT_QUICKFIX + char_u *use_ef; /* 'errorfile' from -q argument */ + #endif + + int want_full_screen; + int stdout_isatty; /* is stdout a terminal? */ + int not_a_term; /* no warning for missing term? */ + char_u *term; /* specified terminal name */ + #ifdef FEAT_CRYPT + int ask_for_key; /* -x argument */ + #endif + int no_swap_file; /* "-n" argument used */ + #ifdef FEAT_EVAL + int use_debug_break_level; + #endif + #ifdef FEAT_WINDOWS + int window_count; /* number of windows to use */ + int window_layout; /* 0, WIN_HOR, WIN_VER or WIN_TABS */ + #endif + + #ifdef FEAT_CLIENTSERVER + int serverArg; /* TRUE when argument for a server */ + char_u *serverName_arg; /* cmdline arg for server name */ + char_u *serverStr; /* remote server command */ + char_u *serverStrEnc; /* encoding of serverStr */ + char_u *servername; /* allocated name for our server */ + #endif + #if !defined(UNIX) + # define EXPAND_FILENAMES + int literal; /* don't expand file names */ + #endif + #ifdef MSWIN + int full_path; /* file name argument was full path */ + #endif + #ifdef FEAT_DIFF + int diff_mode; /* start with 'diff' set */ + #endif + } mparm_T; *** ../vim-7.4.2050/src/version.c 2016-07-16 18:24:52.468279220 +0200 --- src/version.c 2016-07-16 18:48:29.585964924 +0200 *************** *** 760,761 **** --- 760,763 ---- { /* Add new patch number below this line */ + /**/ + 2051, /**/ -- You got to work at a mill? Lucky! I got sent back to work in the acid-mines for my daily crust of stale bread... which not even the birds would eat. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///