3 * Copyright (c) 1991-1994, Larry Wall
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.
10 #if !defined(__STDC__)
21 #define Null(type) ((type)NULL)
22 #define Nullch Null(char*)
23 #define Nullfp Null(FILE*)
24 #define Nullsv Null(SV*)
26 /* bool is built-in for g++-2.6.3, which might be used for an extension.
27 gcc-2.6.2 under Linux defines _G_HAVE_BOOL to 0, and does not
29 #if !defined(HAS_BOOL) && !(_G_HAVE_BOOL)
35 #endif /* !defined(HAS_BOOL) && !(_G_HAVE_BOOL) */
47 typedef unsigned char U8;
50 typedef unsigned short U16;
52 #if BYTEORDER > 0x4321
54 typedef unsigned int U32;
57 typedef unsigned long U32;
60 #define Ctl(ch) (ch & 037)
62 #define strNE(s1,s2) (strcmp(s1,s2))
63 #define strEQ(s1,s2) (!strcmp(s1,s2))
64 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
65 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
66 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
67 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
68 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
69 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
71 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
78 #define isALNUM(c) (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
79 #define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
80 #define isALPHA(c) NXIsAlpha((unsigned int)c)
81 #define isSPACE(c) NXIsSpace((unsigned int)c)
82 #define isDIGIT(c) NXIsDigit((unsigned int)c)
83 #define isUPPER(c) NXIsUpper((unsigned int)c)
84 #define isLOWER(c) NXIsLower((unsigned int)c)
85 #define toUPPER(c) NXToUpper((unsigned int)c)
86 #define toLOWER(c) NXToLower((unsigned int)c)
87 #else /* USE_NEXT_CTYPE */
88 #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
89 #define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
90 #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
91 #define isALPHA(c) isalpha((unsigned char)(c))
92 #define isSPACE(c) isspace((unsigned char)(c))
93 #define isDIGIT(c) isdigit((unsigned char)(c))
94 #define isUPPER(c) isupper((unsigned char)(c))
95 #define isLOWER(c) islower((unsigned char)(c))
96 #define toUPPER(c) toupper((unsigned char)(c))
97 #define toLOWER(c) tolower((unsigned char)(c))
99 #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
100 #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
101 #define isALPHA(c) (isascii(c) && isalpha(c))
102 #define isSPACE(c) (isascii(c) && isspace(c))
103 #define isDIGIT(c) (isascii(c) && isdigit(c))
104 #define isUPPER(c) (isascii(c) && isupper(c))
105 #define isLOWER(c) (isascii(c) && islower(c))
106 #define toUPPER(c) toupper(c)
107 #define toLOWER(c) tolower(c)
109 #endif /* USE_NEXT_CTYPE */
111 /* Line numbers are unsigned, 16 bits. */
114 #define NOLINE ((line_t)0)
116 #define NOLINE ((line_t) 65535)
122 char *safemalloc _((MEM_SIZE));
123 char *saferealloc _((char *, MEM_SIZE));
124 void safefree _((char *));
127 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
128 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
129 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
130 memzero((char*)(v), (n) * sizeof(t))
131 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
132 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
134 #define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
135 #define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
136 #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
137 memzero((char*)(v), (n) * sizeof(t))
138 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
139 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
141 #define Safefree(d) safefree((char*)d)
142 #define NEWSV(x,len) newSV(len)
145 char *safexrealloc();
147 #define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
148 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
149 #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
150 memzero((char*)(v), (n) * sizeof(t))
151 #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
152 #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
153 #define Safefree(d) safexfree((char*)d)
154 #define NEWSV(x,len) newSV(x,len)
155 #define MAXXCOUNT 1200
156 long xcount[MAXXCOUNT];
157 long lastxcount[MAXXCOUNT];
158 #endif /* LEAKTEST */
159 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
160 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
161 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
163 #define New(x,v,n,s) (v = Null(s *))
164 #define Newc(x,v,n,s,c) (v = Null(s *))
165 #define Newz(x,v,n,s) (v = Null(s *))
166 #define Renew(v,n,s) (v = Null(s *))
167 #define Move(s,d,n,t)
168 #define Copy(s,d,n,t)
170 #define Safefree(d) d = d
173 #ifdef USE_STRUCT_COPY
174 #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
176 #define StructCopy(s,d,t) Copy(s,d,1,t)