175584Sru// -*- C++ -*-
2151497Sru/* Copyright (C) 1989-2000, 2001, 2002, 2003, 2005
3151497Sru   Free Software Foundation, Inc.
475584Sru     Written by James Clark (jjc@jclark.com)
575584Sru
675584SruThis file is part of groff.
775584Sru
875584Srugroff is free software; you can redistribute it and/or modify it under
975584Sruthe terms of the GNU General Public License as published by the Free
1075584SruSoftware Foundation; either version 2, or (at your option) any later
1175584Sruversion.
1275584Sru
1375584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY
1475584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or
1575584SruFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1675584Srufor more details.
1775584Sru
1875584SruYou should have received a copy of the GNU General Public License along
1975584Sruwith groff; see the file COPYING.  If not, write to the Free Software
20151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
2175584Sru
22104862Sru#ifdef HAVE_CONFIG_H
23104862Sru#include <config.h>
24104862Sru#endif
25104862Sru
2675584Sruextern "C" {
2779543Sru#ifndef HAVE_STRERROR
2875584Sru  char *strerror(int);
2975584Sru#endif
3075584Sru  const char *i_to_a(int);
31104862Sru  const char *ui_to_a(unsigned int);
3275584Sru  const char *if_to_a(int, int);
3375584Sru}
3475584Sru
35151497Sru#define __GETOPT_PREFIX groff_
36104862Sru#include <getopt.h>
3775584Sru
38114402Sru#ifdef HAVE_SETLOCALE
39114402Sru#include <locale.h>
40114402Sru#else
41114402Sru#define setlocale(category, locale) do {} while(0)
42114402Sru#endif
43114402Sru
4475584Sruchar *strsave(const char *s);
4575584Sruint is_prime(unsigned);
46151497Srudouble groff_hypot(double, double);
4775584Sru
4875584Sru#include <stdio.h>
4975584Sru#include <string.h>
5075584Sru#ifdef HAVE_STRINGS_H
5175584Sru#include <strings.h>
5275584Sru#endif
5375584Sru
54151497Sru#include <stdarg.h>
55151497Sru
56151497Sru/* HP-UX 10.20 and LynxOS 4.0.0 don't declare snprintf() */
57114402Sru#if !defined(HAVE_SNPRINTF) || defined(NEED_DECLARATION_SNPRINTF)
58151497Sruextern "C" { int snprintf(char *, size_t, const char *, /*args*/ ...); }
59104862Sru#endif
6075584Sru
61151497Sru/* LynxOS 4.0.0 has snprintf() but no vsnprintf() */
62151497Sru#if !defined(HAVE_VSNPRINTF) || defined(NEED_DECLARATION_VSNPRINTF)
63151497Sruextern "C" { int vsnprintf(char *, size_t, const char *, va_list); }
64151497Sru#endif
65151497Sru
66151497Sru/* LynxOS 4.0.0 doesn't declare vfprintf() */
67151497Sru#ifdef NEED_DECLARATION_VFPRINTF
68151497Sruextern "C" { int vfprintf(FILE *, const char *, va_list); }
69151497Sru#endif
70151497Sru
71104862Sru#ifndef HAVE_MKSTEMP
72104862Sru/* since mkstemp() is defined as a real C++ function if taken from
73114402Sru   groff's mkstemp.cpp we need a declaration */
74104862Sruint mkstemp(char *tmpl);
75104862Sru#endif /* HAVE_MKSTEMP */
76104862Sru
77104862Sruint mksdir(char *tmpl);
78104862Sru
79104862SruFILE *xtmpfile(char **namep = 0,
80104862Sru	       const char *postfix_long = 0, const char *postfix_short = 0,
81104862Sru	       int do_unlink = 1);
82104862Sruchar *xtmptemplate(const char *postfix_long, const char *postfix_short);
83104862Sru
8475584Sru#ifdef NEED_DECLARATION_POPEN
8575584Sruextern "C" { FILE *popen(const char *, const char *); }
8675584Sru#endif /* NEED_DECLARATION_POPEN */
8775584Sru
8875584Sru#ifdef NEED_DECLARATION_PCLOSE
8975584Sruextern "C" { int pclose (FILE *); }
9075584Sru#endif /* NEED_DECLARATION_PCLOSE */
9175584Sru
9279543Srusize_t file_name_max(const char *fname);
93151497Srusize_t path_name_max();
9479543Sru
9575584Sruint interpret_lf_args(const char *p);
9675584Sru
97104862Sruextern char invalid_char_table[];
9875584Sru
99104862Sruinline int invalid_input_char(int c)
10075584Sru{
101104862Sru  return c >= 0 && invalid_char_table[c];
10275584Sru}
10375584Sru
104104862Sru#ifdef HAVE_STRCASECMP
105104862Sru#ifdef NEED_DECLARATION_STRCASECMP
106151497Sru// Ultrix4.3's string.h fails to declare this.
107151497Sruextern "C" { int strcasecmp(const char *, const char *); }
108104862Sru#endif /* NEED_DECLARATION_STRCASECMP */
109114402Sru#else /* not HAVE_STRCASECMP */
110151497Sruextern "C" { int strcasecmp(const char *, const char *); }
111104862Sru#endif /* HAVE_STRCASECMP */
112104862Sru
11375584Sru#if !defined(_AIX) && !defined(sinix) && !defined(__sinix__)
11475584Sru#ifdef HAVE_STRNCASECMP
11575584Sru#ifdef NEED_DECLARATION_STRNCASECMP
116151497Sru// SunOS's string.h fails to declare this.
117151497Sruextern "C" { int strncasecmp(const char *, const char *, int); }
11875584Sru#endif /* NEED_DECLARATION_STRNCASECMP */
119114402Sru#else /* not HAVE_STRNCASECMP */
120151497Sruextern "C" { int strncasecmp(const char *, const char *, size_t); }
12175584Sru#endif /* HAVE_STRNCASECMP */
12275584Sru#endif /* !_AIX && !sinix && !__sinix__ */
12375584Sru
12475584Sru#ifdef HAVE_CC_LIMITS_H
12575584Sru#include <limits.h>
12675584Sru#else /* not HAVE_CC_LIMITS_H */
12775584Sru#define INT_MAX 2147483647
12875584Sru#endif /* not HAVE_CC_LIMITS_H */
12975584Sru
13075584Sru/* It's not safe to rely on people getting INT_MIN right (ie signed). */
13175584Sru
13275584Sru#ifdef INT_MIN
13375584Sru#undef INT_MIN
13475584Sru#endif
13575584Sru
13675584Sru#ifdef CFRONT_ANSI_BUG
13775584Sru
13875584Sru/* This works around a bug in cfront 2.0 used with ANSI C compilers. */
13975584Sru
14075584Sru#define INT_MIN ((long)(-INT_MAX-1))
14175584Sru
14275584Sru#else /* not CFRONT_ANSI_BUG */
14375584Sru
14475584Sru#define INT_MIN (-INT_MAX-1)
14575584Sru
14675584Sru#endif /* not CFRONT_ANSI_BUG */
14775584Sru
14875584Sru/* Maximum number of digits in the decimal representation of an int
14975584Sru(not including the -). */
15075584Sru
15175584Sru#define INT_DIGITS 10
15275584Sru
15375584Sru#ifdef PI
15475584Sru#undef PI
15575584Sru#endif
15675584Sru
15775584Sruconst double PI = 3.14159265358979323846;
15875584Sru
15975584Sru/* ad_delete deletes an array of objects with destructors;
16075584Srua_delete deletes an array of objects without destructors */
16175584Sru
16275584Sru#ifdef ARRAY_DELETE_NEEDS_SIZE
16375584Sru/* for 2.0 systems */
16475584Sru#define ad_delete(size) delete [size]
16575584Sru#define a_delete delete
16675584Sru#else /* not ARRAY_DELETE_NEEDS_SIZE */
16775584Sru/* for ARM systems */
16875584Sru#define ad_delete(size) delete []
16975584Sru#define a_delete delete []
17075584Sru#endif /* not ARRAY_DELETE_NEEDS_SIZE */
171