1N/A/* handy.h
1N/A *
1N/A * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
1N/A * 2000, 2001, 2002, 2004, by Larry Wall and others
1N/A *
1N/A * You may distribute under the terms of either the GNU General Public
1N/A * License or the Artistic License, as specified in the README file.
1N/A *
1N/A */
1N/A
1N/A#if !defined(__STDC__)
1N/A#ifdef NULL
1N/A#undef NULL
1N/A#endif
1N/A#ifndef I286
1N/A# define NULL 0
1N/A#else
1N/A# define NULL 0L
1N/A#endif
1N/A#endif
1N/A
1N/A#define Null(type) ((type)NULL)
1N/A
1N/A/*
1N/A=head1 Handy Values
1N/A
1N/A=for apidoc AmU||Nullch
1N/ANull character pointer.
1N/A
1N/A=for apidoc AmU||Nullsv
1N/ANull SV pointer.
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#define Nullch Null(char*)
1N/A#define Nullfp Null(PerlIO*)
1N/A#define Nullsv Null(SV*)
1N/A
1N/A#ifdef TRUE
1N/A#undef TRUE
1N/A#endif
1N/A#ifdef FALSE
1N/A#undef FALSE
1N/A#endif
1N/A#define TRUE (1)
1N/A#define FALSE (0)
1N/A
1N/A
1N/A/* XXX Configure ought to have a test for a boolean type, if I can
1N/A just figure out all the headers such a test needs.
1N/A Andy Dougherty August 1996
1N/A*/
1N/A/* bool is built-in for g++-2.6.3 and later, which might be used
1N/A for extensions. <_G_config.h> defines _G_HAVE_BOOL, but we can't
1N/A be sure _G_config.h will be included before this file. _G_config.h
1N/A also defines _G_HAVE_BOOL for both gcc and g++, but only g++
1N/A actually has bool. Hence, _G_HAVE_BOOL is pretty useless for us.
1N/A g++ can be identified by __GNUG__.
1N/A Andy Dougherty February 2000
1N/A*/
1N/A#ifdef __GNUG__ /* GNU g++ has bool built-in */
1N/A# ifndef HAS_BOOL
1N/A# define HAS_BOOL 1
1N/A# endif
1N/A#endif
1N/A
1N/A/* The NeXT dynamic loader headers will not build with the bool macro
1N/A So declare them now to clear confusion.
1N/A*/
1N/A#if defined(NeXT) || defined(__NeXT__)
1N/A# undef FALSE
1N/A# undef TRUE
1N/A typedef enum bool { FALSE = 0, TRUE = 1 } bool;
1N/A# define ENUM_BOOL 1
1N/A# ifndef HAS_BOOL
1N/A# define HAS_BOOL 1
1N/A# endif /* !HAS_BOOL */
1N/A#endif /* NeXT || __NeXT__ */
1N/A
1N/A#ifndef HAS_BOOL
1N/A# if defined(UTS) || defined(VMS)
1N/A# define bool int
1N/A# else
1N/A# define bool char
1N/A# endif
1N/A# define HAS_BOOL 1
1N/A#endif
1N/A
1N/A/* XXX A note on the perl source internal type system. The
1N/A original intent was that I32 be *exactly* 32 bits.
1N/A
1N/A Currently, we only guarantee that I32 is *at least* 32 bits.
1N/A Specifically, if int is 64 bits, then so is I32. (This is the case
1N/A for the Cray.) This has the advantage of meshing nicely with
1N/A standard library calls (where we pass an I32 and the library is
1N/A expecting an int), but the disadvantage that an I32 is not 32 bits.
1N/A Andy Dougherty August 1996
1N/A
1N/A There is no guarantee that there is *any* integral type with
1N/A exactly 32 bits. It is perfectly legal for a system to have
1N/A sizeof(short) == sizeof(int) == sizeof(long) == 8.
1N/A
1N/A Similarly, there is no guarantee that I16 and U16 have exactly 16
1N/A bits.
1N/A
1N/A For dealing with issues that may arise from various 32/64-bit
1N/A systems, we will ask Configure to check out
1N/A
1N/A SHORTSIZE == sizeof(short)
1N/A INTSIZE == sizeof(int)
1N/A LONGSIZE == sizeof(long)
1N/A LONGLONGSIZE == sizeof(long long) (if HAS_LONG_LONG)
1N/A PTRSIZE == sizeof(void *)
1N/A DOUBLESIZE == sizeof(double)
1N/A LONG_DOUBLESIZE == sizeof(long double) (if HAS_LONG_DOUBLE).
1N/A
1N/A*/
1N/A
1N/A#ifdef I_INTTYPES /* e.g. Linux has int64_t without <inttypes.h> */
1N/A# include <inttypes.h>
1N/A# ifdef INT32_MIN_BROKEN
1N/A# undef INT32_MIN
1N/A# define INT32_MIN (-2147483647-1)
1N/A# endif
1N/A# ifdef INT64_MIN_BROKEN
1N/A# undef INT64_MIN
1N/A# define INT64_MIN (-9223372036854775807LL-1)
1N/A# endif
1N/A#endif
1N/A
1N/Atypedef I8TYPE I8;
1N/Atypedef U8TYPE U8;
1N/Atypedef I16TYPE I16;
1N/Atypedef U16TYPE U16;
1N/Atypedef I32TYPE I32;
1N/Atypedef U32TYPE U32;
1N/A#ifdef PERL_CORE
1N/A# ifdef HAS_QUAD
1N/Atypedef I64TYPE I64;
1N/Atypedef U64TYPE U64;
1N/A# endif
1N/A#endif /* PERL_CORE */
1N/A
1N/A#if defined(HAS_QUAD) && defined(USE_64_BIT_INT)
1N/A# ifndef UINT64_C /* usually from <inttypes.h> */
1N/A# if defined(HAS_LONG_LONG) && QUADKIND == QUAD_IS_LONG_LONG
1N/A# define INT64_C(c) CAT2(c,LL)
1N/A# define UINT64_C(c) CAT2(c,ULL)
1N/A# else
1N/A# if LONGSIZE == 8 && QUADKIND == QUAD_IS_LONG
1N/A# define INT64_C(c) CAT2(c,L)
1N/A# define UINT64_C(c) CAT2(c,UL)
1N/A# else
1N/A# define INT64_C(c) ((I64TYPE)(c))
1N/A# define UINT64_C(c) ((U64TYPE)(c))
1N/A# endif
1N/A# endif
1N/A# endif
1N/A#endif
1N/A
1N/A/* Mention I8SIZE, U8SIZE, I16SIZE, U16SIZE, I32SIZE, U32SIZE,
1N/A I64SIZE, and U64SIZE here so that metaconfig pulls them in. */
1N/A
1N/A#if defined(UINT8_MAX) && defined(INT16_MAX) && defined(INT32_MAX)
1N/A
1N/A/* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
1N/A Please search CHAR_MAX in perl.h for further details. */
1N/A#define U8_MAX UINT8_MAX
1N/A#define U8_MIN UINT8_MIN
1N/A
1N/A#define I16_MAX INT16_MAX
1N/A#define I16_MIN INT16_MIN
1N/A#define U16_MAX UINT16_MAX
1N/A#define U16_MIN UINT16_MIN
1N/A
1N/A#define I32_MAX INT32_MAX
1N/A#define I32_MIN INT32_MIN
1N/A#ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
1N/A# define U32_MAX UINT32_MAX
1N/A#else
1N/A# define U32_MAX 4294967295U
1N/A#endif
1N/A#define U32_MIN UINT32_MIN
1N/A
1N/A#else
1N/A
1N/A/* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
1N/A Please search CHAR_MAX in perl.h for further details. */
1N/A#define U8_MAX PERL_UCHAR_MAX
1N/A#define U8_MIN PERL_UCHAR_MIN
1N/A
1N/A#define I16_MAX PERL_SHORT_MAX
1N/A#define I16_MIN PERL_SHORT_MIN
1N/A#define U16_MAX PERL_USHORT_MAX
1N/A#define U16_MIN PERL_USHORT_MIN
1N/A
1N/A#if LONGSIZE > 4
1N/A# define I32_MAX PERL_INT_MAX
1N/A# define I32_MIN PERL_INT_MIN
1N/A# define U32_MAX PERL_UINT_MAX
1N/A# define U32_MIN PERL_UINT_MIN
1N/A#else
1N/A# define I32_MAX PERL_LONG_MAX
1N/A# define I32_MIN PERL_LONG_MIN
1N/A# define U32_MAX PERL_ULONG_MAX
1N/A# define U32_MIN PERL_ULONG_MIN
1N/A#endif
1N/A
1N/A#endif
1N/A
1N/A/* log(2) is pretty close to 0.30103, just in case anyone is grepping for it */
1N/A#define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
1N/A#define TYPE_DIGITS(T) BIT_DIGITS(sizeof(T) * 8)
1N/A#define TYPE_CHARS(T) (TYPE_DIGITS(T) + 2) /* sign, NUL */
1N/A
1N/A#define Ctl(ch) ((ch) & 037)
1N/A
1N/A/*
1N/A=head1 Miscellaneous Functions
1N/A
1N/A=for apidoc Am|bool|strNE|char* s1|char* s2
1N/ATest two strings to see if they are different. Returns true or
1N/Afalse.
1N/A
1N/A=for apidoc Am|bool|strEQ|char* s1|char* s2
1N/ATest two strings to see if they are equal. Returns true or false.
1N/A
1N/A=for apidoc Am|bool|strLT|char* s1|char* s2
1N/ATest two strings to see if the first, C<s1>, is less than the second,
1N/AC<s2>. Returns true or false.
1N/A
1N/A=for apidoc Am|bool|strLE|char* s1|char* s2
1N/ATest two strings to see if the first, C<s1>, is less than or equal to the
1N/Asecond, C<s2>. Returns true or false.
1N/A
1N/A=for apidoc Am|bool|strGT|char* s1|char* s2
1N/ATest two strings to see if the first, C<s1>, is greater than the second,
1N/AC<s2>. Returns true or false.
1N/A
1N/A=for apidoc Am|bool|strGE|char* s1|char* s2
1N/ATest two strings to see if the first, C<s1>, is greater than or equal to
1N/Athe second, C<s2>. Returns true or false.
1N/A
1N/A=for apidoc Am|bool|strnNE|char* s1|char* s2|STRLEN len
1N/ATest two strings to see if they are different. The C<len> parameter
1N/Aindicates the number of bytes to compare. Returns true or false. (A
1N/Awrapper for C<strncmp>).
1N/A
1N/A=for apidoc Am|bool|strnEQ|char* s1|char* s2|STRLEN len
1N/ATest two strings to see if they are equal. The C<len> parameter indicates
1N/Athe number of bytes to compare. Returns true or false. (A wrapper for
1N/AC<strncmp>).
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#define strNE(s1,s2) (strcmp(s1,s2))
1N/A#define strEQ(s1,s2) (!strcmp(s1,s2))
1N/A#define strLT(s1,s2) (strcmp(s1,s2) < 0)
1N/A#define strLE(s1,s2) (strcmp(s1,s2) <= 0)
1N/A#define strGT(s1,s2) (strcmp(s1,s2) > 0)
1N/A#define strGE(s1,s2) (strcmp(s1,s2) >= 0)
1N/A#define strnNE(s1,s2,l) (strncmp(s1,s2,l))
1N/A#define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
1N/A
1N/A#ifdef HAS_MEMCMP
1N/A# define memNE(s1,s2,l) (memcmp(s1,s2,l))
1N/A# define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
1N/A#else
1N/A# define memNE(s1,s2,l) (bcmp(s1,s2,l))
1N/A# define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
1N/A#endif
1N/A
1N/A/*
1N/A * Character classes.
1N/A *
1N/A * Unfortunately, the introduction of locales means that we
1N/A * can't trust isupper(), etc. to tell the truth. And when
1N/A * it comes to /\w+/ with tainting enabled, we *must* be able
1N/A * to trust our character classes.
1N/A *
1N/A * Therefore, the default tests in the text of Perl will be
1N/A * independent of locale. Any code that wants to depend on
1N/A * the current locale will use the tests that begin with "lc".
1N/A */
1N/A
1N/A#ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
1N/A# ifndef CTYPE256
1N/A# define CTYPE256
1N/A# endif
1N/A#endif
1N/A
1N/A/*
1N/A
1N/A=head1 Character classes
1N/A
1N/A=for apidoc Am|bool|isALNUM|char ch
1N/AReturns a boolean indicating whether the C C<char> is an ASCII alphanumeric
1N/Acharacter (including underscore) or digit.
1N/A
1N/A=for apidoc Am|bool|isALPHA|char ch
1N/AReturns a boolean indicating whether the C C<char> is an ASCII alphabetic
1N/Acharacter.
1N/A
1N/A=for apidoc Am|bool|isSPACE|char ch
1N/AReturns a boolean indicating whether the C C<char> is whitespace.
1N/A
1N/A=for apidoc Am|bool|isDIGIT|char ch
1N/AReturns a boolean indicating whether the C C<char> is an ASCII
1N/Adigit.
1N/A
1N/A=for apidoc Am|bool|isUPPER|char ch
1N/AReturns a boolean indicating whether the C C<char> is an uppercase
1N/Acharacter.
1N/A
1N/A=for apidoc Am|bool|isLOWER|char ch
1N/AReturns a boolean indicating whether the C C<char> is a lowercase
1N/Acharacter.
1N/A
1N/A=for apidoc Am|char|toUPPER|char ch
1N/AConverts the specified character to uppercase.
1N/A
1N/A=for apidoc Am|char|toLOWER|char ch
1N/AConverts the specified character to lowercase.
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_')
1N/A#define isIDFIRST(c) (isALPHA(c) || (c) == '_')
1N/A#define isALPHA(c) (isUPPER(c) || isLOWER(c))
1N/A#define isSPACE(c) \
1N/A ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' || (c) == '\f')
1N/A#define isPSXSPC(c) (isSPACE(c) || (c) == '\v')
1N/A#define isBLANK(c) ((c) == ' ' || (c) == '\t')
1N/A#define isDIGIT(c) ((c) >= '0' && (c) <= '9')
1N/A#ifdef EBCDIC
1N/A /* In EBCDIC we do not do locales: therefore() isupper() is fine. */
1N/A# define isUPPER(c) isupper(c)
1N/A# define isLOWER(c) islower(c)
1N/A# define isALNUMC(c) isalnum(c)
1N/A# define isASCII(c) isascii(c)
1N/A# define isCNTRL(c) iscntrl(c)
1N/A# define isGRAPH(c) isgraph(c)
1N/A# define isPRINT(c) isprint(c)
1N/A# define isPUNCT(c) ispunct(c)
1N/A# define isXDIGIT(c) isxdigit(c)
1N/A# define toUPPER(c) toupper(c)
1N/A# define toLOWER(c) tolower(c)
1N/A#else
1N/A# define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
1N/A# define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
1N/A# define isALNUMC(c) (isALPHA(c) || isDIGIT(c))
1N/A# define isASCII(c) ((c) <= 127)
1N/A# define isCNTRL(c) ((c) < ' ' || (c) == 127)
1N/A# define isGRAPH(c) (isALNUM(c) || isPUNCT(c))
1N/A# define isPRINT(c) (((c) > 32 && (c) < 127) || (c) == ' ')
1N/A# define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126))
1N/A# define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
1N/A# define toUPPER(c) (isLOWER(c) ? (c) - ('a' - 'A') : (c))
1N/A# define toLOWER(c) (isUPPER(c) ? (c) + ('a' - 'A') : (c))
1N/A#endif
1N/A
1N/A#ifdef USE_NEXT_CTYPE
1N/A
1N/A# define isALNUM_LC(c) \
1N/A (NXIsAlNum((unsigned int)(c)) || (char)(c) == '_')
1N/A# define isIDFIRST_LC(c) \
1N/A (NXIsAlpha((unsigned int)(c)) || (char)(c) == '_')
1N/A# define isALPHA_LC(c) NXIsAlpha((unsigned int)(c))
1N/A# define isSPACE_LC(c) NXIsSpace((unsigned int)(c))
1N/A# define isDIGIT_LC(c) NXIsDigit((unsigned int)(c))
1N/A# define isUPPER_LC(c) NXIsUpper((unsigned int)(c))
1N/A# define isLOWER_LC(c) NXIsLower((unsigned int)(c))
1N/A# define isALNUMC_LC(c) NXIsAlNum((unsigned int)(c))
1N/A# define isCNTRL_LC(c) NXIsCntrl((unsigned int)(c))
1N/A# define isGRAPH_LC(c) NXIsGraph((unsigned int)(c))
1N/A# define isPRINT_LC(c) NXIsPrint((unsigned int)(c))
1N/A# define isPUNCT_LC(c) NXIsPunct((unsigned int)(c))
1N/A# define toUPPER_LC(c) NXToUpper((unsigned int)(c))
1N/A# define toLOWER_LC(c) NXToLower((unsigned int)(c))
1N/A
1N/A#else /* !USE_NEXT_CTYPE */
1N/A
1N/A# if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
1N/A
1N/A# define isALNUM_LC(c) (isalnum((unsigned char)(c)) || (char)(c) == '_')
1N/A# define isIDFIRST_LC(c) (isalpha((unsigned char)(c)) || (char)(c) == '_')
1N/A# define isALPHA_LC(c) isalpha((unsigned char)(c))
1N/A# define isSPACE_LC(c) isspace((unsigned char)(c))
1N/A# define isDIGIT_LC(c) isdigit((unsigned char)(c))
1N/A# define isUPPER_LC(c) isupper((unsigned char)(c))
1N/A# define isLOWER_LC(c) islower((unsigned char)(c))
1N/A# define isALNUMC_LC(c) isalnum((unsigned char)(c))
1N/A# define isCNTRL_LC(c) iscntrl((unsigned char)(c))
1N/A# define isGRAPH_LC(c) isgraph((unsigned char)(c))
1N/A# define isPRINT_LC(c) isprint((unsigned char)(c))
1N/A# define isPUNCT_LC(c) ispunct((unsigned char)(c))
1N/A# define toUPPER_LC(c) toupper((unsigned char)(c))
1N/A# define toLOWER_LC(c) tolower((unsigned char)(c))
1N/A
1N/A# else
1N/A
1N/A# define isALNUM_LC(c) (isascii(c) && (isalnum(c) || (c) == '_'))
1N/A# define isIDFIRST_LC(c) (isascii(c) && (isalpha(c) || (c) == '_'))
1N/A# define isALPHA_LC(c) (isascii(c) && isalpha(c))
1N/A# define isSPACE_LC(c) (isascii(c) && isspace(c))
1N/A# define isDIGIT_LC(c) (isascii(c) && isdigit(c))
1N/A# define isUPPER_LC(c) (isascii(c) && isupper(c))
1N/A# define isLOWER_LC(c) (isascii(c) && islower(c))
1N/A# define isALNUMC_LC(c) (isascii(c) && isalnum(c))
1N/A# define isCNTRL_LC(c) (isascii(c) && iscntrl(c))
1N/A# define isGRAPH_LC(c) (isascii(c) && isgraph(c))
1N/A# define isPRINT_LC(c) (isascii(c) && isprint(c))
1N/A# define isPUNCT_LC(c) (isascii(c) && ispunct(c))
1N/A# define toUPPER_LC(c) toupper(c)
1N/A# define toLOWER_LC(c) tolower(c)
1N/A
1N/A# endif
1N/A#endif /* USE_NEXT_CTYPE */
1N/A
1N/A#define isPSXSPC_LC(c) (isSPACE_LC(c) || (c) == '\v')
1N/A#define isBLANK_LC(c) isBLANK(c) /* could be wrong */
1N/A
1N/A#define isALNUM_uni(c) is_uni_alnum(c)
1N/A#define isIDFIRST_uni(c) is_uni_idfirst(c)
1N/A#define isALPHA_uni(c) is_uni_alpha(c)
1N/A#define isSPACE_uni(c) is_uni_space(c)
1N/A#define isDIGIT_uni(c) is_uni_digit(c)
1N/A#define isUPPER_uni(c) is_uni_upper(c)
1N/A#define isLOWER_uni(c) is_uni_lower(c)
1N/A#define isALNUMC_uni(c) is_uni_alnumc(c)
1N/A#define isASCII_uni(c) is_uni_ascii(c)
1N/A#define isCNTRL_uni(c) is_uni_cntrl(c)
1N/A#define isGRAPH_uni(c) is_uni_graph(c)
1N/A#define isPRINT_uni(c) is_uni_print(c)
1N/A#define isPUNCT_uni(c) is_uni_punct(c)
1N/A#define isXDIGIT_uni(c) is_uni_xdigit(c)
1N/A#define toUPPER_uni(c,s,l) to_uni_upper(c,s,l)
1N/A#define toTITLE_uni(c,s,l) to_uni_title(c,s,l)
1N/A#define toLOWER_uni(c,s,l) to_uni_lower(c,s,l)
1N/A#define toFOLD_uni(c,s,l) to_uni_fold(c,s,l)
1N/A
1N/A#define isPSXSPC_uni(c) (isSPACE_uni(c) ||(c) == '\f')
1N/A#define isBLANK_uni(c) isBLANK(c) /* could be wrong */
1N/A
1N/A#define isALNUM_LC_uvchr(c) (c < 256 ? isALNUM_LC(c) : is_uni_alnum_lc(c))
1N/A#define isIDFIRST_LC_uvchr(c) (c < 256 ? isIDFIRST_LC(c) : is_uni_idfirst_lc(c))
1N/A#define isALPHA_LC_uvchr(c) (c < 256 ? isALPHA_LC(c) : is_uni_alpha_lc(c))
1N/A#define isSPACE_LC_uvchr(c) (c < 256 ? isSPACE_LC(c) : is_uni_space_lc(c))
1N/A#define isDIGIT_LC_uvchr(c) (c < 256 ? isDIGIT_LC(c) : is_uni_digit_lc(c))
1N/A#define isUPPER_LC_uvchr(c) (c < 256 ? isUPPER_LC(c) : is_uni_upper_lc(c))
1N/A#define isLOWER_LC_uvchr(c) (c < 256 ? isLOWER_LC(c) : is_uni_lower_lc(c))
1N/A#define isALNUMC_LC_uvchr(c) (c < 256 ? isALNUMC_LC(c) : is_uni_alnumc_lc(c))
1N/A#define isCNTRL_LC_uvchr(c) (c < 256 ? isCNTRL_LC(c) : is_uni_cntrl_lc(c))
1N/A#define isGRAPH_LC_uvchr(c) (c < 256 ? isGRAPH_LC(c) : is_uni_graph_lc(c))
1N/A#define isPRINT_LC_uvchr(c) (c < 256 ? isPRINT_LC(c) : is_uni_print_lc(c))
1N/A#define isPUNCT_LC_uvchr(c) (c < 256 ? isPUNCT_LC(c) : is_uni_punct_lc(c))
1N/A
1N/A#define isPSXSPC_LC_uni(c) (isSPACE_LC_uni(c) ||(c) == '\f')
1N/A#define isBLANK_LC_uni(c) isBLANK(c) /* could be wrong */
1N/A
1N/A#define isALNUM_utf8(p) is_utf8_alnum(p)
1N/A/* The ID_Start of Unicode is quite limiting: it assumes a L-class
1N/A * character (meaning that you cannot have, say, a CJK character).
1N/A * Instead, let's allow ID_Continue but not digits. */
1N/A#define isIDFIRST_utf8(p) (is_utf8_idcont(p) && !is_utf8_digit(p))
1N/A#define isALPHA_utf8(p) is_utf8_alpha(p)
1N/A#define isSPACE_utf8(p) is_utf8_space(p)
1N/A#define isDIGIT_utf8(p) is_utf8_digit(p)
1N/A#define isUPPER_utf8(p) is_utf8_upper(p)
1N/A#define isLOWER_utf8(p) is_utf8_lower(p)
1N/A#define isALNUMC_utf8(p) is_utf8_alnumc(p)
1N/A#define isASCII_utf8(p) is_utf8_ascii(p)
1N/A#define isCNTRL_utf8(p) is_utf8_cntrl(p)
1N/A#define isGRAPH_utf8(p) is_utf8_graph(p)
1N/A#define isPRINT_utf8(p) is_utf8_print(p)
1N/A#define isPUNCT_utf8(p) is_utf8_punct(p)
1N/A#define isXDIGIT_utf8(p) is_utf8_xdigit(p)
1N/A#define toUPPER_utf8(p,s,l) to_utf8_upper(p,s,l)
1N/A#define toTITLE_utf8(p,s,l) to_utf8_title(p,s,l)
1N/A#define toLOWER_utf8(p,s,l) to_utf8_lower(p,s,l)
1N/A
1N/A#define isPSXSPC_utf8(c) (isSPACE_utf8(c) ||(c) == '\f')
1N/A#define isBLANK_utf8(c) isBLANK(c) /* could be wrong */
1N/A
1N/A#define isALNUM_LC_utf8(p) isALNUM_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isIDFIRST_LC_utf8(p) isIDFIRST_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isALPHA_LC_utf8(p) isALPHA_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isSPACE_LC_utf8(p) isSPACE_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isDIGIT_LC_utf8(p) isDIGIT_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isUPPER_LC_utf8(p) isUPPER_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isLOWER_LC_utf8(p) isLOWER_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isALNUMC_LC_utf8(p) isALNUMC_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isCNTRL_LC_utf8(p) isCNTRL_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isGRAPH_LC_utf8(p) isGRAPH_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isPRINT_LC_utf8(p) isPRINT_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A#define isPUNCT_LC_utf8(p) isPUNCT_LC_uvchr(utf8_to_uvchr(p, 0))
1N/A
1N/A#define isPSXSPC_LC_utf8(c) (isSPACE_LC_utf8(c) ||(c) == '\f')
1N/A#define isBLANK_LC_utf8(c) isBLANK(c) /* could be wrong */
1N/A
1N/A#ifdef EBCDIC
1N/A# ifdef PERL_IMPLICIT_CONTEXT
1N/A# define toCTRL(c) Perl_ebcdic_control(aTHX_ c)
1N/A# else
1N/A# define toCTRL Perl_ebcdic_control
1N/A# endif
1N/A#else
1N/A /* This conversion works both ways, strangely enough. */
1N/A# define toCTRL(c) (toUPPER(c) ^ 64)
1N/A#endif
1N/A
1N/A/* Line numbers are unsigned, 32 bits. */
1N/Atypedef U32 line_t;
1N/A#ifdef lint
1N/A#define NOLINE ((line_t)0)
1N/A#else
1N/A#define NOLINE ((line_t) 4294967295UL)
1N/A#endif
1N/A
1N/A
1N/A/*
1N/A=head1 SV Manipulation Functions
1N/A
1N/A=for apidoc Am|SV*|NEWSV|int id|STRLEN len
1N/ACreates a new SV. A non-zero C<len> parameter indicates the number of
1N/Abytes of preallocated string space the SV should have. An extra byte for a
1N/Atailing NUL is also reserved. (SvPOK is not set for the SV even if string
1N/Aspace is allocated.) The reference count for the new SV is set to 1.
1N/AC<id> is an integer id between 0 and 1299 (used to identify leaks).
1N/A
1N/A=head1 Memory Management
1N/A
1N/A=for apidoc Am|void|New|int id|void* ptr|int nitems|type
1N/AThe XSUB-writer's interface to the C C<malloc> function.
1N/A
1N/A=for apidoc Am|void|Newc|int id|void* ptr|int nitems|type|cast
1N/AThe XSUB-writer's interface to the C C<malloc> function, with
1N/Acast.
1N/A
1N/A=for apidoc Am|void|Newz|int id|void* ptr|int nitems|type
1N/AThe XSUB-writer's interface to the C C<malloc> function. The allocated
1N/Amemory is zeroed with C<memzero>.
1N/A
1N/A=for apidoc Am|void|Renew|void* ptr|int nitems|type
1N/AThe XSUB-writer's interface to the C C<realloc> function.
1N/A
1N/A=for apidoc Am|void|Renewc|void* ptr|int nitems|type|cast
1N/AThe XSUB-writer's interface to the C C<realloc> function, with
1N/Acast.
1N/A
1N/A=for apidoc Am|void|Safefree|void* ptr
1N/AThe XSUB-writer's interface to the C C<free> function.
1N/A
1N/A=for apidoc Am|void|Move|void* src|void* dest|int nitems|type
1N/AThe XSUB-writer's interface to the C C<memmove> function. The C<src> is the
1N/Asource, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
1N/Athe type. Can do overlapping moves. See also C<Copy>.
1N/A
1N/A=for apidoc Am|void|Copy|void* src|void* dest|int nitems|type
1N/AThe XSUB-writer's interface to the C C<memcpy> function. The C<src> is the
1N/Asource, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
1N/Athe type. May fail on overlapping copies. See also C<Move>.
1N/A
1N/A=for apidoc Am|void|Zero|void* dest|int nitems|type
1N/A
1N/AThe XSUB-writer's interface to the C C<memzero> function. The C<dest> is the
1N/Adestination, C<nitems> is the number of items, and C<type> is the type.
1N/A
1N/A=for apidoc Am|void|StructCopy|type src|type dest|type
1N/AThis is an architecture-independent macro to copy one structure to another.
1N/A
1N/A=for apidoc Am|void|Poison|void* dest|int nitems|type
1N/A
1N/AFill up memory with a pattern (byte 0xAB over and over again) that
1N/Ahopefully catches attempts to access uninitialized memory.
1N/A
1N/A=cut */
1N/A
1N/A#ifndef lint
1N/A
1N/A#define NEWSV(x,len) newSV(len)
1N/A
1N/A#ifdef PERL_MALLOC_WRAP
1N/A#define MEM_WRAP_CHECK(n,t) \
1N/A (void)((n)>((MEM_SIZE)~0)/sizeof(t)?(Perl_croak_nocontext(PL_memory_wrap),0):0)
1N/A#define MEM_WRAP_CHECK_1(n,t,a) \
1N/A (void)((n)>((MEM_SIZE)~0)/sizeof(t)?(Perl_croak_nocontext(a),0):0)
1N/A#define MEM_WRAP_CHECK_2(n,t,a,b) \
1N/A (void)((n)>((MEM_SIZE)~0)/sizeof(t)?(Perl_croak_nocontext(a,b),0):0)
1N/A
1N/A#define New(x,v,n,t) (v = (MEM_WRAP_CHECK(n,t), (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))))
1N/A#define Newc(x,v,n,t,c) (v = (MEM_WRAP_CHECK(n,t), (c*)safemalloc((MEM_SIZE)((n)*sizeof(t)))))
1N/A#define Newz(x,v,n,t) (v = (MEM_WRAP_CHECK(n,t), (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))), \
1N/A memzero((char*)(v), (n)*sizeof(t))
1N/A#define Renew(v,n,t) \
1N/A (v = (MEM_WRAP_CHECK(n,t), (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))))
1N/A#define Renewc(v,n,t,c) \
1N/A (v = (MEM_WRAP_CHECK(n,t), (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))))
1N/A#define Safefree(d) safefree((Malloc_t)(d))
1N/A
1N/A#define Move(s,d,n,t) (MEM_WRAP_CHECK(n,t), (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t)))
1N/A#define Copy(s,d,n,t) (MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
1N/A#define Zero(d,n,t) (MEM_WRAP_CHECK(n,t), (void)memzero((char*)(d), (n) * sizeof(t)))
1N/A
1N/A#define Poison(d,n,t) (MEM_WRAP_CHECK(n,t), (void)memset((char*)(d), 0xAB, (n) * sizeof(t)))
1N/A
1N/A#else
1N/A
1N/A#define MEM_WRAP_CHECK(n,t)
1N/A#define MEM_WRAP_CHECK_1(n,t,a)
1N/A#define MEM_WRAP_CHECK_2(n,t,a,b)
1N/A
1N/A#define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
1N/A#define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
1N/A#define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))), \
1N/A memzero((char*)(v), (n)*sizeof(t))
1N/A#define Renew(v,n,t) \
1N/A (v = (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
1N/A#define Renewc(v,n,t,c) \
1N/A (v = (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
1N/A#define Safefree(d) safefree((Malloc_t)(d))
1N/A
1N/A#define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
1N/A#define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
1N/A#define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
1N/A
1N/A#define Poison(d,n,t) (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
1N/A
1N/A#endif
1N/A
1N/A#else /* lint */
1N/A
1N/A#define New(x,v,n,s) (v = Null(s *))
1N/A#define Newc(x,v,n,s,c) (v = Null(s *))
1N/A#define Newz(x,v,n,s) (v = Null(s *))
1N/A#define Renew(v,n,s) (v = Null(s *))
1N/A#define Move(s,d,n,t)
1N/A#define Copy(s,d,n,t)
1N/A#define Zero(d,n,t)
1N/A#define Poison(d,n,t)
1N/A#define Safefree(d) (d) = (d)
1N/A
1N/A#endif /* lint */
1N/A
1N/A#ifdef USE_STRUCT_COPY
1N/A#define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))
1N/A#else
1N/A#define StructCopy(s,d,t) Copy(s,d,1,t)
1N/A#endif
1N/A
1N/A#define C_ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0]))
1N/A
1N/A#ifdef NEED_VA_COPY
1N/A# ifdef va_copy
1N/A# define Perl_va_copy(s, d) va_copy(d, s)
1N/A# else
1N/A# if defined(__va_copy)
1N/A# define Perl_va_copy(s, d) __va_copy(d, s)
1N/A# else
1N/A# define Perl_va_copy(s, d) Copy(s, d, 1, va_list)
1N/A# endif
1N/A# endif
1N/A#endif
1N/A