blob: 4b3a3f10d2bf55e810205a7b46ea06fcc27974ea [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
Bram Moolenaar8c08b5b2016-07-28 22:24:15 +0200306#ifndef VIM_DEFAULTS_FILE
307# define VIM_DEFAULTS_FILE "$VIMRUNTIME/defaults.vim"
308#endif
309
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310#ifndef EVIM_FILE
311# define EVIM_FILE "$VIMRUNTIME/evim.vim"
312#endif
313
314#ifdef FEAT_VIMINFO
315# ifndef VIMINFO_FILE
316# ifdef VMS
317# define VIMINFO_FILE "sys$login:.viminfo"
318# else
319# define VIMINFO_FILE "$HOME/.viminfo"
320# endif
321# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322# if !defined(VIMINFO_FILE2) && defined(VMS)
323# define VIMINFO_FILE2 "sys$login:_viminfo"
324# endif
325#endif
326
327#ifndef EXRC_FILE
328# define EXRC_FILE ".exrc"
329#endif
330
331#ifndef VIMRC_FILE
332# define VIMRC_FILE ".vimrc"
333#endif
334
335#ifdef FEAT_GUI
336# ifndef GVIMRC_FILE
337# define GVIMRC_FILE ".gvimrc"
338# endif
339#endif
340
341#ifndef SYNTAX_FNAME
342# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
343#endif
344
345#ifndef DFLT_BDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100346# ifdef VMS
347# define DFLT_BDIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100349# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350# endif
351#endif
352
353#ifndef DFLT_DIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100354# ifdef VMS
355# define DFLT_DIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100357# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358# endif
359#endif
360
361#ifndef DFLT_VDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100362# ifdef VMS
363# define DFLT_VDIR "sys$login:vimfiles/view"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100365# define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366# endif
367#endif
368
369#define DFLT_ERRORFILE "errors.err"
370
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100371#ifdef VMS
372# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100374# ifdef RUNTIME_GLOBAL
375# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100377# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378# endif
379#endif
380
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100381#ifdef VMS
382# ifndef VAX
383# define VMS_TEMPNAM /* to fix default .LIS extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000384# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100385# define TEMPNAME "TMP:v?XXXXXX.txt"
386# define TEMPNAMELEN 28
387#else
388/* Try several directories to put the temp files. */
389# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
390# define TEMPNAMELEN 256
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391#endif
392
393/* Special wildcards that need to be handled by the shell */
394#define SPECIAL_WILDCHAR "`'{"
395
396#ifndef HAVE_OPENDIR
397# define NO_EXPANDPATH
398#endif
399
400/*
401 * Unix has plenty of memory, use large buffers
402 */
403#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
Bram Moolenaar38f12a92008-06-20 16:07:02 +0000404
405/* Use the system path length if it makes sense. */
406#if defined(PATH_MAX) && (PATH_MAX > 1000)
407# define MAXPATHL PATH_MAX
408#else
409# define MAXPATHL 1024
410#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411
412#define CHECK_INODE /* used when checking if a swap file already
413 exists for a file */
414#ifdef VMS /* Use less memory because of older systems */
415# ifndef DFLT_MAXMEM
416# define DFLT_MAXMEM (2*1024)
417# endif
418# ifndef DFLT_MAXMEMTOT
419# define DFLT_MAXMEMTOT (5*1024)
420# endif
421#else
422# ifndef DFLT_MAXMEM
423# define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
424# endif
425# ifndef DFLT_MAXMEMTOT
426# define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
427# endif
428#endif
429
430/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
431 * own version */
432/* Some systems have (void *) arguments, some (char *). If we use (char *) it
433 * works for all */
434#ifdef USEMEMMOVE
435# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
436#else
437# ifdef USEBCOPY
438# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
439# else
440# ifdef USEMEMCPY
441# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
442# else
443# define VIM_MEMMOVE /* found in misc2.c */
444# endif
445# endif
446#endif
447
448#ifndef PROTO
449# ifdef HAVE_RENAME
450# define mch_rename(src, dst) rename(src, dst)
451# else
Bram Moolenaard99df422016-01-29 23:20:40 +0100452int mch_rename(const char *src, const char *dest);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454# ifndef VMS
455# ifdef __MVS__
Bram Moolenaar3d27a452007-05-10 17:44:18 +0000456 /* on OS390 Unix getenv() doesn't return a pointer to persistent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457 * storage -> use __getenv() */
458# define mch_getenv(x) (char_u *)__getenv((char *)(x))
459# else
460# define mch_getenv(x) (char_u *)getenv((char *)(x))
461# endif
462# define mch_setenv(name, val, x) setenv(name, val, x)
463# endif
464#endif
465
466#if !defined(S_ISDIR) && defined(S_IFDIR)
467# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
468#endif
469#if !defined(S_ISREG) && defined(S_IFREG)
470# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
471#endif
472#if !defined(S_ISBLK) && defined(S_IFBLK)
473# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
474#endif
475#if !defined(S_ISSOCK) && defined(S_IFSOCK)
476# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
477#endif
478#if !defined(S_ISFIFO) && defined(S_IFIFO)
479# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
480#endif
Bram Moolenaarfe1c56d2007-07-10 15:10:54 +0000481#if !defined(S_ISCHR) && defined(S_IFCHR)
482# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000484
485/* Note: Some systems need both string.h and strings.h (Savage). However,
486 * some systems can't handle both, only use string.h in that case. */
487#ifdef HAVE_STRING_H
488# include <string.h>
489#endif
490#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
491# include <strings.h>
492#endif
493
494#if defined(HAVE_SETJMP_H)
495# include <setjmp.h>
496# ifdef HAVE_SIGSETJMP
497# define JMP_BUF sigjmp_buf
498# define SETJMP(x) sigsetjmp((x), 1)
499# define LONGJMP siglongjmp
500# else
501# define JMP_BUF jmp_buf
502# define SETJMP(x) setjmp(x)
503# define LONGJMP longjmp
504# endif
505#endif
506
Bram Moolenaarc41053062014-03-25 13:46:26 +0100507#ifndef HAVE_DUP
508# define HAVE_DUP /* have dup() */
509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510#define HAVE_ST_MODE /* have stat.st_mode */
511
512/* We have three kinds of ACL support. */
513#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)