blob: 44c331cb84d47f26f1f720ee1ce156d61dcfe416 [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/*
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)
Bram Moolenaar78a15312009-05-15 19:33:18 +0000127# define SIGDEFARG(s) (s) int s UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128# 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187#ifdef HAVE_PWD_H
188# include <pwd.h>
189#endif
190
191#ifdef __COHERENT__
192# undef __ARGS
193#endif
194
195#if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
196 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
197 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
198# define HAVE_TOTAL_MEM
199#endif
200
Bram Moolenaar82881492012-11-20 16:53:39 +0100201
202#ifndef PROTO
203
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204#ifdef VMS
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000205# include <unixio.h>
206# include <unixlib.h>
207# include <signal.h>
208# include <file.h>
209# include <ssdef.h>
210# include <descrip.h>
211# include <libclidef.h>
212# include <lnmdef.h>
213# include <psldef.h>
214# include <prvdef.h>
215# include <dvidef.h>
216# include <dcdef.h>
217# include <stsdef.h>
218# include <iodef.h>
219# include <ttdef.h>
220# include <tt2def.h>
221# include <jpidef.h>
222# include <rms.h>
223# include <trmdef.h>
224# include <string.h>
225# include <starlet.h>
226# include <socket.h>
227# include <lib$routines.h>
Bram Moolenaar4ffa0702013-12-11 17:12:37 +0100228# include <libdef.h>
229# include <libdtdef.h>
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000230
231# ifdef FEAT_GUI_GTK
232# include "gui_gtk_vms.h"
233# endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100234#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235
Bram Moolenaar82881492012-11-20 16:53:39 +0100236#endif /* PROTO */
237
238#ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239typedef struct dsc$descriptor DESC;
240#endif
241
242/*
243 * Unix system-dependent file names
244 */
245#ifndef SYS_VIMRC_FILE
246# define SYS_VIMRC_FILE "$VIM/vimrc"
247#endif
248#ifndef SYS_GVIMRC_FILE
249# define SYS_GVIMRC_FILE "$VIM/gvimrc"
250#endif
251#ifndef DFLT_HELPFILE
252# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
253#endif
254#ifndef FILETYPE_FILE
255# define FILETYPE_FILE "filetype.vim"
256#endif
257#ifndef FTPLUGIN_FILE
258# define FTPLUGIN_FILE "ftplugin.vim"
259#endif
260#ifndef INDENT_FILE
261# define INDENT_FILE "indent.vim"
262#endif
263#ifndef FTOFF_FILE
264# define FTOFF_FILE "ftoff.vim"
265#endif
266#ifndef FTPLUGOF_FILE
267# define FTPLUGOF_FILE "ftplugof.vim"
268#endif
269#ifndef INDOFF_FILE
270# define INDOFF_FILE "indoff.vim"
271#endif
272#ifndef SYS_MENU_FILE
273# define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
274#endif
275
276#ifndef USR_EXRC_FILE
277# ifdef VMS
278# define USR_EXRC_FILE "sys$login:.exrc"
279# else
280# define USR_EXRC_FILE "$HOME/.exrc"
281# endif
282#endif
283
284#if !defined(USR_EXRC_FILE2) && defined(OS2)
285# define USR_EXRC_FILE2 "$VIM/.exrc"
286#endif
287#if !defined(USR_EXRC_FILE2) && defined(VMS)
288# define USR_EXRC_FILE2 "sys$login:_exrc"
289#endif
290
291#ifndef USR_VIMRC_FILE
292# ifdef VMS
293# define USR_VIMRC_FILE "sys$login:.vimrc"
294# else
295# define USR_VIMRC_FILE "$HOME/.vimrc"
296# endif
297#endif
298
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200299
300#if !defined(USR_EXRC_FILE2)
301# ifdef OS2
302# define USR_VIMRC_FILE2 "$HOME/vimfiles/vimrc"
303# else
304# ifdef VMS
305# define USR_VIMRC_FILE2 "sys$login:vimfiles:vimrc"
306# else
307# define USR_VIMRC_FILE2 "~/.vim/vimrc"
308# endif
309# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310#endif
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200311
312#if !defined(USR_VIMRC_FILE3) && defined(OS2)
313# define USR_VIMRC_FILE3 "$VIM/.vimrc"
314#endif
315#if !defined(USR_VIMRC_FILE3) && defined(VMS)
316# define USR_VIMRC_FILE3 "sys$login:_vimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317#endif
318
319#ifndef USR_GVIMRC_FILE
320# ifdef VMS
321# define USR_GVIMRC_FILE "sys$login:.gvimrc"
322# else
323# define USR_GVIMRC_FILE "$HOME/.gvimrc"
324# endif
325#endif
326
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200327#ifndef USR_GVIMRC_FILE2
328# ifdef OS2
329# define USR_GVIMRC_FILE2 "$HOME/vimfiles/gvimrc"
330# else
331# ifdef VMS
332# define USR_GVIMRC_FILE2 "sys$login:vimfiles:gvimrc"
333# else
334# define USR_GVIMRC_FILE2 "~/.vim/gvimrc"
335# endif
336# endif
337#endif
338
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339#ifdef VMS
Bram Moolenaar22971aa2013-06-12 20:35:58 +0200340# ifndef USR_GVIMRC_FILE3
341# define USR_GVIMRC_FILE3 "sys$login:_gvimrc"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000342# endif
343#endif
344
345#ifndef EVIM_FILE
346# define EVIM_FILE "$VIMRUNTIME/evim.vim"
347#endif
348
349#ifdef FEAT_VIMINFO
350# ifndef VIMINFO_FILE
351# ifdef VMS
352# define VIMINFO_FILE "sys$login:.viminfo"
353# else
354# define VIMINFO_FILE "$HOME/.viminfo"
355# endif
356# endif
357# if !defined(VIMINFO_FILE2) && defined(OS2)
358# define VIMINFO_FILE2 "$VIM/.viminfo"
359# endif
360# if !defined(VIMINFO_FILE2) && defined(VMS)
361# define VIMINFO_FILE2 "sys$login:_viminfo"
362# endif
363#endif
364
365#ifndef EXRC_FILE
366# define EXRC_FILE ".exrc"
367#endif
368
369#ifndef VIMRC_FILE
370# define VIMRC_FILE ".vimrc"
371#endif
372
373#ifdef FEAT_GUI
374# ifndef GVIMRC_FILE
375# define GVIMRC_FILE ".gvimrc"
376# endif
377#endif
378
379#ifndef SYNTAX_FNAME
380# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
381#endif
382
383#ifndef DFLT_BDIR
384# ifdef OS2
385# define DFLT_BDIR ".,c:/tmp,~/tmp,~/"
386# else
387# ifdef VMS
388# define DFLT_BDIR "./,sys$login:,tmp:"
389# else
390# define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
391# endif
392# endif
393#endif
394
395#ifndef DFLT_DIR
396# ifdef OS2
397# define DFLT_DIR ".,~/tmp,c:/tmp,/tmp"
398# else
399# ifdef VMS
400# define DFLT_DIR "./,sys$login:,tmp:"
401# else
402# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
403# endif
404# endif
405#endif
406
407#ifndef DFLT_VDIR
408# ifdef OS2
409# define DFLT_VDIR "$VIM/vimfiles/view"
410# else
411# ifdef VMS
412# define DFLT_VDIR "sys$login:vimfiles/view"
413# else
414# define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
415# endif
416# endif
417#endif
418
419#define DFLT_ERRORFILE "errors.err"
420
421#ifdef OS2
422# define DFLT_RUNTIMEPATH "$HOME/vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/vimfiles/after"
423#else
424# ifdef VMS
425# define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
426# else
427# ifdef RUNTIME_GLOBAL
428# define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
429# else
430# define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
431# endif
432# endif
433#endif
434
435#ifdef OS2
436/*
437 * Try several directories to put the temp files.
438 */
439# define TEMPDIRNAMES "$TMP", "$TEMP", "c:\\TMP", "c:\\TEMP", ""
440# define TEMPNAMELEN 128
441#else
442# ifdef VMS
443# ifndef VAX
444# define VMS_TEMPNAM /* to fix default .LIS extension */
445# endif
446# define TEMPNAME "TMP:v?XXXXXX.txt"
447# define TEMPNAMELEN 28
448# else
449# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
450# define TEMPNAMELEN 256
451# endif
452#endif
453
454/* Special wildcards that need to be handled by the shell */
455#define SPECIAL_WILDCHAR "`'{"
456
457#ifndef HAVE_OPENDIR
458# define NO_EXPANDPATH
459#endif
460
461/*
462 * Unix has plenty of memory, use large buffers
463 */
464#define CMDBUFFSIZE 1024 /* size of the command processing buffer */
Bram Moolenaar38f12a92008-06-20 16:07:02 +0000465
466/* Use the system path length if it makes sense. */
467#if defined(PATH_MAX) && (PATH_MAX > 1000)
468# define MAXPATHL PATH_MAX
469#else
470# define MAXPATHL 1024
471#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000472
473#define CHECK_INODE /* used when checking if a swap file already
474 exists for a file */
475#ifdef VMS /* Use less memory because of older systems */
476# ifndef DFLT_MAXMEM
477# define DFLT_MAXMEM (2*1024)
478# endif
479# ifndef DFLT_MAXMEMTOT
480# define DFLT_MAXMEMTOT (5*1024)
481# endif
482#else
483# ifndef DFLT_MAXMEM
484# define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
485# endif
486# ifndef DFLT_MAXMEMTOT
487# define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
488# endif
489#endif
490
491/* memmove is not present on all systems, use memmove, bcopy, memcpy or our
492 * own version */
493/* Some systems have (void *) arguments, some (char *). If we use (char *) it
494 * works for all */
495#ifdef USEMEMMOVE
496# define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
497#else
498# ifdef USEBCOPY
499# define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
500# else
501# ifdef USEMEMCPY
502# define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
503# else
504# define VIM_MEMMOVE /* found in misc2.c */
505# endif
506# endif
507#endif
508
509#ifndef PROTO
510# ifdef HAVE_RENAME
511# define mch_rename(src, dst) rename(src, dst)
512# else
513int mch_rename __ARGS((const char *src, const char *dest));
514# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515# ifndef VMS
516# ifdef __MVS__
Bram Moolenaar3d27a452007-05-10 17:44:18 +0000517 /* on OS390 Unix getenv() doesn't return a pointer to persistent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 * storage -> use __getenv() */
519# define mch_getenv(x) (char_u *)__getenv((char *)(x))
520# else
521# define mch_getenv(x) (char_u *)getenv((char *)(x))
522# endif
523# define mch_setenv(name, val, x) setenv(name, val, x)
524# endif
525#endif
526
527#if !defined(S_ISDIR) && defined(S_IFDIR)
528# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
529#endif
530#if !defined(S_ISREG) && defined(S_IFREG)
531# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
532#endif
533#if !defined(S_ISBLK) && defined(S_IFBLK)
534# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
535#endif
536#if !defined(S_ISSOCK) && defined(S_IFSOCK)
537# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
538#endif
539#if !defined(S_ISFIFO) && defined(S_IFIFO)
540# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
541#endif
Bram Moolenaarfe1c56d2007-07-10 15:10:54 +0000542#if !defined(S_ISCHR) && defined(S_IFCHR)
543# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
544#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545
546/* Note: Some systems need both string.h and strings.h (Savage). However,
547 * some systems can't handle both, only use string.h in that case. */
548#ifdef HAVE_STRING_H
549# include <string.h>
550#endif
551#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
552# include <strings.h>
553#endif
554
555#if defined(HAVE_SETJMP_H)
556# include <setjmp.h>
557# ifdef HAVE_SIGSETJMP
558# define JMP_BUF sigjmp_buf
559# define SETJMP(x) sigsetjmp((x), 1)
560# define LONGJMP siglongjmp
561# else
562# define JMP_BUF jmp_buf
563# define SETJMP(x) setjmp(x)
564# define LONGJMP longjmp
565# endif
566#endif
567
568#define HAVE_DUP /* have dup() */
569#define HAVE_ST_MODE /* have stat.st_mode */
570
571/* We have three kinds of ACL support. */
572#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)