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