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 If the extension includes <_G_config.h> before this file then
28 _G_HAVE_BOOL will be properly set. If, however, the extension includes
29 this file first, then you will have to manually set -DHAS_BOOL in
30 your command line to avoid a conflict.
58 typedef unsigned char U8;
61 typedef unsigned short U16;
63 #if BYTEORDER > 0x4321
65 typedef unsigned int U32;
68 typedef unsigned long U32;
71 #define Ctl(ch) (ch & 037)
73 #define strNE(s1,s2) (strcmp(s1,s2))
74 #define strEQ(s1,s2) (!strcmp(s1,s2))
75 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
76 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
77 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
78 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
79 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
80 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
82 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
89 #define isALNUM(c) (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
90 #define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
91 #define isALPHA(c) NXIsAlpha((unsigned int)c)
92 #define isSPACE(c) NXIsSpace((unsigned int)c)
93 #define isDIGIT(c) NXIsDigit((unsigned int)c)
94 #define isUPPER(c) NXIsUpper((unsigned int)c)
95 #define isLOWER(c) NXIsLower((unsigned int)c)
96 #define toUPPER(c) NXToUpper((unsigned int)c)
97 #define toLOWER(c) NXToLower((unsigned int)c)
98 #else /* USE_NEXT_CTYPE */
99 #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
100 #define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
101 #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
102 #define isALPHA(c) isalpha((unsigned char)(c))
103 #define isSPACE(c) isspace((unsigned char)(c))
104 #define isDIGIT(c) isdigit((unsigned char)(c))
105 #define isUPPER(c) isupper((unsigned char)(c))
106 #define isLOWER(c) islower((unsigned char)(c))
107 #define toUPPER(c) toupper((unsigned char)(c))
108 #define toLOWER(c) tolower((unsigned char)(c))
110 #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
111 #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
112 #define isALPHA(c) (isascii(c) && isalpha(c))
113 #define isSPACE(c) (isascii(c) && isspace(c))
114 #define isDIGIT(c) (isascii(c) && isdigit(c))
115 #define isUPPER(c) (isascii(c) && isupper(c))
116 #define isLOWER(c) (isascii(c) && islower(c))
117 #define toUPPER(c) toupper(c)
118 #define toLOWER(c) tolower(c)
120 #endif /* USE_NEXT_CTYPE */
122 /* Line numbers are unsigned, 16 bits. */
125 #define NOLINE ((line_t)0)
127 #define NOLINE ((line_t) 65535)
133 char *safemalloc _((MEM_SIZE));
134 char *saferealloc _((char *, MEM_SIZE));
135 void safefree _((char *));
138 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
139 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
140 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
141 memzero((char*)(v), (n) * sizeof(t))
142 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
143 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
145 #define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
146 #define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
147 #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
148 memzero((char*)(v), (n) * sizeof(t))
149 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
150 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
152 #define Safefree(d) safefree((char*)d)
153 #define NEWSV(x,len) newSV(len)
156 char *safexrealloc();
158 #define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
159 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
160 #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
161 memzero((char*)(v), (n) * sizeof(t))
162 #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
163 #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
164 #define Safefree(d) safexfree((char*)d)
165 #define NEWSV(x,len) newSV(x,len)
166 #define MAXXCOUNT 1200
167 long xcount[MAXXCOUNT];
168 long lastxcount[MAXXCOUNT];
169 #endif /* LEAKTEST */
170 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
171 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
172 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
174 #define New(x,v,n,s) (v = Null(s *))
175 #define Newc(x,v,n,s,c) (v = Null(s *))
176 #define Newz(x,v,n,s) (v = Null(s *))
177 #define Renew(v,n,s) (v = Null(s *))
178 #define Move(s,d,n,t)
179 #define Copy(s,d,n,t)
181 #define Safefree(d) d = d
184 #ifdef USE_STRUCT_COPY
185 #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
187 #define StructCopy(s,d,t) Copy(s,d,1,t)