1 /* $RCSfile: handy.h,v $$Revision: 4.1 $$Date: 92/08/07 18:21:46 $
3 * Copyright (c) 1991, 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.
9 * Revision 4.1 92/08/07 18:21:46 lwall
11 * Revision 4.0.1.4 92/06/08 13:23:17 lwall
12 * patch20: isascii() may now be supplied by a library routine
13 * patch20: Perl now distinguishes overlapped copies from non-overlapped
15 * Revision 4.0.1.3 91/11/05 22:54:26 lwall
18 * Revision 4.0.1.2 91/11/05 17:23:38 lwall
19 * patch11: prepared for ctype implementations that don't define isascii()
21 * Revision 4.0.1.1 91/06/07 11:09:56 lwall
22 * patch4: new copyright notice
24 * Revision 4.0 91/03/20 01:22:15 lwall
29 #if !defined(__STDC__)
40 #define Null(type) ((type)NULL)
41 #define Nullch Null(char*)
42 #define Nullfp Null(FILE*)
43 #define Nullsv Null(SV*)
62 #define U8 unsigned char
64 #define U16 unsigned short
66 #define U32 unsigned int
71 typedef unsigned char U8;
74 typedef unsigned short U16;
78 typedef unsigned int U32;
81 typedef unsigned long U32;
86 #define Ctl(ch) (ch & 037)
88 #define strNE(s1,s2) (strcmp(s1,s2))
89 #define strEQ(s1,s2) (!strcmp(s1,s2))
90 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
91 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
92 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
93 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
94 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
95 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
97 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
103 #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
104 #define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
105 #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
106 #define isALPHA(c) isalpha((unsigned char)(c))
107 #define isSPACE(c) isspace((unsigned char)(c))
108 #define isDIGIT(c) isdigit((unsigned char)(c))
109 #define isUPPER(c) isupper((unsigned char)(c))
110 #define isLOWER(c) islower((unsigned char)(c))
112 #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
113 #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
114 #define isALPHA(c) (isascii(c) && isalpha(c))
115 #define isSPACE(c) (isascii(c) && isspace(c))
116 #define isDIGIT(c) (isascii(c) && isdigit(c))
117 #define isUPPER(c) (isascii(c) && isupper(c))
118 #define isLOWER(c) (isascii(c) && islower(c))
121 /* Line numbers are unsigned, 16 bits. */
124 #define NOLINE ((line_t)0)
126 #define NOLINE ((line_t) 65535)
137 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
138 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
139 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
140 memzero((char*)(v), (n) * sizeof(t))
141 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
142 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
144 #define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
145 #define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
146 #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
147 memzero((char*)(v), (n) * sizeof(t))
148 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
149 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
151 #define Safefree(d) safefree((char*)d)
152 #define NEWSV(x,len) newSV(len)
155 char *safexrealloc();
157 #define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
158 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
159 #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
160 memzero((char*)(v), (n) * sizeof(t))
161 #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
162 #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
163 #define Safefree(d) safexfree((char*)d)
164 #define NEWSV(x,len) newSV(x,len)
165 #define MAXXCOUNT 1200
166 long xcount[MAXXCOUNT];
167 long lastxcount[MAXXCOUNT];
168 #endif /* LEAKTEST */
169 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
170 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
171 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
173 #define New(x,v,n,s) (v = Null(s *))
174 #define Newc(x,v,n,s,c) (v = Null(s *))
175 #define Newz(x,v,n,s) (v = Null(s *))
176 #define Renew(v,n,s) (v = Null(s *))
177 #define Move(s,d,n,t)
178 #define Copy(s,d,n,t)
180 #define Safefree(d) d = d
183 #ifdef USE_STRUCT_COPY
184 #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
186 #define StructCopy(s,d,t) Copy(s,d,1,t)