blob: 4504cce063f9bb70b8119697f24783289d0ac5f5 [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
Bram Moolenaarb7604cc2016-01-15 21:23:22 +010078# define __ARGS(x) x
Bram Moolenaar071d4272004-06-13 20:20:40 +000079#endif
80
81/* always use unlink() to remove files */
82#ifndef PROTO
83# ifdef VMS
84# define mch_remove(x) delete((char *)(x))
85# define vim_mkdir(x, y) mkdir((char *)(x), y)
86# ifdef VAX
87# else
88# define mch_rmdir(x) rmdir((char *)(x))
89# endif
90# else
91# define vim_mkdir(x, y) mkdir((char *)(x), y)
92# define mch_rmdir(x) rmdir((char *)(x))
93# define mch_remove(x) unlink((char *)(x))
94# endif
95#endif
96
97/* The number of arguments to a signal handler is configured here. */
98/* It used to be a long list of almost all systems. Any system that doesn't
99 * have an argument??? */
100#define SIGHASARG
101
102/* List 3 arg systems here. I guess __sgi, please test and correct me. jw. */
103#if defined(__sgi) && defined(HAVE_SIGCONTEXT)
104# define SIGHAS3ARGS
105#endif
106
107#ifdef SIGHASARG
108# ifdef SIGHAS3ARGS
109# define SIGPROTOARG (int, int, struct sigcontext *)
110# define SIGDEFARG(s) (s, sig2, scont) int s, sig2; struct sigcontext *scont;
111# define SIGDUMMYARG 0, 0, (struct sigcontext *)0
112# else
113# define SIGPROTOARG (int)
Bram Moolenaar78a15312009-05-15 19:33:18 +0000114# define SIGDEFARG(s) (s) int s UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115# define SIGDUMMYARG 0
116# endif
117#else
118# define SIGPROTOARG (void)
119# define SIGDEFARG(s) ()
120# define SIGDUMMYARG
121#endif
122
123#ifdef HAVE_DIRENT_H
124# include <dirent.h>
125# ifndef NAMLEN
126# define NAMLEN(dirent) strlen((dirent)->d_name)
127# endif
128#else
129# define dirent direct
130# define NAMLEN(dirent) (dirent)->d_namlen
131# if HAVE_SYS_NDIR_H
132# include <sys/ndir.h>
133# endif
134# if HAVE_SYS_DIR_H
135# include <sys/dir.h>
136# endif
137# if HAVE_NDIR_H
138# include <ndir.h>
139# endif
140#endif
141
142#if !defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME)
143# include <time.h> /* on some systems time.h should not be
144 included together with sys/time.h */
145#endif
146#ifdef HAVE_SYS_TIME_H
147# include <sys/time.h>
148#endif
149
150#include <signal.h>
151
152#if defined(DIRSIZ) && !defined(MAXNAMLEN)
153# define MAXNAMLEN DIRSIZ
154#endif
155
156#if defined(UFS_MAXNAMLEN) && !defined(MAXNAMLEN)
157# define MAXNAMLEN UFS_MAXNAMLEN /* for dynix/ptx */
158#endif
159
160#if defined(NAME_MAX) && !defined(MAXNAMLEN)
161# define MAXNAMLEN NAME_MAX /* for Linux before .99p3 */
162#endif
163
164/*
165 * Note: if MAXNAMLEN has the wrong value, you will get error messages
166 * for not being able to open the swap file.
167 */
168#if !defined(MAXNAMLEN)
169# define MAXNAMLEN 512 /* for all other Unix */
170#endif
171
172#define BASENAMELEN (MAXNAMLEN - 5)
173
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174#ifdef HAVE_PWD_H
175# include <pwd.h>
176#endif
177
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178#if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
179 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
180 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
181# define HAVE_TOTAL_MEM
182#endif
183
Bram Moolenaar82881492012-11-20 16:53:39 +0100184
185#ifndef PROTO
186
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187#ifdef VMS
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000188# include <unixio.h>
189# include <unixlib.h>
190# include <signal.h>
191# include <file.h>
192# include <ssdef.h>
193# include <descrip.h>
194# include <libclidef.h>
195# include <lnmdef.h>
196# include <psldef.h>
197# include <prvdef.h>
198# include <dvidef.h>
199# include <dcdef.h>
200# include <stsdef.h>
201# include <iodef.h>
202# include <ttdef.h>
203# include <tt2def.h>
204# include <jpidef.h>
205# include <rms.h>
206# include <trmdef.h>
207# include <string.h>
208# include <starlet.h>
209# include <socket.h>
210# include <lib$routines.h>
Bram Moolenaar4ffa0702013-12-11 17:12:37 +0100211# include <libdef.h>
212# include <libdtdef.h>
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000213
214# ifdef FEAT_GUI_GTK
215# include "gui_gtk_vms.h"
216# endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100217#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218
Bram Moolenaar82881492012-11-20 16:53:39 +0100219#endif /* PROTO */
220
221#ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222typedef struct dsc$descriptor DESC;
223#endif
224
225/*
226 * Unix system-dependent file names
227 */
228#ifndef SYS_VIMRC_FILE
229# define SYS_VIMRC_FILE "$VIM/vimrc"
230#endif
231#ifndef SYS_GVIMRC_FILE
232# define SYS_GVIMRC_FILE "$VIM/gvimrc"
233#endif
234#ifndef DFLT_HELPFILE
235# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
236#endif
237#ifndef FILETYPE_FILE
238# define FILETYPE_FILE "filetype.vim"
239#endif
240#ifndef FTPLUGIN_FILE
241# define FTPLUGIN_FILE "ftplugin.vim"
242#endif
243#ifndef INDENT_FILE
244# define INDENT_FILE "indent.vim"
245#endif
246#ifndef FTOFF_FILE
247# define FTOFF_FILE "ftoff.vim"
248#endif
249#ifndef FTPLUGOF_FILE
250# define FTPLUGOF_FILE "ftplugof.vim"
251#endif
252#ifndef INDOFF_FILE
253# define INDOFF_FILE "indoff.vim"
254#endif
255#ifndef SYS_MENU_FILE
256# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
257#endif
258
259#ifndef USR_EXRC_FILE
260# ifdef VMS
261# define USR_EXRC_FILE "sys$login:.exrc"
262# else
263# define USR_EXRC_FILE "$HOME/.exrc"
264# endif
265#endif
266
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267#if !defined(USR_EXRC_FILE2) && defined(VMS)
268# define USR_EXRC_FILE2 "sys$login:_exrc"
269#endif
270
271#ifndef USR_VIMRC_FILE
272# ifdef VMS
273# define USR_VIMRC_FILE "sys$login:.vimrc"
274# else
275# define USR_VIMRC_FILE "$HOME/.vimrc"
276# endif
277#endif
278
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200279
Bram Moolenaarea98f8b2015-05-04 09:31:11 +0200280#if !defined(USR_VIMRC_FILE2)
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100281# ifdef VMS
282# define USR_VIMRC_FILE2 "sys$login:vimfiles/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200283# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100284# define USR_VIMRC_FILE2 "~/.vim/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200285# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286#endif
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200287
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200288#if !defined(USR_VIMRC_FILE3) && defined(VMS)
289# define USR_VIMRC_FILE3 "sys$login:_vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290#endif
291
292#ifndef USR_GVIMRC_FILE
293# ifdef VMS
294# define USR_GVIMRC_FILE "sys$login:.gvimrc"
295# else
296# define USR_GVIMRC_FILE "$HOME/.gvimrc"
297# endif
298#endif
299
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200300#ifndef USR_GVIMRC_FILE2
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100301# ifdef VMS
302# define USR_GVIMRC_FILE2 "sys$login:vimfiles/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200303# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100304# define USR_GVIMRC_FILE2 "~/.vim/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200305# endif
306#endif
307
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308#ifdef VMS
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200309# ifndef USR_GVIMRC_FILE3
310# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311# endif
312#endif
313
314#ifndef EVIM_FILE
315# define EVIM_FILE "$VIMRUNTIME/evim.vim"
316#endif
317
318#ifdef FEAT_VIMINFO
319# ifndef VIMINFO_FILE
320# ifdef VMS
321# define VIMINFO_FILE "sys$login:.viminfo"
322# else
323# define VIMINFO_FILE "$HOME/.viminfo"
324# endif
325# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326# if !defined(VIMINFO_FILE2) && defined(VMS)
327# define VIMINFO_FILE2 "sys$login:_viminfo"
328# endif
329#endif
330
331#ifndef EXRC_FILE
332# define EXRC_FILE ".exrc"
333#endif
334
335#ifndef VIMRC_FILE
336# define VIMRC_FILE ".vimrc"
337#endif
338
339#ifdef FEAT_GUI
340# ifndef GVIMRC_FILE
341# define GVIMRC_FILE ".gvimrc"
342# endif
343#endif
344
345#ifndef SYNTAX_FNAME
346# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
347#endif
348
349#ifndef DFLT_BDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100350# ifdef VMS
351# define DFLT_BDIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100353# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354# endif
355#endif
356
357#ifndef DFLT_DIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100358# ifdef VMS
359# define DFLT_DIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100361# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362# endif
363#endif
364
365#ifndef DFLT_VDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100366# ifdef VMS
367# define DFLT_VDIR "sys$login:vimfiles/view"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100369# define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370# endif
371#endif
372
373#define DFLT_ERRORFILE "errors.err"
374
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100375#ifdef VMS
376# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100378# ifdef RUNTIME_GLOBAL
379# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100381# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382# endif
383#endif
384
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100385#ifdef VMS
386# ifndef VAX
387# define VMS_TEMPNAM /* to fix default .LIS extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100389# define TEMPNAME "TMP:v?XXXXXX.txt"
390# define TEMPNAMELEN 28
391#else
392/* Try several directories to put the temp files. */
393# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
394# define TEMPNAMELEN 256
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395#endif
396
397/* Special wildcards that need to be handled by the shell */
398#define SPECIAL_WILDCHAR "`'{"
399
400#ifndef HAVE_OPENDIR
401# define NO_EXPANDPATH
402#endif
403
404/*
405 * Unix has plenty of memory, use large buffers
406 */
407#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
Bram Moolenaar38f12a92008-06-20 16:07:02 +0000408
409/* Use the system path length if it makes sense. */
410#if defined(PATH_MAX) && (PATH_MAX > 1000)
411# define MAXPATHL PATH_MAX
412#else
413# define MAXPATHL 1024
414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000415
416#define CHECK_INODE /* used when checking if a swap file already
417 exists for a file */
418#ifdef VMS /* Use less memory because of older systems */
419# ifndef DFLT_MAXMEM
420# define DFLT_MAXMEM (2*1024)
421# endif
422# ifndef DFLT_MAXMEMTOT
423# define DFLT_MAXMEMTOT (5*1024)
424# endif
425#else
426# ifndef DFLT_MAXMEM
427# define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
428# endif
429# ifndef DFLT_MAXMEMTOT
430# define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
431# endif
432#endif
433
434/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
435 * own version */
436/* Some systems have (void *) arguments, some (char *). If we use (char *) it
437 * works for all */
438#ifdef USEMEMMOVE
439# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
440#else
441# ifdef USEBCOPY
442# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
443# else
444# ifdef USEMEMCPY
445# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
446# else
447# define VIM_MEMMOVE /* found in misc2.c */
448# endif
449# endif
450#endif
451
452#ifndef PROTO
453# ifdef HAVE_RENAME
454# define mch_rename(src, dst) rename(src, dst)
455# else
456int mch_rename __ARGS((const char *src, const char *dest));
457# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458# ifndef VMS
459# ifdef __MVS__
Bram Moolenaar3d27a452007-05-10 17:44:18 +0000460 /* on OS390 Unix getenv() doesn't return a pointer to persistent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000461 * storage -> use __getenv() */
462# define mch_getenv(x) (char_u *)__getenv((char *)(x))
463# else
464# define mch_getenv(x) (char_u *)getenv((char *)(x))
465# endif
466# define mch_setenv(name, val, x) setenv(name, val, x)
467# endif
468#endif
469
470#if !defined(S_ISDIR) && defined(S_IFDIR)
471# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
472#endif
473#if !defined(S_ISREG) && defined(S_IFREG)
474# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
475#endif
476#if !defined(S_ISBLK) && defined(S_IFBLK)
477# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
478#endif
479#if !defined(S_ISSOCK) && defined(S_IFSOCK)
480# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
481#endif
482#if !defined(S_ISFIFO) && defined(S_IFIFO)
483# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
484#endif
Bram Moolenaarfe1c56d2007-07-10 15:10:54 +0000485#if !defined(S_ISCHR) && defined(S_IFCHR)
486# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000488
489/* Note: Some systems need both string.h and strings.h (Savage). However,
490 * some systems can't handle both, only use string.h in that case. */
491#ifdef HAVE_STRING_H
492# include <string.h>
493#endif
494#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
495# include <strings.h>
496#endif
497
498#if defined(HAVE_SETJMP_H)
499# include <setjmp.h>
500# ifdef HAVE_SIGSETJMP
501# define JMP_BUF sigjmp_buf
502# define SETJMP(x) sigsetjmp((x), 1)
503# define LONGJMP siglongjmp
504# else
505# define JMP_BUF jmp_buf
506# define SETJMP(x) setjmp(x)
507# define LONGJMP longjmp
508# endif
509#endif
510
Bram Moolenaarc41053062014-03-25 13:46:26 +0100511#ifndef HAVE_DUP
512# define HAVE_DUP /* have dup() */
513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514#define HAVE_ST_MODE /* have stat.st_mode */
515
516/* We have three kinds of ACL support. */
517#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)