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