man/l_roff-char.7.in: fix Bernd Warken (Dave Kemper, Werner Lemberg)..
[s-roff.git] / include / lib.h
blobb418a07afe2a35831b2ca368c2fdaf007705a16d
1 /*@
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
11 * version.
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
16 * for more details.
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.
22 #ifndef _LIB_H
23 #define _LIB_H
25 #include "config.h"
27 extern "C" {
28 #ifndef HAVE_STRERROR
29 char *strerror(int);
30 #endif
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_
37 #include <getopt.h>
39 #ifdef HAVE_SETLOCALE
40 #include <locale.h>
41 #define getlocale(category) setlocale(category, NULL)
42 #else /* !HAVE_SETLOCALE */
43 #define LC_ALL 0
44 #define LC_CTYPE 0
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);
53 #include <stdio.h>
54 #include <string.h>
55 #ifdef HAVE_STRINGS_H
56 #include <strings.h>
57 #endif
59 #include <stdarg.h>
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*/ ...); }
64 #endif
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); }
69 #endif
71 /* LynxOS 4.0.0 doesn't declare vfprintf() */
72 #ifdef NEED_DECLARATION_VFPRINTF
73 extern "C" { int vfprintf(FILE *, const char *, va_list); }
74 #endif
76 #ifndef HAVE_MKSTEMP
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,
86 int do_unlink = 1);
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
130 #include <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). */
137 #ifdef INT_MIN
138 #undef INT_MIN
139 #endif
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
158 #ifdef PI
159 #undef PI
160 #endif
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>
179 #endif
180 #if !defined UINT8_MAX && !defined uint8_t
181 # undef int8_t
182 typedef unsigned char uint8_t;
183 typedef signed char int8_t;
184 #endif
185 #if !defined UINT32_MAX && !defined uint32_t
186 # undef int32_t
187 # if INT_MAX == 2147483647
188 typedef unsigned int uint32_t;
189 typedef signed int int32_t;
190 # else
191 typedef unsigned long int uint32_t;
192 typedef signed long int int32_t;
193 # endif
194 #endif
196 #ifndef NELEM
197 # define NELEM(X) (sizeof(X) / sizeof((X)[0]))
198 #endif
200 #define CLASS_DISABLE_COPY(C) private: C(C const &); C &operator=(C const &)
202 #if 1
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
207 #else
208 # define STRING(X) "X"
209 # define XSTRING STRING
210 # define CONCAT(S1,S2) S1/**/S2
211 #endif
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]
219 #undef ISPOW2
220 #define ISPOW2(X) ((((X) - 1) & (X)) == 0)
221 #undef MIN
222 #define MIN(A, B) ((A) < (B) ? (A) : (B))
223 #undef MAX
224 #define MAX(A, B) ((A) < (B) ? (B) : (A))
225 #undef ABS
226 #define ABS(A) ((A) < 0 ? -(A) : (A))
228 #undef DBG
229 #undef NDBG
230 #ifdef NDEBUG
231 # define DBG(X)
232 # define NDBG(X) X
233 #else
234 # define DBG(X) X
235 # define NDBG(X)
236 #endif
238 /* Translation */
239 #undef _
240 #undef N_
241 #undef V_
242 #define _(S) (S)
243 #define N_(S) (S)
244 #define V_(S) (S)
246 #endif // _LIB_H
247 // s-it2-mode