blob: 87555b7896579c02c24cc3201b953d4994ed91e6 [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
ichizok378447f2023-05-11 22:25:42 +010098typedef void (*sighandler_T)(int, int);
99
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100/*
101 * Win32 has plenty of memory, use large buffers
102 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100103#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100105// _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option,
106// thus use a larger number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107#define MAXPATHL 1024
108
109#ifndef BASENAMELEN
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100110# define BASENAMELEN (_MAX_PATH - 5) // length of base of file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111#endif
112
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100113#define TEMPNAMELEN _MAX_PATH // length of temp file name path
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114
115#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100116# define DFLT_MAXMEM (2*1024) // use up to 2 Mbyte for a buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117#endif
118
119#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100120# define DFLT_MAXMEMTOT (5*1024) // use up to 5 Mbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121#endif
122
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200123/*
124 * Reparse Point
125 */
126#ifndef FILE_ATTRIBUTE_REPARSE_POINT
127# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
128#endif
129#ifndef IO_REPARSE_TAG_MOUNT_POINT
130# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
131#endif
132#ifndef IO_REPARSE_TAG_SYMLINK
133# define IO_REPARSE_TAG_SYMLINK 0xA000000C
134#endif
LemonBoy40fd7e62022-05-05 20:18:16 +0100135#ifndef IO_REPARSE_TAG_APPEXECLINK
136# define IO_REPARSE_TAG_APPEXECLINK 0x8000001B
137#endif
138
139/*
140 * Definition of the reparse point buffer.
141 * This is usually defined in the DDK, copy the definition here to avoid
142 * adding it as a dependence only for a single structure.
143 */
144typedef struct _REPARSE_DATA_BUFFER {
145 ULONG ReparseTag;
146 USHORT ReparseDataLength;
147 USHORT Reserved;
148 union {
149 struct {
150 USHORT SubstituteNameOffset;
151 USHORT SubstituteNameLength;
152 USHORT PrintNameOffset;
153 USHORT PrintNameLength;
154 ULONG Flags;
155 WCHAR PathBuffer[1];
156 } SymbolicLinkReparseBuffer;
157 struct {
158 USHORT SubstituteNameOffset;
159 USHORT SubstituteNameLength;
160 USHORT PrintNameOffset;
161 USHORT PrintNameLength;
162 WCHAR PathBuffer[1];
163 } MountPointReparseBuffer;
164 struct {
165 UCHAR DataBuffer[1];
166 } GenericReparseBuffer;
167 struct
168 {
169 ULONG StringCount;
170 WCHAR StringList[1];
171 } AppExecLinkReparseBuffer;
172 } DUMMYUNIONNAME;
173} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200174
K.Takatac351dc12022-01-24 11:24:08 +0000175#ifdef _MSC_VER
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100176 // Support for __try / __except. All versions of MSVC are
177 // expected to have this. Any other compilers that support it?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178# define HAVE_TRY_EXCEPT 1
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100179# include <malloc.h> // for _resetstkoflw()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180#endif
181
182/*
183 * Some simple debugging macros that look and behave a lot like their
184 * namesakes in MFC.
185 */
186
187#ifdef _DEBUG
188
K.Takatac351dc12022-01-24 11:24:08 +0000189# include <crtdbg.h>
190# define ASSERT(f) _ASSERT(f)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191
Bram Moolenaar071d4272004-06-13 20:20:40 +0000192# define TRACE Trace
193# define TRACE0(sz) Trace(_T("%s"), _T(sz))
194# define TRACE1(sz, p1) Trace(_T(sz), p1)
195# define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2)
196# define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3)
197# define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4)
198
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100199// In debug version, writes trace messages to debug stream
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200void __cdecl
201Trace(char *pszFormat, ...);
202
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100203#else // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100205 // These macros should all compile away to nothing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206# define ASSERT(f) ((void)0)
Bram Moolenaar35d7a2f2022-06-09 20:53:54 +0100207# define TRACE 1 ? (void)0 : (void)printf
Bram Moolenaar071d4272004-06-13 20:20:40 +0000208# define TRACE0(sz)
209# define TRACE1(sz, p1)
210# define TRACE2(sz, p1, p2)
211# define TRACE3(sz, p1, p2, p3)
212# define TRACE4(sz, p1, p2, p3, p4)
213
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100214#endif // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000215
216
217#define ASSERT_POINTER(p, type) \
218 ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
219
220#define ASSERT_NULL_OR_POINTER(p, type) \
221 ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
222
Bram Moolenaar7c23d1d2017-02-01 13:14:16 +0100223#ifndef HAVE_SETENV
224# define HAVE_SETENV
225#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226#define mch_getenv(x) (char_u *)getenv((char *)(x))
Bram Moolenaareae1b912019-05-09 15:12:55 +0200227#define vim_mkdir(x, y) mch_mkdir(x)