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*)
42 typedef unsigned char U8;
45 typedef unsigned short U16;
47 #if BYTEORDER > 0x4321
49 typedef unsigned int U32;
52 typedef unsigned long U32;
55 #define Ctl(ch) (ch & 037)
57 #define strNE(s1,s2) (strcmp(s1,s2))
58 #define strEQ(s1,s2) (!strcmp(s1,s2))
59 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
60 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
61 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
62 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
63 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
64 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
66 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
73 #define isALNUM(c) (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
74 #define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
75 #define isALPHA(c) NXIsAlpha((unsigned int)c)
76 #define isSPACE(c) NXIsSpace((unsigned int)c)
77 #define isDIGIT(c) NXIsDigit((unsigned int)c)
78 #define isUPPER(c) NXIsUpper((unsigned int)c)
79 #define isLOWER(c) NXIsLower((unsigned int)c)
80 #define toUPPER(c) NXToUpper((unsigned int)c)
81 #define toLOWER(c) NXToLower((unsigned int)c)
82 #else /* USE_NEXT_CTYPE */
83 #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
84 #define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
85 #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
86 #define isALPHA(c) isalpha((unsigned char)(c))
87 #define isSPACE(c) isspace((unsigned char)(c))
88 #define isDIGIT(c) isdigit((unsigned char)(c))
89 #define isUPPER(c) isupper((unsigned char)(c))
90 #define isLOWER(c) islower((unsigned char)(c))
91 #define toUPPER(c) toupper((unsigned char)(c))
92 #define toLOWER(c) tolower((unsigned char)(c))
94 #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
95 #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
96 #define isALPHA(c) (isascii(c) && isalpha(c))
97 #define isSPACE(c) (isascii(c) && isspace(c))
98 #define isDIGIT(c) (isascii(c) && isdigit(c))
99 #define isUPPER(c) (isascii(c) && isupper(c))
100 #define isLOWER(c) (isascii(c) && islower(c))
101 #define toUPPER(c) toupper(c)
102 #define toLOWER(c) tolower(c)
104 #endif /* USE_NEXT_CTYPE */
106 /* Line numbers are unsigned, 16 bits. */
109 #define NOLINE ((line_t)0)
111 #define NOLINE ((line_t) 65535)
117 char *safemalloc _((MEM_SIZE));
118 char *saferealloc _((char *, MEM_SIZE));
119 void safefree _((char *));
122 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
123 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
124 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
125 memzero((char*)(v), (n) * sizeof(t))
126 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
127 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
129 #define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
130 #define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
131 #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
132 memzero((char*)(v), (n) * sizeof(t))
133 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
134 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
136 #define Safefree(d) safefree((char*)d)
137 #define NEWSV(x,len) newSV(len)
140 char *safexrealloc();
142 #define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
143 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
144 #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
145 memzero((char*)(v), (n) * sizeof(t))
146 #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
147 #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
148 #define Safefree(d) safexfree((char*)d)
149 #define NEWSV(x,len) newSV(x,len)
150 #define MAXXCOUNT 1200
151 long xcount[MAXXCOUNT];
152 long lastxcount[MAXXCOUNT];
153 #endif /* LEAKTEST */
154 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
155 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
156 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
158 #define New(x,v,n,s) (v = Null(s *))
159 #define Newc(x,v,n,s,c) (v = Null(s *))
160 #define Newz(x,v,n,s) (v = Null(s *))
161 #define Renew(v,n,s) (v = Null(s *))
162 #define Move(s,d,n,t)
163 #define Copy(s,d,n,t)
165 #define Safefree(d) d = d
168 #ifdef USE_STRUCT_COPY
169 #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
171 #define StructCopy(s,d,t) Copy(s,d,1,t)