blob: 116b9e8296711d0f2b9639e8e25352bf97d618fa [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
21#define BINARY_FILE_IO
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010022#define USE_EXE_NAME // use argv[0] for $VIM
Bram Moolenaar071d4272004-06-13 20:20:40 +000023#define USE_TERM_CONSOLE
24#ifndef HAVE_STRING_H
25# define HAVE_STRING_H
26#endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000027#ifndef HAVE_MATH_H
28# define HAVE_MATH_H
29#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000030#define HAVE_STRCSPN
Bram Moolenaar071d4272004-06-13 20:20:40 +000031#ifndef __GNUC__
32#define HAVE_STRICMP
33#define HAVE_STRNICMP
34#endif
35#ifndef HAVE_STRFTIME
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010036# define HAVE_STRFTIME // guessed
Bram Moolenaar071d4272004-06-13 20:20:40 +000037#endif
38#define HAVE_MEMSET
39#ifndef HAVE_LOCALE_H
40# define HAVE_LOCALE_H 1
41#endif
42#ifndef HAVE_FCNTL_H
43# define HAVE_FCNTL_H
44#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000045#define HAVE_QSORT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010046#define HAVE_ST_MODE // have stat.st_mode
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010048#define FEAT_SHORTCUT // resolve shortcuts
Bram Moolenaar071d4272004-06-13 20:20:40 +000049
Bram Moolenaareae1b912019-05-09 15:12:55 +020050#if (!defined(_MSC_VER) || _MSC_VER > 1020)
Bram Moolenaar071d4272004-06-13 20:20:40 +000051/*
52 * Access Control List (actually security info).
Bram Moolenaareae1b912019-05-09 15:12:55 +020053 * 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 +000054 */
55# define HAVE_ACL
56#endif
57
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010058#define USE_FNAME_CASE // adjust case of file names
Bram Moolenaara1cb1d12019-10-17 23:00:07 +020059#if !defined(FEAT_CLIPBOARD)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010060# define FEAT_CLIPBOARD // include clipboard support
Bram Moolenaar071d4272004-06-13 20:20:40 +000061#endif
62#if defined(__DATE__) && defined(__TIME__)
63# define HAVE_DATE_TIME
64#endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010065#ifndef FEAT_GUI_MSWIN // GUI works different
66# define BREAKCHECK_SKIP 1 // call mch_breakcheck() each time, it's fast
Bram Moolenaar071d4272004-06-13 20:20:40 +000067#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000068
Bram Moolenaaree273972016-01-02 21:11:51 +010069#define HAVE_TOTAL_MEM
70
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010071#define HAVE_PUTENV // at least Bcc 5.2 and MSC have it
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
Bram Moolenaarafde13b2019-04-28 19:46:49 +020073#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
Dominique Pelleaf4a61a2021-12-27 17:21:41 +000074# define NO_CONSOLE // don't include console-only code
Bram Moolenaar071d4272004-06-13 20:20:40 +000075#endif
76
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010077// toupper() is not really broken, but it's very slow. Probably because of
78// using Unicode characters on Windows NT
Bram Moolenaar071d4272004-06-13 20:20:40 +000079#define BROKEN_TOUPPER
80
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010081#define FNAME_ILLEGAL "\"*?><|" // illegal characters in a file name
Bram Moolenaar071d4272004-06-13 20:20:40 +000082
Bram Moolenaar8e82c052018-08-21 19:47:48 +020083#include <signal.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000084#include <stdlib.h>
85#include <time.h>
Bram Moolenaar914703b2010-05-31 21:59:46 +020086#include <sys/types.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000087
88#ifndef STRICT
89# define STRICT
90#endif
91#ifndef COBJMACROS
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010092# define COBJMACROS // For OLE: Enable "friendlier" access to objects
Bram Moolenaar071d4272004-06-13 20:20:40 +000093#endif
Bram Moolenaar82881492012-11-20 16:53:39 +010094#ifndef PROTO
95# include <windows.h>
Bram Moolenaar9d488952013-07-21 17:53:58 +020096# ifndef SM_CXPADDEDBORDER
97# define SM_CXPADDEDBORDER 92
98# endif
Bram Moolenaar82881492012-11-20 16:53:39 +010099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100
101/*
102 * Win32 has plenty of memory, use large buffers
103 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100104#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100106// _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option,
107// thus use a larger number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108#define MAXPATHL 1024
109
110#ifndef BASENAMELEN
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100111# define BASENAMELEN (_MAX_PATH - 5) // length of base of file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112#endif
113
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100114#define TEMPNAMELEN _MAX_PATH // length of temp file name path
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115
116#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100117# define DFLT_MAXMEM (2*1024) // use up to 2 Mbyte for a buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118#endif
119
120#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100121# define DFLT_MAXMEMTOT (5*1024) // use up to 5 Mbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122#endif
123
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200124/*
125 * Reparse Point
126 */
127#ifndef FILE_ATTRIBUTE_REPARSE_POINT
128# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
129#endif
130#ifndef IO_REPARSE_TAG_MOUNT_POINT
131# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
132#endif
133#ifndef IO_REPARSE_TAG_SYMLINK
134# define IO_REPARSE_TAG_SYMLINK 0xA000000C
135#endif
136
Bram Moolenaareae1b912019-05-09 15:12:55 +0200137#if defined(_MSC_VER)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100138 // Support for __try / __except. All versions of MSVC are
139 // expected to have this. Any other compilers that support it?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140# define HAVE_TRY_EXCEPT 1
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100141# include <malloc.h> // for _resetstkoflw()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142# if defined(_MSC_VER) && (_MSC_VER >= 1300)
143# define RESETSTKOFLW _resetstkoflw
144# else
145# define RESETSTKOFLW myresetstkoflw
146# define MYRESETSTKOFLW
147# endif
148#endif
149
150/*
151 * Some simple debugging macros that look and behave a lot like their
152 * namesakes in MFC.
153 */
154
155#ifdef _DEBUG
156
157# if defined(_MSC_VER) && (_MSC_VER >= 1000)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100158 // Use the new debugging tools in Visual C++ 4.x
Bram Moolenaar071d4272004-06-13 20:20:40 +0000159# include <crtdbg.h>
160# define ASSERT(f) _ASSERT(f)
161# else
162# include <assert.h>
163# define ASSERT(f) assert(f)
164# endif
165
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166# define TRACE Trace
167# define TRACE0(sz) Trace(_T("%s"), _T(sz))
168# define TRACE1(sz, p1) Trace(_T(sz), p1)
169# define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2)
170# define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3)
171# define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4)
172
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100173// In debug version, writes trace messages to debug stream
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174void __cdecl
175Trace(char *pszFormat, ...);
176
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100177#else // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100179 // These macros should all compile away to nothing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180# define ASSERT(f) ((void)0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000181# define TRACE 1 ? (void)0 : printf
182# define TRACE0(sz)
183# define TRACE1(sz, p1)
184# define TRACE2(sz, p1, p2)
185# define TRACE3(sz, p1, p2, p3)
186# define TRACE4(sz, p1, p2, p3, p4)
187
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100188#endif // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000189
190
191#define ASSERT_POINTER(p, type) \
192 ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
193
194#define ASSERT_NULL_OR_POINTER(p, type) \
195 ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
196
Bram Moolenaar7c23d1d2017-02-01 13:14:16 +0100197#ifndef HAVE_SETENV
198# define HAVE_SETENV
199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200#define mch_getenv(x) (char_u *)getenv((char *)(x))
Bram Moolenaareae1b912019-05-09 15:12:55 +0200201#define vim_mkdir(x, y) mch_mkdir(x)