diff src/message.c @ 16451:7ae2396cef62 v8.1.1230

patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe commit https://github.com/vim/vim/commit/afde13b62b8fa25dac4635d5caee8d088b937ee0 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 28 19:46:49 2019 +0200 patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe Problem: A lot of code is shared between vim.exe and gvim.exe. Solution: Optionally put the shared code in vim.dll. (Ken Takata, closes #4287)
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Apr 2019 20:00:10 +0200
parents c1c25e2523a6
children 1b58b34d4d90
line wrap: on
line diff
--- a/src/message.c
+++ b/src/message.c
@@ -2563,8 +2563,12 @@ t_puts(
 msg_use_printf(void)
 {
     return (!msg_check_screen()
-#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
+#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
+# ifdef VIMDLL
+	    || (!gui.in_use && !termcap_active)
+# else
 	    || !termcap_active
+# endif
 #endif
 	    || (swapping_screen() && !termcap_active)
 	       );
@@ -2940,15 +2944,10 @@ do_more_prompt(int typed_char)
 # undef mch_msg
 #endif
 
-/*
- * Give an error message.  To be used when the screen hasn't been initialized
- * yet.  When stderr can't be used, collect error messages until the GUI has
- * started and they can be displayed in a message box.
- */
-    void
-mch_errmsg(char *str)
+#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
+    static void
+mch_errmsg_c(char *str)
 {
-#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
     int	    len = (int)STRLEN(str);
     DWORD   nwrite = 0;
     DWORD   mode = 0;
@@ -2966,34 +2965,57 @@ mch_errmsg(char *str)
     {
 	fprintf(stderr, "%s", str);
     }
-#else
+}
+#endif
+
+/*
+ * Give an error message.  To be used when the screen hasn't been initialized
+ * yet.  When stderr can't be used, collect error messages until the GUI has
+ * started and they can be displayed in a message box.
+ */
+    void
+mch_errmsg(char *str)
+{
+#if !defined(MSWIN) || defined(FEAT_GUI_MSWIN)
     int		len;
-
-# if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI)
+#endif
+
+#if (defined(UNIX) || defined(FEAT_GUI)) && (!defined(ALWAYS_USE_GUI) || !defined(VIMDLL))
     /* On Unix use stderr if it's a tty.
      * When not going to start the GUI also use stderr.
      * On Mac, when started from Finder, stderr is the console. */
     if (
-#  ifdef UNIX
-#   ifdef MACOS_X
+# ifdef UNIX
+#  ifdef MACOS_X
 	    (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0)
-#   else
+#  else
 	    isatty(2)
-#   endif
-#   ifdef FEAT_GUI
-	    ||
-#   endif
 #  endif
 #  ifdef FEAT_GUI
+	    ||
+#  endif
+# endif
+# ifdef FEAT_GUI
 	    !(gui.in_use || gui.starting)
-#  endif
+# endif
 	    )
     {
 	fprintf(stderr, "%s", str);
 	return;
     }
+#endif
+
+#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
+# ifdef VIMDLL
+    if (!(gui.in_use || gui.starting))
 # endif
-
+    {
+	mch_errmsg_c(str);
+	return;
+    }
+#endif
+
+#if !defined(MSWIN) || defined(FEAT_GUI_MSWIN)
     /* avoid a delay for a message that isn't there */
     emsg_on_display = FALSE;
 
@@ -3028,15 +3050,10 @@ mch_errmsg(char *str)
 #endif
 }
 
-/*
- * Give a message.  To be used when the screen hasn't been initialized yet.
- * When there is no tty, collect messages until the GUI has started and they
- * can be displayed in a message box.
- */
-    void
-mch_msg(char *str)
+#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
+    static void
+mch_msg_c(char *str)
 {
-#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
     int	    len = (int)STRLEN(str);
     DWORD   nwrite = 0;
     DWORD   mode;
@@ -3055,32 +3072,53 @@ mch_msg(char *str)
     {
 	printf("%s", str);
     }
-#else
-# if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI)
+}
+#endif
+
+/*
+ * Give a message.  To be used when the screen hasn't been initialized yet.
+ * When there is no tty, collect messages until the GUI has started and they
+ * can be displayed in a message box.
+ */
+    void
+mch_msg(char *str)
+{
+#if (defined(UNIX) || defined(FEAT_GUI)) && (!defined(ALWAYS_USE_GUI) || !defined(VIMDLL))
     /* On Unix use stdout if we have a tty.  This allows "vim -h | more" and
      * uses mch_errmsg() when started from the desktop.
      * When not going to start the GUI also use stdout.
      * On Mac, when started from Finder, stderr is the console. */
     if (
-#  ifdef UNIX
-#   ifdef MACOS_X
+# ifdef UNIX
+#  ifdef MACOS_X
 	    (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0)
-#   else
+#  else
 	    isatty(2)
-#    endif
-#   ifdef FEAT_GUI
+#   endif
+#  ifdef FEAT_GUI
 	    ||
-#   endif
 #  endif
-#  ifdef FEAT_GUI
+# endif
+# ifdef FEAT_GUI
 	    !(gui.in_use || gui.starting)
-#  endif
+# endif
 	    )
     {
 	printf("%s", str);
 	return;
     }
+#endif
+
+#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
+# ifdef VIMDLL
+    if (!(gui.in_use || gui.starting))
 # endif
+    {
+	mch_msg_c(str);
+	return;
+    }
+#endif
+#if !defined(MSWIN) || defined(FEAT_GUI_MSWIN)
     mch_errmsg(str);
 #endif
 }