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