| Commit | Line | Data |
|---|---|---|
| 92d0a6a6 | 1 | // -*- C++ -*- |
| 4d3e9548 | 2 | /* Copyright (C) 1989-2000, 2001, 2002, 2003, 2005, 2006, 2009 |
| 465b256c | 3 | Free Software Foundation, Inc. |
| 92d0a6a6 JR |
4 | Written by James Clark (jjc@jclark.com) |
| 5 | ||
| 6 | This file is part of groff. | |
| 7 | ||
| 8 | groff is free software; you can redistribute it and/or modify it under | |
| 9 | the terms of the GNU General Public License as published by the Free | |
| 4d3e9548 JL |
10 | Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. | |
| 92d0a6a6 JR |
12 | |
| 13 | groff is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 16 | for more details. | |
| 17 | ||
| 4d3e9548 JL |
18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
| 92d0a6a6 JR |
20 | |
| 21 | #ifdef HAVE_CONFIG_H | |
| 22 | #include <config.h> | |
| 23 | #endif | |
| 24 | ||
| 25 | extern "C" { | |
| 26 | #ifndef HAVE_STRERROR | |
| 27 | char *strerror(int); | |
| 28 | #endif | |
| 29 | const char *i_to_a(int); | |
| 30 | const char *ui_to_a(unsigned int); | |
| 31 | const char *if_to_a(int, int); | |
| 32 | } | |
| 33 | ||
| 465b256c | 34 | #define __GETOPT_PREFIX groff_ |
| 92d0a6a6 | 35 | #include <getopt.h> |
| 92d0a6a6 JR |
36 | |
| 37 | #ifdef HAVE_SETLOCALE | |
| 38 | #include <locale.h> | |
| 4d3e9548 JL |
39 | #define getlocale(category) setlocale(category, NULL) |
| 40 | #else /* !HAVE_SETLOCALE */ | |
| 41 | #define LC_ALL 0 | |
| 42 | #define LC_CTYPE 0 | |
| 43 | #define setlocale(category, locale) (void)(category, locale) | |
| 44 | #define getlocale(category) ((void)(category), (char *)"C") | |
| 45 | #endif /* !HAVE_SETLOCALE */ | |
| 92d0a6a6 JR |
46 | |
| 47 | char *strsave(const char *s); | |
| 48 | int is_prime(unsigned); | |
| 465b256c | 49 | double groff_hypot(double, double); |
| 92d0a6a6 JR |
50 | |
| 51 | #include <stdio.h> | |
| 52 | #include <string.h> | |
| 53 | #ifdef HAVE_STRINGS_H | |
| 54 | #include <strings.h> | |
| 55 | #endif | |
| 56 | ||
| 57 | #include <stdarg.h> | |
| 58 | ||
| 59 | /* HP-UX 10.20 and LynxOS 4.0.0 don't declare snprintf() */ | |
| 60 | #if !defined(HAVE_SNPRINTF) || defined(NEED_DECLARATION_SNPRINTF) | |
| 61 | extern "C" { int snprintf(char *, size_t, const char *, /*args*/ ...); } | |
| 62 | #endif | |
| 63 | ||
| 64 | /* LynxOS 4.0.0 has snprintf() but no vsnprintf() */ | |
| 65 | #if !defined(HAVE_VSNPRINTF) || defined(NEED_DECLARATION_VSNPRINTF) | |
| 66 | extern "C" { int vsnprintf(char *, size_t, const char *, va_list); } | |
| 67 | #endif | |
| 68 | ||
| 69 | /* LynxOS 4.0.0 doesn't declare vfprintf() */ | |
| 70 | #ifdef NEED_DECLARATION_VFPRINTF | |
| 71 | extern "C" { int vfprintf(FILE *, const char *, va_list); } | |
| 72 | #endif | |
| 73 | ||
| 74 | #ifndef HAVE_MKSTEMP | |
| 75 | /* since mkstemp() is defined as a real C++ function if taken from | |
| 76 | groff's mkstemp.cpp we need a declaration */ | |
| 77 | int mkstemp(char *tmpl); | |
| 78 | #endif /* HAVE_MKSTEMP */ | |
| 79 | ||
| 80 | int mksdir(char *tmpl); | |
| 81 | ||
| 82 | FILE *xtmpfile(char **namep = 0, | |
| 83 | const char *postfix_long = 0, const char *postfix_short = 0, | |
| 84 | int do_unlink = 1); | |
| 85 | char *xtmptemplate(const char *postfix_long, const char *postfix_short); | |
| 86 | ||
| 87 | #ifdef NEED_DECLARATION_POPEN | |
| 88 | extern "C" { FILE *popen(const char *, const char *); } | |
| 89 | #endif /* NEED_DECLARATION_POPEN */ | |
| 90 | ||
| 91 | #ifdef NEED_DECLARATION_PCLOSE | |
| 92 | extern "C" { int pclose (FILE *); } | |
| 93 | #endif /* NEED_DECLARATION_PCLOSE */ | |
| 94 | ||
| 95 | size_t file_name_max(const char *fname); | |
| 465b256c | 96 | size_t path_name_max(); |
| 92d0a6a6 JR |
97 | |
| 98 | int interpret_lf_args(const char *p); | |
| 99 | ||
| 100 | extern char invalid_char_table[]; | |
| 101 | ||
| 102 | inline int invalid_input_char(int c) | |
| 103 | { | |
| 104 | return c >= 0 && invalid_char_table[c]; | |
| 105 | } | |
| 106 | ||
| 107 | #ifdef HAVE_STRCASECMP | |
| 108 | #ifdef NEED_DECLARATION_STRCASECMP | |
| 109 | // Ultrix4.3's string.h fails to declare this. | |
| 110 | extern "C" { int strcasecmp(const char *, const char *); } | |
| 111 | #endif /* NEED_DECLARATION_STRCASECMP */ | |
| 4d3e9548 | 112 | #else /* !HAVE_STRCASECMP */ |
| 92d0a6a6 JR |
113 | extern "C" { int strcasecmp(const char *, const char *); } |
| 114 | #endif /* HAVE_STRCASECMP */ | |
| 115 | ||
| 116 | #if !defined(_AIX) && !defined(sinix) && !defined(__sinix__) | |
| 117 | #ifdef HAVE_STRNCASECMP | |
| 118 | #ifdef NEED_DECLARATION_STRNCASECMP | |
| 119 | // SunOS's string.h fails to declare this. | |
| 120 | extern "C" { int strncasecmp(const char *, const char *, int); } | |
| 121 | #endif /* NEED_DECLARATION_STRNCASECMP */ | |
| 4d3e9548 | 122 | #else /* !HAVE_STRNCASECMP */ |
| 92d0a6a6 JR |
123 | extern "C" { int strncasecmp(const char *, const char *, size_t); } |
| 124 | #endif /* HAVE_STRNCASECMP */ | |
| 125 | #endif /* !_AIX && !sinix && !__sinix__ */ | |
| 126 | ||
| 127 | #ifdef HAVE_CC_LIMITS_H | |
| 128 | #include <limits.h> | |
| 4d3e9548 | 129 | #else /* !HAVE_CC_LIMITS_H */ |
| 92d0a6a6 | 130 | #define INT_MAX 2147483647 |
| 4d3e9548 | 131 | #endif /* !HAVE_CC_LIMITS_H */ |
| 92d0a6a6 JR |
132 | |
| 133 | /* It's not safe to rely on people getting INT_MIN right (ie signed). */ | |
| 134 | ||
| 135 | #ifdef INT_MIN | |
| 136 | #undef INT_MIN | |
| 137 | #endif | |
| 138 | ||
| 139 | #ifdef CFRONT_ANSI_BUG | |
| 140 | ||
| 141 | /* This works around a bug in cfront 2.0 used with ANSI C compilers. */ | |
| 142 | ||
| 143 | #define INT_MIN ((long)(-INT_MAX-1)) | |
| 144 | ||
| 4d3e9548 | 145 | #else /* !CFRONT_ANSI_BUG */ |
| 92d0a6a6 JR |
146 | |
| 147 | #define INT_MIN (-INT_MAX-1) | |
| 148 | ||
| 4d3e9548 | 149 | #endif /* !CFRONT_ANSI_BUG */ |
| 92d0a6a6 JR |
150 | |
| 151 | /* Maximum number of digits in the decimal representation of an int | |
| 4d3e9548 | 152 | (not including the -). */ |
| 92d0a6a6 JR |
153 | |
| 154 | #define INT_DIGITS 10 | |
| 155 | ||
| 156 | #ifdef PI | |
| 157 | #undef PI | |
| 158 | #endif | |
| 159 | ||
| 160 | const double PI = 3.14159265358979323846; | |
| 161 | ||
| 162 | /* ad_delete deletes an array of objects with destructors; | |
| 4d3e9548 | 163 | a_delete deletes an array of objects without destructors */ |
| 92d0a6a6 JR |
164 | |
| 165 | #ifdef ARRAY_DELETE_NEEDS_SIZE | |
| 166 | /* for 2.0 systems */ | |
| 167 | #define ad_delete(size) delete [size] | |
| 168 | #define a_delete delete | |
| 4d3e9548 | 169 | #else /* !ARRAY_DELETE_NEEDS_SIZE */ |
| 92d0a6a6 JR |
170 | /* for ARM systems */ |
| 171 | #define ad_delete(size) delete [] | |
| 172 | #define a_delete delete [] | |
| 4d3e9548 | 173 | #endif /* !ARRAY_DELETE_NEEDS_SIZE */ |