Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Win32 (Windows NT and Windows 95) machine-dependent things. |
| 11 | */ |
| 12 | |
| 13 | #include "os_dos.h" /* common MS-DOS and Win32 stuff */ |
| 14 | #ifndef __CYGWIN__ |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 15 | /* cproto fails on missing include files */ |
| 16 | # ifndef PROTO |
| 17 | # include <direct.h> /* for _mkdir() */ |
| 18 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 19 | #endif |
| 20 | |
Bram Moolenaar | 66fa271 | 2006-01-22 23:22:22 +0000 | [diff] [blame] | 21 | /* Stop the VC2005 compiler from nagging. */ |
| 22 | #if _MSC_VER >= 1400 |
| 23 | # define _CRT_SECURE_NO_DEPRECATE |
| 24 | # define _CRT_NONSTDC_NO_DEPRECATE |
| 25 | #endif |
| 26 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 27 | #define BINARY_FILE_IO |
| 28 | #define USE_EXE_NAME /* use argv[0] for $VIM */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 29 | #define USE_TERM_CONSOLE |
| 30 | #ifndef HAVE_STRING_H |
| 31 | # define HAVE_STRING_H |
| 32 | #endif |
Bram Moolenaar | 3577c6f | 2008-06-24 21:16:56 +0000 | [diff] [blame] | 33 | #ifndef HAVE_MATH_H |
| 34 | # define HAVE_MATH_H |
| 35 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 36 | #define HAVE_STRCSPN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 37 | #ifndef __GNUC__ |
| 38 | #define HAVE_STRICMP |
| 39 | #define HAVE_STRNICMP |
| 40 | #endif |
| 41 | #ifndef HAVE_STRFTIME |
| 42 | # define HAVE_STRFTIME /* guessed */ |
| 43 | #endif |
| 44 | #define HAVE_MEMSET |
| 45 | #ifndef HAVE_LOCALE_H |
| 46 | # define HAVE_LOCALE_H 1 |
| 47 | #endif |
| 48 | #ifndef HAVE_FCNTL_H |
| 49 | # define HAVE_FCNTL_H |
| 50 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 51 | #define HAVE_QSORT |
| 52 | #define HAVE_ST_MODE /* have stat.st_mode */ |
| 53 | |
| 54 | #define FEAT_SHORTCUT /* resolve shortcuts */ |
| 55 | |
Bram Moolenaar | 39efa89 | 2013-06-29 15:40:04 +0200 | [diff] [blame] | 56 | #if (!defined(__BORLANDC__) || __BORLANDC__ >= 0x550) \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 57 | && (!defined(_MSC_VER) || _MSC_VER > 1020) |
| 58 | /* |
| 59 | * Access Control List (actually security info). |
Bram Moolenaar | 39efa89 | 2013-06-29 15:40:04 +0200 | [diff] [blame] | 60 | * Borland has the acl stuff only in version 5.5 and later. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 61 | * MSVC in 5.0, not in 4.2, don't know about 4.3. |
| 62 | */ |
| 63 | # define HAVE_ACL |
| 64 | #endif |
| 65 | |
| 66 | #define USE_FNAME_CASE /* adjust case of file names */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 67 | #if !defined(FEAT_CLIPBOARD) && defined(FEAT_MOUSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 68 | # define FEAT_CLIPBOARD /* include clipboard support */ |
| 69 | #endif |
| 70 | #if defined(__DATE__) && defined(__TIME__) |
| 71 | # define HAVE_DATE_TIME |
| 72 | #endif |
| 73 | #ifndef FEAT_GUI_W32 /* GUI works different */ |
| 74 | # define BREAKCHECK_SKIP 1 /* call mch_breakcheck() each time, it's fast */ |
| 75 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 76 | |
Bram Moolenaar | ee27397 | 2016-01-02 21:11:51 +0100 | [diff] [blame] | 77 | #define HAVE_TOTAL_MEM |
| 78 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | #define HAVE_PUTENV /* at least Bcc 5.2 and MSC have it */ |
| 80 | |
| 81 | #ifdef FEAT_GUI_W32 |
| 82 | # define NO_CONSOLE /* don't included console-only code */ |
| 83 | #endif |
| 84 | |
| 85 | /* toupper() is not really broken, but it's very slow. Probably because of |
| 86 | * using Unicode characters on Windows NT */ |
| 87 | #define BROKEN_TOUPPER |
| 88 | |
| 89 | #define FNAME_ILLEGAL "\"*?><|" /* illegal characters in a file name */ |
| 90 | |
Bram Moolenaar | 8e82c05 | 2018-08-21 19:47:48 +0200 | [diff] [blame] | 91 | #include <signal.h> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 92 | #include <stdlib.h> |
| 93 | #include <time.h> |
Bram Moolenaar | 914703b | 2010-05-31 21:59:46 +0200 | [diff] [blame] | 94 | #include <sys/types.h> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | |
| 96 | #ifndef STRICT |
| 97 | # define STRICT |
| 98 | #endif |
| 99 | #ifndef COBJMACROS |
| 100 | # define COBJMACROS /* For OLE: Enable "friendlier" access to objects */ |
| 101 | #endif |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 102 | #ifndef PROTO |
| 103 | # include <windows.h> |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 104 | # ifndef SM_CXPADDEDBORDER |
| 105 | # define SM_CXPADDEDBORDER 92 |
| 106 | # endif |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 107 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * Win32 has plenty of memory, use large buffers |
| 111 | */ |
| 112 | #define CMDBUFFSIZE 1024 /* size of the command processing buffer */ |
| 113 | |
Bram Moolenaar | 17aa8cc | 2012-10-21 21:38:45 +0200 | [diff] [blame] | 114 | /* _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 115 | * thus use a larger number. */ |
| 116 | #define MAXPATHL 1024 |
| 117 | |
| 118 | #ifndef BASENAMELEN |
| 119 | # define BASENAMELEN (_MAX_PATH - 5) /* length of base of file name */ |
| 120 | #endif |
| 121 | |
| 122 | #define TEMPNAMELEN _MAX_PATH /* length of temp file name path */ |
| 123 | |
| 124 | #ifndef DFLT_MAXMEM |
| 125 | # define DFLT_MAXMEM (2*1024) /* use up to 2 Mbyte for a buffer */ |
| 126 | #endif |
| 127 | |
| 128 | #ifndef DFLT_MAXMEMTOT |
| 129 | # define DFLT_MAXMEMTOT (5*1024) /* use up to 5 Mbyte for Vim */ |
| 130 | #endif |
| 131 | |
Bram Moolenaar | 2ee95f7 | 2013-09-25 19:13:38 +0200 | [diff] [blame] | 132 | /* |
| 133 | * Reparse Point |
| 134 | */ |
| 135 | #ifndef FILE_ATTRIBUTE_REPARSE_POINT |
| 136 | # define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 |
| 137 | #endif |
| 138 | #ifndef IO_REPARSE_TAG_MOUNT_POINT |
| 139 | # define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003 |
| 140 | #endif |
| 141 | #ifndef IO_REPARSE_TAG_SYMLINK |
| 142 | # define IO_REPARSE_TAG_SYMLINK 0xA000000C |
| 143 | #endif |
| 144 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 145 | #if defined(_MSC_VER) || defined(__BORLANDC__) |
| 146 | /* Support for __try / __except. All versions of MSVC and Borland C are |
| 147 | * expected to have this. Any other compilers that support it? */ |
| 148 | # define HAVE_TRY_EXCEPT 1 |
| 149 | # include <malloc.h> /* for _resetstkoflw() */ |
| 150 | # if defined(_MSC_VER) && (_MSC_VER >= 1300) |
| 151 | # define RESETSTKOFLW _resetstkoflw |
| 152 | # else |
| 153 | # define RESETSTKOFLW myresetstkoflw |
| 154 | # define MYRESETSTKOFLW |
| 155 | # endif |
| 156 | #endif |
| 157 | |
| 158 | /* |
| 159 | * Some simple debugging macros that look and behave a lot like their |
| 160 | * namesakes in MFC. |
| 161 | */ |
| 162 | |
| 163 | #ifdef _DEBUG |
| 164 | |
| 165 | # if defined(_MSC_VER) && (_MSC_VER >= 1000) |
| 166 | /* Use the new debugging tools in Visual C++ 4.x */ |
| 167 | # include <crtdbg.h> |
| 168 | # define ASSERT(f) _ASSERT(f) |
| 169 | # else |
| 170 | # include <assert.h> |
| 171 | # define ASSERT(f) assert(f) |
| 172 | # endif |
| 173 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 174 | # define TRACE Trace |
| 175 | # define TRACE0(sz) Trace(_T("%s"), _T(sz)) |
| 176 | # define TRACE1(sz, p1) Trace(_T(sz), p1) |
| 177 | # define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2) |
| 178 | # define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3) |
| 179 | # define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4) |
| 180 | |
| 181 | /* In debug version, writes trace messages to debug stream */ |
| 182 | void __cdecl |
| 183 | Trace(char *pszFormat, ...); |
| 184 | |
| 185 | #else /* !_DEBUG */ |
| 186 | |
| 187 | /* These macros should all compile away to nothing */ |
| 188 | # define ASSERT(f) ((void)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 189 | # define TRACE 1 ? (void)0 : printf |
| 190 | # define TRACE0(sz) |
| 191 | # define TRACE1(sz, p1) |
| 192 | # define TRACE2(sz, p1, p2) |
| 193 | # define TRACE3(sz, p1, p2, p3) |
| 194 | # define TRACE4(sz, p1, p2, p3, p4) |
| 195 | |
| 196 | #endif /* !_DEBUG */ |
| 197 | |
| 198 | |
| 199 | #define ASSERT_POINTER(p, type) \ |
| 200 | ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE)) |
| 201 | |
| 202 | #define ASSERT_NULL_OR_POINTER(p, type) \ |
| 203 | ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE)) |
| 204 | |
Bram Moolenaar | 7c23d1d | 2017-02-01 13:14:16 +0100 | [diff] [blame] | 205 | #ifndef HAVE_SETENV |
| 206 | # define HAVE_SETENV |
| 207 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 208 | #define mch_getenv(x) (char_u *)getenv((char *)(x)) |
| 209 | #ifdef __BORLANDC__ |
| 210 | # define vim_mkdir(x, y) mkdir(x) |
| 211 | #else |
Bram Moolenaar | 3c9c99c | 2011-05-05 18:31:59 +0200 | [diff] [blame] | 212 | # define vim_mkdir(x, y) mch_mkdir(x) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 213 | #endif |
Bram Moolenaar | 8c85fa3 | 2011-08-10 17:08:03 +0200 | [diff] [blame] | 214 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 215 | /* Enable common dialogs input unicode from IME if possible. */ |
Bram Moolenaar | 8c85fa3 | 2011-08-10 17:08:03 +0200 | [diff] [blame] | 216 | #ifdef FEAT_MBYTE |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 217 | # define pDispatchMessage DispatchMessageW |
| 218 | # define pGetMessage GetMessageW |
| 219 | # define pIsDialogMessage IsDialogMessageW |
| 220 | # define pPeekMessage PeekMessageW |
Bram Moolenaar | 8c85fa3 | 2011-08-10 17:08:03 +0200 | [diff] [blame] | 221 | #else |
| 222 | # define pDispatchMessage DispatchMessage |
| 223 | # define pGetMessage GetMessage |
| 224 | # define pIsDialogMessage IsDialogMessage |
| 225 | # define pPeekMessage PeekMessage |
| 226 | #endif |