Patch 7.4.2176
Problem:    #ifdefs in main() are complicated.
Solution:   Always define vim_main2().  Move params to the file level.
            (suggested by Ken Takata)
Files:      src/main.c, src/structs.h, src/vim.h, src/if_mzsch.c,
            src/proto/if_mzsch.pro


*** ../vim-7.4.2175/src/main.c  2016-08-06 19:01:33.976856777 +0200
--- src/main.c  2016-08-07 15:11:26.660172466 +0200
***************
*** 92,97 ****
--- 92,100 ----
  
  static int has_dash_c_arg = FALSE;
  
+ /* Various parameters passed between main() and other functions. */
+ static mparm_T        params;
+ 
      int
  # ifdef VIMDLL
  _export
***************
*** 106,114 ****
  # 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
--- 109,114 ----
***************
*** 157,162 ****
--- 157,163 ----
  #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,247 ****
                mch_chdir((char *)start_dir);
        }
  #endif
!       fname = alist_name(&GARGLIST[0]);
      }
  
  #if defined(WIN32) && defined(FEAT_MBYTE)
--- 242,248 ----
                mch_chdir((char *)start_dir);
        }
  #endif
!       params.fname = alist_name(&GARGLIST[0]);
      }
  
  #if defined(WIN32) && defined(FEAT_MBYTE)
***************
*** 263,269 ****
         * Hint: to avoid this when typing a command use a forward slash.
         * If the cd fails, it doesn't matter.
         */
!       (void)vim_chdirfile(fname);
        if (start_dir != NULL)
            mch_dirname(start_dir, MAXPATHL);
      }
--- 264,270 ----
         * Hint: to avoid this when typing a command use a forward slash.
         * If the cd fails, it doesn't matter.
         */
!       (void)vim_chdirfile(params.fname);
        if (start_dir != NULL)
            mch_dirname(start_dir, MAXPATHL);
      }
***************
*** 281,287 ****
      /*
       * When listing swap file names, don't do cursor positioning et. al.
       */
!     if (recoverymode && fname == NULL)
        params.want_full_screen = FALSE;
  
      /*
--- 282,288 ----
      /*
       * When listing swap file names, don't do cursor positioning et. al.
       */
!     if (recoverymode && params.fname == NULL)
        params.want_full_screen = FALSE;
  
      /*
***************
*** 312,319 ****
        if (getcwd((char *)NameBuff, MAXPATHL) != NULL
                                                && STRCMP(NameBuff, "/") == 0)
        {
!           if (fname != NULL)
!               (void)vim_chdirfile(fname);
            else
            {
                expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
--- 313,320 ----
        if (getcwd((char *)NameBuff, MAXPATHL) != NULL
                                                && STRCMP(NameBuff, "/") == 0)
        {
!           if (params.fname != NULL)
!               (void)vim_chdirfile(params.fname);
            else
            {
                expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
***************
*** 407,443 ****
       * 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
       */
!     {
!       /* 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);
!     }
! }
  #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
      int
! vim_main2(int argc UNUSED, char **argv UNUSED)
  {
- # 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. */
--- 408,430 ----
       * 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().
       */
!     return mzscheme_main();
! #else
!     return vim_main2();
  #endif
+ }
  #endif /* NO_VIM_MAIN */
  
! /*
!  * 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(void)
  {
  #ifndef NO_VIM_MAIN
      /* Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
       * Allows for setting 'loadplugins' there. */
***************
*** 493,499 ****
       * This uses the 'dir' option, therefore it must be after the
       * initializations.
       */
!     if (recoverymode && fname == NULL)
      {
        recover_names(NULL, TRUE, 0, NULL);
        mch_exit(0);
--- 480,486 ----
       * This uses the 'dir' option, therefore it must be after the
       * initializations.
       */
!     if (recoverymode && params.fname == NULL)
      {
        recover_names(NULL, TRUE, 0, NULL);
        mch_exit(0);
***************
*** 888,903 ****
      */
      main_loop(FALSE, FALSE);
  
      return 0;
  }
- #endif /* NO_VIM_MAIN */
  #endif /* PROTO */
  
  /*
   * Initialisation shared by main() and some tests.
   */
      void
! common_init(mparm_T *params)
  {
  
  #ifdef FEAT_MBYTE
--- 875,891 ----
      */
      main_loop(FALSE, FALSE);
  
+ #endif /* NO_VIM_MAIN */
+ 
      return 0;
  }
  #endif /* PROTO */
  
  /*
   * Initialisation shared by main() and some tests.
   */
      void
! common_init(mparm_T *paramp)
  {
  
  #ifdef FEAT_MBYTE
***************
*** 914,920 ****
  #ifdef MAC_OS_CLASSIC
      /* Prepare for possibly starting GUI sometime */
      /* Macintosh needs this before any memory is allocated. */
!     gui_prepare(&params->argc, params->argv);
      TIME_MSG("GUI prepared");
  #endif
  
--- 902,908 ----
  #ifdef MAC_OS_CLASSIC
      /* Prepare for possibly starting GUI sometime */
      /* Macintosh needs this before any memory is allocated. */
!     gui_prepare(&paramp->argc, paramp->argv);
      TIME_MSG("GUI prepared");
  #endif
  
***************
*** 963,976 ****
       *   --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(&params->argc, params->argv);
      TIME_MSG("GUI prepared");
  #endif
  
--- 951,964 ----
       *   --socketid
       *   --windowid
       */
!     early_arg_scan(paramp);
  
  #ifdef FEAT_SUN_WORKSHOP
!     findYourself(paramp->argv[0]);
  #endif
  #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC)
      /* Prepare for possibly starting GUI sometime */
!     gui_prepare(&paramp->argc, paramp->argv);
      TIME_MSG("GUI prepared");
  #endif
  
***************
*** 985,991 ****
       * (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");
  
      /*
--- 973,979 ----
       * (needed for :! to * work). mch_check_win() will also handle the -d or
       * -dev argument.
       */
!     paramp->stdout_isatty = (mch_check_win(paramp->argc, paramp->argv) != 
FAIL);
      TIME_MSG("window checked");
  
      /*
*** ../vim-7.4.2175/src/structs.h       2016-08-01 20:46:20.606667766 +0200
--- src/structs.h       2016-08-07 14:56:55.815262296 +0200
***************
*** 3160,3166 ****
      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 */
      char_u    *tr_callback;       /* allocated */
      partial_T *tr_partial;
  #endif
--- 3160,3166 ----
      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;        /* msec */
      char_u    *tr_callback;       /* allocated */
      partial_T *tr_partial;
  #endif
***************
*** 3180,3185 ****
--- 3180,3187 ----
      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 */
  
*** ../vim-7.4.2175/src/vim.h   2016-08-06 19:01:33.980856744 +0200
--- src/vim.h   2016-08-07 14:59:40.333922840 +0200
***************
*** 2439,2448 ****
  #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
  
  /* Used for flags of do_in_path() */
  #define DIP_ALL           0x01        /* all matches, not just the first one 
*/
--- 2439,2446 ----
  #define JSON_JS               1   /* use JS instead of JSON */
  #define JSON_NO_NONE  2   /* v:none item not allowed */
  
! /* 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 
*/
*** ../vim-7.4.2175/src/if_mzsch.c      2016-08-01 15:40:24.183878405 +0200
--- src/if_mzsch.c      2016-08-07 14:52:24.885470223 +0200
***************
*** 1009,1016 ****
  #endif
  
      int
! mzscheme_main(int argc, char** argv)
  {
  #ifdef DYNAMIC_MZSCHEME
      /*
       * Racket requires trampolined startup.  We can not load it later.
--- 1009,1019 ----
  #endif
  
      int
! mzscheme_main()
  {
+     int           argc = 0;
+     char    *argv = NULL;
+ 
  #ifdef DYNAMIC_MZSCHEME
      /*
       * Racket requires trampolined startup.  We can not load it later.
***************
*** 1019,1034 ****
      if (!mzscheme_enabled(FALSE))
      {
        disabled = TRUE;
!       return vim_main2(argc, argv);
      }
  #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);
  #else
!     return mzscheme_env_main(NULL, argc, argv);
  #endif
  }
  
--- 1022,1037 ----
      if (!mzscheme_enabled(FALSE))
      {
        disabled = TRUE;
!       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);
  #else
!     return mzscheme_env_main(NULL, argc, &argv);
  #endif
  }
  
***************
*** 1056,1062 ****
       * We trampoline into vim_main2
       * Passing argc, argv through from mzscheme_main
       */
!     vim_main_result = vim_main2(argc, argv);
  #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC)
      /* releasing dummy */
      MZ_GC_REG();
--- 1059,1065 ----
       * We trampoline into vim_main2
       * Passing argc, argv through from mzscheme_main
       */
!     vim_main_result = vim_main2();
  #if !defined(TRAMPOLINED_MZVIM_STARTUP) && defined(MZ_PRECISE_GC)
      /* releasing dummy */
      MZ_GC_REG();
*** ../vim-7.4.2175/src/proto/if_mzsch.pro      2016-01-30 13:28:23.921007206 
+0100
--- src/proto/if_mzsch.pro      2016-08-07 14:52:29.657431310 +0200
***************
*** 3,9 ****
  void mzvim_check_threads(void);
  void mzvim_reset_timer(void);
  void mzscheme_end(void);
! int mzscheme_main(int argc, char **argv);
  void mzscheme_buffer_free(buf_T *buf);
  void mzscheme_window_free(win_T *win);
  void ex_mzscheme(exarg_T *eap);
--- 3,9 ----
  void mzvim_check_threads(void);
  void mzvim_reset_timer(void);
  void mzscheme_end(void);
! int mzscheme_main(void);
  void mzscheme_buffer_free(buf_T *buf);
  void mzscheme_window_free(win_T *win);
  void ex_mzscheme(exarg_T *eap);
*** ../vim-7.4.2175/src/version.c       2016-08-07 14:03:10.125705237 +0200
--- src/version.c       2016-08-07 15:17:45.309086990 +0200
***************
*** 765,766 ****
--- 765,768 ----
  {   /* Add new patch number below this line */
+ /**/
+     2176,
  /**/

-- 
The acknowledged parents of reengineering are Michael Hammer and James Champy.
When I say they're the "parents" I don't mean they had sex - and I apologize
for making you think about it.  I mean they wrote the best-selling business
book _Reengineering the Corporation_, which was published in 1993.
   Businesses flocked to reengineering like frat boys to a drunken
cheerleader.  (This analogy wasn't necessary, but I'm trying to get my mind
off that Hammer and Champy thing.)
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [email protected] -- 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    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui