To: vim_dev@googlegroups.com Subject: Patch 7.4.1963 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1963 Problem: Running Win32 Vim in mintty does not work. Solution: Detect mintty and give a helpful error message. (Ken Takata) Files: src/Make_cyg_ming.mak, src/Make_mvc.mak, src/iscygpty.c, src/iscygpty.h, src/main.c, Filelist *** ../vim-7.4.1962/src/Make_cyg_ming.mak 2016-06-03 19:43:12.615214010 +0200 --- src/Make_cyg_ming.mak 2016-06-26 20:29:37.956238236 +0200 *************** *** 592,597 **** --- 592,598 ---- 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,732 **** --- 728,734 ---- 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,847 **** --- 844,850 ---- 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,892 **** --- 890,901 ---- $(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 *** ../vim-7.4.1962/src/Make_mvc.mak 2016-06-18 21:58:07.322076861 +0200 --- src/Make_mvc.mak 2016-06-26 20:29:37.960238165 +0200 *************** *** 655,660 **** --- 655,662 ---- /machine:$(CPU) !else SUBSYSTEM = console + CUI_INCL = iscygpty.h + CUI_OBJ = $(OUTDIR)\iscygpty.obj !endif !if "$(SUBSYSTEM_VER)" != "" *************** *** 1026,1037 **** tee/tee.exe \ GvimExt/gvimext.dll ! $(VIM).exe: $(OUTDIR) $(OBJ) $(GUI_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) \ $(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) --- 1028,1039 ---- tee/tee.exe \ GvimExt/gvimext.dll ! $(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) $(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,1231 **** $(OUTDIR)/if_tcl.obj: $(OUTDIR) if_tcl.c $(INCL) $(CC) $(CFLAGS) $(TCL_INC) if_tcl.c $(OUTDIR)/json.obj: $(OUTDIR) json.c $(INCL) ! $(OUTDIR)/main.obj: $(OUTDIR) main.c $(INCL) $(OUTDIR)/mark.obj: $(OUTDIR) mark.c $(INCL) --- 1225,1236 ---- $(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) $(CUI_INCL) $(OUTDIR)/mark.obj: $(OUTDIR) mark.c $(INCL) *** ../vim-7.4.1962/src/iscygpty.c 2016-06-26 20:36:11.757259323 +0200 --- src/iscygpty.c 2016-06-26 20:36:49.132596948 +0200 *************** *** 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 + #include + #include + #include + + #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 + #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: */ *** ../vim-7.4.1962/src/iscygpty.h 2016-06-26 20:36:11.765259181 +0200 --- src/iscygpty.h 2016-06-26 20:29:37.960238165 +0200 *************** *** 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 */ *** ../vim-7.4.1962/src/main.c 2016-06-08 21:17:39.053193558 +0200 --- src/main.c 2016-06-26 20:33:54.087699121 +0200 *************** *** 19,24 **** --- 19,28 ---- # include #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,2559 **** --- 2558,2570 ---- 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) *** ../vim-7.4.1962/Filelist 2016-06-20 11:28:11.784296459 +0200 --- Filelist 2016-06-26 20:31:14.150533510 +0200 *************** *** 317,322 **** --- 317,324 ---- src/if_ole.h \ src/if_ole.idl \ src/if_perl_msvc/stdbool.h \ + src/iscygpty.c \ + src/iscygpty.h \ src/iid_ole.c \ src/os_dos.h \ src/os_w32dll.c \ *** ../vim-7.4.1962/src/version.c 2016-06-26 19:38:05.791014796 +0200 --- src/version.c 2016-06-26 20:31:36.950129460 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1963, /**/ -- hundred-and-one symptoms of being an internet addict: 143. You dream in pallettes of 216 websafe colors. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///