1 /* GNU SED, a batch stream editor. 2 Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2, or (at your option) 7 any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 17 18 #ifndef BASICDEFS_H 19 #define BASICDEFS_H 20 21 #include <alloca.h> 22 23 #ifdef HAVE_WCHAR_H 24 # include <wchar.h> 25 #endif 26 #ifdef HAVE_LOCALE_H 27 # include <locale.h> 28 #endif 29 #ifdef HAVE_WCTYPE_H 30 # include <wctype.h> 31 #endif 32 33 34 #ifdef BOOTSTRAP 35 # define false 0 36 # define true 1 37 # define bool unsigned 38 # define __bool_true_false_are_defined 1 39 #else 40 # include <stdbool.h> 41 #endif 42 43 #include <gettext.h> 44 #define N_(String) gettext_noop(String) 45 #define _(String) gettext(String) 46 47 /* type countT is used to keep track of line numbers, etc. */ 48 typedef unsigned long countT; 49 50 /* Oftentimes casts are used as an ugly hack to silence warnings 51 * from the compiler. However, sometimes those warnings really 52 * do point to something worth avoiding. I define this 53 * dummy marker to make searching for them with a text editor 54 * much easier, in case I want to verify that they are all 55 * legitimate. It is defined in the way it is so that it is 56 * easy to disable all casts so that the compiler (or lint) 57 * can tell me potentially interesting things about what would 58 * happen to the code without the explicit casts. 59 */ 60 #ifdef LOUD_LINT 61 # define CAST(x) 62 #else 63 # define CAST(x) (x) 64 #endif 65 66 67 /* Can the compiler grok function prototypes? */ 68 #if (defined __STDC__ && __STDC__-0) || defined __GNUC__ || __PROTOTYPES 69 # define P_(s) s 70 #else 71 # define P_(s) () 72 #endif 73 74 /* (VOID *) is the generic pointer type; some ancient compilers 75 don't know about (void *), and typically use (char *) instead. 76 VCAST() is used to cast to and from (VOID *)s --- but if the 77 compiler *does* support (void *) make this a no-op, so that 78 the compiler can detect if we omitted an essential function 79 declaration somewhere. 80 */ 81 #ifndef VOID 82 # define VOID void 83 # define VCAST(t) 84 #else 85 # define VCAST(t) (t) 86 #endif 87 88 /* some basic definitions to avoid undue promulgating of VCAST ugliness */ 89 #define MALLOC(n,t) (VCAST(t *)ck_malloc((n)*sizeof(t))) 90 #define REALLOC(x,n,t) (VCAST(t *)ck_realloc(VCAST(VOID *)(x),(n)*sizeof(t))) 91 #define MEMDUP(x,n,t) (VCAST(t *)ck_memdup(VCAST(VOID *)(x),(n)*sizeof(t))) 92 #define FREE(x) (ck_free(VCAST(VOID *)x)) 93 #define MEMCPY(d,s,l) (memcpy(VCAST(VOID *)(d),VCAST(const VOID *)(s),l)) 94 #define MEMMOVE(d,s,l) (memmove(VCAST(VOID *)(d),VCAST(const VOID *)(s),l)) 95 #define OB_MALLOC(o,n,t) ((t *)(void *)obstack_alloc(o,(n)*sizeof(t))) 96 97 #define obstack_chunk_alloc ck_malloc 98 #define obstack_chunk_free ck_free 99 100 101 #ifdef HAVE_MEMORY_H 102 # include <memory.h> 103 #endif 104 105 #ifndef HAVE_MEMMOVE 106 # ifndef memmove 107 /* ../lib/libsed.a provides a memmove() if the system doesn't. 108 Here is where we declare its return type; we don't prototype 109 it because that sometimes causes problems when we're running in 110 bootstrap mode on a system which really does support memmove(). */ 111 extern VOID *memmove(); 112 # endif 113 #endif 114 115 #ifndef HAVE_MEMCPY 116 # ifndef memcpy 117 # define memcpy(d, s, n) memmove(d, s, n) 118 # endif 119 #endif 120 121 #ifndef HAVE_STRERROR 122 extern char *strerror P_((int e)); 123 #endif 124 125 126 /* handle misdesigned <ctype.h> macros (snarfed from lib/regex.c) */ 127 /* Jim Meyering writes: 128 129 "... Some ctype macros are valid only for character codes that 130 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when 131 using /bin/cc or gcc but without giving an ansi option). So, all 132 ctype uses should be through macros like ISPRINT... If 133 STDC_HEADERS is defined, then autoconf has verified that the ctype 134 macros don't need to be guarded with references to isascii. ... 135 Defining isascii to 1 should let any compiler worth its salt 136 eliminate the && through constant folding." 137 Solaris defines some of these symbols so we must undefine them first. */ 138 139 #undef ISASCII 140 #if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII) 141 # define ISASCII(c) 1 142 #else 143 # define ISASCII(c) isascii(c) 144 #endif 145 146 #if defined isblank || defined HAVE_ISBLANK 147 # define ISBLANK(c) (ISASCII (c) && isblank (c)) 148 #else 149 # define ISBLANK(c) ((c) == ' ' || (c) == '\t') 150 #endif 151 152 #undef ISPRINT 153 #define ISPRINT(c) (ISASCII (c) && isprint (c)) 154 #define ISDIGIT(c) (ISASCII (c) && isdigit (c)) 155 #define ISALNUM(c) (ISASCII (c) && isalnum (c)) 156 #define ISALPHA(c) (ISASCII (c) && isalpha (c)) 157 #define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) 158 #define ISLOWER(c) (ISASCII (c) && islower (c)) 159 #define ISPUNCT(c) (ISASCII (c) && ispunct (c)) 160 #define ISSPACE(c) (ISASCII (c) && isspace (c)) 161 #define ISUPPER(c) (ISASCII (c) && isupper (c)) 162 #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) 163 164 #ifndef initialize_main 165 # ifdef __EMX__ 166 # define initialize_main(argcp, argvp) \ 167 { _response(argcp, argvp); _wildcard(argcp, argvp); } 168 # else /* NOT __EMX__ */ 169 # define initialize_main(argcp, argvp) 170 # endif 171 #endif 172 173 #endif /*!BASICDEFS_H*/ 174