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