comparison src/os_win32.c @ 18810:44b855153d8e v8.1.2393

patch 8.1.2393: using old C style comments Commit: https://github.com/vim/vim/commit/0f8737355d291679659579a48db1861b88970293 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 5 20:28:46 2019 +0100 patch 8.1.2393: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Thu, 05 Dec 2019 20:30:04 +0100
parents 1756fe125914
children 44906eff69f9
comparison
equal deleted inserted replaced
18809:8c6177fec9cb 18810:44b855153d8e
28 28
29 #include <sys/types.h> 29 #include <sys/types.h>
30 #include <signal.h> 30 #include <signal.h>
31 #include <limits.h> 31 #include <limits.h>
32 32
33 /* cproto fails on missing include files */ 33 // cproto fails on missing include files
34 #ifndef PROTO 34 #ifndef PROTO
35 # include <process.h> 35 # include <process.h>
36 #endif 36 #endif
37 37
38 #undef chdir 38 #undef chdir
80 # ifndef DOUBLE_CLICK 80 # ifndef DOUBLE_CLICK
81 # define DOUBLE_CLICK 0x0002 81 # define DOUBLE_CLICK 0x0002
82 # endif 82 # endif
83 #endif 83 #endif
84 84
85 /* Record all output and all keyboard & mouse input */ 85 // Record all output and all keyboard & mouse input
86 /* #define MCH_WRITE_DUMP */ 86 // #define MCH_WRITE_DUMP
87 87
88 #ifdef MCH_WRITE_DUMP 88 #ifdef MCH_WRITE_DUMP
89 FILE* fdDump = NULL; 89 FILE* fdDump = NULL;
90 #endif 90 #endif
91 91
141 typedef int PSNSECINFO; 141 typedef int PSNSECINFO;
142 typedef int PSNSECINFOW; 142 typedef int PSNSECINFOW;
143 typedef int STARTUPINFO; 143 typedef int STARTUPINFO;
144 typedef int PROCESS_INFORMATION; 144 typedef int PROCESS_INFORMATION;
145 typedef int LPSECURITY_ATTRIBUTES; 145 typedef int LPSECURITY_ATTRIBUTES;
146 # define __stdcall /* empty */ 146 # define __stdcall // empty
147 #endif 147 #endif
148 148
149 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) 149 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
150 /* Win32 Console handles for input and output */ 150 // Win32 Console handles for input and output
151 static HANDLE g_hConIn = INVALID_HANDLE_VALUE; 151 static HANDLE g_hConIn = INVALID_HANDLE_VALUE;
152 static HANDLE g_hConOut = INVALID_HANDLE_VALUE; 152 static HANDLE g_hConOut = INVALID_HANDLE_VALUE;
153 153
154 /* Win32 Screen buffer,coordinate,console I/O information */ 154 // Win32 Screen buffer,coordinate,console I/O information
155 static SMALL_RECT g_srScrollRegion; 155 static SMALL_RECT g_srScrollRegion;
156 static COORD g_coord; /* 0-based, but external coords are 1-based */ 156 static COORD g_coord; // 0-based, but external coords are 1-based
157 157
158 /* The attribute of the screen when the editor was started */ 158 // The attribute of the screen when the editor was started
159 static WORD g_attrDefault = 7; /* lightgray text on black background */ 159 static WORD g_attrDefault = 7; // lightgray text on black background
160 static WORD g_attrCurrent; 160 static WORD g_attrCurrent;
161 161
162 static int g_fCBrkPressed = FALSE; /* set by ctrl-break interrupt */ 162 static int g_fCBrkPressed = FALSE; // set by ctrl-break interrupt
163 static int g_fCtrlCPressed = FALSE; /* set when ctrl-C or ctrl-break detected */ 163 static int g_fCtrlCPressed = FALSE; // set when ctrl-C or ctrl-break detected
164 static int g_fForceExit = FALSE; /* set when forcefully exiting */ 164 static int g_fForceExit = FALSE; // set when forcefully exiting
165 165
166 static void scroll(unsigned cLines); 166 static void scroll(unsigned cLines);
167 static void set_scroll_region(unsigned left, unsigned top, 167 static void set_scroll_region(unsigned left, unsigned top,
168 unsigned right, unsigned bottom); 168 unsigned right, unsigned bottom);
169 static void set_scroll_region_tb(unsigned top, unsigned bottom); 169 static void set_scroll_region_tb(unsigned top, unsigned bottom);
217 217
218 static void set_console_color_rgb(void); 218 static void set_console_color_rgb(void);
219 static void reset_console_color_rgb(void); 219 static void reset_console_color_rgb(void);
220 #endif 220 #endif
221 221
222 /* This flag is newly created from Windows 10 */ 222 // This flag is newly created from Windows 10
223 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING 223 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
224 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 224 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
225 #endif 225 #endif
226 226
227 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) 227 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
228 static int suppress_winsize = 1; /* don't fiddle with console */ 228 static int suppress_winsize = 1; // don't fiddle with console
229 #endif 229 #endif
230 230
231 static char_u *exe_path = NULL; 231 static char_u *exe_path = NULL;
232 232
233 static BOOL win8_or_later = FALSE; 233 static BOOL win8_or_later = FALSE;
234 234
235 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) 235 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
236 /* Dynamic loading for portability */ 236 // Dynamic loading for portability
237 typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX 237 typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX
238 { 238 {
239 ULONG cbSize; 239 ULONG cbSize;
240 COORD dwSize; 240 COORD dwSize;
241 COORD dwCursorPosition; 241 COORD dwCursorPosition;
337 { 337 {
338 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT 338 if (s_irCache[head].EventType == WINDOW_BUFFER_SIZE_EVENT
339 && s_irCache[head + 1].EventType 339 && s_irCache[head + 1].EventType
340 == WINDOW_BUFFER_SIZE_EVENT) 340 == WINDOW_BUFFER_SIZE_EVENT)
341 { 341 {
342 /* Remove duplicate event to avoid flicker. */ 342 // Remove duplicate event to avoid flicker.
343 for (i = head; i < tail; ++i) 343 for (i = head; i < tail; ++i)
344 s_irCache[i] = s_irCache[i + 1]; 344 s_irCache[i] = s_irCache[i + 1];
345 --tail; 345 --tail;
346 continue; 346 continue;
347 } 347 }
401 #endif 401 #endif
402 402
403 static void 403 static void
404 get_exe_name(void) 404 get_exe_name(void)
405 { 405 {
406 /* Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned 406 // Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned
407 * as the maximum length that works (plus a NUL byte). */ 407 // as the maximum length that works (plus a NUL byte).
408 #define MAX_ENV_PATH_LEN 8192 408 #define MAX_ENV_PATH_LEN 8192
409 char temp[MAX_ENV_PATH_LEN]; 409 char temp[MAX_ENV_PATH_LEN];
410 char_u *p; 410 char_u *p;
411 411
412 if (exe_name == NULL) 412 if (exe_name == NULL)
413 { 413 {
414 /* store the name of the executable, may be used for $VIM */ 414 // store the name of the executable, may be used for $VIM
415 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); 415 GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1);
416 if (*temp != NUL) 416 if (*temp != NUL)
417 exe_name = FullName_save((char_u *)temp, FALSE); 417 exe_name = FullName_save((char_u *)temp, FALSE);
418 } 418 }
419 419
421 { 421 {
422 exe_path = vim_strnsave(exe_name, 422 exe_path = vim_strnsave(exe_name,
423 (int)(gettail_sep(exe_name) - exe_name)); 423 (int)(gettail_sep(exe_name) - exe_name));
424 if (exe_path != NULL) 424 if (exe_path != NULL)
425 { 425 {
426 /* Append our starting directory to $PATH, so that when doing 426 // Append our starting directory to $PATH, so that when doing
427 * "!xxd" it's found in our starting directory. Needed because 427 // "!xxd" it's found in our starting directory. Needed because
428 * SearchPath() also looks there. */ 428 // SearchPath() also looks there.
429 p = mch_getenv("PATH"); 429 p = mch_getenv("PATH");
430 if (p == NULL 430 if (p == NULL
431 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) 431 || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN)
432 { 432 {
433 if (p == NULL || *p == NUL) 433 if (p == NULL || *p == NUL)
469 HINSTANCE 469 HINSTANCE
470 vimLoadLib(char *name) 470 vimLoadLib(char *name)
471 { 471 {
472 HINSTANCE dll = NULL; 472 HINSTANCE dll = NULL;
473 473
474 /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call 474 // NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
475 * vimLoadLib() recursively, which causes a stack overflow. */ 475 // vimLoadLib() recursively, which causes a stack overflow.
476 if (exe_path == NULL) 476 if (exe_path == NULL)
477 get_exe_name(); 477 get_exe_name();
478 if (exe_path != NULL) 478 if (exe_path != NULL)
479 { 479 {
480 WCHAR old_dirw[MAXPATHL]; 480 WCHAR old_dirw[MAXPATHL];
481 481
482 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) 482 if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0)
483 { 483 {
484 /* Change directory to where the executable is, both to make 484 // Change directory to where the executable is, both to make
485 * sure we find a .dll there and to avoid looking for a .dll 485 // sure we find a .dll there and to avoid looking for a .dll
486 * in the current directory. */ 486 // in the current directory.
487 SetCurrentDirectory((LPCSTR)exe_path); 487 SetCurrentDirectory((LPCSTR)exe_path);
488 dll = LoadLibrary(name); 488 dll = LoadLibrary(name);
489 SetCurrentDirectoryW(old_dirw); 489 SetCurrentDirectoryW(old_dirw);
490 return dll; 490 return dll;
491 } 491 }
526 { 526 {
527 PBYTE pImage = (PBYTE)hInst; 527 PBYTE pImage = (PBYTE)hInst;
528 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; 528 PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst;
529 PIMAGE_NT_HEADERS pPE; 529 PIMAGE_NT_HEADERS pPE;
530 PIMAGE_IMPORT_DESCRIPTOR pImpDesc; 530 PIMAGE_IMPORT_DESCRIPTOR pImpDesc;
531 PIMAGE_THUNK_DATA pIAT; /* Import Address Table */ 531 PIMAGE_THUNK_DATA pIAT; // Import Address Table
532 PIMAGE_THUNK_DATA pINT; /* Import Name Table */ 532 PIMAGE_THUNK_DATA pINT; // Import Name Table
533 PIMAGE_IMPORT_BY_NAME pImpName; 533 PIMAGE_IMPORT_BY_NAME pImpName;
534 534
535 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) 535 if (pDOS->e_magic != IMAGE_DOS_SIGNATURE)
536 return NULL; 536 return NULL;
537 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew); 537 pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew);
597 # ifndef GETTEXT_DLL 597 # ifndef GETTEXT_DLL
598 # define GETTEXT_DLL "libintl.dll" 598 # define GETTEXT_DLL "libintl.dll"
599 # define GETTEXT_DLL_ALT1 "libintl-8.dll" 599 # define GETTEXT_DLL_ALT1 "libintl-8.dll"
600 # define GETTEXT_DLL_ALT2 "intl.dll" 600 # define GETTEXT_DLL_ALT2 "intl.dll"
601 # endif 601 # endif
602 /* Dummy functions */ 602 // Dummy functions
603 static char *null_libintl_gettext(const char *); 603 static char *null_libintl_gettext(const char *);
604 static char *null_libintl_ngettext(const char *, const char *, unsigned long n); 604 static char *null_libintl_ngettext(const char *, const char *, unsigned long n);
605 static char *null_libintl_textdomain(const char *); 605 static char *null_libintl_textdomain(const char *);
606 static char *null_libintl_bindtextdomain(const char *, const char *); 606 static char *null_libintl_bindtextdomain(const char *, const char *);
607 static char *null_libintl_bind_textdomain_codeset(const char *, const char *); 607 static char *null_libintl_bind_textdomain_codeset(const char *, const char *);
674 } 674 }
675 return 0; 675 return 0;
676 } 676 }
677 } 677 }
678 678
679 /* The bind_textdomain_codeset() function is optional. */ 679 // The bind_textdomain_codeset() function is optional.
680 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, 680 dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL,
681 "bind_textdomain_codeset"); 681 "bind_textdomain_codeset");
682 if (dyn_libintl_bind_textdomain_codeset == NULL) 682 if (dyn_libintl_bind_textdomain_codeset == NULL)
683 dyn_libintl_bind_textdomain_codeset = 683 dyn_libintl_bind_textdomain_codeset =
684 null_libintl_bind_textdomain_codeset; 684 null_libintl_bind_textdomain_codeset;
685 685
686 /* _wputenv() function for the libintl.dll is optional. */ 686 // _wputenv() function for the libintl.dll is optional.
687 hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv"); 687 hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv");
688 if (hmsvcrt != NULL) 688 if (hmsvcrt != NULL)
689 dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv"); 689 dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv");
690 if (dyn_libintl_wputenv == NULL || dyn_libintl_wputenv == _wputenv) 690 if (dyn_libintl_wputenv == NULL || dyn_libintl_wputenv == _wputenv)
691 dyn_libintl_wputenv = null_libintl_wputenv; 691 dyn_libintl_wputenv = null_libintl_wputenv;
748 null_libintl_wputenv(const wchar_t *envstring UNUSED) 748 null_libintl_wputenv(const wchar_t *envstring UNUSED)
749 { 749 {
750 return 0; 750 return 0;
751 } 751 }
752 752
753 #endif /* DYNAMIC_GETTEXT */ 753 #endif // DYNAMIC_GETTEXT
754 754
755 /* This symbol is not defined in older versions of the SDK or Visual C++ */ 755 // This symbol is not defined in older versions of the SDK or Visual C++
756 756
757 #ifndef VER_PLATFORM_WIN32_WINDOWS 757 #ifndef VER_PLATFORM_WIN32_WINDOWS
758 # define VER_PLATFORM_WIN32_WINDOWS 1 758 # define VER_PLATFORM_WIN32_WINDOWS 1
759 #endif 759 #endif
760 760
826 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2) 826 if ((ovi.dwMajorVersion == 6 && ovi.dwMinorVersion >= 2)
827 || ovi.dwMajorVersion > 6) 827 || ovi.dwMajorVersion > 6)
828 win8_or_later = TRUE; 828 win8_or_later = TRUE;
829 829
830 #ifdef HAVE_ACL 830 #ifdef HAVE_ACL
831 /* Enable privilege for getting or setting SACLs. */ 831 // Enable privilege for getting or setting SACLs.
832 win32_enable_privilege(SE_SECURITY_NAME, TRUE); 832 win32_enable_privilege(SE_SECURITY_NAME, TRUE);
833 #endif 833 #endif
834 done = TRUE; 834 done = TRUE;
835 } 835 }
836 } 836 }
841 # define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) 841 # define CTRL (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)
842 # define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) 842 # define ALT (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)
843 # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) 843 # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED)
844 844
845 845
846 /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. 846 // When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode.
847 * We map function keys to their ANSI terminal equivalents, as produced 847 // We map function keys to their ANSI terminal equivalents, as produced
848 * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any 848 // by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any
849 * ANSI key with a value >= '\300' is nonstandard, but provided anyway 849 // ANSI key with a value >= '\300' is nonstandard, but provided anyway
850 * so that the user can have access to all SHIFT-, CTRL-, and ALT- 850 // so that the user can have access to all SHIFT-, CTRL-, and ALT-
851 * combinations of function/arrow/etc keys. 851 // combinations of function/arrow/etc keys.
852 */
853 852
854 static const struct 853 static const struct
855 { 854 {
856 WORD wVirtKey; 855 WORD wVirtKey;
857 BOOL fAnsiKey; 856 BOOL fAnsiKey;
925 # define UChar UnicodeChar 924 # define UChar UnicodeChar
926 # else 925 # else
927 # define UChar uChar.UnicodeChar 926 # define UChar uChar.UnicodeChar
928 # endif 927 # endif
929 928
930 /* The return code indicates key code size. */ 929 /*
930 * The return code indicates key code size.
931 */
931 static int 932 static int
932 win32_kbd_patch_key( 933 win32_kbd_patch_key(
933 KEY_EVENT_RECORD *pker) 934 KEY_EVENT_RECORD *pker)
934 { 935 {
935 UINT uMods = pker->dwControlKeyState; 936 UINT uMods = pker->dwControlKeyState;
948 if (pker->UChar != 0) 949 if (pker->UChar != 0)
949 return 1; 950 return 1;
950 951
951 vim_memset(abKeystate, 0, sizeof (abKeystate)); 952 vim_memset(abKeystate, 0, sizeof (abKeystate));
952 953
953 /* Clear any pending dead keys */ 954 // Clear any pending dead keys
954 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); 955 ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0);
955 956
956 if (uMods & SHIFT_PRESSED) 957 if (uMods & SHIFT_PRESSED)
957 abKeystate[VK_SHIFT] = 0x80; 958 abKeystate[VK_SHIFT] = 0x80;
958 if (uMods & CAPSLOCK_ON) 959 if (uMods & CAPSLOCK_ON)
990 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL); 991 const int nModifs = pker->dwControlKeyState & (SHIFT | ALT | CTRL);
991 992
992 *pch = *pch2 = NUL; 993 *pch = *pch2 = NUL;
993 g_fJustGotFocus = FALSE; 994 g_fJustGotFocus = FALSE;
994 995
995 /* ignore key up events */ 996 // ignore key up events
996 if (!pker->bKeyDown) 997 if (!pker->bKeyDown)
997 return FALSE; 998 return FALSE;
998 999
999 /* ignore some keystrokes */ 1000 // ignore some keystrokes
1000 switch (pker->wVirtualKeyCode) 1001 switch (pker->wVirtualKeyCode)
1001 { 1002 {
1002 /* modifiers */ 1003 // modifiers
1003 case VK_SHIFT: 1004 case VK_SHIFT:
1004 case VK_CONTROL: 1005 case VK_CONTROL:
1005 case VK_MENU: /* Alt key */ 1006 case VK_MENU: // Alt key
1006 return FALSE; 1007 return FALSE;
1007 1008
1008 default: 1009 default:
1009 break; 1010 break;
1010 } 1011 }
1011 1012
1012 /* special cases */ 1013 // special cases
1013 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) 1014 if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL)
1014 { 1015 {
1015 /* Ctrl-6 is Ctrl-^ */ 1016 // Ctrl-6 is Ctrl-^
1016 if (pker->wVirtualKeyCode == '6') 1017 if (pker->wVirtualKeyCode == '6')
1017 { 1018 {
1018 *pch = Ctrl_HAT; 1019 *pch = Ctrl_HAT;
1019 return TRUE; 1020 return TRUE;
1020 } 1021 }
1021 /* Ctrl-2 is Ctrl-@ */ 1022 // Ctrl-2 is Ctrl-@
1022 else if (pker->wVirtualKeyCode == '2') 1023 else if (pker->wVirtualKeyCode == '2')
1023 { 1024 {
1024 *pch = NUL; 1025 *pch = NUL;
1025 return TRUE; 1026 return TRUE;
1026 } 1027 }
1027 /* Ctrl-- is Ctrl-_ */ 1028 // Ctrl-- is Ctrl-_
1028 else if (pker->wVirtualKeyCode == 0xBD) 1029 else if (pker->wVirtualKeyCode == 0xBD)
1029 { 1030 {
1030 *pch = Ctrl__; 1031 *pch = Ctrl__;
1031 return TRUE; 1032 return TRUE;
1032 } 1033 }
1033 } 1034 }
1034 1035
1035 /* Shift-TAB */ 1036 // Shift-TAB
1036 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) 1037 if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED))
1037 { 1038 {
1038 *pch = K_NUL; 1039 *pch = K_NUL;
1039 *pch2 = '\017'; 1040 *pch2 = '\017';
1040 return TRUE; 1041 return TRUE;
1074 { 1075 {
1075 *pch = (i > 0) ? pker->UChar : NUL; 1076 *pch = (i > 0) ? pker->UChar : NUL;
1076 1077
1077 if (pmodifiers != NULL) 1078 if (pmodifiers != NULL)
1078 { 1079 {
1079 /* Pass on the ALT key as a modifier, but only when not combined 1080 // Pass on the ALT key as a modifier, but only when not combined
1080 * with CTRL (which is ALTGR). */ 1081 // with CTRL (which is ALTGR).
1081 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) 1082 if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0)
1082 *pmodifiers |= MOD_MASK_ALT; 1083 *pmodifiers |= MOD_MASK_ALT;
1083 1084
1084 /* Pass on SHIFT only for special keys, because we don't know when 1085 // Pass on SHIFT only for special keys, because we don't know when
1085 * it's already included with the character. */ 1086 // it's already included with the character.
1086 if ((nModifs & SHIFT) != 0 && *pch <= 0x20) 1087 if ((nModifs & SHIFT) != 0 && *pch <= 0x20)
1087 *pmodifiers |= MOD_MASK_SHIFT; 1088 *pmodifiers |= MOD_MASK_SHIFT;
1088 1089
1089 /* Pass on CTRL only for non-special keys, because we don't know 1090 // Pass on CTRL only for non-special keys, because we don't know
1090 * when it's already included with the character. And not when 1091 // when it's already included with the character. And not when
1091 * combined with ALT (which is ALTGR). */ 1092 // combined with ALT (which is ALTGR).
1092 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 1093 if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0
1093 && *pch >= 0x20 && *pch < 0x80) 1094 && *pch >= 0x20 && *pch < 0x80)
1094 *pmodifiers |= MOD_MASK_CTRL; 1095 *pmodifiers |= MOD_MASK_CTRL;
1095 } 1096 }
1096 } 1097 }
1097 1098
1098 return (*pch != NUL); 1099 return (*pch != NUL);
1099 } 1100 }
1100 1101
1101 #endif /* FEAT_GUI_MSWIN */ 1102 #endif // FEAT_GUI_MSWIN
1102 1103
1103 1104
1104 /* 1105 /*
1105 * For the GUI the mouse handling is in gui_w32.c. 1106 * For the GUI the mouse handling is in gui_w32.c.
1106 */ 1107 */
1108 void 1109 void
1109 mch_setmouse(int on UNUSED) 1110 mch_setmouse(int on UNUSED)
1110 { 1111 {
1111 } 1112 }
1112 #else 1113 #else
1113 static int g_fMouseAvail = FALSE; /* mouse present */ 1114 static int g_fMouseAvail = FALSE; // mouse present
1114 static int g_fMouseActive = FALSE; /* mouse enabled */ 1115 static int g_fMouseActive = FALSE; // mouse enabled
1115 static int g_nMouseClick = -1; /* mouse status */ 1116 static int g_nMouseClick = -1; // mouse status
1116 static int g_xMouse; /* mouse x coordinate */ 1117 static int g_xMouse; // mouse x coordinate
1117 static int g_yMouse; /* mouse y coordinate */ 1118 static int g_yMouse; // mouse y coordinate
1118 1119
1119 /* 1120 /*
1120 * Enable or disable mouse input 1121 * Enable or disable mouse input
1121 */ 1122 */
1122 void 1123 void
1196 static int s_cClicks = 1; 1197 static int s_cClicks = 1;
1197 static BOOL s_fReleased = TRUE; 1198 static BOOL s_fReleased = TRUE;
1198 static DWORD s_dwLastClickTime = 0; 1199 static DWORD s_dwLastClickTime = 0;
1199 static BOOL s_fNextIsMiddle = FALSE; 1200 static BOOL s_fNextIsMiddle = FALSE;
1200 1201
1201 static DWORD cButtons = 0; /* number of buttons supported */ 1202 static DWORD cButtons = 0; // number of buttons supported
1202 1203
1203 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; 1204 const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED;
1204 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; 1205 const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED;
1205 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED; 1206 const DWORD RIGHT = RIGHTMOST_BUTTON_PRESSED;
1206 const DWORD LEFT_RIGHT = LEFT | RIGHT; 1207 const DWORD LEFT_RIGHT = LEFT | RIGHT;
1214 { 1215 {
1215 g_nMouseClick = -1; 1216 g_nMouseClick = -1;
1216 return FALSE; 1217 return FALSE;
1217 } 1218 }
1218 1219
1219 /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ 1220 // get a spurious MOUSE_EVENT immediately after receiving focus; ignore
1220 if (g_fJustGotFocus) 1221 if (g_fJustGotFocus)
1221 { 1222 {
1222 g_fJustGotFocus = FALSE; 1223 g_fJustGotFocus = FALSE;
1223 return FALSE; 1224 return FALSE;
1224 } 1225 }
1225 1226
1226 /* unprocessed mouse click? */ 1227 // unprocessed mouse click?
1227 if (g_nMouseClick != -1) 1228 if (g_nMouseClick != -1)
1228 return TRUE; 1229 return TRUE;
1229 1230
1230 nButton = -1; 1231 nButton = -1;
1231 g_xMouse = pmer->dwMousePosition.X; 1232 g_xMouse = pmer->dwMousePosition.X;
1232 g_yMouse = pmer->dwMousePosition.Y; 1233 g_yMouse = pmer->dwMousePosition.Y;
1233 1234
1234 if (pmer->dwEventFlags == MOUSE_MOVED) 1235 if (pmer->dwEventFlags == MOUSE_MOVED)
1235 { 1236 {
1236 /* Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these 1237 // Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these
1237 * events even when the mouse moves only within a char cell.) */ 1238 // events even when the mouse moves only within a char cell.)
1238 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) 1239 if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse)
1239 return FALSE; 1240 return FALSE;
1240 } 1241 }
1241 1242
1242 /* If no buttons are pressed... */ 1243 // If no buttons are pressed...
1243 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) 1244 if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0)
1244 { 1245 {
1245 nButton = MOUSE_RELEASE; 1246 nButton = MOUSE_RELEASE;
1246 1247
1247 /* If the last thing returned was MOUSE_RELEASE, ignore this */ 1248 // If the last thing returned was MOUSE_RELEASE, ignore this
1248 if (s_fReleased) 1249 if (s_fReleased)
1249 { 1250 {
1250 # ifdef FEAT_BEVAL_TERM 1251 # ifdef FEAT_BEVAL_TERM
1251 /* do return mouse move events when we want them */ 1252 // do return mouse move events when we want them
1252 if (p_bevalterm) 1253 if (p_bevalterm)
1253 nButton = MOUSE_DRAG; 1254 nButton = MOUSE_DRAG;
1254 else 1255 else
1255 # endif 1256 # endif
1256 return FALSE; 1257 return FALSE;
1257 } 1258 }
1258 1259
1259 s_fReleased = TRUE; 1260 s_fReleased = TRUE;
1260 } 1261 }
1261 else /* one or more buttons pressed */ 1262 else // one or more buttons pressed
1262 { 1263 {
1263 /* on a 2-button mouse, hold down left and right buttons 1264 // on a 2-button mouse, hold down left and right buttons
1264 * simultaneously to get MIDDLE. */ 1265 // simultaneously to get MIDDLE.
1265 1266
1266 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) 1267 if (cButtons == 2 && s_nOldButton != MOUSE_DRAG)
1267 { 1268 {
1268 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); 1269 DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT);
1269 1270
1270 /* if either left or right button only is pressed, see if the 1271 // if either left or right button only is pressed, see if the
1271 * next mouse event has both of them pressed */ 1272 // next mouse event has both of them pressed
1272 if (dwLR == LEFT || dwLR == RIGHT) 1273 if (dwLR == LEFT || dwLR == RIGHT)
1273 { 1274 {
1274 for (;;) 1275 for (;;)
1275 { 1276 {
1276 /* wait a short time for next input event */ 1277 // wait a short time for next input event
1277 if (WaitForSingleObject(g_hConIn, p_mouset / 3) 1278 if (WaitForSingleObject(g_hConIn, p_mouset / 3)
1278 != WAIT_OBJECT_0) 1279 != WAIT_OBJECT_0)
1279 break; 1280 break;
1280 else 1281 else
1281 { 1282 {
1297 return decode_mouse_event(pmer2); 1298 return decode_mouse_event(pmer2);
1298 } 1299 }
1299 else if (s_xOldMouse == pmer2->dwMousePosition.X && 1300 else if (s_xOldMouse == pmer2->dwMousePosition.X &&
1300 s_yOldMouse == pmer2->dwMousePosition.Y) 1301 s_yOldMouse == pmer2->dwMousePosition.Y)
1301 { 1302 {
1302 /* throw away spurious mouse move */ 1303 // throw away spurious mouse move
1303 read_console_input(g_hConIn, &ir, 1, &cRecords); 1304 read_console_input(g_hConIn, &ir, 1, &cRecords);
1304 1305
1305 /* are there any more mouse events in queue? */ 1306 // are there any more mouse events in queue?
1306 peek_console_input(g_hConIn, &ir, 1, &cRecords); 1307 peek_console_input(g_hConIn, &ir, 1, &cRecords);
1307 1308
1308 if (cRecords==0 || ir.EventType != MOUSE_EVENT) 1309 if (cRecords==0 || ir.EventType != MOUSE_EVENT)
1309 break; 1310 break;
1310 } 1311 }
1347 s_fReleased = s_fNextIsMiddle; 1348 s_fReleased = s_fNextIsMiddle;
1348 } 1349 }
1349 1350
1350 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) 1351 if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK)
1351 { 1352 {
1352 /* button pressed or released, without mouse moving */ 1353 // button pressed or released, without mouse moving
1353 if (nButton != -1 && nButton != MOUSE_RELEASE) 1354 if (nButton != -1 && nButton != MOUSE_RELEASE)
1354 { 1355 {
1355 DWORD dwCurrentTime = GetTickCount(); 1356 DWORD dwCurrentTime = GetTickCount();
1356 1357
1357 if (s_xOldMouse != g_xMouse 1358 if (s_xOldMouse != g_xMouse
1397 g_nMouseClick |= MOUSE_ALT; 1398 g_nMouseClick |= MOUSE_ALT;
1398 1399
1399 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) 1400 if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE)
1400 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); 1401 SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks);
1401 1402
1402 /* only pass on interesting (i.e., different) mouse events */ 1403 // only pass on interesting (i.e., different) mouse events
1403 if (s_xOldMouse == g_xMouse 1404 if (s_xOldMouse == g_xMouse
1404 && s_yOldMouse == g_yMouse 1405 && s_yOldMouse == g_yMouse
1405 && s_nOldMouseClick == g_nMouseClick) 1406 && s_nOldMouseClick == g_nMouseClick)
1406 { 1407 {
1407 g_nMouseClick = -1; 1408 g_nMouseClick = -1;
1454 * How the cursor is drawn depends on the current mode. 1455 * How the cursor is drawn depends on the current mode.
1455 */ 1456 */
1456 idx = get_shape_idx(FALSE); 1457 idx = get_shape_idx(FALSE);
1457 1458
1458 if (shape_table[idx].shape == SHAPE_BLOCK) 1459 if (shape_table[idx].shape == SHAPE_BLOCK)
1459 thickness = 99; /* 100 doesn't work on W95 */ 1460 thickness = 99; // 100 doesn't work on W95
1460 else 1461 else
1461 thickness = shape_table[idx].percentage; 1462 thickness = shape_table[idx].percentage;
1462 mch_set_cursor_shape(thickness); 1463 mch_set_cursor_shape(thickness);
1463 } 1464 }
1464 #endif 1465 #endif
1492 # ifdef FEAT_TIMERS 1493 # ifdef FEAT_TIMERS
1493 int tb_change_cnt = typebuf.tb_change_cnt; 1494 int tb_change_cnt = typebuf.tb_change_cnt;
1494 # endif 1495 # endif
1495 1496
1496 if (msec > 0) 1497 if (msec > 0)
1497 /* Wait until the specified time has elapsed. */ 1498 // Wait until the specified time has elapsed.
1498 dwEndTime = GetTickCount() + msec; 1499 dwEndTime = GetTickCount() + msec;
1499 else if (msec < 0) 1500 else if (msec < 0)
1500 /* Wait forever. */ 1501 // Wait forever.
1501 dwEndTime = INFINITE; 1502 dwEndTime = INFINITE;
1502 1503
1503 // We need to loop until the end of the time period, because 1504 // We need to loop until the end of the time period, because
1504 // we might get multiple unusable mouse events in that time. 1505 // we might get multiple unusable mouse events in that time.
1505 for (;;) 1506 for (;;)
1525 ) 1526 )
1526 return TRUE; 1527 return TRUE;
1527 1528
1528 if (msec > 0) 1529 if (msec > 0)
1529 { 1530 {
1530 /* If the specified wait time has passed, return. Beware that 1531 // If the specified wait time has passed, return. Beware that
1531 * GetTickCount() may wrap around (overflow). */ 1532 // GetTickCount() may wrap around (overflow).
1532 dwNow = GetTickCount(); 1533 dwNow = GetTickCount();
1533 if ((int)(dwNow - dwEndTime) >= 0) 1534 if ((int)(dwNow - dwEndTime) >= 0)
1534 break; 1535 break;
1535 } 1536 }
1536 if (msec != 0) 1537 if (msec != 0)
1537 { 1538 {
1538 DWORD dwWaitTime = dwEndTime - dwNow; 1539 DWORD dwWaitTime = dwEndTime - dwNow;
1539 1540
1540 # ifdef FEAT_JOB_CHANNEL 1541 # ifdef FEAT_JOB_CHANNEL
1541 /* Check channel while waiting for input. */ 1542 // Check channel while waiting for input.
1542 if (dwWaitTime > 100) 1543 if (dwWaitTime > 100)
1543 { 1544 {
1544 dwWaitTime = 100; 1545 dwWaitTime = 100;
1545 /* If there is readahead then parse_queued_messages() timed out 1546 // If there is readahead then parse_queued_messages() timed out
1546 * and we should call it again soon. */ 1547 // and we should call it again soon.
1547 if (channel_any_readahead()) 1548 if (channel_any_readahead())
1548 dwWaitTime = 10; 1549 dwWaitTime = 10;
1549 } 1550 }
1550 # endif 1551 # endif
1551 # ifdef FEAT_BEVAL_GUI 1552 # ifdef FEAT_BEVAL_GUI
1552 if (p_beval && dwWaitTime > 100) 1553 if (p_beval && dwWaitTime > 100)
1553 /* The 'balloonexpr' may indirectly invoke a callback while 1554 // The 'balloonexpr' may indirectly invoke a callback while
1554 * waiting for a character, need to check often. */ 1555 // waiting for a character, need to check often.
1555 dwWaitTime = 100; 1556 dwWaitTime = 100;
1556 # endif 1557 # endif
1557 # ifdef FEAT_MZSCHEME 1558 # ifdef FEAT_MZSCHEME
1558 if (mzthreads_allowed() && p_mzq > 0 1559 if (mzthreads_allowed() && p_mzq > 0
1559 && (msec < 0 || (long)dwWaitTime > p_mzq)) 1560 && (msec < 0 || (long)dwWaitTime > p_mzq))
1560 dwWaitTime = p_mzq; /* don't wait longer than 'mzquantum' */ 1561 dwWaitTime = p_mzq; // don't wait longer than 'mzquantum'
1561 # endif 1562 # endif
1562 # ifdef FEAT_TIMERS 1563 # ifdef FEAT_TIMERS
1563 // When waiting very briefly don't trigger timers. 1564 // When waiting very briefly don't trigger timers.
1564 if (dwWaitTime > 10) 1565 if (dwWaitTime > 10)
1565 { 1566 {
1601 1602
1602 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) 1603 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
1603 { 1604 {
1604 if (csbi.dwCursorPosition.Y != msg_row) 1605 if (csbi.dwCursorPosition.Y != msg_row)
1605 { 1606 {
1606 /* The screen is now messed up, must redraw the 1607 // The screen is now messed up, must redraw the
1607 * command line and later all the windows. */ 1608 // command line and later all the windows.
1608 redraw_all_later(CLEAR); 1609 redraw_all_later(CLEAR);
1609 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); 1610 cmdline_row -= (msg_row - csbi.dwCursorPosition.Y);
1610 redrawcmd(); 1611 redrawcmd();
1611 } 1612 }
1612 } 1613 }
1616 if (cRecords > 0) 1617 if (cRecords > 0)
1617 { 1618 {
1618 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) 1619 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown)
1619 { 1620 {
1620 # ifdef FEAT_MBYTE_IME 1621 # ifdef FEAT_MBYTE_IME
1621 /* Windows IME sends two '\n's with only one 'ENTER'. First: 1622 // Windows IME sends two '\n's with only one 'ENTER'. First:
1622 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */ 1623 // wVirtualKeyCode == 13. second: wVirtualKeyCode == 0
1623 if (ir.Event.KeyEvent.UChar == 0 1624 if (ir.Event.KeyEvent.UChar == 0
1624 && ir.Event.KeyEvent.wVirtualKeyCode == 13) 1625 && ir.Event.KeyEvent.wVirtualKeyCode == 13)
1625 { 1626 {
1626 read_console_input(g_hConIn, &ir, 1, &cRecords); 1627 read_console_input(g_hConIn, &ir, 1, &cRecords);
1627 continue; 1628 continue;
1658 else if (msec == 0) 1659 else if (msec == 0)
1659 break; 1660 break;
1660 } 1661 }
1661 1662
1662 # ifdef FEAT_CLIENTSERVER 1663 # ifdef FEAT_CLIENTSERVER
1663 /* Something might have been received while we were waiting. */ 1664 // Something might have been received while we were waiting.
1664 if (input_available()) 1665 if (input_available())
1665 return TRUE; 1666 return TRUE;
1666 # endif 1667 # endif
1667 1668
1668 return FALSE; 1669 return FALSE;
1752 if (decode_mouse_event(&ir.Event.MouseEvent)) 1753 if (decode_mouse_event(&ir.Event.MouseEvent))
1753 return 0; 1754 return 0;
1754 } 1755 }
1755 } 1756 }
1756 } 1757 }
1757 #endif /* !FEAT_GUI_MSWIN */ 1758 #endif // !FEAT_GUI_MSWIN
1758 1759
1759 1760
1760 /* 1761 /*
1761 * mch_inchar(): low-level input function. 1762 * mch_inchar(): low-level input function.
1762 * Get one or more characters from the keyboard or the mouse. 1763 * Get one or more characters from the keyboard or the mouse.
1775 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) 1776 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
1776 1777
1777 int len; 1778 int len;
1778 int c; 1779 int c;
1779 # define TYPEAHEADLEN 20 1780 # define TYPEAHEADLEN 20
1780 static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */ 1781 static char_u typeahead[TYPEAHEADLEN]; // previously typed bytes.
1781 static int typeaheadlen = 0; 1782 static int typeaheadlen = 0;
1782 1783
1783 # ifdef VIMDLL 1784 # ifdef VIMDLL
1784 if (gui.in_use) 1785 if (gui.in_use)
1785 return 0; 1786 return 0;
1786 # endif 1787 # endif
1787 1788
1788 /* First use any typeahead that was kept because "buf" was too small. */ 1789 // First use any typeahead that was kept because "buf" was too small.
1789 if (typeaheadlen > 0) 1790 if (typeaheadlen > 0)
1790 goto theend; 1791 goto theend;
1791 1792
1792 if (time >= 0) 1793 if (time >= 0)
1793 { 1794 {
1794 if (!WaitForChar(time, FALSE)) /* no character available */ 1795 if (!WaitForChar(time, FALSE)) // no character available
1795 return 0; 1796 return 0;
1796 } 1797 }
1797 else /* time == -1, wait forever */ 1798 else // time == -1, wait forever
1798 { 1799 {
1799 mch_set_winsize_now(); /* Allow winsize changes from now on */ 1800 mch_set_winsize_now(); // Allow winsize changes from now on
1800 1801
1801 /* 1802 /*
1802 * If there is no character available within 2 seconds (default) 1803 * If there is no character available within 2 seconds (default)
1803 * write the autoscript file to disk. Or cause the CursorHold event 1804 * write the autoscript file to disk. Or cause the CursorHold event
1804 * to be triggered. 1805 * to be triggered.
1818 1819
1819 /* 1820 /*
1820 * Try to read as many characters as there are, until the buffer is full. 1821 * Try to read as many characters as there are, until the buffer is full.
1821 */ 1822 */
1822 1823
1823 /* we will get at least one key. Get more if they are available. */ 1824 // we will get at least one key. Get more if they are available.
1824 g_fCBrkPressed = FALSE; 1825 g_fCBrkPressed = FALSE;
1825 1826
1826 # ifdef MCH_WRITE_DUMP 1827 # ifdef MCH_WRITE_DUMP
1827 if (fdDump) 1828 if (fdDump)
1828 fputc('[', fdDump); 1829 fputc('[', fdDump);
1829 # endif 1830 # endif
1830 1831
1831 /* Keep looping until there is something in the typeahead buffer and more 1832 // Keep looping until there is something in the typeahead buffer and more
1832 * to get and still room in the buffer (up to two bytes for a char and 1833 // to get and still room in the buffer (up to two bytes for a char and
1833 * three bytes for a modifier). */ 1834 // three bytes for a modifier).
1834 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) 1835 while ((typeaheadlen == 0 || WaitForChar(0L, FALSE))
1835 && typeaheadlen + 5 <= TYPEAHEADLEN) 1836 && typeaheadlen + 5 <= TYPEAHEADLEN)
1836 { 1837 {
1837 if (typebuf_changed(tb_change_cnt)) 1838 if (typebuf_changed(tb_change_cnt))
1838 { 1839 {
1839 /* "buf" may be invalid now if a client put something in the 1840 // "buf" may be invalid now if a client put something in the
1840 * typeahead buffer and "buf" is in the typeahead buffer. */ 1841 // typeahead buffer and "buf" is in the typeahead buffer.
1841 typeaheadlen = 0; 1842 typeaheadlen = 0;
1842 break; 1843 break;
1843 } 1844 }
1844 if (g_nMouseClick != -1) 1845 if (g_nMouseClick != -1)
1845 { 1846 {
1862 1863
1863 c = tgetch(&modifiers, &ch2); 1864 c = tgetch(&modifiers, &ch2);
1864 1865
1865 if (typebuf_changed(tb_change_cnt)) 1866 if (typebuf_changed(tb_change_cnt))
1866 { 1867 {
1867 /* "buf" may be invalid now if a client put something in the 1868 // "buf" may be invalid now if a client put something in the
1868 * typeahead buffer and "buf" is in the typeahead buffer. */ 1869 // typeahead buffer and "buf" is in the typeahead buffer.
1869 typeaheadlen = 0; 1870 typeaheadlen = 0;
1870 break; 1871 break;
1871 } 1872 }
1872 1873
1873 if (c == Ctrl_C && ctrl_c_interrupts) 1874 if (c == Ctrl_C && ctrl_c_interrupts)
1887 int i; 1888 int i;
1888 char_u *p; 1889 char_u *p;
1889 WCHAR ch[2]; 1890 WCHAR ch[2];
1890 1891
1891 ch[0] = c; 1892 ch[0] = c;
1892 if (c >= 0xD800 && c <= 0xDBFF) /* High surrogate */ 1893 if (c >= 0xD800 && c <= 0xDBFF) // High surrogate
1893 { 1894 {
1894 ch[1] = tgetch(&modifiers, &ch2); 1895 ch[1] = tgetch(&modifiers, &ch2);
1895 n++; 1896 n++;
1896 } 1897 }
1897 p = utf16_to_enc(ch, &n); 1898 p = utf16_to_enc(ch, &n);
1931 typeahead[typeaheadlen + n + 1] = (char_u)ch2; 1932 typeahead[typeaheadlen + n + 1] = (char_u)ch2;
1932 n += 2; 1933 n += 2;
1933 } 1934 }
1934 } 1935 }
1935 1936
1936 /* Use the ALT key to set the 8th bit of the character 1937 // Use the ALT key to set the 8th bit of the character
1937 * when it's one byte, the 8th bit isn't set yet and not 1938 // when it's one byte, the 8th bit isn't set yet and not
1938 * using a double-byte encoding (would become a lead 1939 // using a double-byte encoding (would become a lead
1939 * byte). */ 1940 // byte).
1940 if ((modifiers & MOD_MASK_ALT) 1941 if ((modifiers & MOD_MASK_ALT)
1941 && n == 1 1942 && n == 1
1942 && (typeahead[typeaheadlen] & 0x80) == 0 1943 && (typeahead[typeaheadlen] & 0x80) == 0
1943 && !enc_dbcs 1944 && !enc_dbcs
1944 ) 1945 )
1948 modifiers &= ~MOD_MASK_ALT; 1949 modifiers &= ~MOD_MASK_ALT;
1949 } 1950 }
1950 1951
1951 if (modifiers != 0) 1952 if (modifiers != 0)
1952 { 1953 {
1953 /* Prepend modifiers to the character. */ 1954 // Prepend modifiers to the character.
1954 mch_memmove(typeahead + typeaheadlen + 3, 1955 mch_memmove(typeahead + typeaheadlen + 3,
1955 typeahead + typeaheadlen, n); 1956 typeahead + typeaheadlen, n);
1956 typeahead[typeaheadlen++] = K_SPECIAL; 1957 typeahead[typeaheadlen++] = K_SPECIAL;
1957 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER; 1958 typeahead[typeaheadlen++] = (char_u)KS_MODIFIER;
1958 typeahead[typeaheadlen++] = modifiers; 1959 typeahead[typeaheadlen++] = modifiers;
1975 fflush(fdDump); 1976 fflush(fdDump);
1976 } 1977 }
1977 # endif 1978 # endif
1978 1979
1979 theend: 1980 theend:
1980 /* Move typeahead to "buf", as much as fits. */ 1981 // Move typeahead to "buf", as much as fits.
1981 len = 0; 1982 len = 0;
1982 while (len < maxlen && typeaheadlen > 0) 1983 while (len < maxlen && typeaheadlen > 0)
1983 { 1984 {
1984 buf[len++] = typeahead[0]; 1985 buf[len++] = typeahead[0];
1985 mch_memmove(typeahead, typeahead + 1, --typeaheadlen); 1986 mch_memmove(typeahead, typeahead + 1, --typeaheadlen);
1986 } 1987 }
1987 return len; 1988 return len;
1988 1989
1989 #else /* FEAT_GUI_MSWIN */ 1990 #else // FEAT_GUI_MSWIN
1990 return 0; 1991 return 0;
1991 #endif /* FEAT_GUI_MSWIN */ 1992 #endif // FEAT_GUI_MSWIN
1992 } 1993 }
1993 1994
1994 #ifndef PROTO 1995 #ifndef PROTO
1995 # ifndef __MINGW32__ 1996 # ifndef __MINGW32__
1996 # include <shellapi.h> /* required for FindExecutable() */ 1997 # include <shellapi.h> // required for FindExecutable()
1997 # endif 1998 # endif
1998 #endif 1999 #endif
1999 2000
2000 /* 2001 /*
2001 * If "use_path" is TRUE: Return TRUE if "name" is in $PATH. 2002 * If "use_path" is TRUE: Return TRUE if "name" is in $PATH.
2090 { 2091 {
2091 # ifndef __MINGW32__ 2092 # ifndef __MINGW32__
2092 extern int _fmode; 2093 extern int _fmode;
2093 # endif 2094 # endif
2094 2095
2095 /* Silently handle invalid parameters to CRT functions */ 2096 // Silently handle invalid parameters to CRT functions
2096 SET_INVALID_PARAM_HANDLER; 2097 SET_INVALID_PARAM_HANDLER;
2097 2098
2098 /* Let critical errors result in a failure, not in a dialog box. Required 2099 // Let critical errors result in a failure, not in a dialog box. Required
2099 * for the timestamp test to work on removed floppies. */ 2100 // for the timestamp test to work on removed floppies.
2100 SetErrorMode(SEM_FAILCRITICALERRORS); 2101 SetErrorMode(SEM_FAILCRITICALERRORS);
2101 2102
2102 _fmode = O_BINARY; /* we do our own CR-LF translation */ 2103 _fmode = O_BINARY; // we do our own CR-LF translation
2103 2104
2104 /* Specify window size. Is there a place to get the default from? */ 2105 // Specify window size. Is there a place to get the default from?
2105 Rows = 25; 2106 Rows = 25;
2106 Columns = 80; 2107 Columns = 80;
2107 2108
2108 /* Look for 'vimrun' */ 2109 // Look for 'vimrun'
2109 { 2110 {
2110 char_u vimrun_location[_MAX_PATH + 4]; 2111 char_u vimrun_location[_MAX_PATH + 4];
2111 2112
2112 /* First try in same directory as gvim.exe */ 2113 // First try in same directory as gvim.exe
2113 STRCPY(vimrun_location, exe_name); 2114 STRCPY(vimrun_location, exe_name);
2114 STRCPY(gettail(vimrun_location), "vimrun.exe"); 2115 STRCPY(gettail(vimrun_location), "vimrun.exe");
2115 if (mch_getperm(vimrun_location) >= 0) 2116 if (mch_getperm(vimrun_location) >= 0)
2116 { 2117 {
2117 if (*skiptowhite(vimrun_location) != NUL) 2118 if (*skiptowhite(vimrun_location) != NUL)
2118 { 2119 {
2119 /* Enclose path with white space in double quotes. */ 2120 // Enclose path with white space in double quotes.
2120 mch_memmove(vimrun_location + 1, vimrun_location, 2121 mch_memmove(vimrun_location + 1, vimrun_location,
2121 STRLEN(vimrun_location) + 1); 2122 STRLEN(vimrun_location) + 1);
2122 *vimrun_location = '"'; 2123 *vimrun_location = '"';
2123 STRCPY(gettail(vimrun_location), "vimrun\" "); 2124 STRCPY(gettail(vimrun_location), "vimrun\" ");
2124 } 2125 }
2129 s_dont_use_vimrun = FALSE; 2130 s_dont_use_vimrun = FALSE;
2130 } 2131 }
2131 else if (executable_exists("vimrun.exe", NULL, TRUE)) 2132 else if (executable_exists("vimrun.exe", NULL, TRUE))
2132 s_dont_use_vimrun = FALSE; 2133 s_dont_use_vimrun = FALSE;
2133 2134
2134 /* Don't give the warning for a missing vimrun.exe right now, but only 2135 // Don't give the warning for a missing vimrun.exe right now, but only
2135 * when vimrun was supposed to be used. Don't bother people that do 2136 // when vimrun was supposed to be used. Don't bother people that do
2136 * not need vimrun.exe. */ 2137 // not need vimrun.exe.
2137 if (s_dont_use_vimrun) 2138 if (s_dont_use_vimrun)
2138 need_vimrun_warning = TRUE; 2139 need_vimrun_warning = TRUE;
2139 } 2140 }
2140 2141
2141 /* 2142 /*
2151 2152
2152 vtp_flag_init(); 2153 vtp_flag_init();
2153 } 2154 }
2154 2155
2155 2156
2156 #endif /* FEAT_GUI_MSWIN */ 2157 #endif // FEAT_GUI_MSWIN
2157 2158
2158 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) 2159 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
2159 2160
2160 # define SRWIDTH(sr) ((sr).Right - (sr).Left + 1) 2161 # define SRWIDTH(sr) ((sr).Right - (sr).Left + 1)
2161 # define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1) 2162 # define SRHEIGHT(sr) ((sr).Bottom - (sr).Top + 1)
2341 * a region of size width by Y_incr. Don't worry if this region is 2342 * a region of size width by Y_incr. Don't worry if this region is
2342 * too large for the remaining buffer; it will be cropped. 2343 * too large for the remaining buffer; it will be cropped.
2343 */ 2344 */
2344 ReadRegion.Top = Y; 2345 ReadRegion.Top = Y;
2345 ReadRegion.Bottom = Y + Y_incr - 1; 2346 ReadRegion.Bottom = Y + Y_incr - 1;
2346 if (!ReadConsoleOutputW(g_hConOut, /* output handle */ 2347 if (!ReadConsoleOutputW(g_hConOut, // output handle
2347 cb->Buffer, /* our buffer */ 2348 cb->Buffer, // our buffer
2348 cb->BufferSize, /* dimensions of our buffer */ 2349 cb->BufferSize, // dimensions of our buffer
2349 BufferCoord, /* offset in our buffer */ 2350 BufferCoord, // offset in our buffer
2350 &ReadRegion)) /* region to save */ 2351 &ReadRegion)) // region to save
2351 { 2352 {
2352 VIM_CLEAR(cb->Buffer); 2353 VIM_CLEAR(cb->Buffer);
2353 VIM_CLEAR(cb->Regions); 2354 VIM_CLEAR(cb->Regions);
2354 return FALSE; 2355 return FALSE;
2355 } 2356 }
2415 for (i = 0; i < cb->NumRegions; i++) 2416 for (i = 0; i < cb->NumRegions; i++)
2416 { 2417 {
2417 BufferCoord.X = cb->Regions[i].Left; 2418 BufferCoord.X = cb->Regions[i].Left;
2418 BufferCoord.Y = cb->Regions[i].Top; 2419 BufferCoord.Y = cb->Regions[i].Top;
2419 WriteRegion = cb->Regions[i]; 2420 WriteRegion = cb->Regions[i];
2420 if (!WriteConsoleOutputW(g_hConOut, /* output handle */ 2421 if (!WriteConsoleOutputW(g_hConOut, // output handle
2421 cb->Buffer, /* our buffer */ 2422 cb->Buffer, // our buffer
2422 cb->BufferSize, /* dimensions of our buffer */ 2423 cb->BufferSize, // dimensions of our buffer
2423 BufferCoord, /* offset in our buffer */ 2424 BufferCoord, // offset in our buffer
2424 &WriteRegion)) /* region to restore */ 2425 &WriteRegion)) // region to restore
2425 return FALSE; 2426 return FALSE;
2426 } 2427 }
2427 } 2428 }
2428 2429
2429 return TRUE; 2430 return TRUE;
2436 static ConsoleBuffer g_cbNonTermcap = { 0 }; 2437 static ConsoleBuffer g_cbNonTermcap = { 0 };
2437 static ConsoleBuffer g_cbTermcap = { 0 }; 2438 static ConsoleBuffer g_cbTermcap = { 0 };
2438 2439
2439 # ifdef FEAT_TITLE 2440 # ifdef FEAT_TITLE
2440 char g_szOrigTitle[256] = { 0 }; 2441 char g_szOrigTitle[256] = { 0 };
2441 HWND g_hWnd = NULL; /* also used in os_mswin.c */ 2442 HWND g_hWnd = NULL; // also used in os_mswin.c
2442 static HICON g_hOrigIconSmall = NULL; 2443 static HICON g_hOrigIconSmall = NULL;
2443 static HICON g_hOrigIcon = NULL; 2444 static HICON g_hOrigIcon = NULL;
2444 static HICON g_hVimIcon = NULL; 2445 static HICON g_hVimIcon = NULL;
2445 static BOOL g_fCanChangeIcon = FALSE; 2446 static BOOL g_fCanChangeIcon = FALSE;
2446 2447
2447 /* ICON* are not defined in VC++ 4.0 */ 2448 // ICON* are not defined in VC++ 4.0
2448 # ifndef ICON_SMALL 2449 # ifndef ICON_SMALL
2449 # define ICON_SMALL 0 2450 # define ICON_SMALL 0
2450 # endif 2451 # endif
2451 # ifndef ICON_BIG 2452 # ifndef ICON_BIG
2452 # define ICON_BIG 1 2453 # define ICON_BIG 1
2514 * console window the user sees is owned by a remote process). 2515 * console window the user sees is owned by a remote process).
2515 */ 2516 */
2516 static void 2517 static void
2517 SaveConsoleTitleAndIcon(void) 2518 SaveConsoleTitleAndIcon(void)
2518 { 2519 {
2519 /* Save the original title. */ 2520 // Save the original title.
2520 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) 2521 if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle)))
2521 return; 2522 return;
2522 2523
2523 /* 2524 /*
2524 * Obtain a handle to the console window using GetConsoleWindow() from 2525 * Obtain a handle to the console window using GetConsoleWindow() from
2529 */ 2530 */
2530 g_hWnd = GetConsoleWindow(); 2531 g_hWnd = GetConsoleWindow();
2531 if (g_hWnd == NULL) 2532 if (g_hWnd == NULL)
2532 return; 2533 return;
2533 2534
2534 /* Save the original console window icon. */ 2535 // Save the original console window icon.
2535 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); 2536 GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon);
2536 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) 2537 if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL)
2537 return; 2538 return;
2538 2539
2539 /* Extract the first icon contained in the Vim executable. */ 2540 // Extract the first icon contained in the Vim executable.
2540 if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL) 2541 if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL)
2541 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); 2542 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0);
2542 if (g_hVimIcon != NULL) 2543 if (g_hVimIcon != NULL)
2543 g_fCanChangeIcon = TRUE; 2544 g_fCanChangeIcon = TRUE;
2544 } 2545 }
2561 # endif 2562 # endif
2562 # ifndef __MINGW32__ 2563 # ifndef __MINGW32__
2563 extern int _fmode; 2564 extern int _fmode;
2564 # endif 2565 # endif
2565 2566
2566 /* Silently handle invalid parameters to CRT functions */ 2567 // Silently handle invalid parameters to CRT functions
2567 SET_INVALID_PARAM_HANDLER; 2568 SET_INVALID_PARAM_HANDLER;
2568 2569
2569 /* Let critical errors result in a failure, not in a dialog box. Required 2570 // Let critical errors result in a failure, not in a dialog box. Required
2570 * for the timestamp test to work on removed floppies. */ 2571 // for the timestamp test to work on removed floppies.
2571 SetErrorMode(SEM_FAILCRITICALERRORS); 2572 SetErrorMode(SEM_FAILCRITICALERRORS);
2572 2573
2573 _fmode = O_BINARY; /* we do our own CR-LF translation */ 2574 _fmode = O_BINARY; // we do our own CR-LF translation
2574 out_flush(); 2575 out_flush();
2575 2576
2576 /* Obtain handles for the standard Console I/O devices */ 2577 // Obtain handles for the standard Console I/O devices
2577 if (read_cmd_fd == 0) 2578 if (read_cmd_fd == 0)
2578 g_hConIn = GetStdHandle(STD_INPUT_HANDLE); 2579 g_hConIn = GetStdHandle(STD_INPUT_HANDLE);
2579 else 2580 else
2580 create_conin(); 2581 create_conin();
2581 g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE); 2582 g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
2582 2583
2583 # ifdef FEAT_RESTORE_ORIG_SCREEN 2584 # ifdef FEAT_RESTORE_ORIG_SCREEN
2584 /* Save the initial console buffer for later restoration */ 2585 // Save the initial console buffer for later restoration
2585 SaveConsoleBuffer(&g_cbOrig); 2586 SaveConsoleBuffer(&g_cbOrig);
2586 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; 2587 g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes;
2587 # else 2588 # else
2588 /* Get current text attributes */ 2589 // Get current text attributes
2589 GetConsoleScreenBufferInfo(g_hConOut, &csbi); 2590 GetConsoleScreenBufferInfo(g_hConOut, &csbi);
2590 g_attrCurrent = g_attrDefault = csbi.wAttributes; 2591 g_attrCurrent = g_attrDefault = csbi.wAttributes;
2591 # endif 2592 # endif
2592 if (cterm_normal_fg_color == 0) 2593 if (cterm_normal_fg_color == 0)
2593 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1; 2594 cterm_normal_fg_color = (g_attrCurrent & 0xf) + 1;
2596 2597
2597 // Fg and Bg color index number at startup 2598 // Fg and Bg color index number at startup
2598 g_color_index_fg = g_attrDefault & 0xf; 2599 g_color_index_fg = g_attrDefault & 0xf;
2599 g_color_index_bg = (g_attrDefault >> 4) & 0xf; 2600 g_color_index_bg = (g_attrDefault >> 4) & 0xf;
2600 2601
2601 /* set termcap codes to current text attributes */ 2602 // set termcap codes to current text attributes
2602 update_tcap(g_attrCurrent); 2603 update_tcap(g_attrCurrent);
2603 2604
2604 GetConsoleCursorInfo(g_hConOut, &g_cci); 2605 GetConsoleCursorInfo(g_hConOut, &g_cci);
2605 GetConsoleMode(g_hConIn, &g_cmodein); 2606 GetConsoleMode(g_hConIn, &g_cmodein);
2606 GetConsoleMode(g_hConOut, &g_cmodeout); 2607 GetConsoleMode(g_hConOut, &g_cmodeout);
2657 2658
2658 stoptermcap(); 2659 stoptermcap();
2659 if (g_fWindInitCalled) 2660 if (g_fWindInitCalled)
2660 settmode(TMODE_COOK); 2661 settmode(TMODE_COOK);
2661 2662
2662 ml_close_all(TRUE); /* remove all memfiles */ 2663 ml_close_all(TRUE); // remove all memfiles
2663 2664
2664 if (g_fWindInitCalled) 2665 if (g_fWindInitCalled)
2665 { 2666 {
2666 # ifdef FEAT_TITLE 2667 # ifdef FEAT_TITLE
2667 mch_restore_title(SAVE_RESTORE_BOTH); 2668 mch_restore_title(SAVE_RESTORE_BOTH);
2695 dyn_libintl_end(); 2696 dyn_libintl_end();
2696 # endif 2697 # endif
2697 2698
2698 exit(r); 2699 exit(r);
2699 } 2700 }
2700 #endif /* !FEAT_GUI_MSWIN */ 2701 #endif // !FEAT_GUI_MSWIN
2701 2702
2702 void 2703 void
2703 mch_init(void) 2704 mch_init(void)
2704 { 2705 {
2705 #ifdef VIMDLL 2706 #ifdef VIMDLL
2738 char **argv UNUSED) 2739 char **argv UNUSED)
2739 { 2740 {
2740 get_exe_name(); 2741 get_exe_name();
2741 2742
2742 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) 2743 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
2743 return OK; /* GUI always has a tty */ 2744 return OK; // GUI always has a tty
2744 #else 2745 #else
2745 # ifdef VIMDLL 2746 # ifdef VIMDLL
2746 if (gui.in_use) 2747 if (gui.in_use)
2747 return OK; 2748 return OK;
2748 # endif 2749 # endif
2796 int 2797 int
2797 mch_get_user_name( 2798 mch_get_user_name(
2798 char_u *s, 2799 char_u *s,
2799 int len) 2800 int len)
2800 { 2801 {
2801 WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ 2802 WCHAR wszUserName[256 + 1]; // UNLEN is 256
2802 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); 2803 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR);
2803 2804
2804 if (GetUserNameW(wszUserName, &wcch)) 2805 if (GetUserNameW(wszUserName, &wcch))
2805 { 2806 {
2806 char_u *p = utf16_to_enc(wszUserName, NULL); 2807 char_u *p = utf16_to_enc(wszUserName, NULL);
2975 mch_ishidden(char_u *name) 2976 mch_ishidden(char_u *name)
2976 { 2977 {
2977 int f = win32_getattrs(name); 2978 int f = win32_getattrs(name);
2978 2979
2979 if (f == -1) 2980 if (f == -1)
2980 return FALSE; /* file does not exist at all */ 2981 return FALSE; // file does not exist at all
2981 2982
2982 return (f & FILE_ATTRIBUTE_HIDDEN) != 0; 2983 return (f & FILE_ATTRIBUTE_HIDDEN) != 0;
2983 } 2984 }
2984 2985
2985 /* 2986 /*
2990 mch_isdir(char_u *name) 2991 mch_isdir(char_u *name)
2991 { 2992 {
2992 int f = win32_getattrs(name); 2993 int f = win32_getattrs(name);
2993 2994
2994 if (f == -1) 2995 if (f == -1)
2995 return FALSE; /* file does not exist at all */ 2996 return FALSE; // file does not exist at all
2996 2997
2997 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; 2998 return (f & FILE_ATTRIBUTE_DIRECTORY) != 0;
2998 } 2999 }
2999 3000
3000 /* 3001 /*
3268 p = (char_u *)".com;.exe;.bat;.cmd"; 3269 p = (char_u *)".com;.exe;.bat;.cmd";
3269 while (*p) 3270 while (*p)
3270 { 3271 {
3271 if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) 3272 if (p[0] == '.' && (p[1] == NUL || p[1] == ';'))
3272 { 3273 {
3273 /* A single "." means no extension is added. */ 3274 // A single "." means no extension is added.
3274 buf[len] = NUL; 3275 buf[len] = NUL;
3275 ++p; 3276 ++p;
3276 if (*p) 3277 if (*p)
3277 ++p; 3278 ++p;
3278 } 3279 }
3295 { 3296 {
3296 HANDLE hFile; 3297 HANDLE hFile;
3297 int type; 3298 int type;
3298 WCHAR *wn; 3299 WCHAR *wn;
3299 3300
3300 /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to 3301 // We can't open a file with a name "\\.\con" or "\\.\prn" and trying to
3301 * read from it later will cause Vim to hang. Thus return NODE_WRITABLE 3302 // read from it later will cause Vim to hang. Thus return NODE_WRITABLE
3302 * here. */ 3303 // here.
3303 if (STRNCMP(name, "\\\\.\\", 4) == 0) 3304 if (STRNCMP(name, "\\\\.\\", 4) == 0)
3304 return NODE_WRITABLE; 3305 return NODE_WRITABLE;
3305 3306
3306 wn = enc_to_utf16(name, NULL); 3307 wn = enc_to_utf16(name, NULL);
3307 if (wn == NULL) 3308 if (wn == NULL)
3505 return TRUE; 3506 return TRUE;
3506 3507
3507 case CTRL_BREAK_EVENT: 3508 case CTRL_BREAK_EVENT:
3508 g_fCBrkPressed = TRUE; 3509 g_fCBrkPressed = TRUE;
3509 ctrl_break_was_pressed = TRUE; 3510 ctrl_break_was_pressed = TRUE;
3510 /* ReadConsoleInput is blocking, send a key event to continue. */ 3511 // ReadConsoleInput is blocking, send a key event to continue.
3511 ir.EventType = KEY_EVENT; 3512 ir.EventType = KEY_EVENT;
3512 ir.Event.KeyEvent.bKeyDown = TRUE; 3513 ir.Event.KeyEvent.bKeyDown = TRUE;
3513 ir.Event.KeyEvent.wRepeatCount = 1; 3514 ir.Event.KeyEvent.wRepeatCount = 1;
3514 ir.Event.KeyEvent.wVirtualKeyCode = VK_CANCEL; 3515 ir.Event.KeyEvent.wVirtualKeyCode = VK_CANCEL;
3515 ir.Event.KeyEvent.wVirtualScanCode = 0; 3516 ir.Event.KeyEvent.wVirtualScanCode = 0;
3516 ir.Event.KeyEvent.dwControlKeyState = 0; 3517 ir.Event.KeyEvent.dwControlKeyState = 0;
3517 ir.Event.KeyEvent.uChar.UnicodeChar = 0; 3518 ir.Event.KeyEvent.uChar.UnicodeChar = 0;
3518 WriteConsoleInput(g_hConIn, &ir, 1, &out); 3519 WriteConsoleInput(g_hConIn, &ir, 1, &out);
3519 return TRUE; 3520 return TRUE;
3520 3521
3521 /* fatal events: shut down gracefully */ 3522 // fatal events: shut down gracefully
3522 case CTRL_CLOSE_EVENT: 3523 case CTRL_CLOSE_EVENT:
3523 case CTRL_LOGOFF_EVENT: 3524 case CTRL_LOGOFF_EVENT:
3524 case CTRL_SHUTDOWN_EVENT: 3525 case CTRL_SHUTDOWN_EVENT:
3525 windgoto((int)Rows - 1, 0); 3526 windgoto((int)Rows - 1, 0);
3526 g_fForceExit = TRUE; 3527 g_fForceExit = TRUE;
3533 : _("shutdown"))); 3534 : _("shutdown")));
3534 # ifdef DEBUG 3535 # ifdef DEBUG
3535 OutputDebugString(IObuff); 3536 OutputDebugString(IObuff);
3536 # endif 3537 # endif
3537 3538
3538 preserve_exit(); /* output IObuff, preserve files and exit */ 3539 preserve_exit(); // output IObuff, preserve files and exit
3539 3540
3540 return TRUE; /* not reached */ 3541 return TRUE; // not reached
3541 3542
3542 default: 3543 default:
3543 return FALSE; 3544 return FALSE;
3544 } 3545 }
3545 } 3546 }
3567 ENABLE_ECHO_INPUT); 3568 ENABLE_ECHO_INPUT);
3568 if (g_fMouseActive) 3569 if (g_fMouseActive)
3569 cmodein |= ENABLE_MOUSE_INPUT; 3570 cmodein |= ENABLE_MOUSE_INPUT;
3570 cmodeout &= ~( 3571 cmodeout &= ~(
3571 # ifdef FEAT_TERMGUICOLORS 3572 # ifdef FEAT_TERMGUICOLORS
3572 /* Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using 3573 // Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using
3573 * VTP. */ 3574 // VTP.
3574 ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) | 3575 ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) |
3575 # else 3576 # else
3576 ENABLE_PROCESSED_OUTPUT | 3577 ENABLE_PROCESSED_OUTPUT |
3577 # endif 3578 # endif
3578 ENABLE_WRAP_AT_EOL_OUTPUT); 3579 ENABLE_WRAP_AT_EOL_OUTPUT);
3579 bEnableHandler = TRUE; 3580 bEnableHandler = TRUE;
3580 } 3581 }
3581 else /* cooked */ 3582 else // cooked
3582 { 3583 {
3583 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | 3584 cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT |
3584 ENABLE_ECHO_INPUT); 3585 ENABLE_ECHO_INPUT);
3585 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); 3586 cmodeout |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
3586 bEnableHandler = FALSE; 3587 bEnableHandler = FALSE;
3688 ResizeConBufAndWindow( 3689 ResizeConBufAndWindow(
3689 HANDLE hConsole, 3690 HANDLE hConsole,
3690 int xSize, 3691 int xSize,
3691 int ySize) 3692 int ySize)
3692 { 3693 {
3693 CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ 3694 CONSOLE_SCREEN_BUFFER_INFO csbi; // hold current console buffer info
3694 SMALL_RECT srWindowRect; /* hold the new console size */ 3695 SMALL_RECT srWindowRect; // hold the new console size
3695 COORD coordScreen; 3696 COORD coordScreen;
3696 COORD cursor; 3697 COORD cursor;
3697 static int resized = FALSE; 3698 static int resized = FALSE;
3698 3699
3699 # ifdef MCH_WRITE_DUMP 3700 # ifdef MCH_WRITE_DUMP
3702 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize); 3703 fprintf(fdDump, "ResizeConBufAndWindow(%d, %d)\n", xSize, ySize);
3703 fflush(fdDump); 3704 fflush(fdDump);
3704 } 3705 }
3705 # endif 3706 # endif
3706 3707
3707 /* get the largest size we can size the console window to */ 3708 // get the largest size we can size the console window to
3708 coordScreen = GetLargestConsoleWindowSize(hConsole); 3709 coordScreen = GetLargestConsoleWindowSize(hConsole);
3709 3710
3710 /* define the new console window size and scroll position */ 3711 // define the new console window size and scroll position
3711 srWindowRect.Left = srWindowRect.Top = (SHORT) 0; 3712 srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
3712 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); 3713 srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1);
3713 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); 3714 srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1);
3714 3715
3715 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi)) 3716 if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
3770 3771
3771 # ifdef VIMDLL 3772 # ifdef VIMDLL
3772 if (gui.in_use) 3773 if (gui.in_use)
3773 return; 3774 return;
3774 # endif 3775 # endif
3775 /* Don't change window size while still starting up */ 3776 // Don't change window size while still starting up
3776 if (suppress_winsize != 0) 3777 if (suppress_winsize != 0)
3777 { 3778 {
3778 suppress_winsize = 2; 3779 suppress_winsize = 2;
3779 return; 3780 return;
3780 } 3781 }
3781 3782
3782 if (term_console) 3783 if (term_console)
3783 { 3784 {
3784 coordScreen = GetLargestConsoleWindowSize(g_hConOut); 3785 coordScreen = GetLargestConsoleWindowSize(g_hConOut);
3785 3786
3786 /* Clamp Rows and Columns to reasonable values */ 3787 // Clamp Rows and Columns to reasonable values
3787 if (Rows > coordScreen.Y) 3788 if (Rows > coordScreen.Y)
3788 Rows = coordScreen.Y; 3789 Rows = coordScreen.Y;
3789 if (Columns > coordScreen.X) 3790 if (Columns > coordScreen.X)
3790 Columns = coordScreen.X; 3791 Columns = coordScreen.X;
3791 3792
3819 mch_set_shellsize(); 3820 mch_set_shellsize();
3820 shell_resized(); 3821 shell_resized();
3821 } 3822 }
3822 suppress_winsize = 0; 3823 suppress_winsize = 0;
3823 } 3824 }
3824 #endif /* FEAT_GUI_MSWIN */ 3825 #endif // FEAT_GUI_MSWIN
3825 3826
3826 static BOOL 3827 static BOOL
3827 vim_create_process( 3828 vim_create_process(
3828 char *cmd, 3829 char *cmd,
3829 BOOL inherit_handles, 3830 BOOL inherit_handles,
3914 else 3915 else
3915 si.wShowWindow = SW_SHOWNORMAL; 3916 si.wShowWindow = SW_SHOWNORMAL;
3916 si.cbReserved2 = 0; 3917 si.cbReserved2 = 0;
3917 si.lpReserved2 = NULL; 3918 si.lpReserved2 = NULL;
3918 3919
3919 /* Now, run the command */ 3920 // Now, run the command
3920 vim_create_process(cmd, FALSE, 3921 vim_create_process(cmd, FALSE,
3921 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE, 3922 CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE,
3922 &si, &pi, NULL, NULL); 3923 &si, &pi, NULL, NULL);
3923 3924
3924 /* Wait for the command to terminate before continuing */ 3925 // Wait for the command to terminate before continuing
3925 { 3926 {
3926 # ifdef FEAT_GUI 3927 # ifdef FEAT_GUI
3927 int delay = 1; 3928 int delay = 1;
3928 3929
3929 /* Keep updating the window while waiting for the shell to finish. */ 3930 // Keep updating the window while waiting for the shell to finish.
3930 for (;;) 3931 for (;;)
3931 { 3932 {
3932 MSG msg; 3933 MSG msg;
3933 3934
3934 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) 3935 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE))
3939 continue; 3940 continue;
3940 } 3941 }
3941 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) 3942 if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT)
3942 break; 3943 break;
3943 3944
3944 /* We start waiting for a very short time and then increase it, so 3945 // We start waiting for a very short time and then increase it, so
3945 * that we respond quickly when the process is quick, and don't 3946 // that we respond quickly when the process is quick, and don't
3946 * consume too much overhead when it's slow. */ 3947 // consume too much overhead when it's slow.
3947 if (delay < 50) 3948 if (delay < 50)
3948 delay += 10; 3949 delay += 10;
3949 } 3950 }
3950 # else 3951 # else
3951 WaitForSingleObject(pi.hProcess, INFINITE); 3952 WaitForSingleObject(pi.hProcess, INFINITE);
3952 # endif 3953 # endif
3953 3954
3954 /* Get the command exit code */ 3955 // Get the command exit code
3955 GetExitCodeProcess(pi.hProcess, &ret); 3956 GetExitCodeProcess(pi.hProcess, &ret);
3956 } 3957 }
3957 3958
3958 /* Close the handles to the subprocess, so that it goes away */ 3959 // Close the handles to the subprocess, so that it goes away
3959 CloseHandle(pi.hThread); 3960 CloseHandle(pi.hThread);
3960 CloseHandle(pi.hProcess); 3961 CloseHandle(pi.hProcess);
3961 3962
3962 /* Try to get input focus back. Doesn't always work though. */ 3963 // Try to get input focus back. Doesn't always work though.
3963 PostMessage(hwnd, WM_SETFOCUS, 0, 0); 3964 PostMessage(hwnd, WM_SETFOCUS, 0, 0);
3964 3965
3965 return ret; 3966 return ret;
3966 } 3967 }
3967 3968
3986 l = (DWORD)STRLEN(lp + written); 3987 l = (DWORD)STRLEN(lp + written);
3987 if (l == 0) 3988 if (l == 0)
3988 len = 0; 3989 len = 0;
3989 else if (lp[written] == NL) 3990 else if (lp[written] == NL)
3990 { 3991 {
3991 /* NL -> NUL translation */ 3992 // NL -> NUL translation
3992 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); 3993 WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL);
3993 } 3994 }
3994 else 3995 else
3995 { 3996 {
3996 s = vim_strchr(lp + written, NL); 3997 s = vim_strchr(lp + written, NL);
3998 s == NULL ? l : (DWORD)(s - (lp + written)), 3999 s == NULL ? l : (DWORD)(s - (lp + written)),
3999 &len, NULL); 4000 &len, NULL);
4000 } 4001 }
4001 if (len == (int)l) 4002 if (len == (int)l)
4002 { 4003 {
4003 /* Finished a line, add a NL, unless this line should not have 4004 // Finished a line, add a NL, unless this line should not have
4004 * one. */ 4005 // one.
4005 if (lnum != curbuf->b_op_end.lnum 4006 if (lnum != curbuf->b_op_end.lnum
4006 || (!curbuf->b_p_bin 4007 || (!curbuf->b_p_bin
4007 && curbuf->b_p_fixeol) 4008 && curbuf->b_p_fixeol)
4008 || (lnum != curbuf->b_no_eol_lnum 4009 || (lnum != curbuf->b_no_eol_lnum
4009 && (lnum != curbuf->b_ml.ml_line_count 4010 && (lnum != curbuf->b_ml.ml_line_count
4022 } 4023 }
4023 else if (len > 0) 4024 else if (len > 0)
4024 written += len; 4025 written += len;
4025 } 4026 }
4026 4027
4027 /* finished all the lines, close pipe */ 4028 // finished all the lines, close pipe
4028 CloseHandle(g_hChildStd_IN_Wr); 4029 CloseHandle(g_hChildStd_IN_Wr);
4029 return 0; 4030 return 0;
4030 } 4031 }
4031 4032
4032 4033
4033 # define BUFLEN 100 /* length for buffer, stolen from unix version */ 4034 # define BUFLEN 100 // length for buffer, stolen from unix version
4034 4035
4035 /* 4036 /*
4036 * This function read from the children's stdout and write the 4037 * This function read from the children's stdout and write the
4037 * data on screen or in the buffer accordingly. 4038 * data on screen or in the buffer accordingly.
4038 */ 4039 */
4048 int ret; 4049 int ret;
4049 DWORD len; 4050 DWORD len;
4050 DWORD toRead; 4051 DWORD toRead;
4051 int repeatCount; 4052 int repeatCount;
4052 4053
4053 /* we query the pipe to see if there is any data to read 4054 // we query the pipe to see if there is any data to read
4054 * to avoid to perform a blocking read */ 4055 // to avoid to perform a blocking read
4055 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ 4056 ret = PeekNamedPipe(g_hChildStd_OUT_Rd, // pipe to query
4056 NULL, /* optional buffer */ 4057 NULL, // optional buffer
4057 0, /* buffer size */ 4058 0, // buffer size
4058 NULL, /* number of read bytes */ 4059 NULL, // number of read bytes
4059 &availableBytes, /* available bytes total */ 4060 &availableBytes, // available bytes total
4060 NULL); /* byteLeft */ 4061 NULL); // byteLeft
4061 4062
4062 repeatCount = 0; 4063 repeatCount = 0;
4063 /* We got real data in the pipe, read it */ 4064 // We got real data in the pipe, read it
4064 while (ret != 0 && availableBytes > 0) 4065 while (ret != 0 && availableBytes > 0)
4065 { 4066 {
4066 repeatCount++; 4067 repeatCount++;
4067 toRead = (DWORD)(BUFLEN - *buffer_off); 4068 toRead = (DWORD)(BUFLEN - *buffer_off);
4068 toRead = availableBytes < toRead ? availableBytes : toRead; 4069 toRead = availableBytes < toRead ? availableBytes : toRead;
4069 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); 4070 ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL);
4070 4071
4071 /* If we haven't read anything, there is a problem */ 4072 // If we haven't read anything, there is a problem
4072 if (len == 0) 4073 if (len == 0)
4073 break; 4074 break;
4074 4075
4075 availableBytes -= len; 4076 availableBytes -= len;
4076 4077
4077 if (options & SHELL_READ) 4078 if (options & SHELL_READ)
4078 { 4079 {
4079 /* Do NUL -> NL translation, append NL separated 4080 // Do NUL -> NL translation, append NL separated
4080 * lines to the current buffer. */ 4081 // lines to the current buffer.
4081 for (i = 0; i < len; ++i) 4082 for (i = 0; i < len; ++i)
4082 { 4083 {
4083 if (buffer[i] == NL) 4084 if (buffer[i] == NL)
4084 append_ga_line(ga); 4085 append_ga_line(ga);
4085 else if (buffer[i] == NUL) 4086 else if (buffer[i] == NUL)
4095 char_u *p; 4096 char_u *p;
4096 4097
4097 len += *buffer_off; 4098 len += *buffer_off;
4098 buffer[len] = NUL; 4099 buffer[len] = NUL;
4099 4100
4100 /* Check if the last character in buffer[] is 4101 // Check if the last character in buffer[] is
4101 * incomplete, keep these bytes for the next 4102 // incomplete, keep these bytes for the next
4102 * round. */ 4103 // round.
4103 for (p = buffer; p < buffer + len; p += l) 4104 for (p = buffer; p < buffer + len; p += l)
4104 { 4105 {
4105 l = MB_CPTR2LEN(p); 4106 l = MB_CPTR2LEN(p);
4106 if (l == 0) 4107 if (l == 0)
4107 l = 1; /* NUL byte? */ 4108 l = 1; // NUL byte?
4108 else if (MB_BYTE2LEN(*p) != l) 4109 else if (MB_BYTE2LEN(*p) != l)
4109 break; 4110 break;
4110 } 4111 }
4111 if (p == buffer) /* no complete character */ 4112 if (p == buffer) // no complete character
4112 { 4113 {
4113 /* avoid getting stuck at an illegal byte */ 4114 // avoid getting stuck at an illegal byte
4114 if (len >= 12) 4115 if (len >= 12)
4115 ++p; 4116 ++p;
4116 else 4117 else
4117 { 4118 {
4118 *buffer_off = len; 4119 *buffer_off = len;
4157 HANDLE g_hChildStd_IN_Rd = NULL; 4158 HANDLE g_hChildStd_IN_Rd = NULL;
4158 HANDLE g_hChildStd_IN_Wr = NULL; 4159 HANDLE g_hChildStd_IN_Wr = NULL;
4159 HANDLE g_hChildStd_OUT_Rd = NULL; 4160 HANDLE g_hChildStd_OUT_Rd = NULL;
4160 HANDLE g_hChildStd_OUT_Wr = NULL; 4161 HANDLE g_hChildStd_OUT_Wr = NULL;
4161 4162
4162 char_u buffer[BUFLEN + 1]; /* reading buffer + size */ 4163 char_u buffer[BUFLEN + 1]; // reading buffer + size
4163 DWORD len; 4164 DWORD len;
4164 4165
4165 /* buffer used to receive keys */ 4166 // buffer used to receive keys
4166 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ 4167 char_u ta_buf[BUFLEN + 1]; // TypeAHead
4167 int ta_len = 0; /* valid bytes in ta_buf[] */ 4168 int ta_len = 0; // valid bytes in ta_buf[]
4168 4169
4169 DWORD i; 4170 DWORD i;
4170 int c; 4171 int c;
4171 int noread_cnt = 0; 4172 int noread_cnt = 0;
4172 garray_T ga; 4173 garray_T ga;
4173 int delay = 1; 4174 int delay = 1;
4174 DWORD buffer_off = 0; /* valid bytes in buffer[] */ 4175 DWORD buffer_off = 0; // valid bytes in buffer[]
4175 char *p = NULL; 4176 char *p = NULL;
4176 4177
4177 SECURITY_ATTRIBUTES saAttr; 4178 SECURITY_ATTRIBUTES saAttr;
4178 4179
4179 /* Set the bInheritHandle flag so pipe handles are inherited. */ 4180 // Set the bInheritHandle flag so pipe handles are inherited.
4180 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 4181 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
4181 saAttr.bInheritHandle = TRUE; 4182 saAttr.bInheritHandle = TRUE;
4182 saAttr.lpSecurityDescriptor = NULL; 4183 saAttr.lpSecurityDescriptor = NULL;
4183 4184
4184 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) 4185 if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0)
4185 /* Ensure the read handle to the pipe for STDOUT is not inherited. */ 4186 // Ensure the read handle to the pipe for STDOUT is not inherited.
4186 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) 4187 || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0)
4187 /* Create a pipe for the child process's STDIN. */ 4188 // Create a pipe for the child process's STDIN.
4188 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) 4189 || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0)
4189 /* Ensure the write handle to the pipe for STDIN is not inherited. */ 4190 // Ensure the write handle to the pipe for STDIN is not inherited.
4190 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) 4191 || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) )
4191 { 4192 {
4192 CloseHandle(g_hChildStd_IN_Rd); 4193 CloseHandle(g_hChildStd_IN_Rd);
4193 CloseHandle(g_hChildStd_IN_Wr); 4194 CloseHandle(g_hChildStd_IN_Wr);
4194 CloseHandle(g_hChildStd_OUT_Rd); 4195 CloseHandle(g_hChildStd_OUT_Rd);
4200 si.lpReserved = NULL; 4201 si.lpReserved = NULL;
4201 si.lpDesktop = NULL; 4202 si.lpDesktop = NULL;
4202 si.lpTitle = NULL; 4203 si.lpTitle = NULL;
4203 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; 4204 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
4204 4205
4205 /* set-up our file redirection */ 4206 // set-up our file redirection
4206 si.hStdError = g_hChildStd_OUT_Wr; 4207 si.hStdError = g_hChildStd_OUT_Wr;
4207 si.hStdOutput = g_hChildStd_OUT_Wr; 4208 si.hStdOutput = g_hChildStd_OUT_Wr;
4208 si.hStdInput = g_hChildStd_IN_Rd; 4209 si.hStdInput = g_hChildStd_IN_Rd;
4209 si.wShowWindow = SW_HIDE; 4210 si.wShowWindow = SW_HIDE;
4210 si.cbReserved2 = 0; 4211 si.cbReserved2 = 0;
4220 unescape_shellxquote((char_u *)p, p_sxe); 4221 unescape_shellxquote((char_u *)p, p_sxe);
4221 else 4222 else
4222 p = cmd; 4223 p = cmd;
4223 } 4224 }
4224 4225
4225 /* Now, run the command. 4226 // Now, run the command.
4226 * About "Inherit handles" being TRUE: this command can be litigious, 4227 // About "Inherit handles" being TRUE: this command can be litigious,
4227 * handle inheritance was deactivated for pending temp file, but, if we 4228 // handle inheritance was deactivated for pending temp file, but, if we
4228 * deactivate it, the pipes don't work for some reason. */ 4229 // deactivate it, the pipes don't work for some reason.
4229 vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE, 4230 vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE,
4230 &si, &pi, NULL, NULL); 4231 &si, &pi, NULL, NULL);
4231 4232
4232 if (p != cmd) 4233 if (p != cmd)
4233 vim_free(p); 4234 vim_free(p);
4234 4235
4235 /* Close our unused side of the pipes */ 4236 // Close our unused side of the pipes
4236 CloseHandle(g_hChildStd_IN_Rd); 4237 CloseHandle(g_hChildStd_IN_Rd);
4237 CloseHandle(g_hChildStd_OUT_Wr); 4238 CloseHandle(g_hChildStd_OUT_Wr);
4238 4239
4239 if (options & SHELL_WRITE) 4240 if (options & SHELL_WRITE)
4240 { 4241 {
4241 HANDLE thread = (HANDLE) 4242 HANDLE thread = (HANDLE)
4242 _beginthreadex(NULL, /* security attributes */ 4243 _beginthreadex(NULL, // security attributes
4243 0, /* default stack size */ 4244 0, // default stack size
4244 sub_process_writer, /* function to be executed */ 4245 sub_process_writer, // function to be executed
4245 g_hChildStd_IN_Wr, /* parameter */ 4246 g_hChildStd_IN_Wr, // parameter
4246 0, /* creation flag, start immediately */ 4247 0, // creation flag, start immediately
4247 NULL); /* we don't care about thread id */ 4248 NULL); // we don't care about thread id
4248 CloseHandle(thread); 4249 CloseHandle(thread);
4249 g_hChildStd_IN_Wr = NULL; 4250 g_hChildStd_IN_Wr = NULL;
4250 } 4251 }
4251 4252
4252 /* Keep updating the window while waiting for the shell to finish. */ 4253 // Keep updating the window while waiting for the shell to finish.
4253 for (;;) 4254 for (;;)
4254 { 4255 {
4255 MSG msg; 4256 MSG msg;
4256 4257
4257 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE)) 4258 if (pPeekMessage(&msg, (HWND)NULL, 0, 0, PM_REMOVE))
4258 { 4259 {
4259 TranslateMessage(&msg); 4260 TranslateMessage(&msg);
4260 pDispatchMessage(&msg); 4261 pDispatchMessage(&msg);
4261 } 4262 }
4262 4263
4263 /* write pipe information in the window */ 4264 // write pipe information in the window
4264 if ((options & (SHELL_READ|SHELL_WRITE)) 4265 if ((options & (SHELL_READ|SHELL_WRITE))
4265 # ifdef FEAT_GUI 4266 # ifdef FEAT_GUI
4266 || gui.in_use 4267 || gui.in_use
4267 # endif 4268 # endif
4268 ) 4269 )
4278 ) 4279 )
4279 && (ta_len > 0 || noread_cnt > 4)) 4280 && (ta_len > 0 || noread_cnt > 4))
4280 { 4281 {
4281 if (ta_len == 0) 4282 if (ta_len == 0)
4282 { 4283 {
4283 /* Get extra characters when we don't have any. Reset the 4284 // Get extra characters when we don't have any. Reset the
4284 * counter and timer. */ 4285 // counter and timer.
4285 noread_cnt = 0; 4286 noread_cnt = 0;
4286 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); 4287 len = ui_inchar(ta_buf, BUFLEN, 10L, 0);
4287 } 4288 }
4288 if (ta_len > 0 || len > 0) 4289 if (ta_len > 0 || len > 0)
4289 { 4290 {
4293 */ 4294 */
4294 if (len == 1 && cmd != NULL) 4295 if (len == 1 && cmd != NULL)
4295 { 4296 {
4296 if (ta_buf[ta_len] == Ctrl_C) 4297 if (ta_buf[ta_len] == Ctrl_C)
4297 { 4298 {
4298 /* Learn what exit code is expected, for 4299 // Learn what exit code is expected, for
4299 * now put 9 as SIGKILL */ 4300 // now put 9 as SIGKILL
4300 TerminateProcess(pi.hProcess, 9); 4301 TerminateProcess(pi.hProcess, 9);
4301 } 4302 }
4302 if (ta_buf[ta_len] == Ctrl_D) 4303 if (ta_buf[ta_len] == Ctrl_D)
4303 { 4304 {
4304 CloseHandle(g_hChildStd_IN_Wr); 4305 CloseHandle(g_hChildStd_IN_Wr);
4305 g_hChildStd_IN_Wr = NULL; 4306 g_hChildStd_IN_Wr = NULL;
4306 } 4307 }
4307 } 4308 }
4308 4309
4309 /* replace K_BS by <BS> and K_DEL by <DEL> */ 4310 // replace K_BS by <BS> and K_DEL by <DEL>
4310 for (i = ta_len; i < ta_len + len; ++i) 4311 for (i = ta_len; i < ta_len + len; ++i)
4311 { 4312 {
4312 if (ta_buf[i] == CSI && len - i > 2) 4313 if (ta_buf[i] == CSI && len - i > 2)
4313 { 4314 {
4314 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); 4315 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]);
4388 } 4389 }
4389 4390
4390 ++noread_cnt; 4391 ++noread_cnt;
4391 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); 4392 dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off);
4392 4393
4393 /* We start waiting for a very short time and then increase it, so 4394 // We start waiting for a very short time and then increase it, so
4394 * that we respond quickly when the process is quick, and don't 4395 // that we respond quickly when the process is quick, and don't
4395 * consume too much overhead when it's slow. */ 4396 // consume too much overhead when it's slow.
4396 if (delay < 50) 4397 if (delay < 50)
4397 delay += 10; 4398 delay += 10;
4398 } 4399 }
4399 4400
4400 /* Close the pipe */ 4401 // Close the pipe
4401 CloseHandle(g_hChildStd_OUT_Rd); 4402 CloseHandle(g_hChildStd_OUT_Rd);
4402 if (g_hChildStd_IN_Wr != NULL) 4403 if (g_hChildStd_IN_Wr != NULL)
4403 CloseHandle(g_hChildStd_IN_Wr); 4404 CloseHandle(g_hChildStd_IN_Wr);
4404 4405
4405 WaitForSingleObject(pi.hProcess, INFINITE); 4406 WaitForSingleObject(pi.hProcess, INFINITE);
4406 4407
4407 /* Get the command exit code */ 4408 // Get the command exit code
4408 GetExitCodeProcess(pi.hProcess, &ret); 4409 GetExitCodeProcess(pi.hProcess, &ret);
4409 4410
4410 if (options & SHELL_READ) 4411 if (options & SHELL_READ)
4411 { 4412 {
4412 if (ga.ga_len > 0) 4413 if (ga.ga_len > 0)
4413 { 4414 {
4414 append_ga_line(&ga); 4415 append_ga_line(&ga);
4415 /* remember that the NL was missing */ 4416 // remember that the NL was missing
4416 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; 4417 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
4417 } 4418 }
4418 else 4419 else
4419 curbuf->b_no_eol_lnum = 0; 4420 curbuf->b_no_eol_lnum = 0;
4420 ga_clear(&ga); 4421 ga_clear(&ga);
4421 } 4422 }
4422 4423
4423 /* Close the handles to the subprocess, so that it goes away */ 4424 // Close the handles to the subprocess, so that it goes away
4424 CloseHandle(pi.hThread); 4425 CloseHandle(pi.hThread);
4425 CloseHandle(pi.hProcess); 4426 CloseHandle(pi.hProcess);
4426 4427
4427 return ret; 4428 return ret;
4428 } 4429 }
4429 4430
4430 static int 4431 static int
4431 mch_system_g(char *cmd, int options) 4432 mch_system_g(char *cmd, int options)
4432 { 4433 {
4433 /* if we can pipe and the shelltemp option is off */ 4434 // if we can pipe and the shelltemp option is off
4434 if (!p_stmp) 4435 if (!p_stmp)
4435 return mch_system_piped(cmd, options); 4436 return mch_system_piped(cmd, options);
4436 else 4437 else
4437 return mch_system_classic(cmd, options); 4438 return mch_system_classic(cmd, options);
4438 } 4439 }
4493 * Use a terminal window to run a shell command in. 4494 * Use a terminal window to run a shell command in.
4494 */ 4495 */
4495 static int 4496 static int
4496 mch_call_shell_terminal( 4497 mch_call_shell_terminal(
4497 char_u *cmd, 4498 char_u *cmd,
4498 int options UNUSED) /* SHELL_*, see vim.h */ 4499 int options UNUSED) // SHELL_*, see vim.h
4499 { 4500 {
4500 jobopt_T opt; 4501 jobopt_T opt;
4501 char_u *newcmd = NULL; 4502 char_u *newcmd = NULL;
4502 typval_T argvar[2]; 4503 typval_T argvar[2];
4503 long_u cmdlen; 4504 long_u cmdlen;
4504 int retval = -1; 4505 int retval = -1;
4505 buf_T *buf; 4506 buf_T *buf;
4506 job_T *job; 4507 job_T *job;
4507 aco_save_T aco; 4508 aco_save_T aco;
4508 oparg_T oa; /* operator arguments */ 4509 oparg_T oa; // operator arguments
4509 4510
4510 if (cmd == NULL) 4511 if (cmd == NULL)
4511 cmdlen = STRLEN(p_sh) + 1; 4512 cmdlen = STRLEN(p_sh) + 1;
4512 else 4513 else
4513 cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; 4514 cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10;
4538 } 4539 }
4539 4540
4540 job = term_getjob(buf->b_term); 4541 job = term_getjob(buf->b_term);
4541 ++job->jv_refcount; 4542 ++job->jv_refcount;
4542 4543
4543 /* Find a window to make "buf" curbuf. */ 4544 // Find a window to make "buf" curbuf.
4544 aucmd_prepbuf(&aco, buf); 4545 aucmd_prepbuf(&aco, buf);
4545 4546
4546 clear_oparg(&oa); 4547 clear_oparg(&oa);
4547 while (term_use_loop()) 4548 while (term_use_loop())
4548 { 4549 {
4549 if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) 4550 if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active)
4550 { 4551 {
4551 /* If terminal_loop() returns OK we got a key that is handled 4552 // If terminal_loop() returns OK we got a key that is handled
4552 * in Normal model. We don't do redrawing anyway. */ 4553 // in Normal model. We don't do redrawing anyway.
4553 if (terminal_loop(TRUE) == OK) 4554 if (terminal_loop(TRUE) == OK)
4554 normal_cmd(&oa, TRUE); 4555 normal_cmd(&oa, TRUE);
4555 } 4556 }
4556 else 4557 else
4557 normal_cmd(&oa, TRUE); 4558 normal_cmd(&oa, TRUE);
4559 retval = job->jv_exitval; 4560 retval = job->jv_exitval;
4560 ch_log(NULL, "system command finished"); 4561 ch_log(NULL, "system command finished");
4561 4562
4562 job_unref(job); 4563 job_unref(job);
4563 4564
4564 /* restore curwin/curbuf and a few other things */ 4565 // restore curwin/curbuf and a few other things
4565 aucmd_restbuf(&aco); 4566 aucmd_restbuf(&aco);
4566 4567
4567 wait_return(TRUE); 4568 wait_return(TRUE);
4568 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE); 4569 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
4569 4570
4576 * Either execute a command by calling the shell or start a new shell 4577 * Either execute a command by calling the shell or start a new shell
4577 */ 4578 */
4578 int 4579 int
4579 mch_call_shell( 4580 mch_call_shell(
4580 char_u *cmd, 4581 char_u *cmd,
4581 int options) /* SHELL_*, see vim.h */ 4582 int options) // SHELL_*, see vim.h
4582 { 4583 {
4583 int x = 0; 4584 int x = 0;
4584 int tmode = cur_tmode; 4585 int tmode = cur_tmode;
4585 #ifdef FEAT_TITLE 4586 #ifdef FEAT_TITLE
4586 WCHAR szShellTitle[512]; 4587 WCHAR szShellTitle[512];
4587 4588
4588 /* Change the title to reflect that we are in a subshell. */ 4589 // Change the title to reflect that we are in a subshell.
4589 if (GetConsoleTitleW(szShellTitle, 4590 if (GetConsoleTitleW(szShellTitle,
4590 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) 4591 sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0)
4591 { 4592 {
4592 if (cmd == NULL) 4593 if (cmd == NULL)
4593 wcscat(szShellTitle, L" :sh"); 4594 wcscat(szShellTitle, L" :sh");
4662 signal(SIGSEGV, SIG_IGN); 4663 signal(SIGSEGV, SIG_IGN);
4663 signal(SIGTERM, SIG_IGN); 4664 signal(SIGTERM, SIG_IGN);
4664 signal(SIGABRT, SIG_IGN); 4665 signal(SIGABRT, SIG_IGN);
4665 4666
4666 if (options & SHELL_COOKED) 4667 if (options & SHELL_COOKED)
4667 settmode(TMODE_COOK); /* set to normal mode */ 4668 settmode(TMODE_COOK); // set to normal mode
4668 4669
4669 if (cmd == NULL) 4670 if (cmd == NULL)
4670 { 4671 {
4671 x = mch_system((char *)p_sh, options); 4672 x = mch_system((char *)p_sh, options);
4672 } 4673 }
4673 else 4674 else
4674 { 4675 {
4675 /* we use "command" or "cmd" to start the shell; slow but easy */ 4676 // we use "command" or "cmd" to start the shell; slow but easy
4676 char_u *newcmd = NULL; 4677 char_u *newcmd = NULL;
4677 char_u *cmdbase = cmd; 4678 char_u *cmdbase = cmd;
4678 long_u cmdlen; 4679 long_u cmdlen;
4679 4680
4680 /* Skip a leading ", ( and "(. */ 4681 // Skip a leading ", ( and "(.
4681 if (*cmdbase == '"' ) 4682 if (*cmdbase == '"' )
4682 ++cmdbase; 4683 ++cmdbase;
4683 if (*cmdbase == '(') 4684 if (*cmdbase == '(')
4684 ++cmdbase; 4685 ++cmdbase;
4685 4686
4724 NULL); // Temp file 4725 NULL); // Temp file
4725 si.hStdOutput = si.hStdInput; 4726 si.hStdOutput = si.hStdInput;
4726 si.hStdError = si.hStdInput; 4727 si.hStdError = si.hStdInput;
4727 } 4728 }
4728 4729
4729 /* Remove a trailing ", ) and )" if they have a match 4730 // Remove a trailing ", ) and )" if they have a match
4730 * at the start of the command. */ 4731 // at the start of the command.
4731 if (cmdbase > cmd) 4732 if (cmdbase > cmd)
4732 { 4733 {
4733 p = cmdbase + STRLEN(cmdbase); 4734 p = cmdbase + STRLEN(cmdbase);
4734 if (p > cmdbase && p[-1] == '"' && *cmd == '"') 4735 if (p > cmdbase && p[-1] == '"' && *cmd == '"')
4735 *--p = NUL; 4736 *--p = NUL;
4758 4759
4759 subcmd = vim_strsave_escaped_ext(cmdbase, 4760 subcmd = vim_strsave_escaped_ext(cmdbase,
4760 (char_u *)"|", '^', FALSE); 4761 (char_u *)"|", '^', FALSE);
4761 if (subcmd != NULL) 4762 if (subcmd != NULL)
4762 { 4763 {
4763 /* make "cmd.exe /c arguments" */ 4764 // make "cmd.exe /c arguments"
4764 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; 4765 cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5;
4765 newcmd = alloc(cmdlen); 4766 newcmd = alloc(cmdlen);
4766 if (newcmd != NULL) 4767 if (newcmd != NULL)
4767 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s", 4768 vim_snprintf((char *)newcmd, cmdlen, "%s /c %s",
4768 cmd_shell, subcmd); 4769 cmd_shell, subcmd);
4797 if (newcmd != cmdbase) 4798 if (newcmd != cmdbase)
4798 vim_free(newcmd); 4799 vim_free(newcmd);
4799 4800
4800 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) 4801 if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL)
4801 { 4802 {
4802 /* Close the handle to \\.\NUL created above. */ 4803 // Close the handle to \\.\NUL created above.
4803 CloseHandle(si.hStdInput); 4804 CloseHandle(si.hStdInput);
4804 } 4805 }
4805 /* Close the handles to the subprocess, so that it goes away */ 4806 // Close the handles to the subprocess, so that it goes away
4806 CloseHandle(pi.hThread); 4807 CloseHandle(pi.hThread);
4807 CloseHandle(pi.hProcess); 4808 CloseHandle(pi.hProcess);
4808 } 4809 }
4809 else 4810 else
4810 { 4811 {
4869 } 4870 }
4870 } 4871 }
4871 } 4872 }
4872 4873
4873 if (tmode == TMODE_RAW) 4874 if (tmode == TMODE_RAW)
4874 settmode(TMODE_RAW); /* set to raw mode */ 4875 settmode(TMODE_RAW); // set to raw mode
4875 4876
4876 /* Print the return value, unless "vimrun" was used. */ 4877 // Print the return value, unless "vimrun" was used.
4877 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent 4878 if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent
4878 #if defined(FEAT_GUI_MSWIN) 4879 #if defined(FEAT_GUI_MSWIN)
4879 && ((gui.in_use || gui.starting) ? 4880 && ((gui.in_use || gui.starting) ?
4880 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1) 4881 ((options & SHELL_DOOUT) || s_dont_use_vimrun || !p_stmp) : 1)
4881 #endif 4882 #endif
4936 { 4937 {
4937 hashitem_T *hi; 4938 hashitem_T *hi;
4938 long_u todo = env != NULL ? env->dv_hashtab.ht_used : 0; 4939 long_u todo = env != NULL ? env->dv_hashtab.ht_used : 0;
4939 LPVOID base = GetEnvironmentStringsW(); 4940 LPVOID base = GetEnvironmentStringsW();
4940 4941
4941 /* for last \0 */ 4942 // for last \0
4942 if (ga_grow(gap, 1) == FAIL) 4943 if (ga_grow(gap, 1) == FAIL)
4943 return; 4944 return;
4944 4945
4945 if (base) 4946 if (base)
4946 { 4947 {
4947 WCHAR *p = (WCHAR*) base; 4948 WCHAR *p = (WCHAR*) base;
4948 4949
4949 /* for last \0 */ 4950 // for last \0
4950 if (ga_grow(gap, 1) == FAIL) 4951 if (ga_grow(gap, 1) == FAIL)
4951 return; 4952 return;
4952 4953
4953 while (*p != 0 || *(p + 1) != 0) 4954 while (*p != 0 || *(p + 1) != 0)
4954 { 4955 {
5226 5227
5227 ga_clear(&ga); 5228 ga_clear(&ga);
5228 5229
5229 if (!AssignProcessToJobObject(jo, pi.hProcess)) 5230 if (!AssignProcessToJobObject(jo, pi.hProcess))
5230 { 5231 {
5231 /* if failing, switch the way to terminate 5232 // if failing, switch the way to terminate
5232 * process with TerminateProcess. */ 5233 // process with TerminateProcess.
5233 CloseHandle(jo); 5234 CloseHandle(jo);
5234 jo = NULL; 5235 jo = NULL;
5235 } 5236 }
5236 ResumeThread(pi.hThread); 5237 ResumeThread(pi.hThread);
5237 CloseHandle(pi.hThread); 5238 CloseHandle(pi.hThread);
5371 { 5372 {
5372 int ret; 5373 int ret;
5373 5374
5374 if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL) 5375 if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL)
5375 { 5376 {
5376 /* deadly signal */ 5377 // deadly signal
5377 if (job->jv_job_object != NULL) 5378 if (job->jv_job_object != NULL)
5378 { 5379 {
5379 if (job->jv_channel != NULL && job->jv_channel->ch_anonymous_pipe) 5380 if (job->jv_channel != NULL && job->jv_channel->ch_anonymous_pipe)
5380 job->jv_channel->ch_killing = TRUE; 5381 job->jv_channel->ch_killing = TRUE;
5381 return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL; 5382 return TerminateJobObject(job->jv_job_object, 0) ? OK : FAIL;
5521 SetConsoleCursorPosition(g_hConOut, coord); 5522 SetConsoleCursorPosition(g_hConOut, coord);
5522 } 5523 }
5523 5524
5524 g_fTermcapMode = FALSE; 5525 g_fTermcapMode = FALSE;
5525 } 5526 }
5526 #endif /* FEAT_GUI_MSWIN */ 5527 #endif // FEAT_GUI_MSWIN
5527 5528
5528 5529
5529 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) 5530 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
5530 void 5531 void
5531 mch_write( 5532 mch_write(
5532 char_u *s UNUSED, 5533 char_u *s UNUSED,
5533 int len UNUSED) 5534 int len UNUSED)
5534 { 5535 {
5535 /* never used */ 5536 // never used
5536 } 5537 }
5537 5538
5538 #else 5539 #else
5539 5540
5540 /* 5541 /*
5958 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, 5959 ReadConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns,
5959 coordOrigin, &dwDummy); 5960 coordOrigin, &dwDummy);
5960 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, 5961 FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns,
5961 coordOrigin, &dwDummy); 5962 coordOrigin, &dwDummy);
5962 5963
5963 Sleep(15); /* wait for 15 msec */ 5964 Sleep(15); // wait for 15 msec
5964 if (!USE_VTP) 5965 if (!USE_VTP)
5965 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, 5966 WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns,
5966 coordOrigin, &dwDummy); 5967 coordOrigin, &dwDummy);
5967 vim_free(oldattrs); 5968 vim_free(oldattrs);
5968 } 5969 }
6075 { 6076 {
6076 write(1, s, (unsigned)len); 6077 write(1, s, (unsigned)len);
6077 return; 6078 return;
6078 } 6079 }
6079 6080
6080 /* translate ESC | sequences into faked bios calls */ 6081 // translate ESC | sequences into faked bios calls
6081 while (len--) 6082 while (len--)
6082 { 6083 {
6083 /* optimization: use one single write_chars for runs of text, 6084 // optimization: use one single write_chars for runs of text,
6084 * rather than once per character It ain't curses, but it helps. */ 6085 // rather than once per character It ain't curses, but it helps.
6085 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); 6086 DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033");
6086 6087
6087 if (p_wd) 6088 if (p_wd)
6088 { 6089 {
6089 WaitForChar(p_wd, FALSE); 6090 WaitForChar(p_wd, FALSE);
6107 len -= (nWritten - 1); 6108 len -= (nWritten - 1);
6108 s += nWritten; 6109 s += nWritten;
6109 } 6110 }
6110 else if (s[0] == '\n') 6111 else if (s[0] == '\n')
6111 { 6112 {
6112 /* \n, newline: go to the beginning of the next line or scroll */ 6113 // \n, newline: go to the beginning of the next line or scroll
6113 if (g_coord.Y == g_srScrollRegion.Bottom) 6114 if (g_coord.Y == g_srScrollRegion.Bottom)
6114 { 6115 {
6115 scroll(1); 6116 scroll(1);
6116 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1); 6117 gotoxy(g_srScrollRegion.Left + 1, g_srScrollRegion.Bottom + 1);
6117 } 6118 }
6125 # endif 6126 # endif
6126 s++; 6127 s++;
6127 } 6128 }
6128 else if (s[0] == '\r') 6129 else if (s[0] == '\r')
6129 { 6130 {
6130 /* \r, carriage return: go to beginning of line */ 6131 // \r, carriage return: go to beginning of line
6131 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); 6132 gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1);
6132 # ifdef MCH_WRITE_DUMP 6133 # ifdef MCH_WRITE_DUMP
6133 if (fdDump) 6134 if (fdDump)
6134 fputs("\\r\n", fdDump); 6135 fputs("\\r\n", fdDump);
6135 # endif 6136 # endif
6136 s++; 6137 s++;
6137 } 6138 }
6138 else if (s[0] == '\b') 6139 else if (s[0] == '\b')
6139 { 6140 {
6140 /* \b, backspace: move cursor one position left */ 6141 // \b, backspace: move cursor one position left
6141 if (g_coord.X > g_srScrollRegion.Left) 6142 if (g_coord.X > g_srScrollRegion.Left)
6142 g_coord.X--; 6143 g_coord.X--;
6143 else if (g_coord.Y > g_srScrollRegion.Top) 6144 else if (g_coord.Y > g_srScrollRegion.Top)
6144 { 6145 {
6145 g_coord.X = g_srScrollRegion.Right; 6146 g_coord.X = g_srScrollRegion.Right;
6152 # endif 6153 # endif
6153 s++; 6154 s++;
6154 } 6155 }
6155 else if (s[0] == '\a') 6156 else if (s[0] == '\a')
6156 { 6157 {
6157 /* \a, bell */ 6158 // \a, bell
6158 MessageBeep(0xFFFFFFFF); 6159 MessageBeep(0xFFFFFFFF);
6159 # ifdef MCH_WRITE_DUMP 6160 # ifdef MCH_WRITE_DUMP
6160 if (fdDump) 6161 if (fdDump)
6161 fputs("\\a\n", fdDump); 6162 fputs("\\a\n", fdDump);
6162 # endif 6163 # endif
6330 } 6331 }
6331 # endif 6332 # endif
6332 } 6333 }
6333 else 6334 else
6334 { 6335 {
6335 /* Write a single character */ 6336 // Write a single character
6336 DWORD nWritten; 6337 DWORD nWritten;
6337 6338
6338 nWritten = write_chars(s, 1); 6339 nWritten = write_chars(s, 1);
6339 # ifdef MCH_WRITE_DUMP 6340 # ifdef MCH_WRITE_DUMP
6340 if (fdDump) 6341 if (fdDump)
6354 if (fdDump) 6355 if (fdDump)
6355 fflush(fdDump); 6356 fflush(fdDump);
6356 # endif 6357 # endif
6357 } 6358 }
6358 6359
6359 #endif /* FEAT_GUI_MSWIN */ 6360 #endif // FEAT_GUI_MSWIN
6360 6361
6361 6362
6362 /* 6363 /*
6363 * Delay for "msec" milliseconds. 6364 * Delay for "msec" milliseconds.
6364 */ 6365 */
6366 mch_delay( 6367 mch_delay(
6367 long msec, 6368 long msec,
6368 int ignoreinput UNUSED) 6369 int ignoreinput UNUSED)
6369 { 6370 {
6370 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) 6371 #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
6371 Sleep((int)msec); /* never wait for input */ 6372 Sleep((int)msec); // never wait for input
6372 #else /* Console */ 6373 #else // Console
6373 # ifdef VIMDLL 6374 # ifdef VIMDLL
6374 if (gui.in_use) 6375 if (gui.in_use)
6375 { 6376 {
6376 Sleep((int)msec); /* never wait for input */ 6377 Sleep((int)msec); // never wait for input
6377 return; 6378 return;
6378 } 6379 }
6379 # endif 6380 # endif
6380 if (ignoreinput) 6381 if (ignoreinput)
6381 # ifdef FEAT_MZSCHEME 6382 # ifdef FEAT_MZSCHEME
6382 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq) 6383 if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq)
6383 { 6384 {
6384 int towait = p_mzq; 6385 int towait = p_mzq;
6385 6386
6386 /* if msec is large enough, wait by portions in p_mzq */ 6387 // if msec is large enough, wait by portions in p_mzq
6387 while (msec > 0) 6388 while (msec > 0)
6388 { 6389 {
6389 mzvim_check_threads(); 6390 mzvim_check_threads();
6390 if (msec < towait) 6391 if (msec < towait)
6391 towait = msec; 6392 towait = msec;
6449 got_int = TRUE; 6450 got_int = TRUE;
6450 } 6451 }
6451 #endif 6452 #endif
6452 } 6453 }
6453 6454
6454 /* physical RAM to leave for the OS */ 6455 // physical RAM to leave for the OS
6455 #define WINNT_RESERVE_BYTES (256*1024*1024) 6456 #define WINNT_RESERVE_BYTES (256*1024*1024)
6456 6457
6457 /* 6458 /*
6458 * How much main memory in KiB that can be used by VIM. 6459 * How much main memory in KiB that can be used by VIM.
6459 */ 6460 */
6460 long_u 6461 long_u
6461 mch_total_mem(int special UNUSED) 6462 mch_total_mem(int special UNUSED)
6462 { 6463 {
6463 MEMORYSTATUSEX ms; 6464 MEMORYSTATUSEX ms;
6464 6465
6465 /* Need to use GlobalMemoryStatusEx() when there is more memory than 6466 // Need to use GlobalMemoryStatusEx() when there is more memory than
6466 * what fits in 32 bits. */ 6467 // what fits in 32 bits.
6467 ms.dwLength = sizeof(MEMORYSTATUSEX); 6468 ms.dwLength = sizeof(MEMORYSTATUSEX);
6468 GlobalMemoryStatusEx(&ms); 6469 GlobalMemoryStatusEx(&ms);
6469 if (ms.ullAvailVirtual < ms.ullTotalPhys) 6470 if (ms.ullAvailVirtual < ms.ullTotalPhys)
6470 { 6471 {
6471 /* Process address space fits in physical RAM, use all of it. */ 6472 // Process address space fits in physical RAM, use all of it.
6472 return (long_u)(ms.ullAvailVirtual / 1024); 6473 return (long_u)(ms.ullAvailVirtual / 1024);
6473 } 6474 }
6474 if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES) 6475 if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES)
6475 { 6476 {
6476 /* Catch old NT box or perverse hardware setup. */ 6477 // Catch old NT box or perverse hardware setup.
6477 return (long_u)((ms.ullTotalPhys / 2) / 1024); 6478 return (long_u)((ms.ullTotalPhys / 2) / 1024);
6478 } 6479 }
6479 /* Use physical RAM less reserve for OS + data. */ 6480 // Use physical RAM less reserve for OS + data.
6480 return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024); 6481 return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024);
6481 } 6482 }
6482 6483
6483 /* 6484 /*
6484 * mch_wrename() works around a bug in rename (aka MoveFile) in 6485 * mch_wrename() works around a bug in rename (aka MoveFile) in
6608 */ 6609 */
6609 int 6610 int
6610 mch_access(char *n, int p) 6611 mch_access(char *n, int p)
6611 { 6612 {
6612 HANDLE hFile; 6613 HANDLE hFile;
6613 int retval = -1; /* default: fail */ 6614 int retval = -1; // default: fail
6614 WCHAR *wn; 6615 WCHAR *wn;
6615 6616
6616 wn = enc_to_utf16((char_u *)n, NULL); 6617 wn = enc_to_utf16((char_u *)n, NULL);
6617 if (wn == NULL) 6618 if (wn == NULL)
6618 return -1; 6619 return -1;
6621 { 6622 {
6622 WCHAR TempNameW[_MAX_PATH + 16] = L""; 6623 WCHAR TempNameW[_MAX_PATH + 16] = L"";
6623 6624
6624 if (p & R_OK) 6625 if (p & R_OK)
6625 { 6626 {
6626 /* Read check is performed by seeing if we can do a find file on 6627 // Read check is performed by seeing if we can do a find file on
6627 * the directory for any file. */ 6628 // the directory for any file.
6628 int i; 6629 int i;
6629 WIN32_FIND_DATAW d; 6630 WIN32_FIND_DATAW d;
6630 6631
6631 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i) 6632 for (i = 0; i < _MAX_PATH && wn[i] != 0; ++i)
6632 TempNameW[i] = wn[i]; 6633 TempNameW[i] = wn[i];
6642 (void)FindClose(hFile); 6643 (void)FindClose(hFile);
6643 } 6644 }
6644 6645
6645 if (p & W_OK) 6646 if (p & W_OK)
6646 { 6647 {
6647 /* Trying to create a temporary file in the directory should catch 6648 // Trying to create a temporary file in the directory should catch
6648 * directories on read-only network shares. However, in 6649 // directories on read-only network shares. However, in
6649 * directories whose ACL allows writes but denies deletes will end 6650 // directories whose ACL allows writes but denies deletes will end
6650 * up keeping the temporary file :-(. */ 6651 // up keeping the temporary file :-(.
6651 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) 6652 if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW))
6652 goto getout; 6653 goto getout;
6653 else 6654 else
6654 DeleteFileW(TempNameW); 6655 DeleteFileW(TempNameW);
6655 } 6656 }
6657 else 6658 else
6658 { 6659 {
6659 // Don't consider a file read-only if another process has opened it. 6660 // Don't consider a file read-only if another process has opened it.
6660 DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; 6661 DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
6661 6662
6662 /* Trying to open the file for the required access does ACL, read-only 6663 // Trying to open the file for the required access does ACL, read-only
6663 * network share, and file attribute checks. */ 6664 // network share, and file attribute checks.
6664 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) 6665 DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0)
6665 | ((p & R_OK) ? GENERIC_READ : 0); 6666 | ((p & R_OK) ? GENERIC_READ : 0);
6666 6667
6667 hFile = CreateFileW(wn, access_mode, share_mode, 6668 hFile = CreateFileW(wn, access_mode, share_mode,
6668 NULL, OPEN_EXISTING, 0, NULL); 6669 NULL, OPEN_EXISTING, 0, NULL);
6669 if (hFile == INVALID_HANDLE_VALUE) 6670 if (hFile == INVALID_HANDLE_VALUE)
6670 goto getout; 6671 goto getout;
6671 CloseHandle(hFile); 6672 CloseHandle(hFile);
6672 } 6673 }
6673 6674
6674 retval = 0; /* success */ 6675 retval = 0; // success
6675 getout: 6676 getout:
6676 vim_free(wn); 6677 vim_free(wn);
6677 return retval; 6678 return retval;
6678 } 6679 }
6679 6680
6703 { 6704 {
6704 WCHAR *wn, *wm; 6705 WCHAR *wn, *wm;
6705 FILE *f = NULL; 6706 FILE *f = NULL;
6706 6707
6707 #if defined(DEBUG) && _MSC_VER >= 1400 6708 #if defined(DEBUG) && _MSC_VER >= 1400
6708 /* Work around an annoying assertion in the Microsoft debug CRT 6709 // Work around an annoying assertion in the Microsoft debug CRT
6709 * when mode's text/binary setting doesn't match _get_fmode(). */ 6710 // when mode's text/binary setting doesn't match _get_fmode().
6710 char newMode = mode[strlen(mode) - 1]; 6711 char newMode = mode[strlen(mode) - 1];
6711 int oldMode = 0; 6712 int oldMode = 0;
6712 6713
6713 _get_fmode(&oldMode); 6714 _get_fmode(&oldMode);
6714 if (newMode == 't') 6715 if (newMode == 't')
6768 long done; 6769 long done;
6769 DWORD todo; 6770 DWORD todo;
6770 DWORD readcnt, written; 6771 DWORD readcnt, written;
6771 char buf[4096]; 6772 char buf[4096];
6772 6773
6773 /* Copy block of bytes at a time. Abort when something goes wrong. */ 6774 // Copy block of bytes at a time. Abort when something goes wrong.
6774 for (done = 0; done < len; done += written) 6775 for (done = 0; done < len; done += written)
6775 { 6776 {
6776 /* (size_t) cast for Borland C 5.5 */ 6777 // (size_t) cast for Borland C 5.5
6777 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) 6778 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf)
6778 : (size_t)(len - done)); 6779 : (size_t)(len - done));
6779 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, 6780 if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt,
6780 FALSE, FALSE, context) 6781 FALSE, FALSE, context)
6781 || readcnt != todo 6782 || readcnt != todo
6804 DWORD readcount; 6805 DWORD readcount;
6805 void *context = NULL; 6806 void *context = NULL;
6806 DWORD lo, hi; 6807 DWORD lo, hi;
6807 int len; 6808 int len;
6808 6809
6809 /* Convert the file names to wide characters. */ 6810 // Convert the file names to wide characters.
6810 fromw = enc_to_utf16(from, NULL); 6811 fromw = enc_to_utf16(from, NULL);
6811 tow = enc_to_utf16(to, NULL); 6812 tow = enc_to_utf16(to, NULL);
6812 if (fromw != NULL && tow != NULL) 6813 if (fromw != NULL && tow != NULL)
6813 { 6814 {
6814 /* Open the file for reading. */ 6815 // Open the file for reading.
6815 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, 6816 sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL,
6816 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); 6817 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
6817 if (sh != INVALID_HANDLE_VALUE) 6818 if (sh != INVALID_HANDLE_VALUE)
6818 { 6819 {
6819 /* Use BackupRead() to find the info streams. Repeat until we 6820 // Use BackupRead() to find the info streams. Repeat until we
6820 * have done them all.*/ 6821 // have done them all.
6821 for (;;) 6822 for (;;)
6822 { 6823 {
6823 /* Get the header to find the length of the stream name. If 6824 // Get the header to find the length of the stream name. If
6824 * the "readcount" is zero we have done all info streams. */ 6825 // the "readcount" is zero we have done all info streams.
6825 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); 6826 ZeroMemory(&sid, sizeof(WIN32_STREAM_ID));
6826 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); 6827 headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId);
6827 if (!BackupRead(sh, (LPBYTE)&sid, headersize, 6828 if (!BackupRead(sh, (LPBYTE)&sid, headersize,
6828 &readcount, FALSE, FALSE, &context) 6829 &readcount, FALSE, FALSE, &context)
6829 || readcount == 0) 6830 || readcount == 0)
6830 break; 6831 break;
6831 6832
6832 /* We only deal with streams that have a name. The normal 6833 // We only deal with streams that have a name. The normal
6833 * file data appears to be without a name, even though docs 6834 // file data appears to be without a name, even though docs
6834 * suggest it is called "::$DATA". */ 6835 // suggest it is called "::$DATA".
6835 if (sid.dwStreamNameSize > 0) 6836 if (sid.dwStreamNameSize > 0)
6836 { 6837 {
6837 /* Read the stream name. */ 6838 // Read the stream name.
6838 if (!BackupRead(sh, (LPBYTE)streamname, 6839 if (!BackupRead(sh, (LPBYTE)streamname,
6839 sid.dwStreamNameSize, 6840 sid.dwStreamNameSize,
6840 &readcount, FALSE, FALSE, &context)) 6841 &readcount, FALSE, FALSE, &context))
6841 break; 6842 break;
6842 6843
6843 /* Copy an info stream with a name ":anything:$DATA". 6844 // Copy an info stream with a name ":anything:$DATA".
6844 * Skip "::$DATA", it has no stream name (examples suggest 6845 // Skip "::$DATA", it has no stream name (examples suggest
6845 * it might be used for the normal file contents). 6846 // it might be used for the normal file contents).
6846 * Note that BackupRead() counts bytes, but the name is in 6847 // Note that BackupRead() counts bytes, but the name is in
6847 * wide characters. */ 6848 // wide characters.
6848 len = readcount / sizeof(WCHAR); 6849 len = readcount / sizeof(WCHAR);
6849 streamname[len] = 0; 6850 streamname[len] = 0;
6850 if (len > 7 && wcsicmp(streamname + len - 6, 6851 if (len > 7 && wcsicmp(streamname + len - 6,
6851 L":$DATA") == 0) 6852 L":$DATA") == 0)
6852 { 6853 {
6854 copy_substream(sh, &context, tow, streamname, 6855 copy_substream(sh, &context, tow, streamname,
6855 (long)sid.Size.u.LowPart); 6856 (long)sid.Size.u.LowPart);
6856 } 6857 }
6857 } 6858 }
6858 6859
6859 /* Advance to the next stream. We might try seeking too far, 6860 // Advance to the next stream. We might try seeking too far,
6860 * but BackupSeek() doesn't skip over stream borders, thus 6861 // but BackupSeek() doesn't skip over stream borders, thus
6861 * that's OK. */ 6862 // that's OK.
6862 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, 6863 (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart,
6863 &lo, &hi, &context); 6864 &lo, &hi, &context);
6864 } 6865 }
6865 6866
6866 /* Clear the context. */ 6867 // Clear the context.
6867 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); 6868 (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context);
6868 6869
6869 CloseHandle(sh); 6870 CloseHandle(sh);
6870 } 6871 }
6871 } 6872 }
6879 * Always returns zero, errors are ignored. 6880 * Always returns zero, errors are ignored.
6880 */ 6881 */
6881 int 6882 int
6882 mch_copy_file_attribute(char_u *from, char_u *to) 6883 mch_copy_file_attribute(char_u *from, char_u *to)
6883 { 6884 {
6884 /* File streams only work on Windows NT and later. */ 6885 // File streams only work on Windows NT and later.
6885 copy_infostreams(from, to); 6886 copy_infostreams(from, to);
6886 return 0; 6887 return 0;
6887 } 6888 }
6888 6889
6889 #if defined(MYRESETSTKOFLW) || defined(PROTO) 6890 #if defined(MYRESETSTKOFLW) || defined(PROTO)
6890 /* 6891 /*
6891 * Recreate a destroyed stack guard page in win32. 6892 * Recreate a destroyed stack guard page in win32.
6892 * Written by Benjamin Peterson. 6893 * Written by Benjamin Peterson.
6893 */ 6894 */
6894 6895
6895 /* These magic numbers are from the MS header files */ 6896 // These magic numbers are from the MS header files
6896 # define MIN_STACK_WINNT 2 6897 # define MIN_STACK_WINNT 2
6897 6898
6898 /* 6899 /*
6899 * This function does the same thing as _resetstkoflw(), which is only 6900 * This function does the same thing as _resetstkoflw(), which is only
6900 * available in DevStudio .net and later. 6901 * available in DevStudio .net and later.
6910 MEMORY_BASIC_INFORMATION mbi; 6911 MEMORY_BASIC_INFORMATION mbi;
6911 SYSTEM_INFO si; 6912 SYSTEM_INFO si;
6912 DWORD nPageSize; 6913 DWORD nPageSize;
6913 DWORD dummy; 6914 DWORD dummy;
6914 6915
6915 /* We need to know the system page size. */ 6916 // We need to know the system page size.
6916 GetSystemInfo(&si); 6917 GetSystemInfo(&si);
6917 nPageSize = si.dwPageSize; 6918 nPageSize = si.dwPageSize;
6918 6919
6919 /* ...and the current stack pointer */ 6920 // ...and the current stack pointer
6920 pStackPtr = (BYTE*)_alloca(1); 6921 pStackPtr = (BYTE*)_alloca(1);
6921 6922
6922 /* ...and the base of the stack. */ 6923 // ...and the base of the stack.
6923 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) 6924 if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0)
6924 return 0; 6925 return 0;
6925 pStackBase = (BYTE*)mbi.AllocationBase; 6926 pStackBase = (BYTE*)mbi.AllocationBase;
6926 6927
6927 /* ...and the page thats min_stack_req pages away from stack base; this is 6928 // ...and the page thats min_stack_req pages away from stack base; this is
6928 * the lowest page we could use. */ 6929 // the lowest page we could use.
6929 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; 6930 pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize;
6930 6931
6931 { 6932 {
6932 /* We want the first committed page in the stack Start at the stack 6933 // We want the first committed page in the stack Start at the stack
6933 * base and move forward through memory until we find a committed block. 6934 // base and move forward through memory until we find a committed block.
6934 */
6935 BYTE *pBlock = pStackBase; 6935 BYTE *pBlock = pStackBase;
6936 6936
6937 for (;;) 6937 for (;;)
6938 { 6938 {
6939 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0) 6939 if (VirtualQuery(pBlock, &mbi, sizeof mbi) == 0)
6943 6943
6944 if (mbi.State & MEM_COMMIT) 6944 if (mbi.State & MEM_COMMIT)
6945 break; 6945 break;
6946 } 6946 }
6947 6947
6948 /* mbi now describes the first committed block in the stack. */ 6948 // mbi now describes the first committed block in the stack.
6949 if (mbi.Protect & PAGE_GUARD) 6949 if (mbi.Protect & PAGE_GUARD)
6950 return 1; 6950 return 1;
6951 6951
6952 /* decide where the guard page should start */ 6952 // decide where the guard page should start
6953 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) 6953 if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage)
6954 pGuardPage = pLowestPossiblePage; 6954 pGuardPage = pLowestPossiblePage;
6955 else 6955 else
6956 pGuardPage = (BYTE*)mbi.BaseAddress; 6956 pGuardPage = (BYTE*)mbi.BaseAddress;
6957 6957
6958 /* allocate the guard page */ 6958 // allocate the guard page
6959 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) 6959 if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE))
6960 return 0; 6960 return 0;
6961 6961
6962 /* apply the guard attribute to the page */ 6962 // apply the guard attribute to the page
6963 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, 6963 if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD,
6964 &dummy)) 6964 &dummy))
6965 return 0; 6965 return 0;
6966 } 6966 }
6967 6967
6976 static int nArgsW = 0; 6976 static int nArgsW = 0;
6977 static LPWSTR *ArglistW = NULL; 6977 static LPWSTR *ArglistW = NULL;
6978 static int global_argc = 0; 6978 static int global_argc = 0;
6979 static char **global_argv; 6979 static char **global_argv;
6980 6980
6981 static int used_file_argc = 0; /* last argument in global_argv[] used 6981 static int used_file_argc = 0; // last argument in global_argv[] used
6982 for the argument list. */ 6982 // for the argument list.
6983 static int *used_file_indexes = NULL; /* indexes in global_argv[] for 6983 static int *used_file_indexes = NULL; // indexes in global_argv[] for
6984 command line arguments added to 6984 // command line arguments added to
6985 the argument list */ 6985 // the argument list
6986 static int used_file_count = 0; /* nr of entries in used_file_indexes */ 6986 static int used_file_count = 0; // nr of entries in used_file_indexes
6987 static int used_file_literal = FALSE; /* take file names literally */ 6987 static int used_file_literal = FALSE; // take file names literally
6988 static int used_file_full_path = FALSE; /* file name was full path */ 6988 static int used_file_full_path = FALSE; // file name was full path
6989 static int used_file_diff_mode = FALSE; /* file name was with diff mode */ 6989 static int used_file_diff_mode = FALSE; // file name was with diff mode
6990 static int used_alist_count = 0; 6990 static int used_alist_count = 0;
6991 6991
6992 6992
6993 /* 6993 /*
6994 * Get the command line arguments. Unicode version. 6994 * Get the command line arguments. Unicode version.
7012 argv[argc] = NULL; 7012 argv[argc] = NULL;
7013 for (i = 0; i < argc; ++i) 7013 for (i = 0; i < argc; ++i)
7014 { 7014 {
7015 int len; 7015 int len;
7016 7016
7017 /* Convert each Unicode argument to the current codepage. */ 7017 // Convert each Unicode argument to the current codepage.
7018 WideCharToMultiByte_alloc(GetACP(), 0, 7018 WideCharToMultiByte_alloc(GetACP(), 0,
7019 ArglistW[i], (int)wcslen(ArglistW[i]) + 1, 7019 ArglistW[i], (int)wcslen(ArglistW[i]) + 1,
7020 (LPSTR *)&argv[i], &len, 0, 0); 7020 (LPSTR *)&argv[i], &len, 0, 0);
7021 if (argv[i] == NULL) 7021 if (argv[i] == NULL)
7022 { 7022 {
7023 /* Out of memory, clear everything. */ 7023 // Out of memory, clear everything.
7024 while (i > 0) 7024 while (i > 0)
7025 free(argv[--i]); 7025 free(argv[--i]);
7026 free(argv); 7026 free(argv);
7027 argv = NULL; 7027 argv = NULL;
7028 argc = 0; 7028 argc = 0;
7100 int i; 7100 int i;
7101 int idx; 7101 int idx;
7102 char_u *str; 7102 char_u *str;
7103 int *fnum_list; 7103 int *fnum_list;
7104 7104
7105 /* Safety checks: 7105 // Safety checks:
7106 * - if argument count differs between the wide and non-wide argument 7106 // - if argument count differs between the wide and non-wide argument
7107 * list, something must be wrong. 7107 // list, something must be wrong.
7108 * - the file name arguments must have been located. 7108 // - the file name arguments must have been located.
7109 * - the length of the argument list wasn't changed by the user. 7109 // - the length of the argument list wasn't changed by the user.
7110 */
7111 if (global_argc != nArgsW 7110 if (global_argc != nArgsW
7112 || ArglistW == NULL 7111 || ArglistW == NULL
7113 || used_file_indexes == NULL 7112 || used_file_indexes == NULL
7114 || used_file_count == 0 7113 || used_file_count == 0
7115 || used_alist_count != GARGCOUNT) 7114 || used_alist_count != GARGCOUNT)
7116 return; 7115 return;
7117 7116
7118 /* Remember the buffer numbers for the arguments. */ 7117 // Remember the buffer numbers for the arguments.
7119 fnum_list = ALLOC_MULT(int, GARGCOUNT); 7118 fnum_list = ALLOC_MULT(int, GARGCOUNT);
7120 if (fnum_list == NULL) 7119 if (fnum_list == NULL)
7121 return; /* out of memory */ 7120 return; // out of memory
7122 for (i = 0; i < GARGCOUNT; ++i) 7121 for (i = 0; i < GARGCOUNT; ++i)
7123 fnum_list[i] = GARGLIST[i].ae_fnum; 7122 fnum_list[i] = GARGLIST[i].ae_fnum;
7124 7123
7125 /* Clear the argument list. Make room for the new arguments. */ 7124 // Clear the argument list. Make room for the new arguments.
7126 alist_clear(&global_alist); 7125 alist_clear(&global_alist);
7127 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) 7126 if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL)
7128 return; /* out of memory */ 7127 return; // out of memory
7129 7128
7130 for (i = 0; i < used_file_count; ++i) 7129 for (i = 0; i < used_file_count; ++i)
7131 { 7130 {
7132 idx = used_file_indexes[i]; 7131 idx = used_file_indexes[i];
7133 str = utf16_to_enc(ArglistW[idx], NULL); 7132 str = utf16_to_enc(ArglistW[idx], NULL);
7134 if (str != NULL) 7133 if (str != NULL)
7135 { 7134 {
7136 int literal = used_file_literal; 7135 int literal = used_file_literal;
7137 7136
7138 #ifdef FEAT_DIFF 7137 #ifdef FEAT_DIFF
7139 /* When using diff mode may need to concatenate file name to 7138 // When using diff mode may need to concatenate file name to
7140 * directory name. Just like it's done in main(). */ 7139 // directory name. Just like it's done in main().
7141 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 7140 if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0
7142 && !mch_isdir(alist_name(&GARGLIST[0]))) 7141 && !mch_isdir(alist_name(&GARGLIST[0])))
7143 { 7142 {
7144 char_u *r; 7143 char_u *r;
7145 7144
7149 vim_free(str); 7148 vim_free(str);
7150 str = r; 7149 str = r;
7151 } 7150 }
7152 } 7151 }
7153 #endif 7152 #endif
7154 /* Re-use the old buffer by renaming it. When not using literal 7153 // Re-use the old buffer by renaming it. When not using literal
7155 * names it's done by alist_expand() below. */ 7154 // names it's done by alist_expand() below.
7156 if (used_file_literal) 7155 if (used_file_literal)
7157 buf_set_name(fnum_list[i], str); 7156 buf_set_name(fnum_list[i], str);
7158 7157
7159 /* Check backtick literal. backtick literal is already expanded in 7158 // Check backtick literal. backtick literal is already expanded in
7160 * main.c, so this part add str as literal. */ 7159 // main.c, so this part add str as literal.
7161 if (literal == FALSE) 7160 if (literal == FALSE)
7162 { 7161 {
7163 size_t len = STRLEN(str); 7162 size_t len = STRLEN(str);
7164 7163
7165 if (len > 2 && *str == '`' && *(str + len - 1) == '`') 7164 if (len > 2 && *str == '`' && *(str + len - 1) == '`')
7169 } 7168 }
7170 } 7169 }
7171 7170
7172 if (!used_file_literal) 7171 if (!used_file_literal)
7173 { 7172 {
7174 /* Now expand wildcards in the arguments. */ 7173 // Now expand wildcards in the arguments.
7175 /* Temporarily add '(' and ')' to 'isfname'. These are valid 7174 // Temporarily add '(' and ')' to 'isfname'. These are valid
7176 * filename characters but are excluded from 'isfname' to make 7175 // filename characters but are excluded from 'isfname' to make
7177 * "gf" work on a file name in parenthesis (e.g.: see vim.h). 7176 // "gf" work on a file name in parenthesis (e.g.: see vim.h).
7178 * Also, unset wildignore to not be influenced by this option. 7177 // Also, unset wildignore to not be influenced by this option.
7179 * The arguments specified in command-line should be kept even if 7178 // The arguments specified in command-line should be kept even if
7180 * encoding options were changed. */ 7179 // encoding options were changed.
7181 do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)"); 7180 do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)");
7182 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); 7181 do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig=");
7183 alist_expand(fnum_list, used_alist_count); 7182 alist_expand(fnum_list, used_alist_count);
7184 do_cmdline_cmd((char_u *)":let &isf = SaVe_ISF|unlet SaVe_ISF"); 7183 do_cmdline_cmd((char_u *)":let &isf = SaVe_ISF|unlet SaVe_ISF");
7185 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); 7184 do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG");
7186 } 7185 }
7187 7186
7188 /* If wildcard expansion failed, we are editing the first file of the 7187 // If wildcard expansion failed, we are editing the first file of the
7189 * arglist and there is no file name: Edit the first argument now. */ 7188 // arglist and there is no file name: Edit the first argument now.
7190 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) 7189 if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL)
7191 { 7190 {
7192 do_cmdline_cmd((char_u *)":rewind"); 7191 do_cmdline_cmd((char_u *)":rewind");
7193 if (GARGCOUNT == 1 && used_file_full_path) 7192 if (GARGCOUNT == 1 && used_file_full_path)
7194 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop"); 7193 (void)vim_chdirfile(alist_name(&GARGLIST[0]), "drop");
7304 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi; 7303 DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
7305 # ifdef FEAT_TERMGUICOLORS 7304 # ifdef FEAT_TERMGUICOLORS
7306 COLORREF fg, bg; 7305 COLORREF fg, bg;
7307 # endif 7306 # endif
7308 7307
7309 /* Use functions supported from Vista */ 7308 // Use functions supported from Vista
7310 hKerneldll = GetModuleHandle("kernel32.dll"); 7309 hKerneldll = GetModuleHandle("kernel32.dll");
7311 if (hKerneldll != NULL) 7310 if (hKerneldll != NULL)
7312 { 7311 {
7313 pGetConsoleScreenBufferInfoEx = 7312 pGetConsoleScreenBufferInfoEx =
7314 (PfnGetConsoleScreenBufferInfoEx)GetProcAddress( 7313 (PfnGetConsoleScreenBufferInfoEx)GetProcAddress(
7375 vtp_sgr_bulks( 7374 vtp_sgr_bulks(
7376 int argc, 7375 int argc,
7377 int *args 7376 int *args
7378 ) 7377 )
7379 { 7378 {
7380 /* 2('\033[') + 4('255.') * 16 + NUL */ 7379 // 2('\033[') + 4('255.') * 16 + NUL
7381 char_u buf[2 + (4 * 16) + 1]; 7380 char_u buf[2 + (4 * 16) + 1];
7382 char_u *p; 7381 char_u *p;
7383 int i; 7382 int i;
7384 7383
7385 p = buf; 7384 p = buf;