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)
diff --git a/src/message.c b/src/message.c
index e18f952..bf677d4 100644
--- a/src/message.c
+++ b/src/message.c
@@ -2563,8 +2563,12 @@
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 @@
# 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 @@
{
fprintf(stderr, "%s", str);
}
-#else
- int len;
+}
+#endif
-# if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI)
+/*
+ * 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;
+#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
- !(gui.in_use || gui.starting)
+ ||
# endif
+# endif
+# ifdef FEAT_GUI
+ !(gui.in_use || gui.starting)
+# endif
)
{
fprintf(stderr, "%s", str);
return;
}
-# endif
+#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 @@
#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 @@
{
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
-# endif
# ifdef FEAT_GUI
- !(gui.in_use || gui.starting)
+ ||
# endif
+# endif
+# ifdef FEAT_GUI
+ !(gui.in_use || gui.starting)
+# 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
}