blob: a98951e3dfc91339fc82d6cc12ca0b99b323dd2e [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 Moolenaar9bf703d2019-11-30 19:44:38 +010014// cproto fails on missing include files
K.Takata972db232022-02-04 10:45:38 +000015#ifndef PROTO
16# include <direct.h> // for _mkdir()
Bram Moolenaar071d4272004-06-13 20:20:40 +000017#endif
18
19#define BINARY_FILE_IO
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010020#define USE_EXE_NAME // use argv[0] for $VIM
Bram Moolenaar071d4272004-06-13 20:20:40 +000021#define USE_TERM_CONSOLE
22#ifndef HAVE_STRING_H
23# define HAVE_STRING_H
24#endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000025#ifndef HAVE_MATH_H
26# define HAVE_MATH_H
27#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000028#define HAVE_STRCSPN
Bram Moolenaar071d4272004-06-13 20:20:40 +000029#ifndef __GNUC__
30#define HAVE_STRICMP
31#define HAVE_STRNICMP
32#endif
33#ifndef HAVE_STRFTIME
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010034# define HAVE_STRFTIME // guessed
Bram Moolenaar071d4272004-06-13 20:20:40 +000035#endif
36#define HAVE_MEMSET
37#ifndef HAVE_LOCALE_H
38# define HAVE_LOCALE_H 1
39#endif
40#ifndef HAVE_FCNTL_H
41# define HAVE_FCNTL_H
42#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#define HAVE_QSORT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010044#define HAVE_ST_MODE // have stat.st_mode
Bram Moolenaar071d4272004-06-13 20:20:40 +000045
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010046#define FEAT_SHORTCUT // resolve shortcuts
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
K.Takatac351dc12022-01-24 11:24:08 +000048// Access Control List (actually security info).
49#define HAVE_ACL
Bram Moolenaar071d4272004-06-13 20:20:40 +000050
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010051#define USE_FNAME_CASE // adjust case of file names
Bram Moolenaara1cb1d12019-10-17 23:00:07 +020052#if !defined(FEAT_CLIPBOARD)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010053# define FEAT_CLIPBOARD // include clipboard support
Bram Moolenaar071d4272004-06-13 20:20:40 +000054#endif
55#if defined(__DATE__) && defined(__TIME__)
56# define HAVE_DATE_TIME
57#endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010058#ifndef FEAT_GUI_MSWIN // GUI works different
59# define BREAKCHECK_SKIP 1 // call mch_breakcheck() each time, it's fast
Bram Moolenaar071d4272004-06-13 20:20:40 +000060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
Bram Moolenaaree273972016-01-02 21:11:51 +010062#define HAVE_TOTAL_MEM
63
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010064#define HAVE_PUTENV // at least Bcc 5.2 and MSC have it
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
Bram Moolenaarafde13b2019-04-28 19:46:49 +020066#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
Dominique Pelleaf4a61a2021-12-27 17:21:41 +000067# define NO_CONSOLE // don't include console-only code
Bram Moolenaar071d4272004-06-13 20:20:40 +000068#endif
69
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010070// toupper() is not really broken, but it's very slow. Probably because of
71// using Unicode characters on Windows NT
Bram Moolenaar071d4272004-06-13 20:20:40 +000072#define BROKEN_TOUPPER
73
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010074#define FNAME_ILLEGAL "\"*?><|" // illegal characters in a file name
Bram Moolenaar071d4272004-06-13 20:20:40 +000075
Bram Moolenaar8e82c052018-08-21 19:47:48 +020076#include <signal.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000077#include <stdlib.h>
78#include <time.h>
Bram Moolenaar914703b2010-05-31 21:59:46 +020079#include <sys/types.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000080
81#ifndef STRICT
82# define STRICT
83#endif
84#ifndef COBJMACROS
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010085# define COBJMACROS // For OLE: Enable "friendlier" access to objects
Bram Moolenaar071d4272004-06-13 20:20:40 +000086#endif
Bram Moolenaar82881492012-11-20 16:53:39 +010087#ifndef PROTO
88# include <windows.h>
Bram Moolenaar9d488952013-07-21 17:53:58 +020089# ifndef SM_CXPADDEDBORDER
90# define SM_CXPADDEDBORDER 92
91# endif
Bram Moolenaar82881492012-11-20 16:53:39 +010092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
94/*
95 * Win32 has plenty of memory, use large buffers
96 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010097#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +000098
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010099// _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option,
100// thus use a larger number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101#define MAXPATHL 1024
102
103#ifndef BASENAMELEN
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100104# define BASENAMELEN (_MAX_PATH - 5) // length of base of file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105#endif
106
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100107#define TEMPNAMELEN _MAX_PATH // length of temp file name path
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
109#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100110# define DFLT_MAXMEM (2*1024) // use up to 2 Mbyte for a buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111#endif
112
113#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100114# define DFLT_MAXMEMTOT (5*1024) // use up to 5 Mbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115#endif
116
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200117/*
118 * Reparse Point
119 */
120#ifndef FILE_ATTRIBUTE_REPARSE_POINT
121# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
122#endif
123#ifndef IO_REPARSE_TAG_MOUNT_POINT
124# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
125#endif
126#ifndef IO_REPARSE_TAG_SYMLINK
127# define IO_REPARSE_TAG_SYMLINK 0xA000000C
128#endif
LemonBoy40fd7e62022-05-05 20:18:16 +0100129#ifndef IO_REPARSE_TAG_APPEXECLINK
130# define IO_REPARSE_TAG_APPEXECLINK 0x8000001B
131#endif
132
133/*
134 * Definition of the reparse point buffer.
135 * This is usually defined in the DDK, copy the definition here to avoid
136 * adding it as a dependence only for a single structure.
137 */
138typedef struct _REPARSE_DATA_BUFFER {
139 ULONG ReparseTag;
140 USHORT ReparseDataLength;
141 USHORT Reserved;
142 union {
143 struct {
144 USHORT SubstituteNameOffset;
145 USHORT SubstituteNameLength;
146 USHORT PrintNameOffset;
147 USHORT PrintNameLength;
148 ULONG Flags;
149 WCHAR PathBuffer[1];
150 } SymbolicLinkReparseBuffer;
151 struct {
152 USHORT SubstituteNameOffset;
153 USHORT SubstituteNameLength;
154 USHORT PrintNameOffset;
155 USHORT PrintNameLength;
156 WCHAR PathBuffer[1];
157 } MountPointReparseBuffer;
158 struct {
159 UCHAR DataBuffer[1];
160 } GenericReparseBuffer;
161 struct
162 {
163 ULONG StringCount;
164 WCHAR StringList[1];
165 } AppExecLinkReparseBuffer;
166 } DUMMYUNIONNAME;
167} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200168
K.Takatac351dc12022-01-24 11:24:08 +0000169#ifdef _MSC_VER
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100170 // Support for __try / __except. All versions of MSVC are
171 // expected to have this. Any other compilers that support it?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172# define HAVE_TRY_EXCEPT 1
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100173# include <malloc.h> // for _resetstkoflw()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174#endif
175
176/*
177 * Some simple debugging macros that look and behave a lot like their
178 * namesakes in MFC.
179 */
180
181#ifdef _DEBUG
182
K.Takatac351dc12022-01-24 11:24:08 +0000183# include <crtdbg.h>
184# define ASSERT(f) _ASSERT(f)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186# define TRACE Trace
187# define TRACE0(sz) Trace(_T("%s"), _T(sz))
188# define TRACE1(sz, p1) Trace(_T(sz), p1)
189# define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2)
190# define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3)
191# define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4)
192
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100193// In debug version, writes trace messages to debug stream
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194void __cdecl
195Trace(char *pszFormat, ...);
196
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100197#else // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100199 // These macros should all compile away to nothing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200# define ASSERT(f) ((void)0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000201# define TRACE 1 ? (void)0 : printf
202# define TRACE0(sz)
203# define TRACE1(sz, p1)
204# define TRACE2(sz, p1, p2)
205# define TRACE3(sz, p1, p2, p3)
206# define TRACE4(sz, p1, p2, p3, p4)
207
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100208#endif // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209
210
211#define ASSERT_POINTER(p, type) \
212 ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
213
214#define ASSERT_NULL_OR_POINTER(p, type) \
215 ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
216
Bram Moolenaar7c23d1d2017-02-01 13:14:16 +0100217#ifndef HAVE_SETENV
218# define HAVE_SETENV
219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220#define mch_getenv(x) (char_u *)getenv((char *)(x))
Bram Moolenaareae1b912019-05-09 15:12:55 +0200221#define vim_mkdir(x, y) mch_mkdir(x)