]> granicus.if.org Git - vim/commitdiff
patch 7.4.2176 v7.4.2176
authorBram Moolenaar <Bram@vim.org>
Sun, 7 Aug 2016 13:19:26 +0000 (15:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 7 Aug 2016 13:19:26 +0000 (15:19 +0200)
Problem:    #ifdefs in main() are complicated.
Solution:   Always define vim_main2().  Move params to the file level.
            (suggested by Ken Takata)

src/if_mzsch.c
src/main.c
src/proto/if_mzsch.pro
src/structs.h
src/version.c
src/vim.h

index 7a462ad54b2ccf377b86be11fc6d521880c375ff..41388109ea7cae4021da7b4e42f9ca9a5d3409f6 100644 (file)
@@ -1009,8 +1009,11 @@ static intptr_t _tls_index = 0;
 #endif
 
     int
-mzscheme_main(int argc, char** argv)
+mzscheme_main()
 {
+    int            argc = 0;
+    char    *argv = NULL;
+
 #ifdef DYNAMIC_MZSCHEME
     /*
      * Racket requires trampolined startup.  We can not load it later.
@@ -1019,16 +1022,16 @@ mzscheme_main(int argc, char** argv)
     if (!mzscheme_enabled(FALSE))
     {
        disabled = TRUE;
-       return vim_main2(argc, argv);
+       return vim_main2();
     }
 #endif
 #ifdef HAVE_TLS_SPACE
     scheme_register_tls_space(&tls_space, _tls_index);
 #endif
 #ifdef TRAMPOLINED_MZVIM_STARTUP
-    return scheme_main_setup(TRUE, mzscheme_env_main, argc, argv);
+    return scheme_main_setup(TRUE, mzscheme_env_main, argc, &argv);
 #else
-    return mzscheme_env_main(NULL, argc, argv);
+    return mzscheme_env_main(NULL, argc, &argv);
 #endif
 }
 
@@ -1056,7 +1059,7 @@ mzscheme_env_main(Scheme_Env *env, int argc, char **argv)
      * We trampoline into vim_main2
      * Passing argc, argv through from mzscheme_main
      */
-    vim_main_result = vim_main2(argc, argv);
+    vim_main_result = vim_main2();
 #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC)
     /* releasing dummy */
     MZ_GC_REG();
index 48e90c27ffe05590143a4599d81ce7aedaef789a..c694532860260a95521a1d4a3698f96556337fd3 100644 (file)
@@ -92,6 +92,9 @@ static char_u *start_dir = NULL;      /* current working dir on startup */
 
 static int has_dash_c_arg = FALSE;
 
+/* Various parameters passed between main() and other functions. */
+static mparm_T params;
+
     int
 # ifdef VIMDLL
 _export
@@ -106,9 +109,6 @@ main
 # endif
 (int argc, char **argv)
 {
-    char_u     *fname = NULL;          /* file name from command line */
-    mparm_T    params;                 /* various parameters passed between
-                                        * main() and other functions. */
 #ifdef STARTUPTIME
     int                i;
 #endif
@@ -157,6 +157,7 @@ main
 #endif
 
 #ifdef STARTUPTIME
+    /* Need to find "--startuptime" before actually parsing arguments. */
     for (i = 1; i < argc; ++i)
     {
        if (STRICMP(argv[i], "--startuptime") == 0 && i + 1 < argc)
@@ -241,7 +242,7 @@ main
                mch_chdir((char *)start_dir);
        }
 #endif
-       fname = alist_name(&GARGLIST[0]);
+       params.fname = alist_name(&GARGLIST[0]);
     }
 
 #if defined(WIN32) && defined(FEAT_MBYTE)
@@ -263,7 +264,7 @@ main
         * Hint: to avoid this when typing a command use a forward slash.
         * If the cd fails, it doesn't matter.
         */
-       (void)vim_chdirfile(fname);
+       (void)vim_chdirfile(params.fname);
        if (start_dir != NULL)
            mch_dirname(start_dir, MAXPATHL);
     }
@@ -281,7 +282,7 @@ main
     /*
      * When listing swap file names, don't do cursor positioning et. al.
      */
-    if (recoverymode && fname == NULL)
+    if (recoverymode && params.fname == NULL)
        params.want_full_screen = FALSE;
 
     /*
@@ -312,8 +313,8 @@ main
        if (getcwd((char *)NameBuff, MAXPATHL) != NULL
                                                && STRCMP(NameBuff, "/") == 0)
        {
-           if (fname != NULL)
-               (void)vim_chdirfile(fname);
+           if (params.fname != NULL)
+               (void)vim_chdirfile(params.fname);
            else
            {
                expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
@@ -407,37 +408,23 @@ main
      * Newer version of MzScheme (Racket) require earlier (trampolined)
      * initialisation via scheme_main_setup.
      * Implement this by initialising it as early as possible
-     * and splitting off remaining Vim main into vim_main2
+     * and splitting off remaining Vim main into vim_main2().
      */
-    {
-       /* Pack up preprocessed command line arguments.
-        * It is safe because Scheme does not access argc/argv. */
-       char *args[2];
-       args[0] = (char *)fname;
-       args[1] = (char *)&params;
-       return mzscheme_main(2, args);
-    }
-}
+    return mzscheme_main();
+#else
+    return vim_main2();
 #endif
+}
 #endif /* NO_VIM_MAIN */
 
-/* vim_main2() needs to be produced when FEAT_MZSCHEME is defined even when
- * NO_VIM_MAIN is defined. */
-#ifdef FEAT_MZSCHEME
+/*
+ * vim_main2() is needed for FEAT_MZSCHEME, but we define it always to keep
+ * things simple.
+ * It is also defined when NO_VIM_MAIN is defined, but then it's empty.
+ */
     int
-vim_main2(int argc UNUSED, char **argv UNUSED)
+vim_main2(void)
 {
-# ifndef NO_VIM_MAIN
-    char_u     *fname = (char_u *)argv[0];
-    mparm_T    params;
-
-    memcpy(&params, argv[1], sizeof(params));
-# else
-    return 0;
-}
-# endif
-#endif
-
 #ifndef NO_VIM_MAIN
     /* Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
      * Allows for setting 'loadplugins' there. */
@@ -493,7 +480,7 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
      * This uses the 'dir' option, therefore it must be after the
      * initializations.
      */
-    if (recoverymode && fname == NULL)
+    if (recoverymode && params.fname == NULL)
     {
        recover_names(NULL, TRUE, 0, NULL);
        mch_exit(0);
@@ -888,16 +875,17 @@ vim_main2(int argc UNUSED, char **argv UNUSED)
     */
     main_loop(FALSE, FALSE);
 
+#endif /* NO_VIM_MAIN */
+
     return 0;
 }
-#endif /* NO_VIM_MAIN */
 #endif /* PROTO */
 
 /*
  * Initialisation shared by main() and some tests.
  */
     void
-common_init(mparm_T *params)
+common_init(mparm_T *paramp)
 {
 
 #ifdef FEAT_MBYTE
@@ -914,7 +902,7 @@ common_init(mparm_T *params)
 #ifdef MAC_OS_CLASSIC
     /* Prepare for possibly starting GUI sometime */
     /* Macintosh needs this before any memory is allocated. */
-    gui_prepare(&params->argc, params->argv);
+    gui_prepare(&paramp->argc, paramp->argv);
     TIME_MSG("GUI prepared");
 #endif
 
@@ -963,14 +951,14 @@ common_init(mparm_T *params)
      *   --socketid
      *   --windowid
      */
-    early_arg_scan(params);
+    early_arg_scan(paramp);
 
 #ifdef FEAT_SUN_WORKSHOP
-    findYourself(params->argv[0]);
+    findYourself(paramp->argv[0]);
 #endif
 #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC)
     /* Prepare for possibly starting GUI sometime */
-    gui_prepare(&params->argc, params->argv);
+    gui_prepare(&paramp->argc, paramp->argv);
     TIME_MSG("GUI prepared");
 #endif
 
@@ -985,7 +973,7 @@ common_init(mparm_T *params)
      * (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);
+    paramp->stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != FAIL);
     TIME_MSG("window checked");
 
     /*
index 193bd499ad125922906f9073dc296c8a589ba37f..bab82cef3f1074338610d7cfe297f52e0b2cca7f 100644 (file)
@@ -3,7 +3,7 @@ int mzscheme_enabled(int verbose);
 void mzvim_check_threads(void);
 void mzvim_reset_timer(void);
 void mzscheme_end(void);
-int mzscheme_main(int argc, char **argv);
+int mzscheme_main(void);
 void mzscheme_buffer_free(buf_T *buf);
 void mzscheme_window_free(win_T *win);
 void ex_mzscheme(exarg_T *eap);
index 5439748286eeaa18b4454becae7387054a5c0495..6cfbb3c25dbb11b86a247297103a9d945bb114e8 100644 (file)
@@ -3160,7 +3160,7 @@ struct timer_S
     timer_T    *tr_prev;
     proftime_T tr_due;             /* when the callback is to be invoked */
     int                tr_repeat;          /* number of times to repeat, -1 forever */
-    long       tr_interval;        /* only set when it repeats */
+    long       tr_interval;        /* msec */
     char_u     *tr_callback;       /* allocated */
     partial_T  *tr_partial;
 #endif
@@ -3180,6 +3180,8 @@ typedef struct
     int                argc;
     char       **argv;
 
+    char_u     *fname;                 /* first file to edit */
+
     int                evim_mode;              /* started as "evim" */
     char_u     *use_vimrc;             /* vimrc from -u argument */
 
index 944dfa4230eb7af5e844de6644d75de7b1c03c41..4d6765f05999bb05c78ca86c9e57787174fc9cc8 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2176,
 /**/
     2175,
 /**/
index 928a558fba08006500c3ba4a80c0a5e8f46a6f7a..96cfc6ccadba129804cf3fb9b64bd496a291ab6a 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2439,10 +2439,8 @@ typedef enum
 #define JSON_JS                1   /* use JS instead of JSON */
 #define JSON_NO_NONE   2   /* v:none item not allowed */
 
-#ifdef FEAT_MZSCHEME
-/* this is in main.c, cproto can't handle it. */
-int vim_main2(int argc, char **argv);
-#endif
+/* This is in main.c, cproto can't handle it. */
+int vim_main2(void);
 
 /* Used for flags of do_in_path() */
 #define DIP_ALL            0x01        /* all matches, not just the first one */