blob: 73881afa2c6b695aadfc97453535350772b4a431 [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
Bram Moolenaar071d4272004-06-13 20:20:40 +000077/* always use unlink() to remove files */
78#ifndef PROTO
79# ifdef VMS
80# define mch_remove(x) delete((char *)(x))
81# define vim_mkdir(x, y) mkdir((char *)(x), y)
82# ifdef VAX
83# else
84# define mch_rmdir(x) rmdir((char *)(x))
85# endif
86# else
87# define vim_mkdir(x, y) mkdir((char *)(x), y)
88# define mch_rmdir(x) rmdir((char *)(x))
89# define mch_remove(x) unlink((char *)(x))
90# endif
91#endif
92
93/* The number of arguments to a signal handler is configured here. */
94/* It used to be a long list of almost all systems. Any system that doesn't
95 * have an argument??? */
96#define SIGHASARG
97
98/* List 3 arg systems here. I guess __sgi, please test and correct me. jw. */
99#if defined(__sgi) && defined(HAVE_SIGCONTEXT)
100# define SIGHAS3ARGS
101#endif
102
103#ifdef SIGHASARG
104# ifdef SIGHAS3ARGS
105# define SIGPROTOARG (int, int, struct sigcontext *)
106# define SIGDEFARG(s) (s, sig2, scont) int s, sig2; struct sigcontext *scont;
107# define SIGDUMMYARG 0, 0, (struct sigcontext *)0
108# else
109# define SIGPROTOARG (int)
Bram Moolenaar78a15312009-05-15 19:33:18 +0000110# define SIGDEFARG(s) (s) int s UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111# define SIGDUMMYARG 0
112# endif
113#else
114# define SIGPROTOARG (void)
115# define SIGDEFARG(s) ()
116# define SIGDUMMYARG
117#endif
118
119#ifdef HAVE_DIRENT_H
120# include <dirent.h>
121# ifndef NAMLEN
122# define NAMLEN(dirent) strlen((dirent)->d_name)
123# endif
124#else
125# define dirent direct
126# define NAMLEN(dirent) (dirent)->d_namlen
127# if HAVE_SYS_NDIR_H
128# include <sys/ndir.h>
129# endif
130# if HAVE_SYS_DIR_H
131# include <sys/dir.h>
132# endif
133# if HAVE_NDIR_H
134# include <ndir.h>
135# endif
136#endif
137
138#if !defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME)
139# include <time.h> /* on some systems time.h should not be
140 included together with sys/time.h */
141#endif
142#ifdef HAVE_SYS_TIME_H
143# include <sys/time.h>
144#endif
145
146#include <signal.h>
147
148#if defined(DIRSIZ) && !defined(MAXNAMLEN)
149# define MAXNAMLEN DIRSIZ
150#endif
151
152#if defined(UFS_MAXNAMLEN) && !defined(MAXNAMLEN)
153# define MAXNAMLEN UFS_MAXNAMLEN /* for dynix/ptx */
154#endif
155
156#if defined(NAME_MAX) && !defined(MAXNAMLEN)
157# define MAXNAMLEN NAME_MAX /* for Linux before .99p3 */
158#endif
159
160/*
161 * Note: if MAXNAMLEN has the wrong value, you will get error messages
162 * for not being able to open the swap file.
163 */
164#if !defined(MAXNAMLEN)
165# define MAXNAMLEN 512 /* for all other Unix */
166#endif
167
168#define BASENAMELEN (MAXNAMLEN - 5)
169
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170#ifdef HAVE_PWD_H
171# include <pwd.h>
172#endif
173
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174#if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
175 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
176 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
177# define HAVE_TOTAL_MEM
178#endif
179
Bram Moolenaar82881492012-11-20 16:53:39 +0100180
181#ifndef PROTO
182
Bram Moolenaar071d4272004-06-13 20:20:40 +0000183#ifdef VMS
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000184# include <unixio.h>
185# include <unixlib.h>
186# include <signal.h>
187# include <file.h>
188# include <ssdef.h>
189# include <descrip.h>
190# include <libclidef.h>
191# include <lnmdef.h>
192# include <psldef.h>
193# include <prvdef.h>
194# include <dvidef.h>
195# include <dcdef.h>
196# include <stsdef.h>
197# include <iodef.h>
198# include <ttdef.h>
199# include <tt2def.h>
200# include <jpidef.h>
201# include <rms.h>
202# include <trmdef.h>
203# include <string.h>
204# include <starlet.h>
205# include <socket.h>
206# include <lib$routines.h>
Bram Moolenaar4ffa0702013-12-11 17:12:37 +0100207# include <libdef.h>
208# include <libdtdef.h>
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000209
210# ifdef FEAT_GUI_GTK
211# include "gui_gtk_vms.h"
212# endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100213#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214
Bram Moolenaar82881492012-11-20 16:53:39 +0100215#endif /* PROTO */
216
217#ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218typedef struct dsc$descriptor DESC;
219#endif
220
221/*
222 * Unix system-dependent file names
223 */
224#ifndef SYS_VIMRC_FILE
225# define SYS_VIMRC_FILE "$VIM/vimrc"
226#endif
227#ifndef SYS_GVIMRC_FILE
228# define SYS_GVIMRC_FILE "$VIM/gvimrc"
229#endif
230#ifndef DFLT_HELPFILE
231# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
232#endif
233#ifndef FILETYPE_FILE
234# define FILETYPE_FILE "filetype.vim"
235#endif
236#ifndef FTPLUGIN_FILE
237# define FTPLUGIN_FILE "ftplugin.vim"
238#endif
239#ifndef INDENT_FILE
240# define INDENT_FILE "indent.vim"
241#endif
242#ifndef FTOFF_FILE
243# define FTOFF_FILE "ftoff.vim"
244#endif
245#ifndef FTPLUGOF_FILE
246# define FTPLUGOF_FILE "ftplugof.vim"
247#endif
248#ifndef INDOFF_FILE
249# define INDOFF_FILE "indoff.vim"
250#endif
251#ifndef SYS_MENU_FILE
252# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
253#endif
254
255#ifndef USR_EXRC_FILE
256# ifdef VMS
257# define USR_EXRC_FILE "sys$login:.exrc"
258# else
259# define USR_EXRC_FILE "$HOME/.exrc"
260# endif
261#endif
262
Bram Moolenaar071d4272004-06-13 20:20:40 +0000263#if !defined(USR_EXRC_FILE2) && defined(VMS)
264# define USR_EXRC_FILE2 "sys$login:_exrc"
265#endif
266
267#ifndef USR_VIMRC_FILE
268# ifdef VMS
269# define USR_VIMRC_FILE "sys$login:.vimrc"
270# else
271# define USR_VIMRC_FILE "$HOME/.vimrc"
272# endif
273#endif
274
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200275
Bram Moolenaarea98f8b2015-05-04 09:31:11 +0200276#if !defined(USR_VIMRC_FILE2)
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100277# ifdef VMS
278# define USR_VIMRC_FILE2 "sys$login:vimfiles/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200279# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100280# define USR_VIMRC_FILE2 "~/.vim/vimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200281# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282#endif
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200283
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200284#if !defined(USR_VIMRC_FILE3) && defined(VMS)
285# define USR_VIMRC_FILE3 "sys$login:_vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286#endif
287
288#ifndef USR_GVIMRC_FILE
289# ifdef VMS
290# define USR_GVIMRC_FILE "sys$login:.gvimrc"
291# else
292# define USR_GVIMRC_FILE "$HOME/.gvimrc"
293# endif
294#endif
295
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200296#ifndef USR_GVIMRC_FILE2
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100297# ifdef VMS
298# define USR_GVIMRC_FILE2 "sys$login:vimfiles/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200299# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100300# define USR_GVIMRC_FILE2 "~/.vim/gvimrc"
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200301# endif
302#endif
303
Bram Moolenaar071d4272004-06-13 20:20:40 +0000304#ifdef VMS
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200305# ifndef USR_GVIMRC_FILE3
306# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307# endif
308#endif
309
310#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)