blob: d052bb5d2744b1d7eb691a9b2a7fbcb3818abc13 [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/*
Bram Moolenaar24e9b6f2020-03-19 16:28:44 +010080 * Generic Vim #define for Mac
Bram Moolenaar071d4272004-06-13 20:20:40 +000081 */
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 Moolenaar071d4272004-06-13 20:20:40 +000089
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010090#define USE_FNAME_CASE // make ":e os_Mac.c" open the file in its
91 // original case, as "os_mac.c"
Bram Moolenaar071d4272004-06-13 20:20:40 +000092#define BINARY_FILE_IO
93#define EOL_DEFAULT EOL_MAC
Bram Moolenaar071d4272004-06-13 20:20:40 +000094#define HAVE_AVAIL_MEM
95
96#ifndef HAVE_CONFIG_H
Bram Moolenaar071d4272004-06-13 20:20:40 +000097# define HAVE_STRING_H
98# define HAVE_STRCSPN
99# define HAVE_MEMSET
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100100# define USE_TMPNAM // use tmpnam() instead of mktemp()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101# define HAVE_FCNTL_H
102# define HAVE_QSORT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100103# define HAVE_ST_MODE // have stat.st_mode
Bram Moolenaara7241f52008-06-24 20:39:31 +0000104# define HAVE_MATH_H
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105
106# if defined(__DATE__) && defined(__TIME__)
107# define HAVE_DATE_TIME
108# endif
109# define HAVE_STRFTIME
110#endif
111
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112/*
113 * Names for the EXRC, HELP and temporary files.
114 * Some of these may have been defined in the makefile.
115 */
116
117#ifndef SYS_VIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200118# define SYS_VIMRC_FILE "$VIM/vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119#endif
120#ifndef SYS_GVIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200121# define SYS_GVIMRC_FILE "$VIM/gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122#endif
123#ifndef SYS_MENU_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200124# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125#endif
126#ifndef SYS_OPTWIN_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200127# define SYS_OPTWIN_FILE "$VIMRUNTIME/optwin.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128#endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200129#ifndef VIM_DEFAULTS_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200130# define VIM_DEFAULTS_FILE "$VIMRUNTIME/defaults.vim"
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132#ifndef EVIM_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200133# define EVIM_FILE "$VIMRUNTIME/evim.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134#endif
135
136#ifdef FEAT_GUI
137# ifndef USR_GVIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200138# define USR_GVIMRC_FILE "~/.gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139# endif
140# ifndef GVIMRC_FILE
141# define GVIMRC_FILE "_gvimrc"
142# endif
143#endif
144#ifndef USR_VIMRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200145# define USR_VIMRC_FILE "~/.vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146#endif
147
148#ifndef USR_EXRC_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200149# define USR_EXRC_FILE "~/.exrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150#endif
151
152#ifndef VIMRC_FILE
153# define VIMRC_FILE "_vimrc"
154#endif
155
156#ifndef EXRC_FILE
157# define EXRC_FILE "_exrc"
158#endif
159
160#ifndef DFLT_HELPFILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200161# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162#endif
163
164#ifndef FILETYPE_FILE
165# define FILETYPE_FILE "filetype.vim"
166#endif
167#ifndef FTPLUGIN_FILE
168# define FTPLUGIN_FILE "ftplugin.vim"
169#endif
170#ifndef INDENT_FILE
171# define INDENT_FILE "indent.vim"
172#endif
173#ifndef FTOFF_FILE
174# define FTOFF_FILE "ftoff.vim"
175#endif
176#ifndef FTPLUGOF_FILE
177# define FTPLUGOF_FILE "ftplugof.vim"
178#endif
179#ifndef INDOFF_FILE
180# define INDOFF_FILE "indoff.vim"
181#endif
182
183#ifndef SYNTAX_FNAME
Bram Moolenaard0573012017-10-28 21:11:06 +0200184# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185#endif
186
187#ifdef FEAT_VIMINFO
188# ifndef VIMINFO_FILE
Bram Moolenaard0573012017-10-28 21:11:06 +0200189# define VIMINFO_FILE "~/.viminfo"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190# endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100191#endif // FEAT_VIMINFO
Bram Moolenaar071d4272004-06-13 20:20:40 +0000192
193#ifndef DFLT_BDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100194# define DFLT_BDIR "." // default for 'backupdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195#endif
196
197#ifndef DFLT_DIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100198# define DFLT_DIR "." // default for 'directory'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000199#endif
200
201#ifndef DFLT_VDIR
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100202# define DFLT_VDIR "$VIM/vimfiles/view" // default for 'viewdir'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203#endif
204
205#define DFLT_ERRORFILE "errors.err"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000206
207#ifndef DFLT_RUNTIMEPATH
Bram Moolenaard0573012017-10-28 21:11:06 +0200208# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209#endif
Bram Moolenaar07268702018-03-01 21:57:32 +0100210#ifndef CLEAN_RUNTIMEPATH
211# define CLEAN_RUNTIMEPATH "$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after"
212#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213
214/*
215 * Macintosh has plenty of memory, use large buffers
216 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100217#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100220# define DFLT_MAXMEM 512 // use up to 512 Kbyte for buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221#endif
222
223#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100224# define DFLT_MAXMEMTOT 2048 // use up to 2048 Kbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225#endif
226
227#define WILDCHAR_LIST "*?[{`$"
228
229/**************/
230#define mch_rename(src, dst) rename(src, dst)
231#define mch_remove(x) unlink((char *)(x))
232#ifndef mch_getenv
Bram Moolenaard0573012017-10-28 21:11:06 +0200233# if defined(__APPLE_CC__)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235# define mch_setenv(name, val, x) setenv(name, val, x)
236# else
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100237 // vim_getenv() is in pty.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238# define USE_VIMPTY_GETENV
239# define mch_getenv(x) vimpty_getenv(x)
240# define mch_setenv(name, val, x) setenv(name, val, x)
241# endif
242#endif
243
244#ifndef HAVE_CONFIG_H
245# ifdef __APPLE_CC__
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100246// Assuming compiling for MacOS X
247// Trying to take advantage of the prebinding
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248# define HAVE_TGETENT
249# define OSPEED_EXTERN
250# define UP_BC_PC_EXTERN
251# endif
252#endif
253
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100254// Some "prep work" definition to be able to compile the MacOS X
255// version with os_unix.c instead of os_mac.c. Based on the result
256// of ./configure for console MacOS X.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000257
Bram Moolenaard0573012017-10-28 21:11:06 +0200258#ifndef SIGPROTOARG
259# define SIGPROTOARG (int)
260#endif
261#ifndef SIGDEFARG
262# define SIGDEFARG(s) (s) int s UNUSED;
263#endif
264#ifndef SIGDUMMYARG
265# define SIGDUMMYARG 0
266#endif
267#undef HAVE_AVAIL_MEM
268#ifndef HAVE_CONFIG_H
269# define RETSIGTYPE void
270# define SIGRETURN return
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100271//# define USE_SYSTEM // Output ship do debugger :(, but not compile
272# define HAVE_SYS_WAIT_H 1 // Attempt
Bram Moolenaard0573012017-10-28 21:11:06 +0200273# define HAVE_TERMIOS_H 1
274# define SYS_SELECT_WITH_SYS_TIME 1
275# define HAVE_SELECT 1
276# define HAVE_SYS_SELECT_H 1
277# define HAVE_PUTENV
278# define HAVE_SETENV
279# define HAVE_RENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280#endif
281
Bram Moolenaard0573012017-10-28 21:11:06 +0200282#if !defined(HAVE_CONFIG_H)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283# define HAVE_PUTENV
284#endif
285
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100286// A Mac constant causing big problem to syntax highlighting
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287#define UNKNOWN_CREATOR '\?\?\?\?'