blob: 34fe1f14cbc8614763f886fcd03ace36c6a39e31 [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
Paul Ollis65745772022-06-05 16:55:54 +01009#ifndef OS_MAC__H
10#define OS_MAC__H
11
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010012// Before Including the MacOS specific files,
Dominique Pelleaf4a61a2021-12-27 17:21:41 +000013// let's set the OPAQUE_TOOLBOX_STRUCTS to 0 so we
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010014// can access the internal structures.
15// (Until fully Carbon compliant)
16// TODO: Can we remove this? (Dany)
Bram Moolenaar071d4272004-06-13 20:20:40 +000017#if 0
18# define OPAQUE_TOOLBOX_STRUCTS 0
19#endif
20
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010021// Include MAC_OS_X_VERSION_* macros
Bram Moolenaar2b1b53f2013-11-02 21:04:38 +010022#ifdef HAVE_AVAILABILITYMACROS_H
23# include <AvailabilityMacros.h>
24#endif
25
Bram Moolenaar071d4272004-06-13 20:20:40 +000026/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000027 * Unix interface
28 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010029#if defined(__APPLE_CC__) // for Project Builder and ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000030# include <unistd.h>
Dominique Pelleb49dfd02023-04-14 21:54:25 +010031// Get stat.h or something similar. Comment: How come some OS get in vim.h
Bram Moolenaar071d4272004-06-13 20:20:40 +000032# include <sys/stat.h>
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010033// && defined(HAVE_CURSE)
34// The curses.h from MacOS X provides by default some BACKWARD compatibility
35// definition which can cause us problem later on. So we undefine a few of them.
Bram Moolenaar071d4272004-06-13 20:20:40 +000036# include <curses.h>
37# undef reg
38# undef ospeed
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010039// OK defined to 0 in MacOS X 10.2 curses! Remove it, we define it to be 1.
Bram Moolenaar071d4272004-06-13 20:20:40 +000040# undef OK
41#endif
42#include <signal.h>
43#include <errno.h>
44#include <stdio.h>
45#include <stdlib.h>
46#include <time.h>
Bram Moolenaar0fd92892006-03-09 22:27:48 +000047#include <dirent.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
49/*
50 * MacOS specific #define
51 */
52
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010053// This will go away when CMD_KEY fully tested
Bram Moolenaar071d4272004-06-13 20:20:40 +000054#define USE_CMD_KEY
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010055// On MacOS X use the / not the :
56// TODO: Should file such as ~/.vimrc reside instead in
57// ~/Library/Vim or ~/Library/Preferences/org.vim.vim/ ? (Dany)
58// When compiled under MacOS X (including CARBON version)
59// we use the Unix File path style. Also when UNIX is defined.
Bram Moolenaard0573012017-10-28 21:11:06 +020060#define USE_UNIXFILENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
62
63/*
Bram Moolenaar24e9b6f2020-03-19 16:28:44 +010064 * Generic Vim #define for Mac
Bram Moolenaar071d4272004-06-13 20:20:40 +000065 */
66
67#define FEAT_SOURCE_FFS
68#define FEAT_SOURCE_FF_MAC
69
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010070#define USE_EXE_NAME // to find $VIM
71#define CASE_INSENSITIVE_FILENAME // ignore case when comparing file names
Bram Moolenaar071d4272004-06-13 20:20:40 +000072#define SPACE_IN_FILENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +000073
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010074#define USE_FNAME_CASE // make ":e os_Mac.c" open the file in its
75 // original case, as "os_mac.c"
Bram Moolenaar071d4272004-06-13 20:20:40 +000076#define BINARY_FILE_IO
77#define EOL_DEFAULT EOL_MAC
Bram Moolenaar071d4272004-06-13 20:20:40 +000078#define HAVE_AVAIL_MEM
79
80#ifndef HAVE_CONFIG_H
Bram Moolenaar071d4272004-06-13 20:20:40 +000081# define HAVE_STRING_H
82# define HAVE_STRCSPN
83# define HAVE_MEMSET
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010084# define USE_TMPNAM // use tmpnam() instead of mktemp()
Bram Moolenaar071d4272004-06-13 20:20:40 +000085# define HAVE_FCNTL_H
86# define HAVE_QSORT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010087# define HAVE_ST_MODE // have stat.st_mode
Bram Moolenaara7241f52008-06-24 20:39:31 +000088# define HAVE_MATH_H
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
90# if defined(__DATE__) && defined(__TIME__)
91# define HAVE_DATE_TIME
92# endif
93# define HAVE_STRFTIME
94#endif
95
Bram Moolenaar071d4272004-06-13 20:20:40 +000096/*
97 * Names for the EXRC, HELP and temporary files.
98 * Some of these may have been defined in the makefile.
99 */
100
101#ifndef SYS_VIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200102# define SYS_VIMRC_FILE "$VIM/vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103#endif
104#ifndef SYS_GVIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200105# define SYS_GVIMRC_FILE "$VIM/gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106#endif
107#ifndef SYS_MENU_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200108# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109#endif
110#ifndef SYS_OPTWIN_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200111# define SYS_OPTWIN_FILE "$VIMRUNTIME/optwin.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112#endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200113#ifndef VIM_DEFAULTS_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200114# define VIM_DEFAULTS_FILE "$VIMRUNTIME/defaults.vim"
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200115#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116#ifndef EVIM_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200117# define EVIM_FILE "$VIMRUNTIME/evim.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118#endif
119
120#ifdef FEAT_GUI
121# ifndef USR_GVIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200122# define USR_GVIMRC_FILE "~/.gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123# endif
124# ifndef GVIMRC_FILE
125# define GVIMRC_FILE "_gvimrc"
126# endif
127#endif
128#ifndef USR_VIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200129# define USR_VIMRC_FILE "~/.vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130#endif
131
132#ifndef USR_EXRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200133# define USR_EXRC_FILE "~/.exrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134#endif
135
136#ifndef VIMRC_FILE
137# define VIMRC_FILE "_vimrc"
138#endif
139
140#ifndef EXRC_FILE
141# define EXRC_FILE "_exrc"
142#endif
143
144#ifndef DFLT_HELPFILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200145# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146#endif
147
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148#ifndef SYNTAX_FNAME
Bram Moolenaard0573012017-10-28 21:11:06 +0200149# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150#endif
151
152#ifdef FEAT_VIMINFO
153# ifndef VIMINFO_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200154# define VIMINFO_FILE "~/.viminfo"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155# endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100156#endif // FEAT_VIMINFO
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157
158#ifndef DFLT_BDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100159# define DFLT_BDIR "." // default for 'backupdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160#endif
161
162#ifndef DFLT_DIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100163# define DFLT_DIR "." // default for 'directory'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164#endif
165
166#ifndef DFLT_VDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100167# define DFLT_VDIR "$VIM/vimfiles/view" // default for 'viewdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168#endif
169
170#define DFLT_ERRORFILE "errors.err"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000171
172#ifndef DFLT_RUNTIMEPATH
Bram Moolenaard0573012017-10-28 21:11:06 +0200173# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174#endif
Bram Moolenaar07268702018-03-01 21:57:32 +0100175#ifndef CLEAN_RUNTIMEPATH
176# define CLEAN_RUNTIMEPATH "$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after"
177#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178
179/*
180 * Macintosh has plenty of memory, use large buffers
181 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100182#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000183
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100185# define DFLT_MAXMEM 512 // use up to 512 Kbyte for buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186#endif
187
188#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100189# define DFLT_MAXMEMTOT 2048 // use up to 2048 Kbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190#endif
191
192#define WILDCHAR_LIST "*?[{`$"
193
194/**************/
195#define mch_rename(src, dst) rename(src, dst)
196#define mch_remove(x) unlink((char *)(x))
197#ifndef mch_getenv
Bram Moolenaard0573012017-10-28 21:11:06 +0200198# if defined(__APPLE_CC__)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200# define mch_setenv(name, val, x) setenv(name, val, x)
201# else
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100202 // vim_getenv() is in pty.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203# define USE_VIMPTY_GETENV
204# define mch_getenv(x) vimpty_getenv(x)
205# define mch_setenv(name, val, x) setenv(name, val, x)
206# endif
207#endif
208
209#ifndef HAVE_CONFIG_H
210# ifdef __APPLE_CC__
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100211// Assuming compiling for MacOS X
212// Trying to take advantage of the prebinding
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213# define HAVE_TGETENT
214# define OSPEED_EXTERN
215# define UP_BC_PC_EXTERN
216# endif
217#endif
218
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100219// Some "prep work" definition to be able to compile the MacOS X
220// version with os_unix.c instead of os_mac.c. Based on the result
221// of ./configure for console MacOS X.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222
Bram Moolenaard0573012017-10-28 21:11:06 +0200223#ifndef SIGPROTOARG
224# define SIGPROTOARG (int)
225#endif
226#ifndef SIGDEFARG
227# define SIGDEFARG(s) (s) int s UNUSED;
228#endif
229#ifndef SIGDUMMYARG
230# define SIGDUMMYARG 0
231#endif
232#undef HAVE_AVAIL_MEM
233#ifndef HAVE_CONFIG_H
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100234//# define USE_SYSTEM // Output ship do debugger :(, but not compile
235# define HAVE_SYS_WAIT_H 1 // Attempt
Bram Moolenaard0573012017-10-28 21:11:06 +0200236# define HAVE_TERMIOS_H 1
237# define SYS_SELECT_WITH_SYS_TIME 1
238# define HAVE_SELECT 1
239# define HAVE_SYS_SELECT_H 1
240# define HAVE_PUTENV
241# define HAVE_SETENV
242# define HAVE_RENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +0000243#endif
244
Bram Moolenaard0573012017-10-28 21:11:06 +0200245#if !defined(HAVE_CONFIG_H)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246# define HAVE_PUTENV
247#endif
248
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100249// A Mac constant causing big problem to syntax highlighting
Bram Moolenaar071d4272004-06-13 20:20:40 +0000250#define UNKNOWN_CREATOR '\?\?\?\?'
Paul Ollis65745772022-06-05 16:55:54 +0100251
252#ifdef FEAT_RELTIME
253
254# include <dispatch/dispatch.h>
255
Yee Cheng Chinda776932023-02-28 15:51:23 +0000256# if !defined(MAC_OS_X_VERSION_10_12) \
257 || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12)
Paul Ollis65745772022-06-05 16:55:54 +0100258typedef int clockid_t;
259# endif
260# ifndef CLOCK_REALTIME
ichizokf5465ff2022-06-09 14:50:10 +0100261# define CLOCK_REALTIME 0
Paul Ollis65745772022-06-05 16:55:54 +0100262# endif
263# ifndef CLOCK_MONOTONIC
ichizokf5465ff2022-06-09 14:50:10 +0100264# define CLOCK_MONOTONIC 1
Paul Ollis65745772022-06-05 16:55:54 +0100265# endif
266
267struct itimerspec
268{
269 struct timespec it_interval; // timer period
270 struct timespec it_value; // initial expiration
271};
272
273struct sigevent;
274
275struct macos_timer
276{
277 dispatch_queue_t tim_queue;
278 dispatch_source_t tim_timer;
279 void (*tim_func)(union sigval);
280 void *tim_arg;
281};
282
283typedef struct macos_timer *timer_t;
284
285extern int timer_create(
286 clockid_t clockid,
287 struct sigevent *sevp,
288 timer_t *timerid);
289
290extern int timer_delete(timer_t timerid);
291
292extern int timer_settime(
293 timer_t timerid, int flags,
294 const struct itimerspec *new_value,
295 struct itimerspec *unused);
296
297#endif // FEAT_RELTIME
298
299#endif // OS_MAC__H