blob: 0dd75cf7f3f25874669a1c55415bbba98ac89a9b [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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000277#if !defined(USR_EXRC_FILE2) && defined(VMS)
278# define USR_EXRC_FILE2 "sys$login:_exrc"
279#endif
280
281#ifndef USR_VIMRC_FILE
282# ifdef VMS
283# define USR_VIMRC_FILE "sys$login:.vimrc"
284# else
285# define USR_VIMRC_FILE "$HOME/.vimrc"
286# endif
287#endif
288
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200289
Bram Moolenaarea98f8b2015-05-04 09:31:11 +0200290#if !defined(USR_VIMRC_FILE2)
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100291# ifdef VMS
292# define USR_VIMRC_FILE2 "sys$login:vimfiles/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200293# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100294# define USR_VIMRC_FILE2 "~/.vim/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200295# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000296#endif
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200297
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200298#if !defined(USR_VIMRC_FILE3) && defined(VMS)
299# define USR_VIMRC_FILE3 "sys$login:_vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300#endif
301
302#ifndef USR_GVIMRC_FILE
303# ifdef VMS
304# define USR_GVIMRC_FILE "sys$login:.gvimrc"
305# else
306# define USR_GVIMRC_FILE "$HOME/.gvimrc"
307# endif
308#endif
309
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200310#ifndef USR_GVIMRC_FILE2
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100311# ifdef VMS
312# define USR_GVIMRC_FILE2 "sys$login:vimfiles/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200313# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100314# define USR_GVIMRC_FILE2 "~/.vim/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200315# endif
316#endif
317
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318#ifdef VMS
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200319# ifndef USR_GVIMRC_FILE3
320# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321# endif
322#endif
323
324#ifndef EVIM_FILE
325# define EVIM_FILE "$VIMRUNTIME/evim.vim"
326#endif
327
328#ifdef FEAT_VIMINFO
329# ifndef VIMINFO_FILE
330# ifdef VMS
331# define VIMINFO_FILE "sys$login:.viminfo"
332# else
333# define VIMINFO_FILE "$HOME/.viminfo"
334# endif
335# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000336# if !defined(VIMINFO_FILE2) && defined(VMS)
337# define VIMINFO_FILE2 "sys$login:_viminfo"
338# endif
339#endif
340
341#ifndef EXRC_FILE
342# define EXRC_FILE ".exrc"
343#endif
344
345#ifndef VIMRC_FILE
346# define VIMRC_FILE ".vimrc"
347#endif
348
349#ifdef FEAT_GUI
350# ifndef GVIMRC_FILE
351# define GVIMRC_FILE ".gvimrc"
352# endif
353#endif
354
355#ifndef SYNTAX_FNAME
356# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
357#endif
358
359#ifndef DFLT_BDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100360# ifdef VMS
361# define DFLT_BDIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100363# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364# endif
365#endif
366
367#ifndef DFLT_DIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100368# ifdef VMS
369# define DFLT_DIR "./,sys$login:,tmp:"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100371# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372# endif
373#endif
374
375#ifndef DFLT_VDIR
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100376# ifdef VMS
377# define DFLT_VDIR "sys$login:vimfiles/view"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100379# define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380# endif
381#endif
382
383#define DFLT_ERRORFILE "errors.err"
384
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100385#ifdef VMS
386# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100388# ifdef RUNTIME_GLOBAL
389# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100391# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392# endif
393#endif
394
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100395#ifdef VMS
396# ifndef VAX
397# define VMS_TEMPNAM /* to fix default .LIS extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100399# define TEMPNAME "TMP:v?XXXXXX.txt"
400# define TEMPNAMELEN 28
401#else
402/* Try several directories to put the temp files. */
403# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
404# define TEMPNAMELEN 256
Bram Moolenaar071d4272004-06-13 20:20:40 +0000405#endif
406
407/* Special wildcards that need to be handled by the shell */
408#define SPECIAL_WILDCHAR "`'{"
409
410#ifndef HAVE_OPENDIR
411# define NO_EXPANDPATH
412#endif
413
414/*
415 * Unix has plenty of memory, use large buffers
416 */
417#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
Bram Moolenaar38f12a92008-06-20 16:07:02 +0000418
419/* Use the system path length if it makes sense. */
420#if defined(PATH_MAX) && (PATH_MAX > 1000)
421# define MAXPATHL PATH_MAX
422#else
423# define MAXPATHL 1024
424#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425
426#define CHECK_INODE /* used when checking if a swap file already
427 exists for a file */
428#ifdef VMS /* Use less memory because of older systems */
429# ifndef DFLT_MAXMEM
430# define DFLT_MAXMEM (2*1024)
431# endif
432# ifndef DFLT_MAXMEMTOT
433# define DFLT_MAXMEMTOT (5*1024)
434# endif
435#else
436# ifndef DFLT_MAXMEM
437# define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
438# endif
439# ifndef DFLT_MAXMEMTOT
440# define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
441# endif
442#endif
443
444/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
445 * own version */
446/* Some systems have (void *) arguments, some (char *). If we use (char *) it
447 * works for all */
448#ifdef USEMEMMOVE
449# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
450#else
451# ifdef USEBCOPY
452# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
453# else
454# ifdef USEMEMCPY
455# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
456# else
457# define VIM_MEMMOVE /* found in misc2.c */
458# endif
459# endif
460#endif
461
462#ifndef PROTO
463# ifdef HAVE_RENAME
464# define mch_rename(src, dst) rename(src, dst)
465# else
466int mch_rename __ARGS((const char *src, const char *dest));
467# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468# ifndef VMS
469# ifdef __MVS__
Bram Moolenaar3d27a452007-05-10 17:44:18 +0000470 /* on OS390 Unix getenv() doesn't return a pointer to persistent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000471 * storage -> use __getenv() */
472# define mch_getenv(x) (char_u *)__getenv((char *)(x))
473# else
474# define mch_getenv(x) (char_u *)getenv((char *)(x))
475# endif
476# define mch_setenv(name, val, x) setenv(name, val, x)
477# endif
478#endif
479
480#if !defined(S_ISDIR) && defined(S_IFDIR)
481# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
482#endif
483#if !defined(S_ISREG) && defined(S_IFREG)
484# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
485#endif
486#if !defined(S_ISBLK) && defined(S_IFBLK)
487# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
488#endif
489#if !defined(S_ISSOCK) && defined(S_IFSOCK)
490# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
491#endif
492#if !defined(S_ISFIFO) && defined(S_IFIFO)
493# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
494#endif
Bram Moolenaarfe1c56d2007-07-10 15:10:54 +0000495#if !defined(S_ISCHR) && defined(S_IFCHR)
496# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
497#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498
499/* Note: Some systems need both string.h and strings.h (Savage). However,
500 * some systems can't handle both, only use string.h in that case. */
501#ifdef HAVE_STRING_H
502# include <string.h>
503#endif
504#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
505# include <strings.h>
506#endif
507
508#if defined(HAVE_SETJMP_H)
509# include <setjmp.h>
510# ifdef HAVE_SIGSETJMP
511# define JMP_BUF sigjmp_buf
512# define SETJMP(x) sigsetjmp((x), 1)
513# define LONGJMP siglongjmp
514# else
515# define JMP_BUF jmp_buf
516# define SETJMP(x) setjmp(x)
517# define LONGJMP longjmp
518# endif
519#endif
520
Bram Moolenaarc41053062014-03-25 13:46:26 +0100521#ifndef HAVE_DUP
522# define HAVE_DUP /* have dup() */
523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524#define HAVE_ST_MODE /* have stat.st_mode */
525
526/* We have three kinds of ACL support. */
527#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)