blob: f1be8c44112ed644f10c3bee967057b95e492678 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
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
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010013#include "os_dos.h" // common MS-DOS and Win32 stuff
Bram Moolenaar071d4272004-06-13 20:20:40 +000014#ifndef __CYGWIN__
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010015// cproto fails on missing include files
Bram Moolenaar82881492012-11-20 16:53:39 +010016# ifndef PROTO
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010017# include <direct.h> // for _mkdir()
Bram Moolenaar82881492012-11-20 16:53:39 +010018# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000019#endif
20
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010021// Stop the VC2005 compiler from nagging.
Bram Moolenaar66fa2712006-01-22 23:22:22 +000022#if _MSC_VER >= 1400
23# define _CRT_SECURE_NO_DEPRECATE
24# define _CRT_NONSTDC_NO_DEPRECATE
25#endif
26
Bram Moolenaar071d4272004-06-13 20:20:40 +000027#define BINARY_FILE_IO
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010028#define USE_EXE_NAME // use argv[0] for $VIM
Bram Moolenaar071d4272004-06-13 20:20:40 +000029#define USE_TERM_CONSOLE
30#ifndef HAVE_STRING_H
31# define HAVE_STRING_H
32#endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000033#ifndef HAVE_MATH_H
34# define HAVE_MATH_H
35#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000036#define HAVE_STRCSPN
Bram Moolenaar071d4272004-06-13 20:20:40 +000037#ifndef __GNUC__
38#define HAVE_STRICMP
39#define HAVE_STRNICMP
40#endif
41#ifndef HAVE_STRFTIME
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010042# define HAVE_STRFTIME // guessed
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#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 Moolenaar071d4272004-06-13 20:20:40 +000051#define HAVE_QSORT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010052#define HAVE_ST_MODE // have stat.st_mode
Bram Moolenaar071d4272004-06-13 20:20:40 +000053
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010054#define FEAT_SHORTCUT // resolve shortcuts
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
Bram Moolenaareae1b912019-05-09 15:12:55 +020056#if (!defined(_MSC_VER) || _MSC_VER > 1020)
Bram Moolenaar071d4272004-06-13 20:20:40 +000057/*
58 * Access Control List (actually security info).
Bram Moolenaareae1b912019-05-09 15:12:55 +020059 * MSVC has acl stuff only in 5.0, not in 4.2, don't know about 4.3.
Bram Moolenaar071d4272004-06-13 20:20:40 +000060 */
61# define HAVE_ACL
62#endif
63
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010064#define USE_FNAME_CASE // adjust case of file names
Bram Moolenaara1cb1d12019-10-17 23:00:07 +020065#if !defined(FEAT_CLIPBOARD)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010066# define FEAT_CLIPBOARD // include clipboard support
Bram Moolenaar071d4272004-06-13 20:20:40 +000067#endif
68#if defined(__DATE__) && defined(__TIME__)
69# define HAVE_DATE_TIME
70#endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010071#ifndef FEAT_GUI_MSWIN // GUI works different
72# define BREAKCHECK_SKIP 1 // call mch_breakcheck() each time, it's fast
Bram Moolenaar071d4272004-06-13 20:20:40 +000073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaaree273972016-01-02 21:11:51 +010075#define HAVE_TOTAL_MEM
76
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010077#define HAVE_PUTENV // at least Bcc 5.2 and MSC have it
Bram Moolenaar071d4272004-06-13 20:20:40 +000078
Bram Moolenaarafde13b2019-04-28 19:46:49 +020079#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010080# define NO_CONSOLE // don't included console-only code
Bram Moolenaar071d4272004-06-13 20:20:40 +000081#endif
82
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010083// toupper() is not really broken, but it's very slow. Probably because of
84// using Unicode characters on Windows NT
Bram Moolenaar071d4272004-06-13 20:20:40 +000085#define BROKEN_TOUPPER
86
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010087#define FNAME_ILLEGAL "\"*?><|" // illegal characters in a file name
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
Bram Moolenaar8e82c052018-08-21 19:47:48 +020089#include <signal.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000090#include <stdlib.h>
91#include <time.h>
Bram Moolenaar914703b2010-05-31 21:59:46 +020092#include <sys/types.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
94#ifndef STRICT
95# define STRICT
96#endif
97#ifndef COBJMACROS
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010098# define COBJMACROS // For OLE: Enable "friendlier" access to objects
Bram Moolenaar071d4272004-06-13 20:20:40 +000099#endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100100#ifndef PROTO
101# include <windows.h>
Bram Moolenaar9d488952013-07-21 17:53:58 +0200102# ifndef SM_CXPADDEDBORDER
103# define SM_CXPADDEDBORDER 92
104# endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100105#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106
107/*
108 * Win32 has plenty of memory, use large buffers
109 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100110#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100112// _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option,
113// thus use a larger number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114#define MAXPATHL 1024
115
116#ifndef BASENAMELEN
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100117# define BASENAMELEN (_MAX_PATH - 5) // length of base of file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118#endif
119
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100120#define TEMPNAMELEN _MAX_PATH // length of temp file name path
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121
122#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100123# define DFLT_MAXMEM (2*1024) // use up to 2 Mbyte for a buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124#endif
125
126#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100127# define DFLT_MAXMEMTOT (5*1024) // use up to 5 Mbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128#endif
129
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200130/*
131 * Reparse Point
132 */
133#ifndef FILE_ATTRIBUTE_REPARSE_POINT
134# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
135#endif
136#ifndef IO_REPARSE_TAG_MOUNT_POINT
137# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
138#endif
139#ifndef IO_REPARSE_TAG_SYMLINK
140# define IO_REPARSE_TAG_SYMLINK 0xA000000C
141#endif
142
Bram Moolenaareae1b912019-05-09 15:12:55 +0200143#if defined(_MSC_VER)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100144 // Support for __try / __except. All versions of MSVC are
145 // expected to have this. Any other compilers that support it?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146# define HAVE_TRY_EXCEPT 1
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100147# include <malloc.h> // for _resetstkoflw()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148# if defined(_MSC_VER) && (_MSC_VER >= 1300)
149# define RESETSTKOFLW _resetstkoflw
150# else
151# define RESETSTKOFLW myresetstkoflw
152# define MYRESETSTKOFLW
153# endif
154#endif
155
156/*
157 * Some simple debugging macros that look and behave a lot like their
158 * namesakes in MFC.
159 */
160
161#ifdef _DEBUG
162
163# if defined(_MSC_VER) && (_MSC_VER >= 1000)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100164 // Use the new debugging tools in Visual C++ 4.x
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165# include <crtdbg.h>
166# define ASSERT(f) _ASSERT(f)
167# else
168# include <assert.h>
169# define ASSERT(f) assert(f)
170# endif
171
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172# define TRACE Trace
173# define TRACE0(sz) Trace(_T("%s"), _T(sz))
174# define TRACE1(sz, p1) Trace(_T(sz), p1)
175# define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2)
176# define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3)
177# define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4)
178
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100179// In debug version, writes trace messages to debug stream
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180void __cdecl
181Trace(char *pszFormat, ...);
182
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100183#else // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100185 // These macros should all compile away to nothing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186# define ASSERT(f) ((void)0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187# define TRACE 1 ? (void)0 : printf
188# define TRACE0(sz)
189# define TRACE1(sz, p1)
190# define TRACE2(sz, p1, p2)
191# define TRACE3(sz, p1, p2, p3)
192# define TRACE4(sz, p1, p2, p3, p4)
193
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100194#endif // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195
196
197#define ASSERT_POINTER(p, type) \
198 ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
199
200#define ASSERT_NULL_OR_POINTER(p, type) \
201 ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
202
Bram Moolenaar7c23d1d2017-02-01 13:14:16 +0100203#ifndef HAVE_SETENV
204# define HAVE_SETENV
205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206#define mch_getenv(x) (char_u *)getenv((char *)(x))
Bram Moolenaareae1b912019-05-09 15:12:55 +0200207#define vim_mkdir(x, y) mch_mkdir(x)
Bram Moolenaar8c85fa32011-08-10 17:08:03 +0200208
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100209// Enable common dialogs input unicode from IME if possible.
Bram Moolenaar264b74f2019-01-24 17:18:42 +0100210#define pDispatchMessage DispatchMessageW
211#define pGetMessage GetMessageW
212#define pIsDialogMessage IsDialogMessageW
213#define pPeekMessage PeekMessageW