2 * Copyright (c) 2014 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
4 * Copyright (C) 1989 - 2003, 2005, 2006
5 * Free Software Foundation, Inc.
6 * Written by James Clark (jjc@jclark.com)
8 * This 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
10 * Software Foundation; either version 2, or (at your option) any later
13 * This 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
18 * You should have received a copy of the GNU General Public License along
19 * with groff; see the file COPYING. If not, write to the Free Software
20 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
31 const char *i_to_a(int);
32 const char *ui_to_a(unsigned int);
33 const char *if_to_a(int, int);
36 #define __GETOPT_PREFIX groff_
41 #define getlocale(category) setlocale(category, NULL)
42 #else /* !HAVE_SETLOCALE */
45 #define setlocale(category, locale) (void)(category, locale)
46 #define getlocale(category) ((void)(category), (char *)"C")
47 #endif /* !HAVE_SETLOCALE */
49 char *strsave(const char *s
);
50 int is_prime(unsigned);
51 double groff_hypot(double, double);
61 /* HP-UX 10.20 and LynxOS 4.0.0 don't declare snprintf() */
62 #if !defined(HAVE_SNPRINTF) || defined(NEED_DECLARATION_SNPRINTF)
63 extern "C" { int snprintf(char *, size_t, const char *, /*args*/ ...); }
66 /* LynxOS 4.0.0 has snprintf() but no vsnprintf() */
67 #if !defined(HAVE_VSNPRINTF) || defined(NEED_DECLARATION_VSNPRINTF)
68 extern "C" { int vsnprintf(char *, size_t, const char *, va_list); }
71 /* LynxOS 4.0.0 doesn't declare vfprintf() */
72 #ifdef NEED_DECLARATION_VFPRINTF
73 extern "C" { int vfprintf(FILE *, const char *, va_list); }
77 /* since mkstemp() is defined as a real C++ function if taken from
78 groff's mkstemp.cpp we need a declaration */
79 int mkstemp(char *tmpl
);
80 #endif /* HAVE_MKSTEMP */
82 int mksdir(char *tmpl
);
84 FILE *xtmpfile(char **namep
= 0,
85 const char *postfix_long
= 0, const char *postfix_short
= 0,
87 char *xtmptemplate(const char *postfix_long
, const char *postfix_short
);
89 #ifdef NEED_DECLARATION_POPEN
90 extern "C" { FILE *popen(const char *, const char *); }
91 #endif /* NEED_DECLARATION_POPEN */
93 #ifdef NEED_DECLARATION_PCLOSE
94 extern "C" { int pclose (FILE *); }
95 #endif /* NEED_DECLARATION_PCLOSE */
97 size_t file_name_max(const char *fname
);
98 size_t path_name_max();
100 int interpret_lf_args(const char *p
);
102 extern char invalid_char_table
[];
104 inline int invalid_input_char(int c
)
106 return c
>= 0 && invalid_char_table
[c
];
109 #ifdef HAVE_STRCASECMP
110 #ifdef NEED_DECLARATION_STRCASECMP
111 // Ultrix4.3's string.h fails to declare this.
112 extern "C" { int strcasecmp(const char *, const char *); }
113 #endif /* NEED_DECLARATION_STRCASECMP */
114 #else /* !HAVE_STRCASECMP */
115 extern "C" { int strcasecmp(const char *, const char *); }
116 #endif /* HAVE_STRCASECMP */
118 #if !defined(_AIX) && !defined(sinix) && !defined(__sinix__)
119 #ifdef HAVE_STRNCASECMP
120 #ifdef NEED_DECLARATION_STRNCASECMP
121 // SunOS's string.h fails to declare this.
122 extern "C" { int strncasecmp(const char *, const char *, int); }
123 #endif /* NEED_DECLARATION_STRNCASECMP */
124 #else /* !HAVE_STRNCASECMP */
125 extern "C" { int strncasecmp(const char *, const char *, size_t); }
126 #endif /* HAVE_STRNCASECMP */
127 #endif /* !_AIX && !sinix && !__sinix__ */
129 #ifdef HAVE_CC_LIMITS_H
131 #else /* !HAVE_CC_LIMITS_H */
132 #define INT_MAX 2147483647
133 #endif /* !HAVE_CC_LIMITS_H */
135 /* It's not safe to rely on people getting INT_MIN right (ie signed). */
141 #ifdef CFRONT_ANSI_BUG
143 /* This works around a bug in cfront 2.0 used with ANSI C compilers. */
145 #define INT_MIN ((long)(-INT_MAX-1))
147 #else /* !CFRONT_ANSI_BUG */
149 #define INT_MIN (-INT_MAX-1)
151 #endif /* !CFRONT_ANSI_BUG */
153 /* Maximum number of digits in the decimal representation of an int
154 (not including the -). */
156 #define INT_DIGITS 10
162 const double PI
= 3.14159265358979323846;
164 /* ad_delete deletes an array of objects with destructors;
165 a_delete deletes an array of objects without destructors */
167 #ifdef ARRAY_DELETE_NEEDS_SIZE
168 /* for 2.0 systems */
169 #define ad_delete(size) delete [size]
170 #define a_delete delete
171 #else /* !ARRAY_DELETE_NEEDS_SIZE */
172 /* for ARM systems */
173 #define ad_delete(size) delete []
174 #define a_delete delete []
175 #endif /* !ARRAY_DELETE_NEEDS_SIZE */
177 #ifdef HAVE_CC_INTTYPES_H
178 # include <inttypes.h>
180 #if !defined UINT8_MAX && !defined uint8_t
182 typedef unsigned char uint8_t;
183 typedef signed char int8_t;
185 #if !defined UINT32_MAX && !defined uint32_t
187 # if INT_MAX == 2147483647
188 typedef unsigned int uint32_t;
189 typedef signed int int32_t;
191 typedef unsigned long int uint32_t;
192 typedef signed long int int32_t;
197 # define NELEM(X) (sizeof(X) / sizeof((X)[0]))
200 #define CLASS_DISABLE_COPY(C) private: C(C const &); C &operator=(C const &)
203 # define STRING(X) #X
204 # define XSTRING(X) STRING(X)
205 # define CONCAT(S1,S2) _CONCAT(S1, S2)
206 # define _CONCAT(S1,S2) S1 ## S2
208 # define STRING(X) "X"
209 # define XSTRING STRING
210 # define CONCAT(S1,S2) S1/**/S2
213 /* Compile-Time-Assert */
214 #define CTA(TEST) _CTA_1(TEST, __LINE__)
215 #define _CTA_1(TEST,L) _CTA_2(TEST, L)
216 #define _CTA_2(TEST,L) \
217 typedef char COMPILE_TIME_ASSERT_failed_at_line_ ## L[(TEST) ? 1 : -1]
220 #define ISPOW2(X) ((((X) - 1) & (X)) == 0)
222 #define MIN(A, B) ((A) < (B) ? (A) : (B))
224 #define MAX(A, B) ((A) < (B) ? (B) : (A))
226 #define ABS(A) ((A) < 0 ? -(A) : (A))