1177548Scsjp// -*- C++ -*- 2177548Scsjp/* Copyright (C) 1989-2000, 2001, 2002, 2003, 2005 3177548Scsjp Free Software Foundation, Inc. 4177548Scsjp Written by James Clark (jjc@jclark.com) 5230108Seadler 6177548ScsjpThis file is part of groff. 7177548Scsjp 8177548Scsjpgroff is free software; you can redistribute it and/or modify it under 9177548Scsjpthe terms of the GNU General Public License as published by the Free 10177548ScsjpSoftware Foundation; either version 2, or (at your option) any later 11177548Scsjpversion. 12177548Scsjp 13177548Scsjpgroff is distributed in the hope that it will be useful, but WITHOUT ANY 14177548ScsjpWARRANTY; without even the implied warranty of MERCHANTABILITY or 15177548ScsjpFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16177548Scsjpfor more details. 17177548Scsjp 18177548ScsjpYou should have received a copy of the GNU General Public License along 19177548Scsjpwith groff; see the file COPYING. If not, write to the Free Software 20177548ScsjpFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 21177548Scsjp 22177548Scsjp#ifdef HAVE_CONFIG_H 23177548Scsjp#include <config.h> 24177548Scsjp#endif 25177548Scsjp 26177548Scsjpextern "C" { 27177548Scsjp#ifndef HAVE_STRERROR 28177548Scsjp char *strerror(int); 29177548Scsjp#endif 30177548Scsjp const char *i_to_a(int); 31177548Scsjp const char *ui_to_a(unsigned int); 32177548Scsjp const char *if_to_a(int, int); 33177548Scsjp} 34177548Scsjp 35177548Scsjp#define __GETOPT_PREFIX groff_ 36177548Scsjp#include <getopt.h> 37177548Scsjp 38177548Scsjp#ifdef HAVE_SETLOCALE 39177548Scsjp#include <locale.h> 40177548Scsjp#else 41177548Scsjp#define setlocale(category, locale) do {} while(0) 42177548Scsjp#endif 43177548Scsjp 44177548Scsjpchar *strsave(const char *s); 45177548Scsjpint is_prime(unsigned); 46177548Scsjpdouble groff_hypot(double, double); 47177548Scsjp 48177548Scsjp#include <stdio.h> 49177548Scsjp#include <string.h> 50#ifdef HAVE_STRINGS_H 51#include <strings.h> 52#endif 53 54#include <stdarg.h> 55 56/* HP-UX 10.20 and LynxOS 4.0.0 don't declare snprintf() */ 57#if !defined(HAVE_SNPRINTF) || defined(NEED_DECLARATION_SNPRINTF) 58extern "C" { int snprintf(char *, size_t, const char *, /*args*/ ...); } 59#endif 60 61/* LynxOS 4.0.0 has snprintf() but no vsnprintf() */ 62#if !defined(HAVE_VSNPRINTF) || defined(NEED_DECLARATION_VSNPRINTF) 63extern "C" { int vsnprintf(char *, size_t, const char *, va_list); } 64#endif 65 66/* LynxOS 4.0.0 doesn't declare vfprintf() */ 67#ifdef NEED_DECLARATION_VFPRINTF 68extern "C" { int vfprintf(FILE *, const char *, va_list); } 69#endif 70 71#ifndef HAVE_MKSTEMP 72/* since mkstemp() is defined as a real C++ function if taken from 73 groff's mkstemp.cpp we need a declaration */ 74int mkstemp(char *tmpl); 75#endif /* HAVE_MKSTEMP */ 76 77int mksdir(char *tmpl); 78 79FILE *xtmpfile(char **namep = 0, 80 const char *postfix_long = 0, const char *postfix_short = 0, 81 int do_unlink = 1); 82char *xtmptemplate(const char *postfix_long, const char *postfix_short); 83 84#ifdef NEED_DECLARATION_POPEN 85extern "C" { FILE *popen(const char *, const char *); } 86#endif /* NEED_DECLARATION_POPEN */ 87 88#ifdef NEED_DECLARATION_PCLOSE 89extern "C" { int pclose (FILE *); } 90#endif /* NEED_DECLARATION_PCLOSE */ 91 92size_t file_name_max(const char *fname); 93size_t path_name_max(); 94 95int interpret_lf_args(const char *p); 96 97extern char invalid_char_table[]; 98 99inline int invalid_input_char(int c) 100{ 101 return c >= 0 && invalid_char_table[c]; 102} 103 104#ifdef HAVE_STRCASECMP 105#ifdef NEED_DECLARATION_STRCASECMP 106// Ultrix4.3's string.h fails to declare this. 107extern "C" { int strcasecmp(const char *, const char *); } 108#endif /* NEED_DECLARATION_STRCASECMP */ 109#else /* not HAVE_STRCASECMP */ 110extern "C" { int strcasecmp(const char *, const char *); } 111#endif /* HAVE_STRCASECMP */ 112 113#if !defined(_AIX) && !defined(sinix) && !defined(__sinix__) 114#ifdef HAVE_STRNCASECMP 115#ifdef NEED_DECLARATION_STRNCASECMP 116// SunOS's string.h fails to declare this. 117extern "C" { int strncasecmp(const char *, const char *, int); } 118#endif /* NEED_DECLARATION_STRNCASECMP */ 119#else /* not HAVE_STRNCASECMP */ 120extern "C" { int strncasecmp(const char *, const char *, size_t); } 121#endif /* HAVE_STRNCASECMP */ 122#endif /* !_AIX && !sinix && !__sinix__ */ 123 124#ifdef HAVE_CC_LIMITS_H 125#include <limits.h> 126#else /* not HAVE_CC_LIMITS_H */ 127#define INT_MAX 2147483647 128#endif /* not HAVE_CC_LIMITS_H */ 129 130/* It's not safe to rely on people getting INT_MIN right (ie signed). */ 131 132#ifdef INT_MIN 133#undef INT_MIN 134#endif 135 136#ifdef CFRONT_ANSI_BUG 137 138/* This works around a bug in cfront 2.0 used with ANSI C compilers. */ 139 140#define INT_MIN ((long)(-INT_MAX-1)) 141 142#else /* not CFRONT_ANSI_BUG */ 143 144#define INT_MIN (-INT_MAX-1) 145 146#endif /* not CFRONT_ANSI_BUG */ 147 148/* Maximum number of digits in the decimal representation of an int 149(not including the -). */ 150 151#define INT_DIGITS 10 152 153#ifdef PI 154#undef PI 155#endif 156 157const double PI = 3.14159265358979323846; 158 159/* ad_delete deletes an array of objects with destructors; 160a_delete deletes an array of objects without destructors */ 161 162#ifdef ARRAY_DELETE_NEEDS_SIZE 163/* for 2.0 systems */ 164#define ad_delete(size) delete [size] 165#define a_delete delete 166#else /* not ARRAY_DELETE_NEEDS_SIZE */ 167/* for ARM systems */ 168#define ad_delete(size) delete [] 169#define a_delete delete [] 170#endif /* not ARRAY_DELETE_NEEDS_SIZE */ 171