blob: d22772353b8f33ba8cb930e08d1d510483904e31 [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
K.Takatac351dc12022-01-24 11:24:08 +000050// Access Control List (actually security info).
51#define HAVE_ACL
Bram Moolenaar071d4272004-06-13 20:20:40 +000052
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010053#define USE_FNAME_CASE // adjust case of file names
Bram Moolenaara1cb1d12019-10-17 23:00:07 +020054#if !defined(FEAT_CLIPBOARD)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010055# define FEAT_CLIPBOARD // include clipboard support
Bram Moolenaar071d4272004-06-13 20:20:40 +000056#endif
57#if defined(__DATE__) && defined(__TIME__)
58# define HAVE_DATE_TIME
59#endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010060#ifndef FEAT_GUI_MSWIN // GUI works different
61# define BREAKCHECK_SKIP 1 // call mch_breakcheck() each time, it's fast
Bram Moolenaar071d4272004-06-13 20:20:40 +000062#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
Bram Moolenaaree273972016-01-02 21:11:51 +010064#define HAVE_TOTAL_MEM
65
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010066#define HAVE_PUTENV // at least Bcc 5.2 and MSC have it
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
Bram Moolenaarafde13b2019-04-28 19:46:49 +020068#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
Dominique Pelleaf4a61a2021-12-27 17:21:41 +000069# define NO_CONSOLE // don't include console-only code
Bram Moolenaar071d4272004-06-13 20:20:40 +000070#endif
71
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010072// toupper() is not really broken, but it's very slow. Probably because of
73// using Unicode characters on Windows NT
Bram Moolenaar071d4272004-06-13 20:20:40 +000074#define BROKEN_TOUPPER
75
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010076#define FNAME_ILLEGAL "\"*?><|" // illegal characters in a file name
Bram Moolenaar071d4272004-06-13 20:20:40 +000077
Bram Moolenaar8e82c052018-08-21 19:47:48 +020078#include <signal.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000079#include <stdlib.h>
80#include <time.h>
Bram Moolenaar914703b2010-05-31 21:59:46 +020081#include <sys/types.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000082
83#ifndef STRICT
84# define STRICT
85#endif
86#ifndef COBJMACROS
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010087# define COBJMACROS // For OLE: Enable "friendlier" access to objects
Bram Moolenaar071d4272004-06-13 20:20:40 +000088#endif
Bram Moolenaar82881492012-11-20 16:53:39 +010089#ifndef PROTO
90# include <windows.h>
Bram Moolenaar9d488952013-07-21 17:53:58 +020091# ifndef SM_CXPADDEDBORDER
92# define SM_CXPADDEDBORDER 92
93# endif
Bram Moolenaar82881492012-11-20 16:53:39 +010094#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96/*
97 * Win32 has plenty of memory, use large buffers
98 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010099#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100101// _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option,
102// thus use a larger number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103#define MAXPATHL 1024
104
105#ifndef BASENAMELEN
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100106# define BASENAMELEN (_MAX_PATH - 5) // length of base of file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107#endif
108
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100109#define TEMPNAMELEN _MAX_PATH // length of temp file name path
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110
111#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100112# define DFLT_MAXMEM (2*1024) // use up to 2 Mbyte for a buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113#endif
114
115#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100116# define DFLT_MAXMEMTOT (5*1024) // use up to 5 Mbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117#endif
118
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200119/*
120 * Reparse Point
121 */
122#ifndef FILE_ATTRIBUTE_REPARSE_POINT
123# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
124#endif
125#ifndef IO_REPARSE_TAG_MOUNT_POINT
126# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
127#endif
128#ifndef IO_REPARSE_TAG_SYMLINK
129# define IO_REPARSE_TAG_SYMLINK 0xA000000C
130#endif
131
K.Takatac351dc12022-01-24 11:24:08 +0000132#ifdef _MSC_VER
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100133 // Support for __try / __except. All versions of MSVC are
134 // expected to have this. Any other compilers that support it?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135# define HAVE_TRY_EXCEPT 1
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100136# include <malloc.h> // for _resetstkoflw()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137#endif
138
139/*
140 * Some simple debugging macros that look and behave a lot like their
141 * namesakes in MFC.
142 */
143
144#ifdef _DEBUG
145
K.Takatac351dc12022-01-24 11:24:08 +0000146# include <crtdbg.h>
147# define ASSERT(f) _ASSERT(f)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149# define TRACE Trace
150# define TRACE0(sz) Trace(_T("%s"), _T(sz))
151# define TRACE1(sz, p1) Trace(_T(sz), p1)
152# define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2)
153# define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3)
154# define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4)
155
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100156// In debug version, writes trace messages to debug stream
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157void __cdecl
158Trace(char *pszFormat, ...);
159
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100160#else // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100162 // These macros should all compile away to nothing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163# define ASSERT(f) ((void)0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164# define TRACE 1 ? (void)0 : printf
165# define TRACE0(sz)
166# define TRACE1(sz, p1)
167# define TRACE2(sz, p1, p2)
168# define TRACE3(sz, p1, p2, p3)
169# define TRACE4(sz, p1, p2, p3, p4)
170
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100171#endif // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172
173
174#define ASSERT_POINTER(p, type) \
175 ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
176
177#define ASSERT_NULL_OR_POINTER(p, type) \
178 ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
179
Bram Moolenaar7c23d1d2017-02-01 13:14:16 +0100180#ifndef HAVE_SETENV
181# define HAVE_SETENV
182#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000183#define mch_getenv(x) (char_u *)getenv((char *)(x))
Bram Moolenaareae1b912019-05-09 15:12:55 +0200184#define vim_mkdir(x, y) mch_mkdir(x)