blob: 314ec324826e154c1c0d6bd9400471a0de5b1048 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
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
19/*
20 * Macintosh machine-dependent things.
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000021 *
22 * Include the Mac header files, unless also compiling with X11 (the header
23 * files have many conflicts).
Bram Moolenaar071d4272004-06-13 20:20:40 +000024 */
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000025#ifndef FEAT_X11
Bram Moolenaar4a85b412006-04-23 22:40:29 +000026# include <Quickdraw.h> /* Apple calls it QuickDraw.h... */
Bram Moolenaarab79bcb2004-07-18 21:34:53 +000027# include <ToolUtils.h>
28# include <LowMem.h>
29# include <Scrap.h>
30# include <Sound.h>
31# include <TextUtils.h>
32# include <Memory.h>
33# include <OSUtils.h>
34# include <Files.h>
35# ifdef FEAT_MBYTE
36# include <Script.h>
37# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000038#endif
39
40/*
41 * Unix interface
42 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#if defined(__APPLE_CC__) /* for Project Builder and ... */
44# include <unistd.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000045/* Get stat.h or something similar. Comment: How come some OS get in in vim.h */
Bram Moolenaar071d4272004-06-13 20:20:40 +000046# include <sys/stat.h>
Bram Moolenaar0fd92892006-03-09 22:27:48 +000047/* && defined(HAVE_CURSE) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000048/* The curses.h from MacOS X provides by default some BACKWARD compatibilty
49 * definition which can cause us problem later on. So we undefine a few of them. */
50# include <curses.h>
51# undef reg
52# undef ospeed
53/* OK defined to 0 in MacOS X 10.2 curses! Remove it, we define it to be 1. */
54# undef OK
55#endif
56#include <signal.h>
57#include <errno.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <time.h>
Bram Moolenaar0fd92892006-03-09 22:27:48 +000061#include <dirent.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000062
63/*
64 * MacOS specific #define
65 */
66
67/* This will go away when CMD_KEY fully tested */
68#define USE_CMD_KEY
69/* On MacOS X use the / not the : */
70/* TODO: Should file such as ~/.vimrc reside instead in
71 * ~/Library/Vim or ~/Library/Preferences/org.vim.vim/ ? (Dany)
72 */
73/* When compiled under MacOS X (including CARBON version)
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000074 * we use the Unix File path style. Also when UNIX is defined. */
Bram Moolenaar071d4272004-06-13 20:20:40 +000075# define USE_UNIXFILENAME
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
77
78/*
79 * Generic Vim #define
80 */
81
82#define FEAT_SOURCE_FFS
83#define FEAT_SOURCE_FF_MAC
84
85#define USE_EXE_NAME /* to find $VIM */
86#define CASE_INSENSITIVE_FILENAME /* ignore case when comparing file names */
87#define SPACE_IN_FILENAME
88#define BREAKCHECK_SKIP 32 /* call mch_breakcheck() each time, it's
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000089 quite fast. Did I forgot to update the
90 comment */
Bram Moolenaar071d4272004-06-13 20:20:40 +000091
92
Bram Moolenaar43abc522005-12-10 20:15:02 +000093#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 Moolenaar5eb86f92004-07-26 12:53:41 +000097#ifndef MACOS_X_UNIX /* I hope that switching these two lines */
98# define USE_CR /* does what I want -- BNF */
Bram Moolenaar071d4272004-06-13 20:20:40 +000099# define NO_CONSOLE /* don't include console mode */
100#endif
101#define HAVE_AVAIL_MEM
102
103#ifndef HAVE_CONFIG_H
104/* #define SYNC_DUP_CLOSE sync() a file with dup() and close() */
105# define HAVE_STRING_H
106# define HAVE_STRCSPN
107# define HAVE_MEMSET
108# define USE_TMPNAM /* use tmpnam() instead of mktemp() */
109# define HAVE_FCNTL_H
110# define HAVE_QSORT
111# define HAVE_ST_MODE /* have stat.st_mode */
Bram Moolenaara7241f52008-06-24 20:39:31 +0000112# define HAVE_MATH_H
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
114# if defined(__DATE__) && defined(__TIME__)
115# define HAVE_DATE_TIME
116# endif
117# define HAVE_STRFTIME
118#endif
119
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120/*
121 * Names for the EXRC, HELP and temporary files.
122 * Some of these may have been defined in the makefile.
123 */
124
125#ifndef SYS_VIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126# define SYS_VIMRC_FILE "$VIM/vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127#endif
128#ifndef SYS_GVIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129# define SYS_GVIMRC_FILE "$VIM/gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130#endif
131#ifndef SYS_MENU_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133#endif
134#ifndef SYS_OPTWIN_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135# define SYS_OPTWIN_FILE "$VIMRUNTIME/optwin.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136#endif
137#ifndef EVIM_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138# define EVIM_FILE "$VIMRUNTIME/evim.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139#endif
140
141#ifdef FEAT_GUI
142# ifndef USR_GVIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143# define USR_GVIMRC_FILE "~/.gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144# endif
145# ifndef GVIMRC_FILE
146# define GVIMRC_FILE "_gvimrc"
147# endif
148#endif
149#ifndef USR_VIMRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150# define USR_VIMRC_FILE "~/.vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151#endif
152
153#ifndef USR_EXRC_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154# define USR_EXRC_FILE "~/.exrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155#endif
156
157#ifndef VIMRC_FILE
158# define VIMRC_FILE "_vimrc"
159#endif
160
161#ifndef EXRC_FILE
162# define EXRC_FILE "_exrc"
163#endif
164
165#ifndef DFLT_HELPFILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167#endif
168
169#ifndef FILETYPE_FILE
170# define FILETYPE_FILE "filetype.vim"
171#endif
172#ifndef FTPLUGIN_FILE
173# define FTPLUGIN_FILE "ftplugin.vim"
174#endif
175#ifndef INDENT_FILE
176# define INDENT_FILE "indent.vim"
177#endif
178#ifndef FTOFF_FILE
179# define FTOFF_FILE "ftoff.vim"
180#endif
181#ifndef FTPLUGOF_FILE
182# define FTPLUGOF_FILE "ftplugof.vim"
183#endif
184#ifndef INDOFF_FILE
185# define INDOFF_FILE "indoff.vim"
186#endif
187
188#ifndef SYNTAX_FNAME
Bram Moolenaar071d4272004-06-13 20:20:40 +0000189# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190#endif
191
192#ifdef FEAT_VIMINFO
193# ifndef VIMINFO_FILE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194# define VIMINFO_FILE "~/.viminfo"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195# endif
196#endif /* FEAT_VIMINFO */
197
198#ifndef DFLT_BDIR
199# define DFLT_BDIR "." /* default for 'backupdir' */
200#endif
201
202#ifndef DFLT_DIR
203# define DFLT_DIR "." /* default for 'directory' */
204#endif
205
206#ifndef DFLT_VDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207# define DFLT_VDIR "$VIM/vimfiles/view" /* default for 'viewdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000208#endif
209
210#define DFLT_ERRORFILE "errors.err"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000211
212#ifndef DFLT_RUNTIMEPATH
Bram Moolenaarab79bcb2004-07-18 21:34:53 +0000213# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214#endif
215
216/*
217 * Macintosh has plenty of memory, use large buffers
218 */
219#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
220
Bram Moolenaara7241f52008-06-24 20:39:31 +0000221#if !defined(MACOS_X_UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222# define MAXPATHL 256 /* Limited by the Pascal Strings */
223# define BASENAMELEN (32-5-1) /* length of base of filename */
224#endif
225
226#ifndef DFLT_MAXMEM
227# define DFLT_MAXMEM 512 /* use up to 512 Kbyte for buffer */
228#endif
229
230#ifndef DFLT_MAXMEMTOT
231# define DFLT_MAXMEMTOT 2048 /* use up to 2048 Kbyte for Vim */
232#endif
233
234#define WILDCHAR_LIST "*?[{`$"
235
236/**************/
237#define mch_rename(src, dst) rename(src, dst)
238#define mch_remove(x) unlink((char *)(x))
239#ifndef mch_getenv
240# if defined(__MRC__) || defined(__SC__)
241# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
242# define mch_setenv(name, val, x) setenv((name), (val))
243# elif defined(__APPLE_CC__)
244# define mch_getenv(name) ((char_u *)getenv((char *)(name)))
245/*# define mch_setenv(name, val, x) setenv((name), (val)) */ /* Obsoleted by Dany on Oct 30, 2001 */
246# define mch_setenv(name, val, x) setenv(name, val, x)
247# else
248 /* vim_getenv() is in pty.c */
249# define USE_VIMPTY_GETENV
250# define mch_getenv(x) vimpty_getenv(x)
251# define mch_setenv(name, val, x) setenv(name, val, x)
252# endif
253#endif
254
255#ifndef HAVE_CONFIG_H
256# ifdef __APPLE_CC__
257/* Assuming compiling for MacOS X */
258/* Trying to take advantage of the prebinding */
259# define HAVE_TGETENT
260# define OSPEED_EXTERN
261# define UP_BC_PC_EXTERN
262# endif
263#endif
264
265/* Some "prep work" definition to be able to compile the MacOS X
266 * version with os_unix.x instead of os_mac.c. Based on the result
267 * of ./configure for console MacOS X.
268 */
269
270#ifdef MACOS_X_UNIX
Bram Moolenaarfab578f2009-06-24 14:41:19 +0000271# ifndef SIGPROTOARG
272# define SIGPROTOARG (int)
273# endif
274# ifndef SIGDEFARG
275# define SIGDEFARG(s) (s) int s UNUSED;
276# endif
277# ifndef SIGDUMMYARG
278# define SIGDUMMYARG 0
279# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280# undef HAVE_AVAIL_MEM
281# ifndef HAVE_CONFIG_H
282# define RETSIGTYPE void
283# define SIGRETURN return
284/*# define USE_SYSTEM */ /* Output ship do debugger :(, but ot compile */
285# define HAVE_SYS_WAIT_H 1 /* Attempt */
286# define HAVE_TERMIOS_H 1
287# define SYS_SELECT_WITH_SYS_TIME 1
288# define HAVE_SELECT 1
289# define HAVE_SYS_SELECT_H 1
290# define HAVE_PUTENV
291# define HAVE_SETENV
292# define HAVE_RENAME
293# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000294#endif
295
296#if defined(MACOS_X) && !defined(HAVE_CONFIG_H)
297# define HAVE_PUTENV
298#endif
299
300/* A Mac constant causing big problem to syntax highlighting */
301#define UNKNOWN_CREATOR '\?\?\?\?'
302
303/*
304 * for debugging
305 */
306#ifdef MACOS_X
307# ifdef _DEBUG
308# define TRACE Trace
309 void Trace(char *fmt, ...);
310# else
311# define TRACE 1 ? (void)0 : printf
312# endif
313#endif