lib.h revision 104862
1// -*- C++ -*- 2/* Copyright (C) 1989-2000, 2001, 2002 Free Software Foundation, Inc. 3 Written by James Clark (jjc@jclark.com) 4 5This file is part of groff. 6 7groff is free software; you can redistribute it and/or modify it under 8the terms of the GNU General Public License as published by the Free 9Software Foundation; either version 2, or (at your option) any later 10version. 11 12groff is distributed in the hope that it will be useful, but WITHOUT ANY 13WARRANTY; without even the implied warranty of MERCHANTABILITY or 14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15for more details. 16 17You should have received a copy of the GNU General Public License along 18with groff; see the file COPYING. If not, write to the Free Software 19Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 21#ifdef HAVE_CONFIG_H 22#include <config.h> 23#endif 24 25extern "C" { 26#ifndef HAVE_STRERROR 27 char *strerror(int); 28#endif 29 const char *i_to_a(int); 30 const char *ui_to_a(unsigned int); 31 const char *if_to_a(int, int); 32} 33 34/* stdio.h on IRIX, OSF/1, emx, and UWIN include getopt.h */ 35/* unistd.h on CYGWIN includes getopt.h */ 36 37#if !(defined(__sgi) \ 38 || (defined(__osf__) && defined(__alpha)) \ 39 || defined(_UWIN) \ 40 || defined(__EMX__) \ 41 || defined(__CYGWIN__)) 42#include <groff-getopt.h> 43#else 44#include <getopt.h> 45#endif 46 47char *strsave(const char *s); 48int is_prime(unsigned); 49 50#include <stdio.h> 51#include <string.h> 52#ifdef HAVE_STRINGS_H 53#include <strings.h> 54#endif 55 56#ifndef HAVE_SNPRINTF 57#include <stdarg.h> 58extern "C" { 59 int snprintf(char *, size_t, const char *, /*args*/ ...); 60 int vsnprintf(char *, size_t, const char *, va_list); 61} 62#endif 63 64#ifndef HAVE_MKSTEMP 65/* since mkstemp() is defined as a real C++ function if taken from 66 groff's mkstemp.cc we need a declaration */ 67int mkstemp(char *tmpl); 68#endif /* HAVE_MKSTEMP */ 69 70int mksdir(char *tmpl); 71 72FILE *xtmpfile(char **namep = 0, 73 const char *postfix_long = 0, const char *postfix_short = 0, 74 int do_unlink = 1); 75char *xtmptemplate(const char *postfix_long, const char *postfix_short); 76 77#ifdef NEED_DECLARATION_POPEN 78extern "C" { FILE *popen(const char *, const char *); } 79#endif /* NEED_DECLARATION_POPEN */ 80 81#ifdef NEED_DECLARATION_PCLOSE 82extern "C" { int pclose (FILE *); } 83#endif /* NEED_DECLARATION_PCLOSE */ 84 85size_t file_name_max(const char *fname); 86 87int interpret_lf_args(const char *p); 88 89extern char invalid_char_table[]; 90 91inline int invalid_input_char(int c) 92{ 93 return c >= 0 && invalid_char_table[c]; 94} 95 96#ifdef HAVE_STRCASECMP 97#ifdef NEED_DECLARATION_STRCASECMP 98extern "C" { 99 // Ultrix4.3's string.h fails to declare this. 100 int strcasecmp(const char *, const char *); 101} 102#endif /* NEED_DECLARATION_STRCASECMP */ 103#endif /* HAVE_STRCASECMP */ 104 105#if !defined(_AIX) && !defined(sinix) && !defined(__sinix__) 106#ifdef HAVE_STRNCASECMP 107#ifdef NEED_DECLARATION_STRNCASECMP 108extern "C" { 109 // SunOS's string.h fails to declare this. 110 int strncasecmp(const char *, const char *, int); 111} 112#endif /* NEED_DECLARATION_STRNCASECMP */ 113#endif /* HAVE_STRNCASECMP */ 114#endif /* !_AIX && !sinix && !__sinix__ */ 115 116#ifndef HAVE_STRCASECMP 117#define strcasecmp(a,b) strcmp((a),(b)) 118#endif 119 120#ifndef HAVE_STRNCASECMP 121#define strncasecmp(a,b,c) strncmp((a),(b),(c)) 122#endif 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