blob: b835df657f553256cb11621adf43905d7bac6c31 [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
Bram Moolenaar071d4272004-06-13 20:20:40 +000036#if defined(__CYGWIN__) || defined(__CYGWIN32__)
37# define WIN32UNIX /* Compiling for Win32 using Unix files. */
38# define BINARY_FILE_IO
Bram Moolenaar24552be2005-12-10 20:17:30 +000039
40# define CASE_INSENSITIVE_FILENAME
41# define USE_FNAME_CASE /* Fix filename case differences. */
Bram Moolenaar071d4272004-06-13 20:20:40 +000042#endif
43
44/* On AIX 4.2 there is a conflicting prototype for ioctl() in stropts.h and
45 * unistd.h. This hack should fix that (suggested by Jeff George).
46 * But on AIX 4.3 it's alright (suggested by Jake Hamby). */
47#if defined(FEAT_GUI) && defined(_AIX) && !defined(_AIX43) && !defined(_NO_PROTO)
48# define _NO_PROTO
49#endif
50
51#ifdef HAVE_UNISTD_H
Bram Moolenaar8f0b2d42009-05-16 14:41:10 +000052# include <unistd.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000053#endif
54
55#ifdef HAVE_LIBC_H
56# include <libc.h> /* for NeXT */
57#endif
58
59#ifdef HAVE_SYS_PARAM_H
60# include <sys/param.h> /* defines BSD, if it's a BSD system */
61#endif
62
63/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000064 * Using getcwd() is preferred, because it checks for a buffer overflow.
65 * Don't use getcwd() on systems do use system("sh -c pwd"). There is an
66 * autoconf check for this.
67 * Use getcwd() anyway if getwd() isn't present.
68 */
69#if defined(HAVE_GETCWD) && !(defined(BAD_GETCWD) && defined(HAVE_GETWD))
70# define USE_GETCWD
71#endif
72
Bram Moolenaar071d4272004-06-13 20:20:40 +000073/* always use unlink() to remove files */
74#ifndef PROTO
75# ifdef VMS
76# define mch_remove(x) delete((char *)(x))
77# define vim_mkdir(x, y) mkdir((char *)(x), y)
78# ifdef VAX
79# else
80# define mch_rmdir(x) rmdir((char *)(x))
81# endif
82# else
83# define vim_mkdir(x, y) mkdir((char *)(x), y)
84# define mch_rmdir(x) rmdir((char *)(x))
85# define mch_remove(x) unlink((char *)(x))
86# endif
87#endif
88
89/* The number of arguments to a signal handler is configured here. */
90/* It used to be a long list of almost all systems. Any system that doesn't
91 * have an argument??? */
92#define SIGHASARG
93
94/* List 3 arg systems here. I guess __sgi, please test and correct me. jw. */
95#if defined(__sgi) && defined(HAVE_SIGCONTEXT)
96# define SIGHAS3ARGS
97#endif
98
99#ifdef SIGHASARG
100# ifdef SIGHAS3ARGS
101# define SIGPROTOARG (int, int, struct sigcontext *)
102# define SIGDEFARG(s) (s, sig2, scont) int s, sig2; struct sigcontext *scont;
103# define SIGDUMMYARG 0, 0, (struct sigcontext *)0
104# else
105# define SIGPROTOARG (int)
Bram Moolenaar78a15312009-05-15 19:33:18 +0000106# define SIGDEFARG(s) (s) int s UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107# define SIGDUMMYARG 0
108# endif
109#else
110# define SIGPROTOARG (void)
111# define SIGDEFARG(s) ()
112# define SIGDUMMYARG
113#endif
114
115#ifdef HAVE_DIRENT_H
116# include <dirent.h>
117# ifndef NAMLEN
118# define NAMLEN(dirent) strlen((dirent)->d_name)
119# endif
120#else
121# define dirent direct
122# define NAMLEN(dirent) (dirent)->d_namlen
123# if HAVE_SYS_NDIR_H
124# include <sys/ndir.h>
125# endif
126# if HAVE_SYS_DIR_H
127# include <sys/dir.h>
128# endif
129# if HAVE_NDIR_H
130# include <ndir.h>
131# endif
132#endif
133
134#if !defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME)
135# include <time.h> /* on some systems time.h should not be
136 included together with sys/time.h */
137#endif
138#ifdef HAVE_SYS_TIME_H
139# include <sys/time.h>
140#endif
141
142#include <signal.h>
143
144#if defined(DIRSIZ) && !defined(MAXNAMLEN)
145# define MAXNAMLEN DIRSIZ
146#endif
147
148#if defined(UFS_MAXNAMLEN) && !defined(MAXNAMLEN)
149# define MAXNAMLEN UFS_MAXNAMLEN /* for dynix/ptx */
150#endif
151
152#if defined(NAME_MAX) && !defined(MAXNAMLEN)
153# define MAXNAMLEN NAME_MAX /* for Linux before .99p3 */
154#endif
155
156/*
157 * Note: if MAXNAMLEN has the wrong value, you will get error messages
158 * for not being able to open the swap file.
159 */
160#if !defined(MAXNAMLEN)
161# define MAXNAMLEN 512 /* for all other Unix */
162#endif
163
164#define BASENAMELEN (MAXNAMLEN - 5)
165
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166#ifdef HAVE_PWD_H
167# include <pwd.h>
168#endif
169
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170#if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
171 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
172 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
173# define HAVE_TOTAL_MEM
174#endif
175
Bram Moolenaar82881492012-11-20 16:53:39 +0100176
177#ifndef PROTO
178
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179#ifdef VMS
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000180# include <unixio.h>
181# include <unixlib.h>
182# include <signal.h>
183# include <file.h>
184# include <ssdef.h>
185# include <descrip.h>
186# include <libclidef.h>
187# include <lnmdef.h>
188# include <psldef.h>
189# include <prvdef.h>
190# include <dvidef.h>
191# include <dcdef.h>
192# include <stsdef.h>
193# include <iodef.h>
194# include <ttdef.h>
195# include <tt2def.h>
196# include <jpidef.h>
197# include <rms.h>
198# include <trmdef.h>
199# include <string.h>
200# include <starlet.h>
201# include <socket.h>
202# include <lib$routines.h>
Bram Moolenaar4ffa0702013-12-11 17:12:37 +0100203# include <libdef.h>
204# include <libdtdef.h>
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000205
206# ifdef FEAT_GUI_GTK
207# include "gui_gtk_vms.h"
208# endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100209#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210
Bram Moolenaar82881492012-11-20 16:53:39 +0100211#endif /* PROTO */
212
213#ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214typedef struct dsc$descriptor DESC;
215#endif
216
217/*
218 * Unix system-dependent file names
219 */
220#ifndef SYS_VIMRC_FILE
221# define SYS_VIMRC_FILE "$VIM/vimrc"
222#endif
223#ifndef SYS_GVIMRC_FILE
224# define SYS_GVIMRC_FILE "$VIM/gvimrc"
225#endif
226#ifndef DFLT_HELPFILE
227# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
228#endif
229#ifndef FILETYPE_FILE
230# define FILETYPE_FILE "filetype.vim"
231#endif
232#ifndef FTPLUGIN_FILE
233# define FTPLUGIN_FILE "ftplugin.vim"
234#endif
235#ifndef INDENT_FILE
236# define INDENT_FILE "indent.vim"
237#endif
238#ifndef FTOFF_FILE
239# define FTOFF_FILE "ftoff.vim"
240#endif
241#ifndef FTPLUGOF_FILE
242# define FTPLUGOF_FILE "ftplugof.vim"
243#endif
244#ifndef INDOFF_FILE
245# define INDOFF_FILE "indoff.vim"
246#endif
247#ifndef SYS_MENU_FILE
248# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
249#endif
250
251#ifndef USR_EXRC_FILE
252# ifdef VMS
253# define USR_EXRC_FILE "sys$login:.exrc"
254# else
255# define USR_EXRC_FILE "$HOME/.exrc"
256# endif
257#endif
258
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259#if !defined(USR_EXRC_FILE2) && defined(VMS)
260# define USR_EXRC_FILE2 "sys$login:_exrc"
261#endif
262
263#ifndef USR_VIMRC_FILE
264# ifdef VMS
265# define USR_VIMRC_FILE "sys$login:.vimrc"
266# else
267# define USR_VIMRC_FILE "$HOME/.vimrc"
268# endif
269#endif
270
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200271
Bram Moolenaarea98f8b2015-05-04 09:31:11 +0200272#if !defined(USR_VIMRC_FILE2)
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100273# ifdef VMS
274# define USR_VIMRC_FILE2 "sys$login:vimfiles/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200275# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100276# define USR_VIMRC_FILE2 "~/.vim/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200277# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278#endif
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200279
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200280#if !defined(USR_VIMRC_FILE3) && defined(VMS)
281# define USR_VIMRC_FILE3 "sys$login:_vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282#endif
283
284#ifndef USR_GVIMRC_FILE
285# ifdef VMS
286# define USR_GVIMRC_FILE "sys$login:.gvimrc"
287# else
288# define USR_GVIMRC_FILE "$HOME/.gvimrc"
289# endif
290#endif
291
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200292#ifndef USR_GVIMRC_FILE2
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100293# ifdef VMS
294# define USR_GVIMRC_FILE2 "sys$login:vimfiles/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200295# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100296# define USR_GVIMRC_FILE2 "~/.vim/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200297# endif
298#endif
299
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300#ifdef VMS
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200301# ifndef USR_GVIMRC_FILE3
302# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303# endif
304#endif
305
306#ifndef EVIM_FILE
307# define EVIM_FILE "$VIMRUNTIME/evim.vim"
308#endif
309
310#ifdef FEAT_VIMINFO
311# ifndef VIMINFO_FILE
312# ifdef VMS
313# define VIMINFO_FILE "sys$login:.viminfo"
314# else
315# define VIMINFO_FILE "$HOME/.viminfo"
316# endif
317# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318# if !defined(VIMINFO_FILE2) && defined(VMS)
319# define VIMINFO_FILE2 "sys$login:_viminfo"
320# endif
321#endif
322
323#ifndef EXRC_FILE
324# define EXRC_FILE ".exrc"
325#endif
326
327#ifndef VIMRC_FILE
328# define VIMRC_FILE ".vimrc"
329#endif
330
331#ifdef FEAT_GUI
332# ifndef GVIMRC_FILE
333# define GVIMRC_FILE ".gvimrc"
334# endif
335#endif
336
337#ifndef SYNTAX_FNAME
338# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
339#endif
340
341#ifndef DFLT_BDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100342# ifdef VMS
343# define DFLT_BDIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100345# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346# endif
347#endif
348
349#ifndef DFLT_DIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100350# ifdef VMS
351# define DFLT_DIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100353# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354# endif
355#endif
356
357#ifndef DFLT_VDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100358# ifdef VMS
359# define DFLT_VDIR "sys$login:vimfiles/view"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100361# define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362# endif
363#endif
364
365#define DFLT_ERRORFILE "errors.err"
366
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100367#ifdef VMS
368# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100370# ifdef RUNTIME_GLOBAL
371# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100373# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000374# endif
375#endif
376
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100377#ifdef VMS
378# ifndef VAX
379# define VMS_TEMPNAM /* to fix default .LIS extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100381# define TEMPNAME "TMP:v?XXXXXX.txt"
382# define TEMPNAMELEN 28
383#else
384/* Try several directories to put the temp files. */
385# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
386# define TEMPNAMELEN 256
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387#endif
388
389/* Special wildcards that need to be handled by the shell */
390#define SPECIAL_WILDCHAR "`'{"
391
392#ifndef HAVE_OPENDIR
393# define NO_EXPANDPATH
394#endif
395
396/*
397 * Unix has plenty of memory, use large buffers
398 */
399#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
Bram Moolenaar38f12a92008-06-20 16:07:02 +0000400
401/* Use the system path length if it makes sense. */
402#if defined(PATH_MAX) && (PATH_MAX > 1000)
403# define MAXPATHL PATH_MAX
404#else
405# define MAXPATHL 1024
406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407
408#define CHECK_INODE /* used when checking if a swap file already
409 exists for a file */
410#ifdef VMS /* Use less memory because of older systems */
411# ifndef DFLT_MAXMEM
412# define DFLT_MAXMEM (2*1024)
413# endif
414# ifndef DFLT_MAXMEMTOT
415# define DFLT_MAXMEMTOT (5*1024)
416# endif
417#else
418# ifndef DFLT_MAXMEM
419# define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
420# endif
421# ifndef DFLT_MAXMEMTOT
422# define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
423# endif
424#endif
425
426/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
427 * own version */
428/* Some systems have (void *) arguments, some (char *). If we use (char *) it
429 * works for all */
430#ifdef USEMEMMOVE
431# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
432#else
433# ifdef USEBCOPY
434# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
435# else
436# ifdef USEMEMCPY
437# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
438# else
439# define VIM_MEMMOVE /* found in misc2.c */
440# endif
441# endif
442#endif
443
444#ifndef PROTO
445# ifdef HAVE_RENAME
446# define mch_rename(src, dst) rename(src, dst)
447# else
Bram Moolenaard99df422016-01-29 23:20:40 +0100448int mch_rename(const char *src, const char *dest);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000450# ifndef VMS
451# ifdef __MVS__
Bram Moolenaar3d27a452007-05-10 17:44:18 +0000452 /* on OS390 Unix getenv() doesn't return a pointer to persistent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453 * storage -> use __getenv() */
454# define mch_getenv(x) (char_u *)__getenv((char *)(x))
455# else
456# define mch_getenv(x) (char_u *)getenv((char *)(x))
457# endif
458# define mch_setenv(name, val, x) setenv(name, val, x)
459# endif
460#endif
461
462#if !defined(S_ISDIR) && defined(S_IFDIR)
463# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
464#endif
465#if !defined(S_ISREG) && defined(S_IFREG)
466# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
467#endif
468#if !defined(S_ISBLK) && defined(S_IFBLK)
469# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
470#endif
471#if !defined(S_ISSOCK) && defined(S_IFSOCK)
472# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
473#endif
474#if !defined(S_ISFIFO) && defined(S_IFIFO)
475# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
476#endif
Bram Moolenaarfe1c56d2007-07-10 15:10:54 +0000477#if !defined(S_ISCHR) && defined(S_IFCHR)
478# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000480
481/* Note: Some systems need both string.h and strings.h (Savage). However,
482 * some systems can't handle both, only use string.h in that case. */
483#ifdef HAVE_STRING_H
484# include <string.h>
485#endif
486#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
487# include <strings.h>
488#endif
489
490#if defined(HAVE_SETJMP_H)
491# include <setjmp.h>
492# ifdef HAVE_SIGSETJMP
493# define JMP_BUF sigjmp_buf
494# define SETJMP(x) sigsetjmp((x), 1)
495# define LONGJMP siglongjmp
496# else
497# define JMP_BUF jmp_buf
498# define SETJMP(x) setjmp(x)
499# define LONGJMP longjmp
500# endif
501#endif
502
Bram Moolenaarc41053062014-03-25 13:46:26 +0100503#ifndef HAVE_DUP
504# define HAVE_DUP /* have dup() */
505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506#define HAVE_ST_MODE /* have stat.st_mode */
507
508/* We have three kinds of ACL support. */
509#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)