[10723] | 1 | /* handy.h |
---|
[9008] | 2 | * |
---|
[14544] | 3 | * Copyright (c) 1991-2000, Larry Wall |
---|
[9008] | 4 | * |
---|
| 5 | * You may distribute under the terms of either the GNU General Public |
---|
| 6 | * License or the Artistic License, as specified in the README file. |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
[10723] | 10 | #if !defined(__STDC__) |
---|
[9008] | 11 | #ifdef NULL |
---|
| 12 | #undef NULL |
---|
| 13 | #endif |
---|
| 14 | #ifndef I286 |
---|
| 15 | # define NULL 0 |
---|
| 16 | #else |
---|
| 17 | # define NULL 0L |
---|
| 18 | #endif |
---|
[10723] | 19 | #endif |
---|
| 20 | |
---|
[9008] | 21 | #define Null(type) ((type)NULL) |
---|
[14544] | 22 | |
---|
| 23 | /* |
---|
| 24 | =for apidoc AmU||Nullch |
---|
| 25 | Null character pointer. |
---|
| 26 | |
---|
| 27 | =for apidoc AmU||Nullsv |
---|
| 28 | Null SV pointer. |
---|
| 29 | |
---|
| 30 | =cut |
---|
| 31 | */ |
---|
| 32 | |
---|
[9008] | 33 | #define Nullch Null(char*) |
---|
[10723] | 34 | #define Nullfp Null(PerlIO*) |
---|
| 35 | #define Nullsv Null(SV*) |
---|
[9008] | 36 | |
---|
| 37 | #ifdef TRUE |
---|
| 38 | #undef TRUE |
---|
| 39 | #endif |
---|
| 40 | #ifdef FALSE |
---|
| 41 | #undef FALSE |
---|
| 42 | #endif |
---|
| 43 | #define TRUE (1) |
---|
| 44 | #define FALSE (0) |
---|
| 45 | |
---|
| 46 | |
---|
[10723] | 47 | /* XXX Configure ought to have a test for a boolean type, if I can |
---|
| 48 | just figure out all the headers such a test needs. |
---|
| 49 | Andy Dougherty August 1996 |
---|
| 50 | */ |
---|
[14544] | 51 | /* bool is built-in for g++-2.6.3 and later, which might be used |
---|
| 52 | for extensions. <_G_config.h> defines _G_HAVE_BOOL, but we can't |
---|
| 53 | be sure _G_config.h will be included before this file. _G_config.h |
---|
| 54 | also defines _G_HAVE_BOOL for both gcc and g++, but only g++ |
---|
| 55 | actually has bool. Hence, _G_HAVE_BOOL is pretty useless for us. |
---|
| 56 | g++ can be identified by __GNUG__. |
---|
| 57 | Andy Dougherty February 2000 |
---|
[10723] | 58 | */ |
---|
[14544] | 59 | #ifdef __GNUG__ /* GNU g++ has bool built-in */ |
---|
[10723] | 60 | # ifndef HAS_BOOL |
---|
[14544] | 61 | # define HAS_BOOL 1 |
---|
[10723] | 62 | # endif |
---|
| 63 | #endif |
---|
| 64 | |
---|
| 65 | /* The NeXT dynamic loader headers will not build with the bool macro |
---|
| 66 | So declare them now to clear confusion. |
---|
| 67 | */ |
---|
[14544] | 68 | #if defined(NeXT) || defined(__NeXT__) |
---|
[10723] | 69 | # undef FALSE |
---|
| 70 | # undef TRUE |
---|
| 71 | typedef enum bool { FALSE = 0, TRUE = 1 } bool; |
---|
| 72 | # define ENUM_BOOL 1 |
---|
| 73 | # ifndef HAS_BOOL |
---|
| 74 | # define HAS_BOOL 1 |
---|
| 75 | # endif /* !HAS_BOOL */ |
---|
[14544] | 76 | #endif /* NeXT || __NeXT__ */ |
---|
[10723] | 77 | |
---|
| 78 | #ifndef HAS_BOOL |
---|
[14544] | 79 | # if defined(UTS) || defined(VMS) |
---|
[10723] | 80 | # define bool int |
---|
| 81 | # else |
---|
| 82 | # define bool char |
---|
| 83 | # endif |
---|
[14544] | 84 | # define HAS_BOOL 1 |
---|
[10723] | 85 | #endif |
---|
| 86 | |
---|
| 87 | /* XXX A note on the perl source internal type system. The |
---|
| 88 | original intent was that I32 be *exactly* 32 bits. |
---|
| 89 | |
---|
| 90 | Currently, we only guarantee that I32 is *at least* 32 bits. |
---|
| 91 | Specifically, if int is 64 bits, then so is I32. (This is the case |
---|
| 92 | for the Cray.) This has the advantage of meshing nicely with |
---|
| 93 | standard library calls (where we pass an I32 and the library is |
---|
| 94 | expecting an int), but the disadvantage that an I32 is not 32 bits. |
---|
| 95 | Andy Dougherty August 1996 |
---|
| 96 | |
---|
[14544] | 97 | There is no guarantee that there is *any* integral type with |
---|
| 98 | exactly 32 bits. It is perfectly legal for a system to have |
---|
| 99 | sizeof(short) == sizeof(int) == sizeof(long) == 8. |
---|
| 100 | |
---|
| 101 | Similarly, there is no guarantee that I16 and U16 have exactly 16 |
---|
| 102 | bits. |
---|
| 103 | |
---|
| 104 | For dealing with issues that may arise from various 32/64-bit |
---|
| 105 | systems, we will ask Configure to check out |
---|
| 106 | |
---|
| 107 | SHORTSIZE == sizeof(short) |
---|
| 108 | INTSIZE == sizeof(int) |
---|
| 109 | LONGSIZE == sizeof(long) |
---|
| 110 | LONGLONGSIZE == sizeof(long long) (if HAS_LONG_LONG) |
---|
| 111 | PTRSIZE == sizeof(void *) |
---|
| 112 | DOUBLESIZE == sizeof(double) |
---|
| 113 | LONG_DOUBLESIZE == sizeof(long double) (if HAS_LONG_DOUBLE). |
---|
| 114 | |
---|
[10723] | 115 | */ |
---|
| 116 | |
---|
[14544] | 117 | typedef I8TYPE I8; |
---|
| 118 | typedef U8TYPE U8; |
---|
| 119 | typedef I16TYPE I16; |
---|
| 120 | typedef U16TYPE U16; |
---|
| 121 | typedef I32TYPE I32; |
---|
| 122 | typedef U32TYPE U32; |
---|
| 123 | #ifdef PERL_CORE |
---|
| 124 | # ifdef HAS_QUAD |
---|
| 125 | # if QUADKIND == QUAD_IS_INT64_T |
---|
| 126 | # include <sys/types.h> |
---|
| 127 | # ifdef I_INTTYPES /* e.g. Linux has int64_t without <inttypes.h> */ |
---|
| 128 | # include <inttypes.h> |
---|
| 129 | # endif |
---|
| 130 | # endif |
---|
| 131 | typedef I64TYPE I64; |
---|
| 132 | typedef U64TYPE U64; |
---|
| 133 | # endif |
---|
| 134 | #endif /* PERL_CORE */ |
---|
| 135 | |
---|
| 136 | /* Mention I8SIZE, U8SIZE, I16SIZE, U16SIZE, I32SIZE, U32SIZE, |
---|
| 137 | I64SIZE, and U64SIZE here so that metaconfig pulls them in. */ |
---|
| 138 | |
---|
| 139 | #if defined(UINT8_MAX) && defined(INT16_MAX) && defined(INT32_MAX) |
---|
| 140 | |
---|
[10723] | 141 | /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type. |
---|
| 142 | Please search CHAR_MAX in perl.h for further details. */ |
---|
[14544] | 143 | #define U8_MAX UINT8_MAX |
---|
| 144 | #define U8_MIN UINT8_MIN |
---|
| 145 | |
---|
| 146 | #define I16_MAX INT16_MAX |
---|
| 147 | #define I16_MIN INT16_MIN |
---|
| 148 | #define U16_MAX UINT16_MAX |
---|
| 149 | #define U16_MIN UINT16_MIN |
---|
| 150 | |
---|
| 151 | #define I32_MAX INT32_MAX |
---|
| 152 | #define I32_MIN INT32_MIN |
---|
| 153 | #define U32_MAX UINT32_MAX |
---|
| 154 | #define U32_MIN UINT32_MIN |
---|
| 155 | |
---|
| 156 | #else |
---|
| 157 | |
---|
| 158 | /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type. |
---|
| 159 | Please search CHAR_MAX in perl.h for further details. */ |
---|
[10723] | 160 | #define U8_MAX PERL_UCHAR_MAX |
---|
| 161 | #define U8_MIN PERL_UCHAR_MIN |
---|
| 162 | |
---|
| 163 | #define I16_MAX PERL_SHORT_MAX |
---|
| 164 | #define I16_MIN PERL_SHORT_MIN |
---|
| 165 | #define U16_MAX PERL_USHORT_MAX |
---|
| 166 | #define U16_MIN PERL_USHORT_MIN |
---|
| 167 | |
---|
[14544] | 168 | #if LONGSIZE > 4 |
---|
[10723] | 169 | # define I32_MAX PERL_INT_MAX |
---|
| 170 | # define I32_MIN PERL_INT_MIN |
---|
| 171 | # define U32_MAX PERL_UINT_MAX |
---|
| 172 | # define U32_MIN PERL_UINT_MIN |
---|
| 173 | #else |
---|
| 174 | # define I32_MAX PERL_LONG_MAX |
---|
| 175 | # define I32_MIN PERL_LONG_MIN |
---|
| 176 | # define U32_MAX PERL_ULONG_MAX |
---|
| 177 | # define U32_MIN PERL_ULONG_MIN |
---|
| 178 | #endif |
---|
| 179 | |
---|
[14544] | 180 | #endif |
---|
| 181 | |
---|
[10723] | 182 | #define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */ |
---|
| 183 | #define TYPE_DIGITS(T) BIT_DIGITS(sizeof(T) * 8) |
---|
| 184 | #define TYPE_CHARS(T) (TYPE_DIGITS(T) + 2) /* sign, NUL */ |
---|
| 185 | |
---|
| 186 | #define Ctl(ch) ((ch) & 037) |
---|
| 187 | |
---|
[14544] | 188 | /* |
---|
| 189 | =for apidoc Am|bool|strNE|char* s1|char* s2 |
---|
| 190 | Test two strings to see if they are different. Returns true or |
---|
| 191 | false. |
---|
| 192 | |
---|
| 193 | =for apidoc Am|bool|strEQ|char* s1|char* s2 |
---|
| 194 | Test two strings to see if they are equal. Returns true or false. |
---|
| 195 | |
---|
| 196 | =for apidoc Am|bool|strLT|char* s1|char* s2 |
---|
| 197 | Test two strings to see if the first, C<s1>, is less than the second, |
---|
| 198 | C<s2>. Returns true or false. |
---|
| 199 | |
---|
| 200 | =for apidoc Am|bool|strLE|char* s1|char* s2 |
---|
| 201 | Test two strings to see if the first, C<s1>, is less than or equal to the |
---|
| 202 | second, C<s2>. Returns true or false. |
---|
| 203 | |
---|
| 204 | =for apidoc Am|bool|strGT|char* s1|char* s2 |
---|
| 205 | Test two strings to see if the first, C<s1>, is greater than the second, |
---|
| 206 | C<s2>. Returns true or false. |
---|
| 207 | |
---|
| 208 | =for apidoc Am|bool|strGE|char* s1|char* s2 |
---|
| 209 | Test two strings to see if the first, C<s1>, is greater than or equal to |
---|
| 210 | the second, C<s2>. Returns true or false. |
---|
| 211 | |
---|
| 212 | =for apidoc Am|bool|strnNE|char* s1|char* s2|STRLEN len |
---|
| 213 | Test two strings to see if they are different. The C<len> parameter |
---|
| 214 | indicates the number of bytes to compare. Returns true or false. (A |
---|
| 215 | wrapper for C<strncmp>). |
---|
| 216 | |
---|
| 217 | =for apidoc Am|bool|strnEQ|char* s1|char* s2|STRLEN len |
---|
| 218 | Test two strings to see if they are equal. The C<len> parameter indicates |
---|
| 219 | the number of bytes to compare. Returns true or false. (A wrapper for |
---|
| 220 | C<strncmp>). |
---|
| 221 | |
---|
| 222 | =cut |
---|
| 223 | */ |
---|
| 224 | |
---|
[9008] | 225 | #define strNE(s1,s2) (strcmp(s1,s2)) |
---|
| 226 | #define strEQ(s1,s2) (!strcmp(s1,s2)) |
---|
| 227 | #define strLT(s1,s2) (strcmp(s1,s2) < 0) |
---|
| 228 | #define strLE(s1,s2) (strcmp(s1,s2) <= 0) |
---|
| 229 | #define strGT(s1,s2) (strcmp(s1,s2) > 0) |
---|
| 230 | #define strGE(s1,s2) (strcmp(s1,s2) >= 0) |
---|
| 231 | #define strnNE(s1,s2,l) (strncmp(s1,s2,l)) |
---|
| 232 | #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l)) |
---|
| 233 | |
---|
[10723] | 234 | #ifdef HAS_MEMCMP |
---|
| 235 | # define memNE(s1,s2,l) (memcmp(s1,s2,l)) |
---|
| 236 | # define memEQ(s1,s2,l) (!memcmp(s1,s2,l)) |
---|
[9008] | 237 | #else |
---|
[10723] | 238 | # define memNE(s1,s2,l) (bcmp(s1,s2,l)) |
---|
| 239 | # define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) |
---|
[9008] | 240 | #endif |
---|
| 241 | |
---|
[10723] | 242 | /* |
---|
| 243 | * Character classes. |
---|
| 244 | * |
---|
| 245 | * Unfortunately, the introduction of locales means that we |
---|
| 246 | * can't trust isupper(), etc. to tell the truth. And when |
---|
| 247 | * it comes to /\w+/ with tainting enabled, we *must* be able |
---|
| 248 | * to trust our character classes. |
---|
| 249 | * |
---|
| 250 | * Therefore, the default tests in the text of Perl will be |
---|
| 251 | * independent of locale. Any code that wants to depend on |
---|
| 252 | * the current locale will use the tests that begin with "lc". |
---|
| 253 | */ |
---|
| 254 | |
---|
| 255 | #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */ |
---|
| 256 | # ifndef CTYPE256 |
---|
| 257 | # define CTYPE256 |
---|
| 258 | # endif |
---|
| 259 | #endif |
---|
| 260 | |
---|
[14544] | 261 | /* |
---|
| 262 | =for apidoc Am|bool|isALNUM|char ch |
---|
| 263 | Returns a boolean indicating whether the C C<char> is an ascii alphanumeric |
---|
| 264 | character or digit. |
---|
| 265 | |
---|
| 266 | =for apidoc Am|bool|isALPHA|char ch |
---|
| 267 | Returns a boolean indicating whether the C C<char> is an ascii alphabetic |
---|
| 268 | character. |
---|
| 269 | |
---|
| 270 | =for apidoc Am|bool|isSPACE|char ch |
---|
| 271 | Returns a boolean indicating whether the C C<char> is whitespace. |
---|
| 272 | |
---|
| 273 | =for apidoc Am|bool|isDIGIT|char ch |
---|
| 274 | Returns a boolean indicating whether the C C<char> is an ascii |
---|
| 275 | digit. |
---|
| 276 | |
---|
| 277 | =for apidoc Am|bool|isUPPER|char ch |
---|
| 278 | Returns a boolean indicating whether the C C<char> is an uppercase |
---|
| 279 | character. |
---|
| 280 | |
---|
| 281 | =for apidoc Am|bool|isLOWER|char ch |
---|
| 282 | Returns a boolean indicating whether the C C<char> is a lowercase |
---|
| 283 | character. |
---|
| 284 | |
---|
| 285 | =for apidoc Am|char|toUPPER|char ch |
---|
| 286 | Converts the specified character to uppercase. |
---|
| 287 | |
---|
| 288 | =for apidoc Am|char|toLOWER|char ch |
---|
| 289 | Converts the specified character to lowercase. |
---|
| 290 | |
---|
| 291 | =cut |
---|
| 292 | */ |
---|
| 293 | |
---|
[10723] | 294 | #define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_') |
---|
| 295 | #define isIDFIRST(c) (isALPHA(c) || (c) == '_') |
---|
| 296 | #define isALPHA(c) (isUPPER(c) || isLOWER(c)) |
---|
| 297 | #define isSPACE(c) \ |
---|
| 298 | ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' || (c) == '\f') |
---|
| 299 | #define isDIGIT(c) ((c) >= '0' && (c) <= '9') |
---|
[14544] | 300 | #ifdef EBCDIC |
---|
| 301 | /* In EBCDIC we do not do locales: therefore() isupper() is fine. */ |
---|
| 302 | # define isUPPER(c) isupper(c) |
---|
| 303 | # define isLOWER(c) islower(c) |
---|
| 304 | # define isALNUMC(c) isalnum(c) |
---|
| 305 | # define isASCII(c) isascii(c) |
---|
| 306 | # define isCNTRL(c) iscntrl(c) |
---|
| 307 | # define isGRAPH(c) isgraph(c) |
---|
| 308 | # define isPRINT(c) isprint(c) |
---|
| 309 | # define isPUNCT(c) ispunct(c) |
---|
| 310 | # define isXDIGIT(c) isxdigit(c) |
---|
| 311 | # define toUPPER(c) toupper(c) |
---|
| 312 | # define toLOWER(c) tolower(c) |
---|
| 313 | #else |
---|
| 314 | # define isUPPER(c) ((c) >= 'A' && (c) <= 'Z') |
---|
| 315 | # define isLOWER(c) ((c) >= 'a' && (c) <= 'z') |
---|
| 316 | # define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) |
---|
| 317 | # define isASCII(c) ((c) <= 127) |
---|
| 318 | # define isCNTRL(c) ((c) < ' ') |
---|
| 319 | # define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) |
---|
| 320 | # define isPRINT(c) (((c) > 32 && (c) < 127) || isSPACE(c)) |
---|
| 321 | # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) |
---|
| 322 | # define isXDIGIT(c) (isdigit(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) |
---|
| 323 | # define toUPPER(c) (isLOWER(c) ? (c) - ('a' - 'A') : (c)) |
---|
| 324 | # define toLOWER(c) (isUPPER(c) ? (c) + ('a' - 'A') : (c)) |
---|
| 325 | #endif |
---|
[10723] | 326 | |
---|
| 327 | #ifdef USE_NEXT_CTYPE |
---|
| 328 | |
---|
| 329 | # define isALNUM_LC(c) \ |
---|
[14544] | 330 | (NXIsAlNum((unsigned int)(c)) || (char)(c) == '_') |
---|
[10723] | 331 | # define isIDFIRST_LC(c) \ |
---|
| 332 | (NXIsAlpha((unsigned int)(c)) || (char)(c) == '_') |
---|
| 333 | # define isALPHA_LC(c) NXIsAlpha((unsigned int)(c)) |
---|
| 334 | # define isSPACE_LC(c) NXIsSpace((unsigned int)(c)) |
---|
| 335 | # define isDIGIT_LC(c) NXIsDigit((unsigned int)(c)) |
---|
| 336 | # define isUPPER_LC(c) NXIsUpper((unsigned int)(c)) |
---|
| 337 | # define isLOWER_LC(c) NXIsLower((unsigned int)(c)) |
---|
[14544] | 338 | # define isALNUMC_LC(c) NXIsAlNum((unsigned int)(c)) |
---|
| 339 | # define isCNTRL_LC(c) NXIsCntrl((unsigned int)(c)) |
---|
| 340 | # define isGRAPH_LC(c) NXIsGraph((unsigned int)(c)) |
---|
[10723] | 341 | # define isPRINT_LC(c) NXIsPrint((unsigned int)(c)) |
---|
[14544] | 342 | # define isPUNCT_LC(c) NXIsPunct((unsigned int)(c)) |
---|
[10723] | 343 | # define toUPPER_LC(c) NXToUpper((unsigned int)(c)) |
---|
| 344 | # define toLOWER_LC(c) NXToLower((unsigned int)(c)) |
---|
| 345 | |
---|
| 346 | #else /* !USE_NEXT_CTYPE */ |
---|
[14544] | 347 | |
---|
[10723] | 348 | # if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII)) |
---|
| 349 | |
---|
[14544] | 350 | # define isALNUM_LC(c) (isalnum((unsigned char)(c)) || (char)(c) == '_') |
---|
[10723] | 351 | # define isIDFIRST_LC(c) (isalpha((unsigned char)(c)) || (char)(c) == '_') |
---|
| 352 | # define isALPHA_LC(c) isalpha((unsigned char)(c)) |
---|
| 353 | # define isSPACE_LC(c) isspace((unsigned char)(c)) |
---|
| 354 | # define isDIGIT_LC(c) isdigit((unsigned char)(c)) |
---|
| 355 | # define isUPPER_LC(c) isupper((unsigned char)(c)) |
---|
| 356 | # define isLOWER_LC(c) islower((unsigned char)(c)) |
---|
[14544] | 357 | # define isALNUMC_LC(c) isalnum((unsigned char)(c)) |
---|
| 358 | # define isCNTRL_LC(c) iscntrl((unsigned char)(c)) |
---|
| 359 | # define isGRAPH_LC(c) isgraph((unsigned char)(c)) |
---|
[10723] | 360 | # define isPRINT_LC(c) isprint((unsigned char)(c)) |
---|
[14544] | 361 | # define isPUNCT_LC(c) ispunct((unsigned char)(c)) |
---|
[10723] | 362 | # define toUPPER_LC(c) toupper((unsigned char)(c)) |
---|
| 363 | # define toLOWER_LC(c) tolower((unsigned char)(c)) |
---|
| 364 | |
---|
| 365 | # else |
---|
| 366 | |
---|
[14544] | 367 | # define isALNUM_LC(c) (isascii(c) && (isalnum(c) || (c) == '_')) |
---|
[10723] | 368 | # define isIDFIRST_LC(c) (isascii(c) && (isalpha(c) || (c) == '_')) |
---|
| 369 | # define isALPHA_LC(c) (isascii(c) && isalpha(c)) |
---|
| 370 | # define isSPACE_LC(c) (isascii(c) && isspace(c)) |
---|
| 371 | # define isDIGIT_LC(c) (isascii(c) && isdigit(c)) |
---|
| 372 | # define isUPPER_LC(c) (isascii(c) && isupper(c)) |
---|
| 373 | # define isLOWER_LC(c) (isascii(c) && islower(c)) |
---|
[14544] | 374 | # define isALNUMC_LC(c) (isascii(c) && isalnum(c)) |
---|
| 375 | # define isCNTRL_LC(c) (isascii(c) && iscntrl(c)) |
---|
| 376 | # define isGRAPH_LC(c) (isascii(c) && isgraph(c)) |
---|
[10723] | 377 | # define isPRINT_LC(c) (isascii(c) && isprint(c)) |
---|
[14544] | 378 | # define isPUNCT_LC(c) (isascii(c) && ispunct(c)) |
---|
[10723] | 379 | # define toUPPER_LC(c) toupper(c) |
---|
| 380 | # define toLOWER_LC(c) tolower(c) |
---|
| 381 | |
---|
| 382 | # endif |
---|
| 383 | #endif /* USE_NEXT_CTYPE */ |
---|
| 384 | |
---|
[14544] | 385 | #define isALNUM_uni(c) is_uni_alnum(c) |
---|
| 386 | #define isIDFIRST_uni(c) is_uni_idfirst(c) |
---|
| 387 | #define isALPHA_uni(c) is_uni_alpha(c) |
---|
| 388 | #define isSPACE_uni(c) is_uni_space(c) |
---|
| 389 | #define isDIGIT_uni(c) is_uni_digit(c) |
---|
| 390 | #define isUPPER_uni(c) is_uni_upper(c) |
---|
| 391 | #define isLOWER_uni(c) is_uni_lower(c) |
---|
| 392 | #define isALNUMC_uni(c) is_uni_alnumc(c) |
---|
| 393 | #define isASCII_uni(c) is_uni_ascii(c) |
---|
| 394 | #define isCNTRL_uni(c) is_uni_cntrl(c) |
---|
| 395 | #define isGRAPH_uni(c) is_uni_graph(c) |
---|
| 396 | #define isPRINT_uni(c) is_uni_print(c) |
---|
| 397 | #define isPUNCT_uni(c) is_uni_punct(c) |
---|
| 398 | #define isXDIGIT_uni(c) is_uni_xdigit(c) |
---|
| 399 | #define toUPPER_uni(c) to_uni_upper(c) |
---|
| 400 | #define toTITLE_uni(c) to_uni_title(c) |
---|
| 401 | #define toLOWER_uni(c) to_uni_lower(c) |
---|
[10723] | 402 | |
---|
[14544] | 403 | #define isALNUM_LC_uni(c) (c < 256 ? isALNUM_LC(c) : is_uni_alnum_lc(c)) |
---|
| 404 | #define isIDFIRST_LC_uni(c) (c < 256 ? isIDFIRST_LC(c) : is_uni_idfirst_lc(c)) |
---|
| 405 | #define isALPHA_LC_uni(c) (c < 256 ? isALPHA_LC(c) : is_uni_alpha_lc(c)) |
---|
| 406 | #define isSPACE_LC_uni(c) (c < 256 ? isSPACE_LC(c) : is_uni_space_lc(c)) |
---|
| 407 | #define isDIGIT_LC_uni(c) (c < 256 ? isDIGIT_LC(c) : is_uni_digit_lc(c)) |
---|
| 408 | #define isUPPER_LC_uni(c) (c < 256 ? isUPPER_LC(c) : is_uni_upper_lc(c)) |
---|
| 409 | #define isLOWER_LC_uni(c) (c < 256 ? isLOWER_LC(c) : is_uni_lower_lc(c)) |
---|
| 410 | #define isALNUMC_LC_uni(c) (c < 256 ? isALNUMC_LC(c) : is_uni_alnumc_lc(c)) |
---|
| 411 | #define isCNTRL_LC_uni(c) (c < 256 ? isCNTRL_LC(c) : is_uni_cntrl_lc(c)) |
---|
| 412 | #define isGRAPH_LC_uni(c) (c < 256 ? isGRAPH_LC(c) : is_uni_graph_lc(c)) |
---|
| 413 | #define isPRINT_LC_uni(c) (c < 256 ? isPRINT_LC(c) : is_uni_print_lc(c)) |
---|
| 414 | #define isPUNCT_LC_uni(c) (c < 256 ? isPUNCT_LC(c) : is_uni_punct_lc(c)) |
---|
| 415 | #define toUPPER_LC_uni(c) (c < 256 ? toUPPER_LC(c) : to_uni_upper_lc(c)) |
---|
| 416 | #define toTITLE_LC_uni(c) (c < 256 ? toUPPER_LC(c) : to_uni_title_lc(c)) |
---|
| 417 | #define toLOWER_LC_uni(c) (c < 256 ? toLOWER_LC(c) : to_uni_lower_lc(c)) |
---|
| 418 | |
---|
| 419 | #define isALNUM_utf8(p) is_utf8_alnum(p) |
---|
| 420 | #define isIDFIRST_utf8(p) is_utf8_idfirst(p) |
---|
| 421 | #define isALPHA_utf8(p) is_utf8_alpha(p) |
---|
| 422 | #define isSPACE_utf8(p) is_utf8_space(p) |
---|
| 423 | #define isDIGIT_utf8(p) is_utf8_digit(p) |
---|
| 424 | #define isUPPER_utf8(p) is_utf8_upper(p) |
---|
| 425 | #define isLOWER_utf8(p) is_utf8_lower(p) |
---|
| 426 | #define isALNUMC_utf8(p) is_utf8_alnumc(p) |
---|
| 427 | #define isASCII_utf8(p) is_utf8_ascii(p) |
---|
| 428 | #define isCNTRL_utf8(p) is_utf8_cntrl(p) |
---|
| 429 | #define isGRAPH_utf8(p) is_utf8_graph(p) |
---|
| 430 | #define isPRINT_utf8(p) is_utf8_print(p) |
---|
| 431 | #define isPUNCT_utf8(p) is_utf8_punct(p) |
---|
| 432 | #define isXDIGIT_utf8(p) is_utf8_xdigit(p) |
---|
| 433 | #define toUPPER_utf8(p) to_utf8_upper(p) |
---|
| 434 | #define toTITLE_utf8(p) to_utf8_title(p) |
---|
| 435 | #define toLOWER_utf8(p) to_utf8_lower(p) |
---|
| 436 | |
---|
| 437 | #define isALNUM_LC_utf8(p) isALNUM_LC_uni(utf8_to_uv(p, 0)) |
---|
| 438 | #define isIDFIRST_LC_utf8(p) isIDFIRST_LC_uni(utf8_to_uv(p, 0)) |
---|
| 439 | #define isALPHA_LC_utf8(p) isALPHA_LC_uni(utf8_to_uv(p, 0)) |
---|
| 440 | #define isSPACE_LC_utf8(p) isSPACE_LC_uni(utf8_to_uv(p, 0)) |
---|
| 441 | #define isDIGIT_LC_utf8(p) isDIGIT_LC_uni(utf8_to_uv(p, 0)) |
---|
| 442 | #define isUPPER_LC_utf8(p) isUPPER_LC_uni(utf8_to_uv(p, 0)) |
---|
| 443 | #define isLOWER_LC_utf8(p) isLOWER_LC_uni(utf8_to_uv(p, 0)) |
---|
| 444 | #define isALNUMC_LC_utf8(p) isALNUMC_LC_uni(utf8_to_uv(p, 0)) |
---|
| 445 | #define isCNTRL_LC_utf8(p) isCNTRL_LC_uni(utf8_to_uv(p, 0)) |
---|
| 446 | #define isGRAPH_LC_utf8(p) isGRAPH_LC_uni(utf8_to_uv(p, 0)) |
---|
| 447 | #define isPRINT_LC_utf8(p) isPRINT_LC_uni(utf8_to_uv(p, 0)) |
---|
| 448 | #define isPUNCT_LC_utf8(p) isPUNCT_LC_uni(utf8_to_uv(p, 0)) |
---|
| 449 | #define toUPPER_LC_utf8(p) toUPPER_LC_uni(utf8_to_uv(p, 0)) |
---|
| 450 | #define toTITLE_LC_utf8(p) toTITLE_LC_uni(utf8_to_uv(p, 0)) |
---|
| 451 | #define toLOWER_LC_utf8(p) toLOWER_LC_uni(utf8_to_uv(p, 0)) |
---|
| 452 | |
---|
| 453 | #ifdef EBCDIC |
---|
| 454 | EXT int ebcdic_control (int); |
---|
| 455 | # define toCTRL(c) ebcdic_control(c) |
---|
| 456 | #else |
---|
| 457 | /* This conversion works both ways, strangely enough. */ |
---|
| 458 | # define toCTRL(c) (toUPPER(c) ^ 64) |
---|
| 459 | #endif |
---|
| 460 | |
---|
[9008] | 461 | /* Line numbers are unsigned, 16 bits. */ |
---|
[10723] | 462 | typedef U16 line_t; |
---|
[9008] | 463 | #ifdef lint |
---|
| 464 | #define NOLINE ((line_t)0) |
---|
| 465 | #else |
---|
| 466 | #define NOLINE ((line_t) 65535) |
---|
| 467 | #endif |
---|
| 468 | |
---|
[14544] | 469 | |
---|
| 470 | /* |
---|
| 471 | XXX LEAKTEST doesn't really work in perl5. There are direct calls to |
---|
[10723] | 472 | safemalloc() in the source, so LEAKTEST won't pick them up. |
---|
[14544] | 473 | (The main "offenders" are extensions.) |
---|
[10723] | 474 | Further, if you try LEAKTEST, you'll also end up calling |
---|
| 475 | Safefree, which might call safexfree() on some things that weren't |
---|
| 476 | malloced with safexmalloc. The correct "fix" to this, if anyone |
---|
| 477 | is interested, is to ensure that all calls go through the New and |
---|
| 478 | Renew macros. |
---|
| 479 | --Andy Dougherty August 1996 |
---|
| 480 | */ |
---|
| 481 | |
---|
[14544] | 482 | /* |
---|
| 483 | =for apidoc Am|SV*|NEWSV|int id|STRLEN len |
---|
| 484 | Creates a new SV. A non-zero C<len> parameter indicates the number of |
---|
| 485 | bytes of preallocated string space the SV should have. An extra byte for a |
---|
| 486 | tailing NUL is also reserved. (SvPOK is not set for the SV even if string |
---|
| 487 | space is allocated.) The reference count for the new SV is set to 1. |
---|
| 488 | C<id> is an integer id between 0 and 1299 (used to identify leaks). |
---|
| 489 | |
---|
| 490 | =for apidoc Am|void|New|int id|void* ptr|int nitems|type |
---|
| 491 | The XSUB-writer's interface to the C C<malloc> function. |
---|
| 492 | |
---|
| 493 | =for apidoc Am|void|Newc|int id|void* ptr|int nitems|type|cast |
---|
| 494 | The XSUB-writer's interface to the C C<malloc> function, with |
---|
| 495 | cast. |
---|
| 496 | |
---|
| 497 | =for apidoc Am|void|Newz|int id|void* ptr|int nitems|type |
---|
| 498 | The XSUB-writer's interface to the C C<malloc> function. The allocated |
---|
| 499 | memory is zeroed with C<memzero>. |
---|
| 500 | |
---|
| 501 | =for apidoc Am|void|Renew|void* ptr|int nitems|type |
---|
| 502 | The XSUB-writer's interface to the C C<realloc> function. |
---|
| 503 | |
---|
| 504 | =for apidoc Am|void|Renewc|void* ptr|int nitems|type|cast |
---|
| 505 | The XSUB-writer's interface to the C C<realloc> function, with |
---|
| 506 | cast. |
---|
| 507 | |
---|
| 508 | =for apidoc Am|void|Safefree|void* src|void* dest|int nitems|type |
---|
| 509 | The XSUB-writer's interface to the C C<free> function. |
---|
| 510 | |
---|
| 511 | =for apidoc Am|void|Move|void* src|void* dest|int nitems|type |
---|
| 512 | The XSUB-writer's interface to the C C<memmove> function. The C<src> is the |
---|
| 513 | source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is |
---|
| 514 | the type. Can do overlapping moves. See also C<Copy>. |
---|
| 515 | |
---|
| 516 | =for apidoc Am|void|Copy|void* src|void* dest|int nitems|type |
---|
| 517 | The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the |
---|
| 518 | source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is |
---|
| 519 | the type. May fail on overlapping copies. See also C<Move>. |
---|
| 520 | |
---|
| 521 | =for apidoc Am|void|Zero|void* dest|int nitems|type |
---|
| 522 | |
---|
| 523 | The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the |
---|
| 524 | destination, C<nitems> is the number of items, and C<type> is the type. |
---|
| 525 | |
---|
| 526 | =for apidoc Am|void|StructCopy|type src|type dest|type |
---|
| 527 | This is an architecture-independant macro to copy one structure to another. |
---|
| 528 | |
---|
| 529 | =cut |
---|
| 530 | */ |
---|
| 531 | |
---|
[9008] | 532 | #ifndef lint |
---|
[14544] | 533 | |
---|
| 534 | #define NEWSV(x,len) newSV(len) |
---|
| 535 | |
---|
[9008] | 536 | #ifndef LEAKTEST |
---|
[10723] | 537 | |
---|
| 538 | #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))) |
---|
| 539 | #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n)*sizeof(t)))) |
---|
| 540 | #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))), \ |
---|
| 541 | memzero((char*)(v), (n)*sizeof(t)) |
---|
| 542 | #define Renew(v,n,t) \ |
---|
| 543 | (v = (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))) |
---|
| 544 | #define Renewc(v,n,t,c) \ |
---|
| 545 | (v = (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))) |
---|
| 546 | #define Safefree(d) safefree((Malloc_t)(d)) |
---|
| 547 | |
---|
[9008] | 548 | #else /* LEAKTEST */ |
---|
[10723] | 549 | |
---|
| 550 | #define New(x,v,n,t) (v = (t*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t)))) |
---|
| 551 | #define Newc(x,v,n,t,c) (v = (c*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t)))) |
---|
| 552 | #define Newz(x,v,n,t) (v = (t*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t)))), \ |
---|
| 553 | memzero((char*)(v), (n)*sizeof(t)) |
---|
| 554 | #define Renew(v,n,t) \ |
---|
| 555 | (v = (t*)safexrealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))) |
---|
| 556 | #define Renewc(v,n,t,c) \ |
---|
| 557 | (v = (c*)safexrealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))) |
---|
[14544] | 558 | #define Safefree(d) safexfree((Malloc_t)(d)) |
---|
[10723] | 559 | |
---|
| 560 | #define MAXXCOUNT 1400 |
---|
[14544] | 561 | #define MAXY_SIZE 80 |
---|
| 562 | #define MAXYCOUNT 16 /* (MAXY_SIZE/4 + 1) */ |
---|
| 563 | extern long xcount[MAXXCOUNT]; |
---|
| 564 | extern long lastxcount[MAXXCOUNT]; |
---|
| 565 | extern long xycount[MAXXCOUNT][MAXYCOUNT]; |
---|
| 566 | extern long lastxycount[MAXXCOUNT][MAXYCOUNT]; |
---|
[10723] | 567 | |
---|
[9008] | 568 | #endif /* LEAKTEST */ |
---|
[10723] | 569 | |
---|
| 570 | #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t)) |
---|
| 571 | #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) |
---|
| 572 | #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t)) |
---|
| 573 | |
---|
[9008] | 574 | #else /* lint */ |
---|
[10723] | 575 | |
---|
| 576 | #define New(x,v,n,s) (v = Null(s *)) |
---|
| 577 | #define Newc(x,v,n,s,c) (v = Null(s *)) |
---|
| 578 | #define Newz(x,v,n,s) (v = Null(s *)) |
---|
| 579 | #define Renew(v,n,s) (v = Null(s *)) |
---|
[9008] | 580 | #define Move(s,d,n,t) |
---|
| 581 | #define Copy(s,d,n,t) |
---|
| 582 | #define Zero(d,n,t) |
---|
[10723] | 583 | #define Safefree(d) (d) = (d) |
---|
| 584 | |
---|
[9008] | 585 | #endif /* lint */ |
---|
| 586 | |
---|
[10723] | 587 | #ifdef USE_STRUCT_COPY |
---|
| 588 | #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s))) |
---|
[9008] | 589 | #else |
---|
| 590 | #define StructCopy(s,d,t) Copy(s,d,1,t) |
---|
| 591 | #endif |
---|