| 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 | #if defined(_AIX) | 
|---|
| 22 | #pragma alloca | 
|---|
| 23 | #else | 
|---|
| 24 | # if !defined(alloca)           /* predefined by HP cc +Olibcalls */ | 
|---|
| 25 | #  ifdef __GNUC__ | 
|---|
| 26 | #   define alloca(size) __builtin_alloca(size) | 
|---|
| 27 | #  else | 
|---|
| 28 | #   if HAVE_ALLOCA_H | 
|---|
| 29 | #    include <alloca.h> | 
|---|
| 30 | #   else | 
|---|
| 31 | #    if defined(__hpux) | 
|---|
| 32 | void *alloca (); | 
|---|
| 33 | #    else | 
|---|
| 34 | #     if !defined(__OS2__) && !defined(WIN32) | 
|---|
| 35 | char *alloca (); | 
|---|
| 36 | #     else | 
|---|
| 37 | #      include <malloc.h>       /* OS/2 defines alloca in here */ | 
|---|
| 38 | #     endif | 
|---|
| 39 | #    endif | 
|---|
| 40 | #   endif | 
|---|
| 41 | #  endif | 
|---|
| 42 | # endif | 
|---|
| 43 | #endif | 
|---|
| 44 |  | 
|---|
| 45 | #ifdef HAVE_WCHAR_H | 
|---|
| 46 | # include <wchar.h> | 
|---|
| 47 | #endif | 
|---|
| 48 | #ifdef HAVE_LOCALE_H | 
|---|
| 49 | # include <locale.h> | 
|---|
| 50 | #endif | 
|---|
| 51 | #ifdef HAVE_WCTYPE_H | 
|---|
| 52 | # include <wctype.h> | 
|---|
| 53 | #endif | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | #ifdef BOOTSTRAP | 
|---|
| 57 | # define false 0 | 
|---|
| 58 | # define true 1 | 
|---|
| 59 | # define bool unsigned | 
|---|
| 60 | # define __bool_true_false_are_defined 1 | 
|---|
| 61 | #else | 
|---|
| 62 | # if HAVE_STDBOOL_H || defined(__HAIKU__) /* haiku/gcc2 hack */ | 
|---|
| 63 | #  include <stdbool.h> | 
|---|
| 64 | # endif | 
|---|
| 65 | #endif | 
|---|
| 66 |  | 
|---|
| 67 | #if ENABLE_NLS | 
|---|
| 68 | # include <libintl.h> | 
|---|
| 69 | #else | 
|---|
| 70 | # define gettext(msgid) (msgid) | 
|---|
| 71 | # define ngettext(sing, plur, n) ((n) == 1 ? (sing) : (plur)) | 
|---|
| 72 | #endif | 
|---|
| 73 | #define _(String) gettext(String) | 
|---|
| 74 |  | 
|---|
| 75 | #ifdef gettext_noop | 
|---|
| 76 | # define N_(String) gettext_noop(String) | 
|---|
| 77 | #else | 
|---|
| 78 | # define N_(String) (String) | 
|---|
| 79 | #endif | 
|---|
| 80 |  | 
|---|
| 81 | /* type countT is used to keep track of line numbers, etc. */ | 
|---|
| 82 | typedef unsigned long countT; | 
|---|
| 83 |  | 
|---|
| 84 | /* Oftentimes casts are used as an ugly hack to silence warnings | 
|---|
| 85 | * from the compiler.  However, sometimes those warnings really | 
|---|
| 86 | * do point to something worth avoiding.  I define this | 
|---|
| 87 | * dummy marker to make searching for them with a text editor | 
|---|
| 88 | * much easier, in case I want to verify that they are all | 
|---|
| 89 | * legitimate.  It is defined in the way it is so that it is | 
|---|
| 90 | * easy to disable all casts so that the compiler (or lint) | 
|---|
| 91 | * can tell me potentially interesting things about what would | 
|---|
| 92 | * happen to the code without the explicit casts. | 
|---|
| 93 | */ | 
|---|
| 94 | #ifdef LOUD_LINT | 
|---|
| 95 | # define CAST(x) | 
|---|
| 96 | #else | 
|---|
| 97 | # define CAST(x) (x) | 
|---|
| 98 | #endif | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 | /* Can the compiler grok function prototypes? */ | 
|---|
| 102 | #if (defined __STDC__ && __STDC__-0) || defined __GNUC__ || defined __SUNPRO_C || __PROTOTYPES | 
|---|
| 103 | # define P_(s)          s | 
|---|
| 104 | #else | 
|---|
| 105 | # define P_(s)          () | 
|---|
| 106 | #endif | 
|---|
| 107 |  | 
|---|
| 108 | /* (VOID *) is the generic pointer type; some ancient compilers | 
|---|
| 109 | don't know about (void *), and typically use (char *) instead. | 
|---|
| 110 | VCAST() is used to cast to and from (VOID *)s --- but if the | 
|---|
| 111 | compiler *does* support (void *) make this a no-op, so that | 
|---|
| 112 | the compiler can detect if we omitted an essential function | 
|---|
| 113 | declaration somewhere. | 
|---|
| 114 | */ | 
|---|
| 115 | #ifndef VOID | 
|---|
| 116 | # define VOID           void | 
|---|
| 117 | # define VCAST(t) | 
|---|
| 118 | #else | 
|---|
| 119 | # define VCAST(t)       (t) | 
|---|
| 120 | #endif | 
|---|
| 121 |  | 
|---|
| 122 | /* some basic definitions to avoid undue promulgating of VCAST ugliness */ | 
|---|
| 123 | #define MALLOC(n,t)      (VCAST(t *)ck_malloc((n)*sizeof(t))) | 
|---|
| 124 | #define REALLOC(x,n,t)   (VCAST(t *)ck_realloc(VCAST(VOID *)(x),(n)*sizeof(t))) | 
|---|
| 125 | #define MEMDUP(x,n,t)    (VCAST(t *)ck_memdup(VCAST(VOID *)(x),(n)*sizeof(t))) | 
|---|
| 126 | #define FREE(x)          (ck_free(VCAST(VOID *)x)) | 
|---|
| 127 | #define MEMCPY(d,s,l)    (memcpy(VCAST(VOID *)(d),VCAST(const VOID *)(s),l)) | 
|---|
| 128 | #define MEMMOVE(d,s,l)   (memmove(VCAST(VOID *)(d),VCAST(const VOID *)(s),l)) | 
|---|
| 129 | #define OB_MALLOC(o,n,t) (VCAST(t *)obstack_alloc(o,(n)*sizeof(t))) | 
|---|
| 130 |  | 
|---|
| 131 | #define obstack_chunk_alloc  ck_malloc | 
|---|
| 132 | #define obstack_chunk_free   ck_free | 
|---|
| 133 |  | 
|---|
| 134 |  | 
|---|
| 135 | #ifdef HAVE_MEMORY_H | 
|---|
| 136 | # include <memory.h> | 
|---|
| 137 | #endif | 
|---|
| 138 |  | 
|---|
| 139 | #ifndef HAVE_MEMMOVE | 
|---|
| 140 | # ifndef memmove | 
|---|
| 141 | /* ../lib/libsed.a provides a memmove() if the system doesn't. | 
|---|
| 142 | Here is where we declare its return type; we don't prototype | 
|---|
| 143 | it because that sometimes causes problems when we're running in | 
|---|
| 144 | bootstrap mode on a system which really does support memmove(). */ | 
|---|
| 145 | extern VOID *memmove(); | 
|---|
| 146 | # endif | 
|---|
| 147 | #endif | 
|---|
| 148 |  | 
|---|
| 149 | #ifndef HAVE_MEMCPY | 
|---|
| 150 | # ifndef memcpy | 
|---|
| 151 | #  define memcpy(d, s, n)       memmove(d, s, n) | 
|---|
| 152 | # endif | 
|---|
| 153 | #endif | 
|---|
| 154 |  | 
|---|
| 155 | #ifndef HAVE_STRERROR | 
|---|
| 156 | extern char *strerror P_((int e)); | 
|---|
| 157 | #endif | 
|---|
| 158 |  | 
|---|
| 159 |  | 
|---|
| 160 | /* handle misdesigned <ctype.h> macros (snarfed from lib/regex.c) */ | 
|---|
| 161 | /* Jim Meyering writes: | 
|---|
| 162 |  | 
|---|
| 163 | "... Some ctype macros are valid only for character codes that | 
|---|
| 164 | isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when | 
|---|
| 165 | using /bin/cc or gcc but without giving an ansi option).  So, all | 
|---|
| 166 | ctype uses should be through macros like ISPRINT...  If | 
|---|
| 167 | STDC_HEADERS is defined, then autoconf has verified that the ctype | 
|---|
| 168 | macros don't need to be guarded with references to isascii. ... | 
|---|
| 169 | Defining isascii to 1 should let any compiler worth its salt | 
|---|
| 170 | eliminate the && through constant folding." | 
|---|
| 171 | Solaris defines some of these symbols so we must undefine them first. */ | 
|---|
| 172 |  | 
|---|
| 173 | #undef ISASCII | 
|---|
| 174 | #if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII) | 
|---|
| 175 | # define ISASCII(c) 1 | 
|---|
| 176 | #else | 
|---|
| 177 | # define ISASCII(c) isascii(c) | 
|---|
| 178 | #endif | 
|---|
| 179 |  | 
|---|
| 180 | #if defined isblank || defined HAVE_ISBLANK | 
|---|
| 181 | # define ISBLANK(c) (ISASCII (c) && isblank (c)) | 
|---|
| 182 | #else | 
|---|
| 183 | # define ISBLANK(c) ((c) == ' ' || (c) == '\t') | 
|---|
| 184 | #endif | 
|---|
| 185 |  | 
|---|
| 186 | #undef ISPRINT | 
|---|
| 187 | #define ISPRINT(c) (ISASCII (c) && isprint (c)) | 
|---|
| 188 | #define ISDIGIT(c) (ISASCII (c) && isdigit (c)) | 
|---|
| 189 | #define ISALNUM(c) (ISASCII (c) && isalnum (c)) | 
|---|
| 190 | #define ISALPHA(c) (ISASCII (c) && isalpha (c)) | 
|---|
| 191 | #define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) | 
|---|
| 192 | #define ISLOWER(c) (ISASCII (c) && islower (c)) | 
|---|
| 193 | #define ISPUNCT(c) (ISASCII (c) && ispunct (c)) | 
|---|
| 194 | #define ISSPACE(c) (ISASCII (c) && isspace (c)) | 
|---|
| 195 | #define ISUPPER(c) (ISASCII (c) && isupper (c)) | 
|---|
| 196 | #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) | 
|---|
| 197 |  | 
|---|
| 198 | #ifndef initialize_main | 
|---|
| 199 | # ifdef __EMX__ | 
|---|
| 200 | #  define initialize_main(argcp, argvp) \ | 
|---|
| 201 | { _response(argcp, argvp); _wildcard(argcp, argvp); } | 
|---|
| 202 | # else /* NOT __EMX__ */ | 
|---|
| 203 | #  define initialize_main(argcp, argvp) | 
|---|
| 204 | # endif | 
|---|
| 205 | #endif | 
|---|
| 206 |  | 
|---|
| 207 | #endif /*!BASICDEFS_H*/ | 
|---|