blob: a7b1dba06a4ead50b8be4e52ca2c4d41c0e28bd5 [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>
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010031// Get stat.h or something similar. Comment: How come some OS get in 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
148#ifndef FILETYPE_FILE
149# define FILETYPE_FILE "filetype.vim"
150#endif
151#ifndef FTPLUGIN_FILE
152# define FTPLUGIN_FILE "ftplugin.vim"
153#endif
154#ifndef INDENT_FILE
155# define INDENT_FILE "indent.vim"
156#endif
157#ifndef FTOFF_FILE
158# define FTOFF_FILE "ftoff.vim"
159#endif
160#ifndef FTPLUGOF_FILE
161# define FTPLUGOF_FILE "ftplugof.vim"
162#endif
163#ifndef INDOFF_FILE
164# define INDOFF_FILE "indoff.vim"
165#endif
166
167#ifndef SYNTAX_FNAME
Bram Moolenaard0573012017-10-28 21:11:06 +0200168# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000169#endif
170
171#ifdef FEAT_VIMINFO
172# ifndef VIMINFO_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200173# define VIMINFO_FILE "~/.viminfo"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174# endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100175#endif // FEAT_VIMINFO
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176
177#ifndef DFLT_BDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100178# define DFLT_BDIR "." // default for 'backupdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179#endif
180
181#ifndef DFLT_DIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100182# define DFLT_DIR "." // default for 'directory'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000183#endif
184
185#ifndef DFLT_VDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100186# define DFLT_VDIR "$VIM/vimfiles/view" // default for 'viewdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187#endif
188
189#define DFLT_ERRORFILE "errors.err"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000190
191#ifndef DFLT_RUNTIMEPATH
Bram Moolenaard0573012017-10-28 21:11:06 +0200192# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193#endif
Bram Moolenaar07268702018-03-01 21:57:32 +0100194#ifndef CLEAN_RUNTIMEPATH
195# define CLEAN_RUNTIMEPATH "$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after"
196#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197
198/*
199 * Macintosh has plenty of memory, use large buffers
200 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100201#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100204# define DFLT_MAXMEM 512 // use up to 512 Kbyte for buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000205#endif
206
207#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100208# define DFLT_MAXMEMTOT 2048 // use up to 2048 Kbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209#endif
210
211#define WILDCHAR_LIST "*?[{`$"
212
213/**************/
214#define mch_rename(src, dst) rename(src, dst)
215#define mch_remove(x) unlink((char *)(x))
216#ifndef mch_getenv
Bram Moolenaard0573012017-10-28 21:11:06 +0200217# if defined(__APPLE_CC__)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219# define mch_setenv(name, val, x) setenv(name, val, x)
220# else
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100221 // vim_getenv() is in pty.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222# define USE_VIMPTY_GETENV
223# define mch_getenv(x) vimpty_getenv(x)
224# define mch_setenv(name, val, x) setenv(name, val, x)
225# endif
226#endif
227
228#ifndef HAVE_CONFIG_H
229# ifdef __APPLE_CC__
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100230// Assuming compiling for MacOS X
231// Trying to take advantage of the prebinding
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232# define HAVE_TGETENT
233# define OSPEED_EXTERN
234# define UP_BC_PC_EXTERN
235# endif
236#endif
237
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100238// Some "prep work" definition to be able to compile the MacOS X
239// version with os_unix.c instead of os_mac.c. Based on the result
240// of ./configure for console MacOS X.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241
Bram Moolenaard0573012017-10-28 21:11:06 +0200242#ifndef SIGPROTOARG
243# define SIGPROTOARG (int)
244#endif
245#ifndef SIGDEFARG
246# define SIGDEFARG(s) (s) int s UNUSED;
247#endif
248#ifndef SIGDUMMYARG
249# define SIGDUMMYARG 0
250#endif
251#undef HAVE_AVAIL_MEM
252#ifndef HAVE_CONFIG_H
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100253//# define USE_SYSTEM // Output ship do debugger :(, but not compile
254# define HAVE_SYS_WAIT_H 1 // Attempt
Bram Moolenaard0573012017-10-28 21:11:06 +0200255# define HAVE_TERMIOS_H 1
256# define SYS_SELECT_WITH_SYS_TIME 1
257# define HAVE_SELECT 1
258# define HAVE_SYS_SELECT_H 1
259# define HAVE_PUTENV
260# define HAVE_SETENV
261# define HAVE_RENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262#endif
263
Bram Moolenaard0573012017-10-28 21:11:06 +0200264#if !defined(HAVE_CONFIG_H)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265# define HAVE_PUTENV
266#endif
267
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100268// A Mac constant causing big problem to syntax highlighting
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269#define UNKNOWN_CREATOR '\?\?\?\?'
Paul Ollis65745772022-06-05 16:55:54 +0100270
271#ifdef FEAT_RELTIME
272
273# include <dispatch/dispatch.h>
274
ichizokf5465ff2022-06-09 14:50:10 +0100275# ifndef MAC_OS_X_VERSION_10_12
Paul Ollis65745772022-06-05 16:55:54 +0100276typedef int clockid_t;
277# endif
278# ifndef CLOCK_REALTIME
ichizokf5465ff2022-06-09 14:50:10 +0100279# define CLOCK_REALTIME 0
Paul Ollis65745772022-06-05 16:55:54 +0100280# endif
281# ifndef CLOCK_MONOTONIC
ichizokf5465ff2022-06-09 14:50:10 +0100282# define CLOCK_MONOTONIC 1
Paul Ollis65745772022-06-05 16:55:54 +0100283# endif
284
285struct itimerspec
286{
287 struct timespec it_interval; // timer period
288 struct timespec it_value; // initial expiration
289};
290
291struct sigevent;
292
293struct macos_timer
294{
295 dispatch_queue_t tim_queue;
296 dispatch_source_t tim_timer;
297 void (*tim_func)(union sigval);
298 void *tim_arg;
299};
300
301typedef struct macos_timer *timer_t;
302
303extern int timer_create(
304 clockid_t clockid,
305 struct sigevent *sevp,
306 timer_t *timerid);
307
308extern int timer_delete(timer_t timerid);
309
310extern int timer_settime(
311 timer_t timerid, int flags,
312 const struct itimerspec *new_value,
313 struct itimerspec *unused);
314
315#endif // FEAT_RELTIME
316
317#endif // OS_MAC__H