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*)
35 /* bool is built-in for g++-2.6.3, which might be used for an extension.
36 If the extension includes <_G_config.h> before this file then
37 _G_HAVE_BOOL will be properly set. If, however, the extension includes
38 this file first, then you will have to manually set -DHAS_BOOL in
39 your command line to avoid a conflict.
49 /* The NeXT dynamic loader headers will not build with the bool macro
50 So declare them now to clear confusion.
55 typedef enum bool { FALSE = 0, TRUE = 1 } bool;
59 # endif /* !HAS_BOOL */
71 typedef unsigned char U8;
74 typedef unsigned short U16;
76 #if BYTEORDER > 0x4321
78 typedef unsigned int U32;
81 typedef unsigned long U32;
84 #define Ctl(ch) (ch & 037)
86 #define strNE(s1,s2) (strcmp(s1,s2))
87 #define strEQ(s1,s2) (!strcmp(s1,s2))
88 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
89 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
90 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
91 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
92 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
93 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
95 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
101 #ifdef USE_NEXT_CTYPE
102 #define isALNUM(c) (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
103 #define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
104 #define isALPHA(c) NXIsAlpha((unsigned int)c)
105 #define isSPACE(c) NXIsSpace((unsigned int)c)
106 #define isDIGIT(c) NXIsDigit((unsigned int)c)
107 #define isUPPER(c) NXIsUpper((unsigned int)c)
108 #define isLOWER(c) NXIsLower((unsigned int)c)
109 #define toUPPER(c) NXToUpper((unsigned int)c)
110 #define toLOWER(c) NXToLower((unsigned int)c)
111 #else /* USE_NEXT_CTYPE */
112 #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
113 #define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
114 #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
115 #define isALPHA(c) isalpha((unsigned char)(c))
116 #define isSPACE(c) isspace((unsigned char)(c))
117 #define isDIGIT(c) isdigit((unsigned char)(c))
118 #define isUPPER(c) isupper((unsigned char)(c))
119 #define isLOWER(c) islower((unsigned char)(c))
120 #define toUPPER(c) toupper((unsigned char)(c))
121 #define toLOWER(c) tolower((unsigned char)(c))
123 #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
124 #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
125 #define isALPHA(c) (isascii(c) && isalpha(c))
126 #define isSPACE(c) (isascii(c) && isspace(c))
127 #define isDIGIT(c) (isascii(c) && isdigit(c))
128 #define isUPPER(c) (isascii(c) && isupper(c))
129 #define isLOWER(c) (isascii(c) && islower(c))
130 #define toUPPER(c) toupper(c)
131 #define toLOWER(c) tolower(c)
133 #endif /* USE_NEXT_CTYPE */
135 /* Line numbers are unsigned, 16 bits. */
138 #define NOLINE ((line_t)0)
140 #define NOLINE ((line_t) 65535)
146 char *safemalloc _((MEM_SIZE));
147 char *saferealloc _((char *, MEM_SIZE));
148 void safefree _((char *));
149 char *safecalloc _((MEM_SIZE, MEM_SIZE));
152 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
153 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
154 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
155 memzero((char*)(v), (n) * sizeof(t))
156 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
157 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
159 #define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
160 #define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
161 #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
162 memzero((char*)(v), (n) * sizeof(t))
163 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
164 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
166 #define Safefree(d) safefree((char*)d)
167 #define NEWSV(x,len) newSV(len)
170 char *safexrealloc();
173 #define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
174 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
175 #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
176 memzero((char*)(v), (n) * sizeof(t))
177 #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
178 #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
179 #define Safefree(d) safexfree((char*)d)
180 #define NEWSV(x,len) newSV(x,len)
181 #define MAXXCOUNT 1200
182 long xcount[MAXXCOUNT];
183 long lastxcount[MAXXCOUNT];
184 #endif /* LEAKTEST */
185 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
186 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
187 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
189 #define New(x,v,n,s) (v = Null(s *))
190 #define Newc(x,v,n,s,c) (v = Null(s *))
191 #define Newz(x,v,n,s) (v = Null(s *))
192 #define Renew(v,n,s) (v = Null(s *))
193 #define Move(s,d,n,t)
194 #define Copy(s,d,n,t)
196 #define Safefree(d) d = d
199 #ifdef USE_STRUCT_COPY
200 #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
202 #define StructCopy(s,d,t) Copy(s,d,1,t)