Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* 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 Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 21 | * |
| 22 | * Include the Mac header files, unless also compiling with X11 (the header |
| 23 | * files have many conflicts). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | */ |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 25 | #ifndef FEAT_X11 |
| 26 | # include <QuickDraw.h> |
| 27 | # 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
| 40 | /* |
| 41 | * Unix interface |
| 42 | */ |
| 43 | #if defined(__MWERKS__) /* for CodeWarrior */ |
| 44 | # include <unistd.h> |
| 45 | # include <utsname.h> |
| 46 | # include <unix.h> |
| 47 | #endif |
| 48 | #if defined(__APPLE_CC__) /* for Project Builder and ... */ |
| 49 | # include <unistd.h> |
| 50 | #endif |
| 51 | /* Get stat.h or something similar. Comment: How come some OS get in in vim.h */ |
| 52 | #if defined(__MWERKS__) |
| 53 | # include <stat.h> |
| 54 | #endif |
| 55 | #if defined(__APPLE_CC__) |
| 56 | # include <sys/stat.h> |
| 57 | #endif |
| 58 | #if defined(__MRC__) || defined(__SC__) /* for Apple MPW Compilers */ |
| 59 | /* There's no stat.h for MPW? */ |
| 60 | # ifdef powerc |
| 61 | # pragma options align=power |
| 62 | # endif |
| 63 | struct stat |
| 64 | { |
| 65 | UInt32 st_mtime; |
| 66 | UInt32 st_mode; |
| 67 | UInt32 st_size; |
| 68 | }; |
| 69 | # ifdef powerc |
| 70 | # pragma options align=reset |
| 71 | # endif |
| 72 | #endif |
| 73 | #if defined(__APPLE_CC__) /* && defined(HAVE_CURSE) */ |
| 74 | /* The curses.h from MacOS X provides by default some BACKWARD compatibilty |
| 75 | * definition which can cause us problem later on. So we undefine a few of them. */ |
| 76 | # include <curses.h> |
| 77 | # undef reg |
| 78 | # undef ospeed |
| 79 | /* OK defined to 0 in MacOS X 10.2 curses! Remove it, we define it to be 1. */ |
| 80 | # undef OK |
| 81 | #endif |
| 82 | #include <signal.h> |
| 83 | #include <errno.h> |
| 84 | #include <stdio.h> |
| 85 | #include <stdlib.h> |
| 86 | #include <time.h> |
| 87 | #ifdef MACOS_X |
| 88 | # include <dirent.h> |
| 89 | #endif |
| 90 | |
| 91 | /* |
| 92 | * Incompatibility checks |
| 93 | */ |
| 94 | |
| 95 | /* Got problem trying to use shared library in 68k */ |
| 96 | #if !defined(__POWERPC__) && defined(FEAT_PYTHON) |
| 97 | # undef FEAT_PYTHON |
| 98 | # warning Auto-disabling Python. Not yet supported in 68k. |
| 99 | #endif |
| 100 | |
| 101 | #if !defined(__POWERPC__) && !defined(__ppc__) |
| 102 | # if !__option(enumsalwaysint) |
| 103 | # error "You must compile with enums always int!" |
| 104 | # endif |
| 105 | # if defined(__MWERKS__) && !defined(__fourbyteints__) |
| 106 | # error "You must compile the project with 4-byte ints" |
| 107 | /* MPW ints are always 4 byte long */ |
| 108 | # endif |
| 109 | #endif |
| 110 | |
| 111 | /* |
| 112 | * MacOS specific #define |
| 113 | */ |
| 114 | |
| 115 | /* This will go away when CMD_KEY fully tested */ |
| 116 | #define USE_CMD_KEY |
| 117 | /* On MacOS X use the / not the : */ |
| 118 | /* TODO: Should file such as ~/.vimrc reside instead in |
| 119 | * ~/Library/Vim or ~/Library/Preferences/org.vim.vim/ ? (Dany) |
| 120 | */ |
| 121 | /* When compiled under MacOS X (including CARBON version) |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 122 | * we use the Unix File path style. Also when UNIX is defined. */ |
| 123 | #if defined(UNIX) || (defined(TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 124 | # undef COLON_AS_PATHSEP |
| 125 | # define USE_UNIXFILENAME |
| 126 | #else |
| 127 | # define COLON_AS_PATHSEP |
| 128 | # define DONT_ADD_PATHSEP_TO_DIR |
| 129 | #endif |
| 130 | |
| 131 | |
| 132 | /* |
| 133 | * Generic Vim #define |
| 134 | */ |
| 135 | |
| 136 | #define FEAT_SOURCE_FFS |
| 137 | #define FEAT_SOURCE_FF_MAC |
| 138 | |
| 139 | #define USE_EXE_NAME /* to find $VIM */ |
| 140 | #define CASE_INSENSITIVE_FILENAME /* ignore case when comparing file names */ |
| 141 | #define SPACE_IN_FILENAME |
| 142 | #define BREAKCHECK_SKIP 32 /* call mch_breakcheck() each time, it's |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 143 | quite fast. Did I forgot to update the |
| 144 | comment */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 145 | |
| 146 | |
Bram Moolenaar | 43abc52 | 2005-12-10 20:15:02 +0000 | [diff] [blame] | 147 | #define USE_FNAME_CASE /* make ":e os_Mac.c" open the file in its |
| 148 | original case, as "os_mac.c" */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 149 | #define BINARY_FILE_IO |
| 150 | #define EOL_DEFAULT EOL_MAC |
Bram Moolenaar | 5eb86f9 | 2004-07-26 12:53:41 +0000 | [diff] [blame] | 151 | #ifndef MACOS_X_UNIX /* I hope that switching these two lines */ |
| 152 | # define USE_CR /* does what I want -- BNF */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 153 | # define NO_CONSOLE /* don't include console mode */ |
| 154 | #endif |
| 155 | #define HAVE_AVAIL_MEM |
| 156 | |
| 157 | #ifndef HAVE_CONFIG_H |
| 158 | /* #define SYNC_DUP_CLOSE sync() a file with dup() and close() */ |
| 159 | # define HAVE_STRING_H |
| 160 | # define HAVE_STRCSPN |
| 161 | # define HAVE_MEMSET |
| 162 | # define USE_TMPNAM /* use tmpnam() instead of mktemp() */ |
| 163 | # define HAVE_FCNTL_H |
| 164 | # define HAVE_QSORT |
| 165 | # define HAVE_ST_MODE /* have stat.st_mode */ |
| 166 | |
| 167 | # if defined(__DATE__) && defined(__TIME__) |
| 168 | # define HAVE_DATE_TIME |
| 169 | # endif |
| 170 | # define HAVE_STRFTIME |
| 171 | #endif |
| 172 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 173 | /* |
| 174 | * Names for the EXRC, HELP and temporary files. |
| 175 | * Some of these may have been defined in the makefile. |
| 176 | */ |
| 177 | |
| 178 | #ifndef SYS_VIMRC_FILE |
| 179 | # ifdef COLON_AS_PATHSEP |
| 180 | # define SYS_VIMRC_FILE "$VIM:vimrc" |
| 181 | # else |
| 182 | # define SYS_VIMRC_FILE "$VIM/vimrc" |
| 183 | # endif |
| 184 | #endif |
| 185 | #ifndef SYS_GVIMRC_FILE |
| 186 | # ifdef COLON_AS_PATHSEP |
| 187 | # define SYS_GVIMRC_FILE "$VIM:gvimrc" |
| 188 | # else |
| 189 | # define SYS_GVIMRC_FILE "$VIM/gvimrc" |
| 190 | # endif |
| 191 | #endif |
| 192 | #ifndef SYS_MENU_FILE |
| 193 | # ifdef COLON_AS_PATHSEP |
| 194 | # define SYS_MENU_FILE "$VIMRUNTIME:menu.vim" |
| 195 | # else |
| 196 | # define SYS_MENU_FILE "$VIMRUNTIME/menu.vim" |
| 197 | # endif |
| 198 | #endif |
| 199 | #ifndef SYS_OPTWIN_FILE |
| 200 | # ifdef COLON_AS_PATHSEP |
| 201 | # define SYS_OPTWIN_FILE "$VIMRUNTIME:optwin.vim" |
| 202 | # else |
| 203 | # define SYS_OPTWIN_FILE "$VIMRUNTIME/optwin.vim" |
| 204 | # endif |
| 205 | #endif |
| 206 | #ifndef EVIM_FILE |
| 207 | # ifdef COLON_AS_PATHSEP |
| 208 | # define EVIM_FILE "$VIMRUNTIME:evim.vim" |
| 209 | # else |
| 210 | # define EVIM_FILE "$VIMRUNTIME/evim.vim" |
| 211 | # endif |
| 212 | #endif |
| 213 | |
| 214 | #ifdef FEAT_GUI |
| 215 | # ifndef USR_GVIMRC_FILE |
| 216 | # ifdef COLON_AS_PATHSEP |
| 217 | # define USR_GVIMRC_FILE "$VIM:.gvimrc" |
| 218 | # else |
| 219 | # define USR_GVIMRC_FILE "~/.gvimrc" |
| 220 | # endif |
| 221 | # endif |
| 222 | # ifndef GVIMRC_FILE |
| 223 | # define GVIMRC_FILE "_gvimrc" |
| 224 | # endif |
| 225 | #endif |
| 226 | #ifndef USR_VIMRC_FILE |
| 227 | # ifdef COLON_AS_PATHSEP |
| 228 | # define USR_VIMRC_FILE "$VIM:.vimrc" |
| 229 | # else |
| 230 | # define USR_VIMRC_FILE "~/.vimrc" |
| 231 | # endif |
| 232 | #endif |
| 233 | |
| 234 | #ifndef USR_EXRC_FILE |
| 235 | # ifdef COLON_AS_PATHSEP |
| 236 | # define USR_EXRC_FILE "$VIM:.exrc" |
| 237 | # else |
| 238 | # define USR_EXRC_FILE "~/.exrc" |
| 239 | # endif |
| 240 | #endif |
| 241 | |
| 242 | #ifndef VIMRC_FILE |
| 243 | # define VIMRC_FILE "_vimrc" |
| 244 | #endif |
| 245 | |
| 246 | #ifndef EXRC_FILE |
| 247 | # define EXRC_FILE "_exrc" |
| 248 | #endif |
| 249 | |
| 250 | #ifndef DFLT_HELPFILE |
| 251 | # ifdef COLON_AS_PATHSEP |
| 252 | # define DFLT_HELPFILE "$VIMRUNTIME:doc:help.txt" |
| 253 | # else |
| 254 | # define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt" |
| 255 | # endif |
| 256 | #endif |
| 257 | |
| 258 | #ifndef FILETYPE_FILE |
| 259 | # define FILETYPE_FILE "filetype.vim" |
| 260 | #endif |
| 261 | #ifndef FTPLUGIN_FILE |
| 262 | # define FTPLUGIN_FILE "ftplugin.vim" |
| 263 | #endif |
| 264 | #ifndef INDENT_FILE |
| 265 | # define INDENT_FILE "indent.vim" |
| 266 | #endif |
| 267 | #ifndef FTOFF_FILE |
| 268 | # define FTOFF_FILE "ftoff.vim" |
| 269 | #endif |
| 270 | #ifndef FTPLUGOF_FILE |
| 271 | # define FTPLUGOF_FILE "ftplugof.vim" |
| 272 | #endif |
| 273 | #ifndef INDOFF_FILE |
| 274 | # define INDOFF_FILE "indoff.vim" |
| 275 | #endif |
| 276 | |
| 277 | #ifndef SYNTAX_FNAME |
| 278 | # ifdef COLON_AS_PATHSEP |
| 279 | # define SYNTAX_FNAME "$VIMRUNTIME:syntax:%s.vim" |
| 280 | # else |
| 281 | # define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim" |
| 282 | # endif |
| 283 | #endif |
| 284 | |
| 285 | #ifdef FEAT_VIMINFO |
| 286 | # ifndef VIMINFO_FILE |
| 287 | # ifdef COLON_AS_PATHSEP |
| 288 | # define VIMINFO_FILE "$VIM:viminfo" |
| 289 | # else |
| 290 | # define VIMINFO_FILE "~/.viminfo" |
| 291 | # endif |
| 292 | # endif |
| 293 | #endif /* FEAT_VIMINFO */ |
| 294 | |
| 295 | #ifndef DFLT_BDIR |
| 296 | # define DFLT_BDIR "." /* default for 'backupdir' */ |
| 297 | #endif |
| 298 | |
| 299 | #ifndef DFLT_DIR |
| 300 | # define DFLT_DIR "." /* default for 'directory' */ |
| 301 | #endif |
| 302 | |
| 303 | #ifndef DFLT_VDIR |
| 304 | # ifdef COLON_AS_PATHSEP |
| 305 | # define DFLT_VDIR "$VIM:vimfiles:view" /* default for 'viewdir' */ |
| 306 | # else |
| 307 | # define DFLT_VDIR "$VIM/vimfiles/view" /* default for 'viewdir' */ |
| 308 | # endif |
| 309 | #endif |
| 310 | |
| 311 | #define DFLT_ERRORFILE "errors.err" |
Bram Moolenaar | ab79bcb | 2004-07-18 21:34:53 +0000 | [diff] [blame] | 312 | |
| 313 | #ifndef DFLT_RUNTIMEPATH |
| 314 | # ifdef COLON_AS_PATHSEP |
| 315 | # define DFLT_RUNTIMEPATH "$VIM:vimfiles,$VIMRUNTIME,$VIM:vimfiles:after" |
| 316 | # else |
| 317 | # define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after" |
| 318 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 319 | #endif |
| 320 | |
| 321 | /* |
| 322 | * Macintosh has plenty of memory, use large buffers |
| 323 | */ |
| 324 | #define CMDBUFFSIZE 1024 /* size of the command processing buffer */ |
| 325 | |
| 326 | #if defined(MACOS_X_UNIX) |
| 327 | # define MAXPATHL 1024 |
| 328 | # define BASENAMELEN (MAXNAMLEN - 5) /* length of base of filename */ |
| 329 | #else |
| 330 | # define MAXPATHL 256 /* Limited by the Pascal Strings */ |
| 331 | # define BASENAMELEN (32-5-1) /* length of base of filename */ |
| 332 | #endif |
| 333 | |
| 334 | #ifndef DFLT_MAXMEM |
| 335 | # define DFLT_MAXMEM 512 /* use up to 512 Kbyte for buffer */ |
| 336 | #endif |
| 337 | |
| 338 | #ifndef DFLT_MAXMEMTOT |
| 339 | # define DFLT_MAXMEMTOT 2048 /* use up to 2048 Kbyte for Vim */ |
| 340 | #endif |
| 341 | |
| 342 | #define WILDCHAR_LIST "*?[{`$" |
| 343 | |
| 344 | /**************/ |
| 345 | #define mch_rename(src, dst) rename(src, dst) |
| 346 | #define mch_remove(x) unlink((char *)(x)) |
| 347 | #ifndef mch_getenv |
| 348 | # if defined(__MRC__) || defined(__SC__) |
| 349 | # define mch_getenv(name) ((char_u *)getenv((char *)(name))) |
| 350 | # define mch_setenv(name, val, x) setenv((name), (val)) |
| 351 | # elif defined(__APPLE_CC__) |
| 352 | # define mch_getenv(name) ((char_u *)getenv((char *)(name))) |
| 353 | /*# define mch_setenv(name, val, x) setenv((name), (val)) */ /* Obsoleted by Dany on Oct 30, 2001 */ |
| 354 | # define mch_setenv(name, val, x) setenv(name, val, x) |
| 355 | # else |
| 356 | /* vim_getenv() is in pty.c */ |
| 357 | # define USE_VIMPTY_GETENV |
| 358 | # define mch_getenv(x) vimpty_getenv(x) |
| 359 | # define mch_setenv(name, val, x) setenv(name, val, x) |
| 360 | # endif |
| 361 | #endif |
| 362 | |
| 363 | #ifndef HAVE_CONFIG_H |
| 364 | # ifdef __APPLE_CC__ |
| 365 | /* Assuming compiling for MacOS X */ |
| 366 | /* Trying to take advantage of the prebinding */ |
| 367 | # define HAVE_TGETENT |
| 368 | # define OSPEED_EXTERN |
| 369 | # define UP_BC_PC_EXTERN |
| 370 | # endif |
| 371 | #endif |
| 372 | |
| 373 | /* Some "prep work" definition to be able to compile the MacOS X |
| 374 | * version with os_unix.x instead of os_mac.c. Based on the result |
| 375 | * of ./configure for console MacOS X. |
| 376 | */ |
| 377 | |
| 378 | #ifdef MACOS_X_UNIX |
| 379 | # define SIGPROTOARG (int) |
| 380 | # define SIGDEFARG(s) (s) int s; |
| 381 | # define SIGDUMMYARG 0 |
| 382 | # undef HAVE_AVAIL_MEM |
| 383 | # ifndef HAVE_CONFIG_H |
| 384 | # define RETSIGTYPE void |
| 385 | # define SIGRETURN return |
| 386 | /*# define USE_SYSTEM */ /* Output ship do debugger :(, but ot compile */ |
| 387 | # define HAVE_SYS_WAIT_H 1 /* Attempt */ |
| 388 | # define HAVE_TERMIOS_H 1 |
| 389 | # define SYS_SELECT_WITH_SYS_TIME 1 |
| 390 | # define HAVE_SELECT 1 |
| 391 | # define HAVE_SYS_SELECT_H 1 |
| 392 | # define HAVE_PUTENV |
| 393 | # define HAVE_SETENV |
| 394 | # define HAVE_RENAME |
| 395 | # endif |
| 396 | # define mch_chdir(s) chdir(s) |
| 397 | #endif |
| 398 | |
| 399 | #if defined(MACOS_X) && !defined(HAVE_CONFIG_H) |
| 400 | # define HAVE_PUTENV |
| 401 | #endif |
| 402 | |
| 403 | /* A Mac constant causing big problem to syntax highlighting */ |
| 404 | #define UNKNOWN_CREATOR '\?\?\?\?' |
| 405 | |
| 406 | /* |
| 407 | * for debugging |
| 408 | */ |
| 409 | #ifdef MACOS_X |
| 410 | # ifdef _DEBUG |
| 411 | # define TRACE Trace |
| 412 | void Trace(char *fmt, ...); |
| 413 | # else |
| 414 | # define TRACE 1 ? (void)0 : printf |
| 415 | # endif |
| 416 | #endif |
| 417 | |
| 418 | #ifdef MACOS_CLASSIC |
| 419 | # define TRACE 1 ? (int)0 : printf |
| 420 | #endif |