blob: c7164de76952181d0adba0de1f6a14d63868fff0 [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
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01009// Before Including the MacOS specific files,
10// lets set the OPAQUE_TOOLBOX_STRUCTS to 0 so we
11// can access the internal structures.
12// (Until fully Carbon compliant)
13// TODO: Can we remove this? (Dany)
Bram Moolenaar071d4272004-06-13 20:20:40 +000014#if 0
15# define OPAQUE_TOOLBOX_STRUCTS 0
16#endif
17
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010018// Include MAC_OS_X_VERSION_* macros
Bram Moolenaar2b1b53f2013-11-02 21:04:38 +010019#ifdef HAVE_AVAILABILITYMACROS_H
20# include <AvailabilityMacros.h>
21#endif
22
Bram Moolenaar071d4272004-06-13 20:20:40 +000023/*
24 * Macintosh machine-dependent things.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000025 *
26 * Include the Mac header files, unless also compiling with X11 (the header
27 * files have many conflicts).
Bram Moolenaar071d4272004-06-13 20:20:40 +000028 */
Bram Moolenaar164fca32010-07-14 13:58:07 +020029#ifdef FEAT_GUI_MAC
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010030# include <Quickdraw.h> // Apple calls it QuickDraw.h...
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000031# include <ToolUtils.h>
32# include <LowMem.h>
33# include <Scrap.h>
34# include <Sound.h>
35# include <TextUtils.h>
36# include <Memory.h>
37# include <OSUtils.h>
38# include <Files.h>
Bram Moolenaar264b74f2019-01-24 17:18:42 +010039# include <Script.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000040#endif
41
42/*
43 * Unix interface
44 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010045#if defined(__APPLE_CC__) // for Project Builder and ...
Bram Moolenaar071d4272004-06-13 20:20:40 +000046# include <unistd.h>
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010047// Get stat.h or something similar. Comment: How come some OS get in in vim.h
Bram Moolenaar071d4272004-06-13 20:20:40 +000048# include <sys/stat.h>
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010049// && defined(HAVE_CURSE)
50// The curses.h from MacOS X provides by default some BACKWARD compatibility
51// definition which can cause us problem later on. So we undefine a few of them.
Bram Moolenaar071d4272004-06-13 20:20:40 +000052# include <curses.h>
53# undef reg
54# undef ospeed
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010055// 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 +000056# undef OK
57#endif
58#include <signal.h>
59#include <errno.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <time.h>
Bram Moolenaar0fd92892006-03-09 22:27:48 +000063#include <dirent.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000064
65/*
66 * MacOS specific #define
67 */
68
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010069// This will go away when CMD_KEY fully tested
Bram Moolenaar071d4272004-06-13 20:20:40 +000070#define USE_CMD_KEY
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010071// On MacOS X use the / not the :
72// TODO: Should file such as ~/.vimrc reside instead in
73// ~/Library/Vim or ~/Library/Preferences/org.vim.vim/ ? (Dany)
74// When compiled under MacOS X (including CARBON version)
75// we use the Unix File path style. Also when UNIX is defined.
Bram Moolenaard0573012017-10-28 21:11:06 +020076#define USE_UNIXFILENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +000077
78
79/*
80 * Generic Vim #define
81 */
82
83#define FEAT_SOURCE_FFS
84#define FEAT_SOURCE_FF_MAC
85
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010086#define USE_EXE_NAME // to find $VIM
87#define CASE_INSENSITIVE_FILENAME // ignore case when comparing file names
Bram Moolenaar071d4272004-06-13 20:20:40 +000088#define SPACE_IN_FILENAME
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010089#define BREAKCHECK_SKIP 32 // call mch_breakcheck() each time, it's
90 // quite fast. Did I forgot to update the
91 // comment
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010093#define USE_FNAME_CASE // make ":e os_Mac.c" open the file in its
94 // original case, as "os_mac.c"
Bram Moolenaar071d4272004-06-13 20:20:40 +000095#define BINARY_FILE_IO
96#define EOL_DEFAULT EOL_MAC
Bram Moolenaar071d4272004-06-13 20:20:40 +000097#define HAVE_AVAIL_MEM
98
99#ifndef HAVE_CONFIG_H
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100# define HAVE_STRING_H
101# define HAVE_STRCSPN
102# define HAVE_MEMSET
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100103# define USE_TMPNAM // use tmpnam() instead of mktemp()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104# define HAVE_FCNTL_H
105# define HAVE_QSORT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100106# define HAVE_ST_MODE // have stat.st_mode
Bram Moolenaara7241f52008-06-24 20:39:31 +0000107# define HAVE_MATH_H
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
109# if defined(__DATE__) && defined(__TIME__)
110# define HAVE_DATE_TIME
111# endif
112# define HAVE_STRFTIME
113#endif
114
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115/*
116 * Names for the EXRC, HELP and temporary files.
117 * Some of these may have been defined in the makefile.
118 */
119
120#ifndef SYS_VIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200121# define SYS_VIMRC_FILE "$VIM/vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122#endif
123#ifndef SYS_GVIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200124# define SYS_GVIMRC_FILE "$VIM/gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125#endif
126#ifndef SYS_MENU_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200127# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128#endif
129#ifndef SYS_OPTWIN_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200130# define SYS_OPTWIN_FILE "$VIMRUNTIME/optwin.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131#endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200132#ifndef VIM_DEFAULTS_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200133# define VIM_DEFAULTS_FILE "$VIMRUNTIME/defaults.vim"
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135#ifndef EVIM_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200136# define EVIM_FILE "$VIMRUNTIME/evim.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137#endif
138
139#ifdef FEAT_GUI
140# ifndef USR_GVIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200141# define USR_GVIMRC_FILE "~/.gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142# endif
143# ifndef GVIMRC_FILE
144# define GVIMRC_FILE "_gvimrc"
145# endif
146#endif
147#ifndef USR_VIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200148# define USR_VIMRC_FILE "~/.vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149#endif
150
151#ifndef USR_EXRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200152# define USR_EXRC_FILE "~/.exrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000153#endif
154
155#ifndef VIMRC_FILE
156# define VIMRC_FILE "_vimrc"
157#endif
158
159#ifndef EXRC_FILE
160# define EXRC_FILE "_exrc"
161#endif
162
163#ifndef DFLT_HELPFILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200164# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165#endif
166
167#ifndef FILETYPE_FILE
168# define FILETYPE_FILE "filetype.vim"
169#endif
170#ifndef FTPLUGIN_FILE
171# define FTPLUGIN_FILE "ftplugin.vim"
172#endif
173#ifndef INDENT_FILE
174# define INDENT_FILE "indent.vim"
175#endif
176#ifndef FTOFF_FILE
177# define FTOFF_FILE "ftoff.vim"
178#endif
179#ifndef FTPLUGOF_FILE
180# define FTPLUGOF_FILE "ftplugof.vim"
181#endif
182#ifndef INDOFF_FILE
183# define INDOFF_FILE "indoff.vim"
184#endif
185
186#ifndef SYNTAX_FNAME
Bram Moolenaard0573012017-10-28 21:11:06 +0200187# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188#endif
189
190#ifdef FEAT_VIMINFO
191# ifndef VIMINFO_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200192# define VIMINFO_FILE "~/.viminfo"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193# endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100194#endif // FEAT_VIMINFO
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195
196#ifndef DFLT_BDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100197# define DFLT_BDIR "." // default for 'backupdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198#endif
199
200#ifndef DFLT_DIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100201# define DFLT_DIR "." // default for 'directory'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202#endif
203
204#ifndef DFLT_VDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100205# define DFLT_VDIR "$VIM/vimfiles/view" // default for 'viewdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000206#endif
207
208#define DFLT_ERRORFILE "errors.err"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000209
210#ifndef DFLT_RUNTIMEPATH
Bram Moolenaard0573012017-10-28 21:11:06 +0200211# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000212#endif
Bram Moolenaar07268702018-03-01 21:57:32 +0100213#ifndef CLEAN_RUNTIMEPATH
214# define CLEAN_RUNTIMEPATH "$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after"
215#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216
217/*
218 * Macintosh has plenty of memory, use large buffers
219 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100220#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100223# define DFLT_MAXMEM 512 // use up to 512 Kbyte for buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224#endif
225
226#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100227# define DFLT_MAXMEMTOT 2048 // use up to 2048 Kbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228#endif
229
230#define WILDCHAR_LIST "*?[{`$"
231
232/**************/
233#define mch_rename(src, dst) rename(src, dst)
234#define mch_remove(x) unlink((char *)(x))
235#ifndef mch_getenv
Bram Moolenaard0573012017-10-28 21:11:06 +0200236# if defined(__APPLE_CC__)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238# define mch_setenv(name, val, x) setenv(name, val, x)
239# else
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100240 // vim_getenv() is in pty.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241# define USE_VIMPTY_GETENV
242# define mch_getenv(x) vimpty_getenv(x)
243# define mch_setenv(name, val, x) setenv(name, val, x)
244# endif
245#endif
246
247#ifndef HAVE_CONFIG_H
248# ifdef __APPLE_CC__
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100249// Assuming compiling for MacOS X
250// Trying to take advantage of the prebinding
Bram Moolenaar071d4272004-06-13 20:20:40 +0000251# define HAVE_TGETENT
252# define OSPEED_EXTERN
253# define UP_BC_PC_EXTERN
254# endif
255#endif
256
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100257// Some "prep work" definition to be able to compile the MacOS X
258// version with os_unix.c instead of os_mac.c. Based on the result
259// of ./configure for console MacOS X.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260
Bram Moolenaard0573012017-10-28 21:11:06 +0200261#ifndef SIGPROTOARG
262# define SIGPROTOARG (int)
263#endif
264#ifndef SIGDEFARG
265# define SIGDEFARG(s) (s) int s UNUSED;
266#endif
267#ifndef SIGDUMMYARG
268# define SIGDUMMYARG 0
269#endif
270#undef HAVE_AVAIL_MEM
271#ifndef HAVE_CONFIG_H
272# define RETSIGTYPE void
273# define SIGRETURN return
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100274//# define USE_SYSTEM // Output ship do debugger :(, but not compile
275# define HAVE_SYS_WAIT_H 1 // Attempt
Bram Moolenaard0573012017-10-28 21:11:06 +0200276# define HAVE_TERMIOS_H 1
277# define SYS_SELECT_WITH_SYS_TIME 1
278# define HAVE_SELECT 1
279# define HAVE_SYS_SELECT_H 1
280# define HAVE_PUTENV
281# define HAVE_SETENV
282# define HAVE_RENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283#endif
284
Bram Moolenaard0573012017-10-28 21:11:06 +0200285#if !defined(HAVE_CONFIG_H)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286# define HAVE_PUTENV
287#endif
288
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100289// A Mac constant causing big problem to syntax highlighting
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290#define UNKNOWN_CREATOR '\?\?\?\?'