blob: 5fc95eee0a05c775fbc00648516b0875026ddf65 [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/*
10 * NextStep has a problem with configure, undefine a few things:
11 */
12#ifdef NeXT
13# ifdef HAVE_UTIME
14# undef HAVE_UTIME
15# endif
16# ifdef HAVE_SYS_UTSNAME_H
17# undef HAVE_SYS_UTSNAME_H
18# endif
19#endif
20
21#include <stdio.h>
22#include <ctype.h>
23
24#ifdef VAXC
25# include <types.h>
26# include <stat.h>
27#else
28# include <sys/types.h>
29# include <sys/stat.h>
30#endif
31
32#ifdef HAVE_STDLIB_H
33# include <stdlib.h>
34#endif
35
36#ifdef __EMX__
37# define HAVE_TOTAL_MEM
38#endif
39
40#if defined(__CYGWIN__) || defined(__CYGWIN32__)
41# define WIN32UNIX /* Compiling for Win32 using Unix files. */
42# define BINARY_FILE_IO
Bram Moolenaar24552be2005-12-10 20:17:30 +000043
44# define CASE_INSENSITIVE_FILENAME
45# define USE_FNAME_CASE /* Fix filename case differences. */
Bram Moolenaar071d4272004-06-13 20:20:40 +000046#endif
47
48/* On AIX 4.2 there is a conflicting prototype for ioctl() in stropts.h and
49 * unistd.h. This hack should fix that (suggested by Jeff George).
50 * But on AIX 4.3 it's alright (suggested by Jake Hamby). */
51#if defined(FEAT_GUI) && defined(_AIX) && !defined(_AIX43) && !defined(_NO_PROTO)
52# define _NO_PROTO
53#endif
54
55#ifdef HAVE_UNISTD_H
Bram Moolenaar8f0b2d42009-05-16 14:41:10 +000056# include <unistd.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000057#endif
58
59#ifdef HAVE_LIBC_H
60# include <libc.h> /* for NeXT */
61#endif
62
63#ifdef HAVE_SYS_PARAM_H
64# include <sys/param.h> /* defines BSD, if it's a BSD system */
65#endif
66
67/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 * Using getcwd() is preferred, because it checks for a buffer overflow.
69 * Don't use getcwd() on systems do use system("sh -c pwd"). There is an
70 * autoconf check for this.
71 * Use getcwd() anyway if getwd() isn't present.
72 */
73#if defined(HAVE_GETCWD) && !(defined(BAD_GETCWD) && defined(HAVE_GETWD))
74# define USE_GETCWD
75#endif
76
77#ifndef __ARGS
78 /* The AIX VisualAge cc compiler defines __EXTENDED__ instead of __STDC__
79 * because it includes pre-ansi features. */
80# if defined(__STDC__) || defined(__GNUC__) || defined(__EXTENDED__)
81# define __ARGS(x) x
82# else
83# define __ARGS(x) ()
84# endif
85#endif
86
87/* always use unlink() to remove files */
88#ifndef PROTO
89# ifdef VMS
90# define mch_remove(x) delete((char *)(x))
91# define vim_mkdir(x, y) mkdir((char *)(x), y)
92# ifdef VAX
93# else
94# define mch_rmdir(x) rmdir((char *)(x))
95# endif
96# else
97# define vim_mkdir(x, y) mkdir((char *)(x), y)
98# define mch_rmdir(x) rmdir((char *)(x))
99# define mch_remove(x) unlink((char *)(x))
100# endif
101#endif
102
103/* The number of arguments to a signal handler is configured here. */
104/* It used to be a long list of almost all systems. Any system that doesn't
105 * have an argument??? */
106#define SIGHASARG
107
108/* List 3 arg systems here. I guess __sgi, please test and correct me. jw. */
109#if defined(__sgi) && defined(HAVE_SIGCONTEXT)
110# define SIGHAS3ARGS
111#endif
112
113#ifdef SIGHASARG
114# ifdef SIGHAS3ARGS
115# define SIGPROTOARG (int, int, struct sigcontext *)
116# define SIGDEFARG(s) (s, sig2, scont) int s, sig2; struct sigcontext *scont;
117# define SIGDUMMYARG 0, 0, (struct sigcontext *)0
118# else
119# define SIGPROTOARG (int)
Bram Moolenaar78a15312009-05-15 19:33:18 +0000120# define SIGDEFARG(s) (s) int s UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121# define SIGDUMMYARG 0
122# endif
123#else
124# define SIGPROTOARG (void)
125# define SIGDEFARG(s) ()
126# define SIGDUMMYARG
127#endif
128
129#ifdef HAVE_DIRENT_H
130# include <dirent.h>
131# ifndef NAMLEN
132# define NAMLEN(dirent) strlen((dirent)->d_name)
133# endif
134#else
135# define dirent direct
136# define NAMLEN(dirent) (dirent)->d_namlen
137# if HAVE_SYS_NDIR_H
138# include <sys/ndir.h>
139# endif
140# if HAVE_SYS_DIR_H
141# include <sys/dir.h>
142# endif
143# if HAVE_NDIR_H
144# include <ndir.h>
145# endif
146#endif
147
148#if !defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME)
149# include <time.h> /* on some systems time.h should not be
150 included together with sys/time.h */
151#endif
152#ifdef HAVE_SYS_TIME_H
153# include <sys/time.h>
154#endif
155
156#include <signal.h>
157
158#if defined(DIRSIZ) && !defined(MAXNAMLEN)
159# define MAXNAMLEN DIRSIZ
160#endif
161
162#if defined(UFS_MAXNAMLEN) && !defined(MAXNAMLEN)
163# define MAXNAMLEN UFS_MAXNAMLEN /* for dynix/ptx */
164#endif
165
166#if defined(NAME_MAX) && !defined(MAXNAMLEN)
167# define MAXNAMLEN NAME_MAX /* for Linux before .99p3 */
168#endif
169
170/*
171 * Note: if MAXNAMLEN has the wrong value, you will get error messages
172 * for not being able to open the swap file.
173 */
174#if !defined(MAXNAMLEN)
175# define MAXNAMLEN 512 /* for all other Unix */
176#endif
177
178#define BASENAMELEN (MAXNAMLEN - 5)
179
Bram Moolenaar071d4272004-06-13 20:20:40 +0000180#ifdef HAVE_PWD_H
181# include <pwd.h>
182#endif
183
184#ifdef __COHERENT__
185# undef __ARGS
186#endif
187
188#if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
189 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
190 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
191# define HAVE_TOTAL_MEM
192#endif
193
Bram Moolenaar82881492012-11-20 16:53:39 +0100194
195#ifndef PROTO
196
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197#ifdef VMS
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000198# include <unixio.h>
199# include <unixlib.h>
200# include <signal.h>
201# include <file.h>
202# include <ssdef.h>
203# include <descrip.h>
204# include <libclidef.h>
205# include <lnmdef.h>
206# include <psldef.h>
207# include <prvdef.h>
208# include <dvidef.h>
209# include <dcdef.h>
210# include <stsdef.h>
211# include <iodef.h>
212# include <ttdef.h>
213# include <tt2def.h>
214# include <jpidef.h>
215# include <rms.h>
216# include <trmdef.h>
217# include <string.h>
218# include <starlet.h>
219# include <socket.h>
220# include <lib$routines.h>
Bram Moolenaar4ffa0702013-12-11 17:12:37 +0100221# include <libdef.h>
222# include <libdtdef.h>
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000223
224# ifdef FEAT_GUI_GTK
225# include "gui_gtk_vms.h"
226# endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100227#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228
Bram Moolenaar82881492012-11-20 16:53:39 +0100229#endif /* PROTO */
230
231#ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232typedef struct dsc$descriptor DESC;
233#endif
234
235/*
236 * Unix system-dependent file names
237 */
238#ifndef SYS_VIMRC_FILE
239# define SYS_VIMRC_FILE "$VIM/vimrc"
240#endif
241#ifndef SYS_GVIMRC_FILE
242# define SYS_GVIMRC_FILE "$VIM/gvimrc"
243#endif
244#ifndef DFLT_HELPFILE
245# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
246#endif
247#ifndef FILETYPE_FILE
248# define FILETYPE_FILE "filetype.vim"
249#endif
250#ifndef FTPLUGIN_FILE
251# define FTPLUGIN_FILE "ftplugin.vim"
252#endif
253#ifndef INDENT_FILE
254# define INDENT_FILE "indent.vim"
255#endif
256#ifndef FTOFF_FILE
257# define FTOFF_FILE "ftoff.vim"
258#endif
259#ifndef FTPLUGOF_FILE
260# define FTPLUGOF_FILE "ftplugof.vim"
261#endif
262#ifndef INDOFF_FILE
263# define INDOFF_FILE "indoff.vim"
264#endif
265#ifndef SYS_MENU_FILE
266# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
267#endif
268
269#ifndef USR_EXRC_FILE
270# ifdef VMS
271# define USR_EXRC_FILE "sys$login:.exrc"
272# else
273# define USR_EXRC_FILE "$HOME/.exrc"
274# endif
275#endif
276
277#if !defined(USR_EXRC_FILE2) && defined(OS2)
278# define USR_EXRC_FILE2 "$VIM/.exrc"
279#endif
280#if !defined(USR_EXRC_FILE2) && defined(VMS)
281# define USR_EXRC_FILE2 "sys$login:_exrc"
282#endif
283
284#ifndef USR_VIMRC_FILE
285# ifdef VMS
286# define USR_VIMRC_FILE "sys$login:.vimrc"
287# else
288# define USR_VIMRC_FILE "$HOME/.vimrc"
289# endif
290#endif
291
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200292
Bram Moolenaarea98f8b2015-05-04 09:31:11 +0200293#if !defined(USR_VIMRC_FILE2)
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200294# ifdef OS2
295# define USR_VIMRC_FILE2 "$HOME/vimfiles/vimrc"
296# else
297# ifdef VMS
Bram Moolenaar206f0112014-03-12 16:51:55 +0100298# define USR_VIMRC_FILE2 "sys$login:vimfiles/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200299# else
300# define USR_VIMRC_FILE2 "~/.vim/vimrc"
301# endif
302# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303#endif
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200304
305#if !defined(USR_VIMRC_FILE3) && defined(OS2)
306# define USR_VIMRC_FILE3 "$VIM/.vimrc"
307#endif
308#if !defined(USR_VIMRC_FILE3) && defined(VMS)
309# define USR_VIMRC_FILE3 "sys$login:_vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310#endif
311
312#ifndef USR_GVIMRC_FILE
313# ifdef VMS
314# define USR_GVIMRC_FILE "sys$login:.gvimrc"
315# else
316# define USR_GVIMRC_FILE "$HOME/.gvimrc"
317# endif
318#endif
319
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200320#ifndef USR_GVIMRC_FILE2
321# ifdef OS2
322# define USR_GVIMRC_FILE2 "$HOME/vimfiles/gvimrc"
323# else
324# ifdef VMS
Bram Moolenaar206f0112014-03-12 16:51:55 +0100325# define USR_GVIMRC_FILE2 "sys$login:vimfiles/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200326# else
327# define USR_GVIMRC_FILE2 "~/.vim/gvimrc"
328# endif
329# endif
330#endif
331
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332#ifdef VMS
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200333# ifndef USR_GVIMRC_FILE3
334# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000335# endif
336#endif
337
338#ifndef EVIM_FILE
339# define EVIM_FILE "$VIMRUNTIME/evim.vim"
340#endif
341
342#ifdef FEAT_VIMINFO
343# ifndef VIMINFO_FILE
344# ifdef VMS
345# define VIMINFO_FILE "sys$login:.viminfo"
346# else
347# define VIMINFO_FILE "$HOME/.viminfo"
348# endif
349# endif
350# if !defined(VIMINFO_FILE2) && defined(OS2)
351# define VIMINFO_FILE2 "$VIM/.viminfo"
352# endif
353# if !defined(VIMINFO_FILE2) && defined(VMS)
354# define VIMINFO_FILE2 "sys$login:_viminfo"
355# endif
356#endif
357
358#ifndef EXRC_FILE
359# define EXRC_FILE ".exrc"
360#endif
361
362#ifndef VIMRC_FILE
363# define VIMRC_FILE ".vimrc"
364#endif
365
366#ifdef FEAT_GUI
367# ifndef GVIMRC_FILE
368# define GVIMRC_FILE ".gvimrc"
369# endif
370#endif
371
372#ifndef SYNTAX_FNAME
373# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
374#endif
375
376#ifndef DFLT_BDIR
377# ifdef OS2
378# define DFLT_BDIR ".,c:/tmp,~/tmp,~/"
379# else
380# ifdef VMS
381# define DFLT_BDIR "./,sys$login:,tmp:"
382# else
383# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
384# endif
385# endif
386#endif
387
388#ifndef DFLT_DIR
389# ifdef OS2
390# define DFLT_DIR ".,~/tmp,c:/tmp,/tmp"
391# else
392# ifdef VMS
393# define DFLT_DIR "./,sys$login:,tmp:"
394# else
395# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
396# endif
397# endif
398#endif
399
400#ifndef DFLT_VDIR
401# ifdef OS2
402# define DFLT_VDIR "$VIM/vimfiles/view"
403# else
404# ifdef VMS
405# define DFLT_VDIR "sys$login:vimfiles/view"
406# else
407# define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
408# endif
409# endif
410#endif
411
412#define DFLT_ERRORFILE "errors.err"
413
414#ifdef OS2
415# define DFLT_RUNTIMEPATH "$HOME/vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/vimfiles/after"
416#else
417# ifdef VMS
418# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
419# else
420# ifdef RUNTIME_GLOBAL
421# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
422# else
423# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
424# endif
425# endif
426#endif
427
428#ifdef OS2
429/*
430 * Try several directories to put the temp files.
431 */
432# define TEMPDIRNAMES "$TMP", "$TEMP", "c:\\TMP", "c:\\TEMP", ""
433# define TEMPNAMELEN 128
434#else
435# ifdef VMS
436# ifndef VAX
437# define VMS_TEMPNAM /* to fix default .LIS extension */
438# endif
439# define TEMPNAME "TMP:v?XXXXXX.txt"
440# define TEMPNAMELEN 28
441# else
442# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
443# define TEMPNAMELEN 256
444# endif
445#endif
446
447/* Special wildcards that need to be handled by the shell */
448#define SPECIAL_WILDCHAR "`'{"
449
450#ifndef HAVE_OPENDIR
451# define NO_EXPANDPATH
452#endif
453
454/*
455 * Unix has plenty of memory, use large buffers
456 */
457#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
Bram Moolenaar38f12a92008-06-20 16:07:02 +0000458
459/* Use the system path length if it makes sense. */
460#if defined(PATH_MAX) && (PATH_MAX > 1000)
461# define MAXPATHL PATH_MAX
462#else
463# define MAXPATHL 1024
464#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
466#define CHECK_INODE /* used when checking if a swap file already
467 exists for a file */
468#ifdef VMS /* Use less memory because of older systems */
469# ifndef DFLT_MAXMEM
470# define DFLT_MAXMEM (2*1024)
471# endif
472# ifndef DFLT_MAXMEMTOT
473# define DFLT_MAXMEMTOT (5*1024)
474# endif
475#else
476# ifndef DFLT_MAXMEM
477# define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
478# endif
479# ifndef DFLT_MAXMEMTOT
480# define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
481# endif
482#endif
483
484/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
485 * own version */
486/* Some systems have (void *) arguments, some (char *). If we use (char *) it
487 * works for all */
488#ifdef USEMEMMOVE
489# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
490#else
491# ifdef USEBCOPY
492# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
493# else
494# ifdef USEMEMCPY
495# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
496# else
497# define VIM_MEMMOVE /* found in misc2.c */
498# endif
499# endif
500#endif
501
502#ifndef PROTO
503# ifdef HAVE_RENAME
504# define mch_rename(src, dst) rename(src, dst)
505# else
506int mch_rename __ARGS((const char *src, const char *dest));
507# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508# ifndef VMS
509# ifdef __MVS__
Bram Moolenaar3d27a452007-05-10 17:44:18 +0000510 /* on OS390 Unix getenv() doesn't return a pointer to persistent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 * storage -> use __getenv() */
512# define mch_getenv(x) (char_u *)__getenv((char *)(x))
513# else
514# define mch_getenv(x) (char_u *)getenv((char *)(x))
515# endif
516# define mch_setenv(name, val, x) setenv(name, val, x)
517# endif
518#endif
519
520#if !defined(S_ISDIR) && defined(S_IFDIR)
521# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
522#endif
523#if !defined(S_ISREG) && defined(S_IFREG)
524# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
525#endif
526#if !defined(S_ISBLK) && defined(S_IFBLK)
527# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
528#endif
529#if !defined(S_ISSOCK) && defined(S_IFSOCK)
530# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
531#endif
532#if !defined(S_ISFIFO) && defined(S_IFIFO)
533# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
534#endif
Bram Moolenaarfe1c56d2007-07-10 15:10:54 +0000535#if !defined(S_ISCHR) && defined(S_IFCHR)
536# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
537#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538
539/* Note: Some systems need both string.h and strings.h (Savage). However,
540 * some systems can't handle both, only use string.h in that case. */
541#ifdef HAVE_STRING_H
542# include <string.h>
543#endif
544#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
545# include <strings.h>
546#endif
547
548#if defined(HAVE_SETJMP_H)
549# include <setjmp.h>
550# ifdef HAVE_SIGSETJMP
551# define JMP_BUF sigjmp_buf
552# define SETJMP(x) sigsetjmp((x), 1)
553# define LONGJMP siglongjmp
554# else
555# define JMP_BUF jmp_buf
556# define SETJMP(x) setjmp(x)
557# define LONGJMP longjmp
558# endif
559#endif
560
Bram Moolenaarc41053062014-03-25 13:46:26 +0100561#ifndef HAVE_DUP
562# define HAVE_DUP /* have dup() */
563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564#define HAVE_ST_MODE /* have stat.st_mode */
565
566/* We have three kinds of ACL support. */
567#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)