Back to index

tetex-bin  3.0
system.h
Go to the documentation of this file.
00001 /* system.h: system-dependent declarations; include this first.
00002    $Id: system.h,v 1.12 2004/04/26 13:56:57 karl Exp $
00003 
00004    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
00005    Foundation, Inc.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software Foundation,
00019    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00020 
00021 #ifndef TEXINFO_SYSTEM_H
00022 #define TEXINFO_SYSTEM_H
00023 
00024 #define _GNU_SOURCE
00025 
00026 #include <config.h>
00027 
00028 #ifdef MIKTEX
00029 #include <gnu-miktex.h>
00030 #define S_ISDIR(x) ((x)&_S_IFDIR) 
00031 #else
00032 /* MiKTeX defines substring() in a separate DLL, where it has its
00033    own __declspec declaration.  We don't want to try to duplicate 
00034    this Microsoft-ism here.  */
00035 extern char *substring (const char *, const char *);
00036 #endif
00037 
00038 /* We follow the order of header inclusion from Autoconf's
00039    ac_includes_default, more or less.  */
00040 #include <stdio.h>
00041 #include <sys/types.h>
00042 #include <ctype.h>
00043 
00044 /* All systems nowadays probably have these functions, but ... */
00045 #ifdef HAVE_LOCALE_H
00046 #include <locale.h>
00047 #endif
00048 #ifndef HAVE_SETLOCALE
00049 #define setlocale(category,locale) /* empty */
00050 #endif
00051 
00052 /* For gettext (NLS).  */
00053 #define const
00054 #include "gettext.h"
00055 #undef const
00056 
00057 #define _(String) gettext (String)
00058 #define N_(String) (String)
00059 
00060 #ifdef STDC_HEADERS
00061 #define getopt system_getopt
00062 #include <stdlib.h>
00063 #undef getopt
00064 #else
00065 extern char *getenv ();
00066 #endif
00067 
00068 /* Don't use bcopy!  Use memmove if source and destination may overlap,
00069    memcpy otherwise.  */
00070 #if HAVE_STRING_H
00071 # if !STDC_HEADERS && HAVE_MEMORY_H
00072 #  include <memory.h>
00073 # endif
00074 # include <string.h>
00075 #endif
00076 
00077 #if HAVE_STRINGS_H
00078 /* Always include <strings.h> if we have it.  This is because that's
00079    what Autoconf's AC_CHECK_DECL does.  On IBM AIX 4.2, strncasecmp is
00080    only declared in strings.h.  */
00081 # include <strings.h>
00082 #endif
00083 
00084 #if !HAVE_STRNCASECMP || !HAVE_STRCASECMP
00085 # include "strcase.h"
00086 #endif
00087 
00088 #if !HAVE_DECL_MEMCHR
00089 char *memchr ();
00090 #endif
00091 
00092 /* <unistd.h> defines _POSIX_VERSION, but Paul Eggert points out that is
00093    only supposed to be used in user code, not other system headers.  */
00094 #ifdef HAVE_UNISTD_H
00095 #include <unistd.h>
00096 #endif /* HAVE_UNISTD_H */
00097 
00098 #include <errno.h>
00099 #ifndef errno
00100 extern int errno;
00101 #endif
00102 #ifdef VMS
00103 #include <perror.h>
00104 #endif
00105 
00106 #ifndef HAVE_DECL_STRERROR
00107 extern char *strerror ();
00108 #endif
00109 
00110 #ifdef HAVE_LIMITS_H
00111 #include <limits.h>
00112 #endif
00113 #ifndef PATH_MAX
00114 #ifndef _POSIX_PATH_MAX
00115 # define _POSIX_PATH_MAX 255
00116 #endif
00117 #define PATH_MAX _POSIX_PATH_MAX
00118 #endif
00119 
00120 #ifndef HAVE_DECL_STRCASECMP
00121 extern int strcasecmp ();
00122 #endif
00123 
00124 #ifndef HAVE_DECL_STRNCASECMP
00125 extern int strncasecmp ();
00126 #endif
00127 
00128 #ifndef HAVE_DECL_STRCOLL
00129 extern int strcoll ();
00130 #endif
00131 
00132 #include <sys/stat.h>
00133 #if STAT_MACROS_BROKEN
00134 # undef S_ISDIR
00135 #endif
00136 #if !defined(S_ISDIR) && defined(S_IFDIR)
00137 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
00138 #endif
00139 
00140 #ifdef HAVE_SYS_FILE_H
00141 #include <sys/file.h>
00142 #endif /* HAVE_SYS_FILE_H */
00143 
00144 #ifndef O_RDONLY
00145 /* Since <fcntl.h> is POSIX, prefer that to <sys/fcntl.h>.
00146    This also avoids some useless warnings on (at least) Linux.  */
00147 #ifdef HAVE_FCNTL_H
00148 #include <fcntl.h>
00149 #else /* not HAVE_FCNTL_H */
00150 #ifdef HAVE_SYS_FCNTL_H
00151 #include <sys/fcntl.h>
00152 #endif /* not HAVE_SYS_FCNTL_H */
00153 #endif /* not HAVE_FCNTL_H */
00154 #endif /* not O_RDONLY */
00155 
00156 /* MS-DOS and similar non-Posix systems have some peculiarities:
00157     - they distinguish between binary and text files;
00158     - they use both `/' and `\\' as directory separator in file names;
00159     - they can have a drive letter X: prepended to a file name;
00160     - they have a separate root directory on each drive;
00161     - their filesystems are case-insensitive;
00162     - directories in environment variables (like INFOPATH) are separated
00163         by `;' rather than `:';
00164     - text files can have their lines ended either with \n or with \r\n pairs;
00165    These are all parameterized here except the last, which is
00166    handled by the source code as appropriate (mostly, in info/).  */
00167 #ifndef O_BINARY
00168 # ifdef _O_BINARY
00169 #  define O_BINARY _O_BINARY
00170 # else
00171 #  define O_BINARY 0
00172 # endif
00173 #endif /* O_BINARY */
00174 
00175 /* We'd like to take advantage of _doprnt if it's around, a la error.c,
00176    but then we'd have no VA_SPRINTF.  */
00177 #if HAVE_VPRINTF
00178 # if __STDC__
00179 #  include <stdarg.h>
00180 #  define VA_START(args, lastarg) va_start(args, lastarg)
00181 # else
00182 #  include <varargs.h>
00183 #  define VA_START(args, lastarg) va_start(args)
00184 # endif
00185 # define VA_FPRINTF(file, fmt, ap) vfprintf (file, fmt, ap)
00186 # define VA_SPRINTF(str, fmt, ap) vsprintf (str, fmt, ap)
00187 #else /* not HAVE_VPRINTF */
00188 # define VA_START(args, lastarg)
00189 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
00190 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
00191 # define va_end(args)
00192 #endif
00193 
00194 #if O_BINARY
00195 # ifdef HAVE_IO_H
00196 #  include <io.h>
00197 # endif
00198 # ifdef __MSDOS__
00199 #  include <limits.h>
00200 #  ifdef __DJGPP__
00201 #   define HAVE_LONG_FILENAMES(dir)  (pathconf (dir, _PC_NAME_MAX) > 12)
00202 #   define NULL_DEVICE      "/dev/null"
00203 #   define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;."
00204     /* DJGPP supports /dev/null, which is okay for Unix aficionados,
00205        shell scripts and Makefiles, but interactive DOS die-hards
00206        would probably want to have NUL as well.  */
00207 #   define ALSO_NULL_DEVICE  "NUL"
00208 #  else  /* O_BINARY && !__DJGPP__ */
00209 #   define HAVE_LONG_FILENAMES(dir)  (0)
00210 #   define NULL_DEVICE      "NUL"
00211 #  endif /* O_BINARY && !__DJGPP__ */
00212 #  define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
00213 #  define DEFAULT_INFO_PRINT_COMMAND ">PRN"
00214 # else   /* O_BINARY && !__MSDOS__ */
00215 #  define setmode(f,m)  _setmode(f,m)
00216 #  define HAVE_LONG_FILENAMES(dir)   (1)
00217 #  define NULL_DEVICE       "NUL"
00218 # endif  /* O_BINARY && !__MSDOS__ */
00219 # ifdef __CYGWIN__
00220 #  define DEFAULT_TMPDIR    "/tmp/"
00221 #  define PATH_SEP   ":"
00222 # else  /* O_BINARY && !__CYGWIN__ */
00223 #  define DEFAULT_TMPDIR    "c:/"
00224 #  define PATH_SEP   ";"
00225 # endif /* O_BINARY && !__CYGWIN__ */
00226   /* Back to any O_BINARY system.  */
00227 # define FILENAME_CMP       strcasecmp
00228 # define FILENAME_CMPN      strncasecmp
00229 # define FOPEN_RBIN  "rb"
00230 # define FOPEN_WBIN  "wb"
00231 # define HAVE_DRIVE(n)      ((n)[0] && (n)[1] == ':')
00232 # define IS_SLASH(c) ((c) == '/' || (c) == '\\')
00233 # define IS_ABSOLUTE(n)     (IS_SLASH((n)[0]) || ((n)[0] && (n)[1] == ':'))
00234 # define PIPE_USE_FORK      0
00235 # define SET_BINARY(f)  do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
00236 # define STRIP_DOT_EXE      1
00237 
00238 #else  /* not O_BINARY, i.e., Unix */
00239 # define SET_BINARY(f)      (void)0
00240 # define FOPEN_RBIN  "r"
00241 # define FOPEN_WBIN  "w"
00242 # define IS_SLASH(c) ((c) == '/')
00243 # define HAVE_DRIVE(n)      (0)
00244 # define IS_ABSOLUTE(n)     ((n)[0] == '/')
00245 # define FILENAME_CMP       strcmp
00246 # define FILENAME_CMPN      strncmp
00247 # define HAVE_LONG_FILENAMES(dir)   (1)
00248 # define PATH_SEP    ":"
00249 # define STRIP_DOT_EXE      0
00250 # ifdef VMS
00251 #  define DEFAULT_TMPDIR "sys$scratch:"
00252 # else
00253 #  define DEFAULT_TMPDIR "/tmp/"
00254 # endif
00255 # define NULL_DEVICE "/dev/null"
00256 # define PIPE_USE_FORK      1
00257 #endif /* not O_BINARY */
00258 
00259 /* Everything but DJGPP.  */
00260 #ifndef ALSO_NULL_DEVICE
00261 # define ALSO_NULL_DEVICE  ""
00262 #endif
00263 
00264 #ifdef HAVE_PWD_H
00265 #include <pwd.h>
00266 #endif
00267 /* Some systems don't declare this function in pwd.h. */
00268 struct passwd *getpwnam (const char *name);
00269 
00270 /* Our library routines not included in any system library.  */
00271 extern void *xmalloc (size_t), *xrealloc (void *, size_t);
00272 extern char *xstrdup (const char *);
00273 extern void xexit (int);
00274 
00275 /* For convenience.  */
00276 #define STREQ(s1,s2) (strcmp (s1, s2) == 0)
00277 #define STRCASEEQ(s1,s2) (strcasecmp (s1, s2) == 0)
00278 #define STRNCASEEQ(s1,s2,n) (strncasecmp (s1, s2, n) == 0)
00279 
00280 /* We don't need anything fancy.  If we did need something fancy, gnulib
00281    has it.  */
00282 #ifdef MIN
00283 #undef MIN
00284 #endif
00285 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00286 #ifdef MAX
00287 #undef MAX
00288 #endif
00289 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00290 
00291 #endif /* TEXINFO_SYSTEM_H */