blob: a0eda822674ee1f76466c171ac3679a43c77333e [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/* 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)
14 */
15#if 0
16# define OPAQUE_TOOLBOX_STRUCTS 0
17#endif
18
Bram Moolenaar2b1b53f2013-11-02 21:04:38 +010019/* Include MAC_OS_X_VERSION_* macros */
20#ifdef HAVE_AVAILABILITYMACROS_H
21# include <AvailabilityMacros.h>
22#endif
23
Bram Moolenaar071d4272004-06-13 20:20:40 +000024/*
25 * Macintosh machine-dependent things.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000026 *
27 * Include the Mac header files, unless also compiling with X11 (the header
28 * files have many conflicts).
Bram Moolenaar071d4272004-06-13 20:20:40 +000029 */
Bram Moolenaar164fca32010-07-14 13:58:07 +020030#ifdef FEAT_GUI_MAC
Bram Moolenaar4a85b412006-04-23 22:40:29 +000031# include <Quickdraw.h> /* Apple calls it QuickDraw.h... */
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000032# include <ToolUtils.h>
33# include <LowMem.h>
34# include <Scrap.h>
35# include <Sound.h>
36# include <TextUtils.h>
37# include <Memory.h>
38# include <OSUtils.h>
39# include <Files.h>
40# ifdef FEAT_MBYTE
41# include <Script.h>
42# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#endif
44
45/*
46 * Unix interface
47 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000048#if defined(__APPLE_CC__) /* for Project Builder and ... */
49# include <unistd.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000050/* Get stat.h or something similar. Comment: How come some OS get in in vim.h */
Bram Moolenaar071d4272004-06-13 20:20:40 +000051# include <sys/stat.h>
Bram Moolenaar0fd92892006-03-09 22:27:48 +000052/* && defined(HAVE_CURSE) */
Bram Moolenaar84a05ac2013-05-06 04:24:17 +020053/* The curses.h from MacOS X provides by default some BACKWARD compatibility
Bram Moolenaar071d4272004-06-13 20:20:40 +000054 * definition which can cause us problem later on. So we undefine a few of them. */
55# include <curses.h>
56# undef reg
57# undef ospeed
58/* OK defined to 0 in MacOS X 10.2 curses! Remove it, we define it to be 1. */
59# undef OK
60#endif
61#include <signal.h>
62#include <errno.h>
63#include <stdio.h>
64#include <stdlib.h>
65#include <time.h>
Bram Moolenaar0fd92892006-03-09 22:27:48 +000066#include <dirent.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
68/*
69 * MacOS specific #define
70 */
71
72/* This will go away when CMD_KEY fully tested */
73#define USE_CMD_KEY
74/* On MacOS X use the / not the : */
75/* TODO: Should file such as ~/.vimrc reside instead in
76 * ~/Library/Vim or ~/Library/Preferences/org.vim.vim/ ? (Dany)
77 */
78/* When compiled under MacOS X (including CARBON version)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000079 * we use the Unix File path style. Also when UNIX is defined. */
Bram Moolenaar071d4272004-06-13 20:20:40 +000080# define USE_UNIXFILENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +000081
82
83/*
84 * Generic Vim #define
85 */
86
87#define FEAT_SOURCE_FFS
88#define FEAT_SOURCE_FF_MAC
89
90#define USE_EXE_NAME /* to find $VIM */
91#define CASE_INSENSITIVE_FILENAME /* ignore case when comparing file names */
92#define SPACE_IN_FILENAME
93#define BREAKCHECK_SKIP 32 /* call mch_breakcheck() each time, it's
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000094 quite fast. Did I forgot to update the
95 comment */
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
97
Bram Moolenaar43abc522005-12-10 20:15:02 +000098#define USE_FNAME_CASE /* make ":e os_Mac.c" open the file in its
99 original case, as "os_mac.c" */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100#define BINARY_FILE_IO
101#define EOL_DEFAULT EOL_MAC
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000102#ifndef MACOS_X_UNIX /* I hope that switching these two lines */
103# define USE_CR /* does what I want -- BNF */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104# define NO_CONSOLE /* don't include console mode */
105#endif
106#define HAVE_AVAIL_MEM
107
108#ifndef HAVE_CONFIG_H
109/* #define SYNC_DUP_CLOSE sync() a file with dup() and close() */
110# define HAVE_STRING_H
111# define HAVE_STRCSPN
112# define HAVE_MEMSET
113# define USE_TMPNAM /* use tmpnam() instead of mktemp() */
114# define HAVE_FCNTL_H
115# define HAVE_QSORT
116# define HAVE_ST_MODE /* have stat.st_mode */
Bram Moolenaara7241f52008-06-24 20:39:31 +0000117# define HAVE_MATH_H
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118
119# if defined(__DATE__) && defined(__TIME__)
120# define HAVE_DATE_TIME
121# endif
122# define HAVE_STRFTIME
123#endif
124
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125/*
126 * Names for the EXRC, HELP and temporary files.
127 * Some of these may have been defined in the makefile.
128 */
129
130#ifndef SYS_VIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131# define SYS_VIMRC_FILE "$VIM/vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132#endif
133#ifndef SYS_GVIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134# define SYS_GVIMRC_FILE "$VIM/gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135#endif
136#ifndef SYS_MENU_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138#endif
139#ifndef SYS_OPTWIN_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140# define SYS_OPTWIN_FILE "$VIMRUNTIME/optwin.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141#endif
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200142#ifndef VIM_DEFAULTS_FILE
143# define VIM_DEFAULTS_FILE "$VIMRUNTIME/defaults.vim"
144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000145#ifndef EVIM_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146# define EVIM_FILE "$VIMRUNTIME/evim.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000147#endif
148
149#ifdef FEAT_GUI
150# ifndef USR_GVIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151# define USR_GVIMRC_FILE "~/.gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152# endif
153# ifndef GVIMRC_FILE
154# define GVIMRC_FILE "_gvimrc"
155# endif
156#endif
157#ifndef USR_VIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000158# define USR_VIMRC_FILE "~/.vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000159#endif
160
161#ifndef USR_EXRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162# define USR_EXRC_FILE "~/.exrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163#endif
164
165#ifndef VIMRC_FILE
166# define VIMRC_FILE "_vimrc"
167#endif
168
169#ifndef EXRC_FILE
170# define EXRC_FILE "_exrc"
171#endif
172
173#ifndef DFLT_HELPFILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175#endif
176
177#ifndef FILETYPE_FILE
178# define FILETYPE_FILE "filetype.vim"
179#endif
180#ifndef FTPLUGIN_FILE
181# define FTPLUGIN_FILE "ftplugin.vim"
182#endif
183#ifndef INDENT_FILE
184# define INDENT_FILE "indent.vim"
185#endif
186#ifndef FTOFF_FILE
187# define FTOFF_FILE "ftoff.vim"
188#endif
189#ifndef FTPLUGOF_FILE
190# define FTPLUGOF_FILE "ftplugof.vim"
191#endif
192#ifndef INDOFF_FILE
193# define INDOFF_FILE "indoff.vim"
194#endif
195
196#ifndef SYNTAX_FNAME
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198#endif
199
200#ifdef FEAT_VIMINFO
201# ifndef VIMINFO_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202# define VIMINFO_FILE "~/.viminfo"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203# endif
204#endif /* FEAT_VIMINFO */
205
206#ifndef DFLT_BDIR
207# define DFLT_BDIR "." /* default for 'backupdir' */
208#endif
209
210#ifndef DFLT_DIR
211# define DFLT_DIR "." /* default for 'directory' */
212#endif
213
214#ifndef DFLT_VDIR
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200215# define DFLT_VDIR "$VIM/vimfiles/view" /* default for 'viewdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216#endif
217
218#define DFLT_ERRORFILE "errors.err"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000219
220#ifndef DFLT_RUNTIMEPATH
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000221# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222#endif
223
224/*
225 * Macintosh has plenty of memory, use large buffers
226 */
227#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
228
Bram Moolenaara7241f52008-06-24 20:39:31 +0000229#if !defined(MACOS_X_UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230# define MAXPATHL 256 /* Limited by the Pascal Strings */
231# define BASENAMELEN (32-5-1) /* length of base of filename */
232#endif
233
234#ifndef DFLT_MAXMEM
235# define DFLT_MAXMEM 512 /* use up to 512 Kbyte for buffer */
236#endif
237
238#ifndef DFLT_MAXMEMTOT
239# define DFLT_MAXMEMTOT 2048 /* use up to 2048 Kbyte for Vim */
240#endif
241
242#define WILDCHAR_LIST "*?[{`$"
243
244/**************/
245#define mch_rename(src, dst) rename(src, dst)
246#define mch_remove(x) unlink((char *)(x))
247#ifndef mch_getenv
248# if defined(__MRC__) || defined(__SC__)
249# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
250# define mch_setenv(name, val, x) setenv((name), (val))
251# elif defined(__APPLE_CC__)
252# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
253/*# define mch_setenv(name, val, x) setenv((name), (val)) */ /* Obsoleted by Dany on Oct 30, 2001 */
254# define mch_setenv(name, val, x) setenv(name, val, x)
255# else
256 /* vim_getenv() is in pty.c */
257# define USE_VIMPTY_GETENV
258# define mch_getenv(x) vimpty_getenv(x)
259# define mch_setenv(name, val, x) setenv(name, val, x)
260# endif
261#endif
262
263#ifndef HAVE_CONFIG_H
264# ifdef __APPLE_CC__
265/* Assuming compiling for MacOS X */
266/* Trying to take advantage of the prebinding */
267# define HAVE_TGETENT
268# define OSPEED_EXTERN
269# define UP_BC_PC_EXTERN
270# endif
271#endif
272
273/* Some "prep work" definition to be able to compile the MacOS X
Bram Moolenaar2b1b53f2013-11-02 21:04:38 +0100274 * version with os_unix.c instead of os_mac.c. Based on the result
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 * of ./configure for console MacOS X.
276 */
277
278#ifdef MACOS_X_UNIX
Bram Moolenaarfab578f2009-06-24 14:41:19 +0000279# ifndef SIGPROTOARG
280# define SIGPROTOARG (int)
281# endif
282# ifndef SIGDEFARG
283# define SIGDEFARG(s) (s) int s UNUSED;
284# endif
285# ifndef SIGDUMMYARG
286# define SIGDUMMYARG 0
287# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288# undef HAVE_AVAIL_MEM
289# ifndef HAVE_CONFIG_H
290# define RETSIGTYPE void
291# define SIGRETURN return
292/*# define USE_SYSTEM */ /* Output ship do debugger :(, but ot compile */
293# define HAVE_SYS_WAIT_H 1 /* Attempt */
294# define HAVE_TERMIOS_H 1
295# define SYS_SELECT_WITH_SYS_TIME 1
296# define HAVE_SELECT 1
297# define HAVE_SYS_SELECT_H 1
298# define HAVE_PUTENV
299# define HAVE_SETENV
300# define HAVE_RENAME
301# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000302#endif
303
304#if defined(MACOS_X) && !defined(HAVE_CONFIG_H)
305# define HAVE_PUTENV
306#endif
307
308/* A Mac constant causing big problem to syntax highlighting */
309#define UNKNOWN_CREATOR '\?\?\?\?'