diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-06-26 20:37:46 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-06-26 20:37:46 +0200 |
commit | 97ff9b9cffd97219d888874b9b3811d55e99c78f (patch) | |
tree | cfd1f0b30064c64e80e3520a9ffa7854b19f36e4 /src | |
parent | 52df117df724a7ad20affdf15214d2df2e507dcc (diff) | |
download | vim-git-97ff9b9cffd97219d888874b9b3811d55e99c78f.tar.gz |
patch 7.4.1963v7.4.1963
Problem: Running Win32 Vim in mintty does not work.
Solution: Detect mintty and give a helpful error message. (Ken Takata)
Diffstat (limited to 'src')
-rw-r--r-- | src/Make_cyg_ming.mak | 9 | ||||
-rw-r--r-- | src/Make_mvc.mak | 11 | ||||
-rw-r--r-- | src/iscygpty.c | 181 | ||||
-rw-r--r-- | src/iscygpty.h | 36 | ||||
-rw-r--r-- | src/main.c | 11 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 247 insertions, 3 deletions
diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index cdf10acee..86bbc3e58 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -592,6 +592,7 @@ endif LIB = -lkernel32 -luser32 -lgdi32 -ladvapi32 -lcomdlg32 -lcomctl32 -lversion GUIOBJ = $(OUTDIR)/gui.o $(OUTDIR)/gui_w32.o $(OUTDIR)/gui_beval.o $(OUTDIR)/os_w32exe.o +CUIOBJ = $(OUTDIR)/iscygpty.o OBJ = \ $(OUTDIR)/blowfish.o \ $(OUTDIR)/buffer.o \ @@ -727,6 +728,7 @@ OBJ += $(GUIOBJ) LFLAGS += -mwindows OUTDIR = gobj$(DEBUG_SUFFIX)$(MZSCHEME_SUFFIX)$(ARCH) else +OBJ += $(CUIOBJ) TARGET := vim$(DEBUG_SUFFIX).exe OUTDIR = obj$(DEBUG_SUFFIX)$(MZSCHEME_SUFFIX)$(ARCH) endif @@ -842,6 +844,7 @@ endif INCL = vim.h feature.h os_win32.h os_dos.h ascii.h keymap.h term.h macros.h \ structs.h regexp.h option.h ex_cmds.h proto.h globals.h farsi.h \ gui.h +CUI_INCL = iscygpty.h $(OUTDIR)/if_python.o : if_python.c if_py_both.h $(INCL) $(CC) -c $(CFLAGS) $(PYTHONINC) $(PYTHON_HOME_DEF) $< -o $@ @@ -887,6 +890,12 @@ if_perl.c: if_perl.xs typemap $(XSUBPP) -prototypes -typemap \ $(PERLTYPEMAP) if_perl.xs > $@ +$(OUTDIR)/iscygpty.o: iscygpty.c $(CUI_INCL) + $(CC) -c $(CFLAGS) iscygpty.c -o $(OUTDIR)/iscygpty.o -D_WIN32_WINNT=0x0600 -DUSE_DYNFILEID -DENABLE_STUB_IMPL + +$(OUTDIR)/main.o: main.c $(INCL) $(CUI_INCL) + $(CC) -c $(CFLAGS) main.c -o $(OUTDIR)/main.o + $(OUTDIR)/netbeans.o: netbeans.c $(INCL) $(NBDEBUG_INCL) $(NBDEBUG_SRC) $(CC) -c $(CFLAGS) netbeans.c -o $(OUTDIR)/netbeans.o diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index f1e3f0138..5687f0999 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -655,6 +655,8 @@ GUI_LIB = \ /machine:$(CPU) !else SUBSYSTEM = console +CUI_INCL = iscygpty.h +CUI_OBJ = $(OUTDIR)\iscygpty.obj !endif !if "$(SUBSYSTEM_VER)" != "" @@ -1026,12 +1028,12 @@ all: $(VIM).exe \ tee/tee.exe \ GvimExt/gvimext.dll -$(VIM).exe: $(OUTDIR) $(OBJ) $(GUI_OBJ) $(OLE_OBJ) $(OLE_IDL) $(MZSCHEME_OBJ) \ +$(VIM).exe: $(OUTDIR) $(OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) $(OLE_IDL) $(MZSCHEME_OBJ) \ $(LUA_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(PYTHON3_OBJ) $(RUBY_OBJ) $(TCL_OBJ) \ $(CSCOPE_OBJ) $(NETBEANS_OBJ) $(CHANNEL_OBJ) $(XPM_OBJ) \ version.c version.h $(CC) $(CFLAGS) version.c - $(link) $(LINKARGS1) -out:$(VIM).exe $(OBJ) $(GUI_OBJ) $(OLE_OBJ) \ + $(link) $(LINKARGS1) -out:$(VIM).exe $(OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) \ $(LUA_OBJ) $(MZSCHEME_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(PYTHON3_OBJ) $(RUBY_OBJ) \ $(TCL_OBJ) $(CSCOPE_OBJ) $(NETBEANS_OBJ) $(CHANNEL_OBJ) \ $(XPM_OBJ) $(OUTDIR)\version.obj $(LINKARGS2) @@ -1223,9 +1225,12 @@ $(OUTDIR)/if_ruby.obj: $(OUTDIR) if_ruby.c $(INCL) $(OUTDIR)/if_tcl.obj: $(OUTDIR) if_tcl.c $(INCL) $(CC) $(CFLAGS) $(TCL_INC) if_tcl.c +$(OUTDIR)/iscygpty.obj: $(OUTDIR) iscygpty.c $(CUI_INCL) + $(CC) $(CFLAGS) iscygpty.c -D_WIN32_WINNT=0x0600 -DUSE_DYNFILEID -DENABLE_STUB_IMPL + $(OUTDIR)/json.obj: $(OUTDIR) json.c $(INCL) -$(OUTDIR)/main.obj: $(OUTDIR) main.c $(INCL) +$(OUTDIR)/main.obj: $(OUTDIR) main.c $(INCL) $(CUI_INCL) $(OUTDIR)/mark.obj: $(OUTDIR) mark.c $(INCL) diff --git a/src/iscygpty.c b/src/iscygpty.c new file mode 100644 index 000000000..4a6dc3d42 --- /dev/null +++ b/src/iscygpty.c @@ -0,0 +1,181 @@ +/* + * iscygpty.c -- part of ptycheck + * https://github.com/k-takata/ptycheck + * + * Copyright (c) 2015-2016 K.Takata + * + * You can redistribute it and/or modify it under the terms of either + * the MIT license (as described below) or the Vim license. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <ctype.h> +#include <io.h> +#include <wchar.h> +#include <windows.h> + +#ifdef USE_FILEEXTD +/* VC 7.1 or earlier doesn't support SAL. */ +# if !defined(_MSC_VER) || (_MSC_VER < 1400) +# define __out +# define __in +# define __in_opt +# endif +/* Win32 FileID API Library: + * http://www.microsoft.com/en-us/download/details.aspx?id=22599 + * Needed for WinXP. */ +# include <fileextd.h> +#else /* USE_FILEEXTD */ +/* VC 8 or earlier. */ +# if defined(_MSC_VER) && (_MSC_VER < 1500) +# ifdef ENABLE_STUB_IMPL +# define STUB_IMPL +# else +# error "Win32 FileID API Library is required for VC2005 or earlier." +# endif +# endif +#endif /* USE_FILEEXTD */ + + +#include "iscygpty.h" + +//#define USE_DYNFILEID +#ifdef USE_DYNFILEID +typedef BOOL (WINAPI *pfnGetFileInformationByHandleEx)( + HANDLE hFile, + FILE_INFO_BY_HANDLE_CLASS FileInformationClass, + LPVOID lpFileInformation, + DWORD dwBufferSize +); +static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL; + +# ifndef USE_FILEEXTD +static BOOL WINAPI stub_GetFileInformationByHandleEx( + HANDLE hFile, + FILE_INFO_BY_HANDLE_CLASS FileInformationClass, + LPVOID lpFileInformation, + DWORD dwBufferSize + ) +{ + return FALSE; +} +# endif + +static void setup_fileid_api(void) +{ + if (pGetFileInformationByHandleEx != NULL) { + return; + } + pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx) + GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), + "GetFileInformationByHandleEx"); + if (pGetFileInformationByHandleEx == NULL) { +# ifdef USE_FILEEXTD + pGetFileInformationByHandleEx = GetFileInformationByHandleEx; +# else + pGetFileInformationByHandleEx = stub_GetFileInformationByHandleEx; +# endif + } +} +#else +# define pGetFileInformationByHandleEx GetFileInformationByHandleEx +# define setup_fileid_api() +#endif + + +#define is_wprefix(s, prefix) \ + (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0) + +/* Check if the fd is a cygwin/msys's pty. */ +int is_cygpty(int fd) +{ +#ifdef STUB_IMPL + return 0; +#else + HANDLE h; + int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH; + FILE_NAME_INFO *nameinfo; + WCHAR *p = NULL; + + setup_fileid_api(); + + h = (HANDLE) _get_osfhandle(fd); + if (h == INVALID_HANDLE_VALUE) { + return 0; + } + /* Cygwin/msys's pty is a pipe. */ + if (GetFileType(h) != FILE_TYPE_PIPE) { + return 0; + } + nameinfo = malloc(size); + if (nameinfo == NULL) { + return 0; + } + /* Check the name of the pipe: + * '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' */ + if (pGetFileInformationByHandleEx(h, FileNameInfo, nameinfo, size)) { + nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0'; + p = nameinfo->FileName; + if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */ + p += 8; + } else if (is_wprefix(p, L"\\msys-")) { /* MSYS and MSYS2 */ + p += 6; + } else { + p = NULL; + } + if (p != NULL) { + while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */ + ++p; + if (is_wprefix(p, L"-pty")) { + p += 4; + } else { + p = NULL; + } + } + if (p != NULL) { + while (*p && isdigit(*p)) /* Skip pty number. */ + ++p; + if (is_wprefix(p, L"-from-master")) { + //p += 12; + } else if (is_wprefix(p, L"-to-master")) { + //p += 10; + } else { + p = NULL; + } + } + } + free(nameinfo); + return (p != NULL); +#endif /* STUB_IMPL */ +} + +/* Check if at least one cygwin/msys pty is used. */ +int is_cygpty_used(void) +{ + int fd, ret = 0; + + for (fd = 0; fd < 3; fd++) { + ret |= is_cygpty(fd); + } + return ret; +} + +/* vim: set ts=4 sw=4: */ diff --git a/src/iscygpty.h b/src/iscygpty.h new file mode 100644 index 000000000..fbca4b409 --- /dev/null +++ b/src/iscygpty.h @@ -0,0 +1,36 @@ +/* + * iscygpty.h -- part of ptycheck + * https://github.com/k-takata/ptycheck + * + * Copyright (c) 2015-2016 K.Takata + * + * You can redistribute it and/or modify it under the terms of either + * the MIT license (as described below) or the Vim license. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _ISCYGPTY_H +#define _ISCYGPTY_H + +int is_cygpty(int fd); +int is_cygpty_used(void); + +#endif /* _ISCYGPTY_H */ diff --git a/src/main.c b/src/main.c index c87780054..958e9c8fc 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,10 @@ # include <limits.h> #endif +#if defined(WIN3264) && !defined(FEAT_GUI_W32) +# include "iscygpty.h" +#endif + /* Maximum number of commands from + or -c arguments. */ #define MAX_ARG_CMDS 10 @@ -2554,6 +2558,13 @@ check_tty(mparm_T *parmp) exit(1); } #endif +#if defined(WIN3264) && !defined(FEAT_GUI_W32) + if (is_cygpty_used()) + { + mch_errmsg(_("Vim: Error: This version of Vim does not run in a Cygwin terminal\n")); + exit(1); + } +#endif if (!parmp->stdout_isatty) mch_errmsg(_("Vim: Warning: Output is not to a terminal\n")); if (!input_isatty) diff --git a/src/version.c b/src/version.c index 286cbcb9e..db3a1581a 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1963, +/**/ 1962, /**/ 1961, |