blob: c1458d66e6cfe2718a577de9e1509f36022008f3 [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
56# include <unistd.h>
57#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/*
68 * Sun defines FILE on SunOS 4.x.x, Solaris has a typedef for FILE
69 */
70#if defined(sun) && !defined(FILE)
71# define SOLARIS
72#endif
73
74/*
75 * Using getcwd() is preferred, because it checks for a buffer overflow.
76 * Don't use getcwd() on systems do use system("sh -c pwd"). There is an
77 * autoconf check for this.
78 * Use getcwd() anyway if getwd() isn't present.
79 */
80#if defined(HAVE_GETCWD) && !(defined(BAD_GETCWD) && defined(HAVE_GETWD))
81# define USE_GETCWD
82#endif
83
84#ifndef __ARGS
85 /* The AIX VisualAge cc compiler defines __EXTENDED__ instead of __STDC__
86 * because it includes pre-ansi features. */
87# if defined(__STDC__) || defined(__GNUC__) || defined(__EXTENDED__)
88# define __ARGS(x) x
89# else
90# define __ARGS(x) ()
91# endif
92#endif
93
94/* always use unlink() to remove files */
95#ifndef PROTO
96# ifdef VMS
97# define mch_remove(x) delete((char *)(x))
98# define vim_mkdir(x, y) mkdir((char *)(x), y)
99# ifdef VAX
100# else
101# define mch_rmdir(x) rmdir((char *)(x))
102# endif
103# else
104# define vim_mkdir(x, y) mkdir((char *)(x), y)
105# define mch_rmdir(x) rmdir((char *)(x))
106# define mch_remove(x) unlink((char *)(x))
107# endif
108#endif
109
110/* The number of arguments to a signal handler is configured here. */
111/* It used to be a long list of almost all systems. Any system that doesn't
112 * have an argument??? */
113#define SIGHASARG
114
115/* List 3 arg systems here. I guess __sgi, please test and correct me. jw. */
116#if defined(__sgi) && defined(HAVE_SIGCONTEXT)
117# define SIGHAS3ARGS
118#endif
119
120#ifdef SIGHASARG
121# ifdef SIGHAS3ARGS
122# define SIGPROTOARG (int, int, struct sigcontext *)
123# define SIGDEFARG(s) (s, sig2, scont) int s, sig2; struct sigcontext *scont;
124# define SIGDUMMYARG 0, 0, (struct sigcontext *)0
125# else
126# define SIGPROTOARG (int)
127# define SIGDEFARG(s) (s) int s;
128# define SIGDUMMYARG 0
129# endif
130#else
131# define SIGPROTOARG (void)
132# define SIGDEFARG(s) ()
133# define SIGDUMMYARG
134#endif
135
136#ifdef HAVE_DIRENT_H
137# include <dirent.h>
138# ifndef NAMLEN
139# define NAMLEN(dirent) strlen((dirent)->d_name)
140# endif
141#else
142# define dirent direct
143# define NAMLEN(dirent) (dirent)->d_namlen
144# if HAVE_SYS_NDIR_H
145# include <sys/ndir.h>
146# endif
147# if HAVE_SYS_DIR_H
148# include <sys/dir.h>
149# endif
150# if HAVE_NDIR_H
151# include <ndir.h>
152# endif
153#endif
154
155#if !defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME)
156# include <time.h> /* on some systems time.h should not be
157 included together with sys/time.h */
158#endif
159#ifdef HAVE_SYS_TIME_H
160# include <sys/time.h>
161#endif
162
163#include <signal.h>
164
165#if defined(DIRSIZ) && !defined(MAXNAMLEN)
166# define MAXNAMLEN DIRSIZ
167#endif
168
169#if defined(UFS_MAXNAMLEN) && !defined(MAXNAMLEN)
170# define MAXNAMLEN UFS_MAXNAMLEN /* for dynix/ptx */
171#endif
172
173#if defined(NAME_MAX) && !defined(MAXNAMLEN)
174# define MAXNAMLEN NAME_MAX /* for Linux before .99p3 */
175#endif
176
177/*
178 * Note: if MAXNAMLEN has the wrong value, you will get error messages
179 * for not being able to open the swap file.
180 */
181#if !defined(MAXNAMLEN)
182# define MAXNAMLEN 512 /* for all other Unix */
183#endif
184
185#define BASENAMELEN (MAXNAMLEN - 5)
186
187#ifdef HAVE_ERRNO_H
188# include <errno.h>
189#endif
190
191#ifdef HAVE_PWD_H
192# include <pwd.h>
193#endif
194
195#ifdef __COHERENT__
196# undef __ARGS
197#endif
198
199#if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
200 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
201 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
202# define HAVE_TOTAL_MEM
203#endif
204
205#ifdef VMS
206#include <unixio.h>
207#include <unixlib.h>
208#include <signal.h>
209#include <file.h>
210#include <ssdef.h>
211#include <descrip.h>
212#include <libclidef.h>
213#include <lnmdef.h>
214#include <psldef.h>
215#include <prvdef.h>
216#include <dvidef.h>
217#include <dcdef.h>
218#include <stsdef.h>
219#include <iodef.h>
220#include <ttdef.h>
221#include <tt2def.h>
222#include <jpidef.h>
223#include <rms.h>
224#include <trmdef.h>
225#include <string.h>
226#include <starlet.h>
227#include <socket.h>
228#include <lib$routines.h>
229
230typedef struct dsc$descriptor DESC;
231#endif
232
233/*
234 * Unix system-dependent file names
235 */
236#ifndef SYS_VIMRC_FILE
237# define SYS_VIMRC_FILE "$VIM/vimrc"
238#endif
239#ifndef SYS_GVIMRC_FILE
240# define SYS_GVIMRC_FILE "$VIM/gvimrc"
241#endif
242#ifndef DFLT_HELPFILE
243# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
244#endif
245#ifndef FILETYPE_FILE
246# define FILETYPE_FILE "filetype.vim"
247#endif
248#ifndef FTPLUGIN_FILE
249# define FTPLUGIN_FILE "ftplugin.vim"
250#endif
251#ifndef INDENT_FILE
252# define INDENT_FILE "indent.vim"
253#endif
254#ifndef FTOFF_FILE
255# define FTOFF_FILE "ftoff.vim"
256#endif
257#ifndef FTPLUGOF_FILE
258# define FTPLUGOF_FILE "ftplugof.vim"
259#endif
260#ifndef INDOFF_FILE
261# define INDOFF_FILE "indoff.vim"
262#endif
263#ifndef SYS_MENU_FILE
264# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
265#endif
266
267#ifndef USR_EXRC_FILE
268# ifdef VMS
269# define USR_EXRC_FILE "sys$login:.exrc"
270# else
271# define USR_EXRC_FILE "$HOME/.exrc"
272# endif
273#endif
274
275#if !defined(USR_EXRC_FILE2) && defined(OS2)
276# define USR_EXRC_FILE2 "$VIM/.exrc"
277#endif
278#if !defined(USR_EXRC_FILE2) && defined(VMS)
279# define USR_EXRC_FILE2 "sys$login:_exrc"
280#endif
281
282#ifndef USR_VIMRC_FILE
283# ifdef VMS
284# define USR_VIMRC_FILE "sys$login:.vimrc"
285# else
286# define USR_VIMRC_FILE "$HOME/.vimrc"
287# endif
288#endif
289
290#if !defined(USR_VIMRC_FILE2) && defined(OS2)
291# define USR_VIMRC_FILE2 "$VIM/.vimrc"
292#endif
293#if !defined(USR_VIMRC_FILE2) && defined(VMS)
294# define USR_VIMRC_FILE2 "sys$login:_vimrc"
295#endif
296
297#ifndef USR_GVIMRC_FILE
298# ifdef VMS
299# define USR_GVIMRC_FILE "sys$login:.gvimrc"
300# else
301# define USR_GVIMRC_FILE "$HOME/.gvimrc"
302# endif
303#endif
304
305#ifdef VMS
306# ifndef USR_GVIMRC_FILE2
307# define USR_GVIMRC_FILE2 "sys$login:_gvimrc"
308# endif
309#endif
310
311#ifndef EVIM_FILE
312# define EVIM_FILE "$VIMRUNTIME/evim.vim"
313#endif
314
315#ifdef FEAT_VIMINFO
316# ifndef VIMINFO_FILE
317# ifdef VMS
318# define VIMINFO_FILE "sys$login:.viminfo"
319# else
320# define VIMINFO_FILE "$HOME/.viminfo"
321# endif
322# endif
323# if !defined(VIMINFO_FILE2) && defined(OS2)
324# define VIMINFO_FILE2 "$VIM/.viminfo"
325# endif
326# 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
350# ifdef OS2
351# define DFLT_BDIR ".,c:/tmp,~/tmp,~/"
352# else
353# ifdef VMS
354# define DFLT_BDIR "./,sys$login:,tmp:"
355# else
356# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
357# endif
358# endif
359#endif
360
361#ifndef DFLT_DIR
362# ifdef OS2
363# define DFLT_DIR ".,~/tmp,c:/tmp,/tmp"
364# else
365# ifdef VMS
366# define DFLT_DIR "./,sys$login:,tmp:"
367# else
368# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
369# endif
370# endif
371#endif
372
373#ifndef DFLT_VDIR
374# ifdef OS2
375# define DFLT_VDIR "$VIM/vimfiles/view"
376# else
377# ifdef VMS
378# define DFLT_VDIR "sys$login:vimfiles/view"
379# else
380# define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
381# endif
382# endif
383#endif
384
385#define DFLT_ERRORFILE "errors.err"
386
387#ifdef OS2
388# define DFLT_RUNTIMEPATH "$HOME/vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/vimfiles/after"
389#else
390# ifdef VMS
391# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
392# else
393# ifdef RUNTIME_GLOBAL
394# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
395# else
396# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
397# endif
398# endif
399#endif
400
401#ifdef OS2
402/*
403 * Try several directories to put the temp files.
404 */
405# define TEMPDIRNAMES "$TMP", "$TEMP", "c:\\TMP", "c:\\TEMP", ""
406# define TEMPNAMELEN 128
407#else
408# ifdef VMS
409# ifndef VAX
410# define VMS_TEMPNAM /* to fix default .LIS extension */
411# endif
412# define TEMPNAME "TMP:v?XXXXXX.txt"
413# define TEMPNAMELEN 28
414# else
415# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
416# define TEMPNAMELEN 256
417# endif
418#endif
419
420/* Special wildcards that need to be handled by the shell */
421#define SPECIAL_WILDCHAR "`'{"
422
423#ifndef HAVE_OPENDIR
424# define NO_EXPANDPATH
425#endif
426
427/*
428 * Unix has plenty of memory, use large buffers
429 */
430#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
431#define MAXPATHL 1024 /* Unix has long paths and plenty of memory */
432
433#define CHECK_INODE /* used when checking if a swap file already
434 exists for a file */
435#ifdef VMS /* Use less memory because of older systems */
436# ifndef DFLT_MAXMEM
437# define DFLT_MAXMEM (2*1024)
438# endif
439# ifndef DFLT_MAXMEMTOT
440# define DFLT_MAXMEMTOT (5*1024)
441# endif
442#else
443# ifndef DFLT_MAXMEM
444# define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
445# endif
446# ifndef DFLT_MAXMEMTOT
447# define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
448# endif
449#endif
450
451/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
452 * own version */
453/* Some systems have (void *) arguments, some (char *). If we use (char *) it
454 * works for all */
455#ifdef USEMEMMOVE
456# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
457#else
458# ifdef USEBCOPY
459# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
460# else
461# ifdef USEMEMCPY
462# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
463# else
464# define VIM_MEMMOVE /* found in misc2.c */
465# endif
466# endif
467#endif
468
469#ifndef PROTO
470# ifdef HAVE_RENAME
471# define mch_rename(src, dst) rename(src, dst)
472# else
473int mch_rename __ARGS((const char *src, const char *dest));
474# endif
475# ifdef VMS
476# define mch_chdir(s) chdir(vms_fixfilename(s))
477# else
478# define mch_chdir(s) chdir(s)
479# endif
480# ifndef VMS
481# ifdef __MVS__
482 /* on OS390 Unix getenv() doesn't return a pointer to persistant
483 * storage -> use __getenv() */
484# define mch_getenv(x) (char_u *)__getenv((char *)(x))
485# else
486# define mch_getenv(x) (char_u *)getenv((char *)(x))
487# endif
488# define mch_setenv(name, val, x) setenv(name, val, x)
489# endif
490#endif
491
492#if !defined(S_ISDIR) && defined(S_IFDIR)
493# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
494#endif
495#if !defined(S_ISREG) && defined(S_IFREG)
496# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
497#endif
498#if !defined(S_ISBLK) && defined(S_IFBLK)
499# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
500#endif
501#if !defined(S_ISSOCK) && defined(S_IFSOCK)
502# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
503#endif
504#if !defined(S_ISFIFO) && defined(S_IFIFO)
505# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
506#endif
507
508/* Note: Some systems need both string.h and strings.h (Savage). However,
509 * some systems can't handle both, only use string.h in that case. */
510#ifdef HAVE_STRING_H
511# include <string.h>
512#endif
513#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
514# include <strings.h>
515#endif
516
517#if defined(HAVE_SETJMP_H)
518# include <setjmp.h>
519# ifdef HAVE_SIGSETJMP
520# define JMP_BUF sigjmp_buf
521# define SETJMP(x) sigsetjmp((x), 1)
522# define LONGJMP siglongjmp
523# else
524# define JMP_BUF jmp_buf
525# define SETJMP(x) setjmp(x)
526# define LONGJMP longjmp
527# endif
528#endif
529
530#define HAVE_DUP /* have dup() */
531#define HAVE_ST_MODE /* have stat.st_mode */
532
533/* We have three kinds of ACL support. */
534#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)