blob: 7f9ee8d09c79ed878f13e1dcc3b4eef8b3671af4 [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 Moolenaare6a16e92022-10-17 14:51:36 +010089
90// Weird: rpcndr.h defines "small" to "char", which causes trouble
91#undef small
92
Bram Moolenaar9d488952013-07-21 17:53:58 +020093# ifndef SM_CXPADDEDBORDER
94# define SM_CXPADDEDBORDER 92
95# endif
Bram Moolenaar82881492012-11-20 16:53:39 +010096#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000097
98/*
99 * Win32 has plenty of memory, use large buffers
100 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100101#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100103// _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option,
104// thus use a larger number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105#define MAXPATHL 1024
106
107#ifndef BASENAMELEN
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100108# define BASENAMELEN (_MAX_PATH - 5) // length of base of file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109#endif
110
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100111#define TEMPNAMELEN _MAX_PATH // length of temp file name path
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112
113#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100114# define DFLT_MAXMEM (2*1024) // use up to 2 Mbyte for a buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115#endif
116
117#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100118# define DFLT_MAXMEMTOT (5*1024) // use up to 5 Mbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119#endif
120
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200121/*
122 * Reparse Point
123 */
124#ifndef FILE_ATTRIBUTE_REPARSE_POINT
125# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
126#endif
127#ifndef IO_REPARSE_TAG_MOUNT_POINT
128# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
129#endif
130#ifndef IO_REPARSE_TAG_SYMLINK
131# define IO_REPARSE_TAG_SYMLINK 0xA000000C
132#endif
LemonBoy40fd7e62022-05-05 20:18:16 +0100133#ifndef IO_REPARSE_TAG_APPEXECLINK
134# define IO_REPARSE_TAG_APPEXECLINK 0x8000001B
135#endif
136
137/*
138 * Definition of the reparse point buffer.
139 * This is usually defined in the DDK, copy the definition here to avoid
140 * adding it as a dependence only for a single structure.
141 */
142typedef struct _REPARSE_DATA_BUFFER {
143 ULONG ReparseTag;
144 USHORT ReparseDataLength;
145 USHORT Reserved;
146 union {
147 struct {
148 USHORT SubstituteNameOffset;
149 USHORT SubstituteNameLength;
150 USHORT PrintNameOffset;
151 USHORT PrintNameLength;
152 ULONG Flags;
153 WCHAR PathBuffer[1];
154 } SymbolicLinkReparseBuffer;
155 struct {
156 USHORT SubstituteNameOffset;
157 USHORT SubstituteNameLength;
158 USHORT PrintNameOffset;
159 USHORT PrintNameLength;
160 WCHAR PathBuffer[1];
161 } MountPointReparseBuffer;
162 struct {
163 UCHAR DataBuffer[1];
164 } GenericReparseBuffer;
165 struct
166 {
167 ULONG StringCount;
168 WCHAR StringList[1];
169 } AppExecLinkReparseBuffer;
170 } DUMMYUNIONNAME;
171} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200172
K.Takatac351dc12022-01-24 11:24:08 +0000173#ifdef _MSC_VER
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100174 // Support for __try / __except. All versions of MSVC are
175 // expected to have this. Any other compilers that support it?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176# define HAVE_TRY_EXCEPT 1
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100177# include <malloc.h> // for _resetstkoflw()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178#endif
179
180/*
181 * Some simple debugging macros that look and behave a lot like their
182 * namesakes in MFC.
183 */
184
185#ifdef _DEBUG
186
K.Takatac351dc12022-01-24 11:24:08 +0000187# include <crtdbg.h>
188# define ASSERT(f) _ASSERT(f)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000189
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190# define TRACE Trace
191# define TRACE0(sz) Trace(_T("%s"), _T(sz))
192# define TRACE1(sz, p1) Trace(_T(sz), p1)
193# define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2)
194# define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3)
195# define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4)
196
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100197// In debug version, writes trace messages to debug stream
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198void __cdecl
199Trace(char *pszFormat, ...);
200
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100201#else // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100203 // These macros should all compile away to nothing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204# define ASSERT(f) ((void)0)
Bram Moolenaar35d7a2f2022-06-09 20:53:54 +0100205# define TRACE 1 ? (void)0 : (void)printf
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206# define TRACE0(sz)
207# define TRACE1(sz, p1)
208# define TRACE2(sz, p1, p2)
209# define TRACE3(sz, p1, p2, p3)
210# define TRACE4(sz, p1, p2, p3, p4)
211
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100212#endif // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213
214
215#define ASSERT_POINTER(p, type) \
216 ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
217
218#define ASSERT_NULL_OR_POINTER(p, type) \
219 ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
220
Bram Moolenaar7c23d1d2017-02-01 13:14:16 +0100221#ifndef HAVE_SETENV
222# define HAVE_SETENV
223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224#define mch_getenv(x) (char_u *)getenv((char *)(x))
Bram Moolenaareae1b912019-05-09 15:12:55 +0200225#define vim_mkdir(x, y) mch_mkdir(x)