1 /* $RCSfile: handy.h,v $$Revision: 4.0.1.4 $$Date: 92/06/08 13:23:17 $
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.0.1.4 92/06/08 13:23:17 lwall
10 * patch20: isascii() may now be supplied by a library routine
11 * patch20: Perl now distinguishes overlapped copies from non-overlapped
13 * Revision 4.0.1.3 91/11/05 22:54:26 lwall
16 * Revision 4.0.1.2 91/11/05 17:23:38 lwall
17 * patch11: prepared for ctype implementations that don't define isascii()
19 * Revision 4.0.1.1 91/06/07 11:09:56 lwall
20 * patch4: new copyright notice
22 * Revision 4.0 91/03/20 01:22:15 lwall
35 #define Null(type) ((type)NULL)
36 #define Nullch Null(char*)
37 #define Nullfp Null(FILE*)
54 #define Ctl(ch) (ch & 037)
56 #define strNE(s1,s2) (strcmp(s1,s2))
57 #define strEQ(s1,s2) (!strcmp(s1,s2))
58 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
59 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
60 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
61 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
62 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
63 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
65 #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
66 #define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
67 #define isALPHA(c) isalpha(c)
68 #define isSPACE(c) isspace(c)
69 #define isDIGIT(c) isdigit(c)
70 #define isUPPER(c) isupper(c)
71 #define isLOWER(c) islower(c)
73 #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
74 #define isALPHA(c) (isascii(c) && isalpha(c))
75 #define isSPACE(c) (isascii(c) && isspace(c))
76 #define isDIGIT(c) (isascii(c) && isdigit(c))
77 #define isUPPER(c) (isascii(c) && isupper(c))
78 #define isLOWER(c) (isascii(c) && islower(c))
81 /* Line numbers are unsigned, 16 bits. */
82 typedef unsigned short line_t;
84 #define NOLINE ((line_t)0)
86 #define NOLINE ((line_t) 65535)
97 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
98 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
99 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
100 memzero((char*)(v), (n) * sizeof(t))
101 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
102 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
104 #define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
105 #define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
106 #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
107 memzero((char*)(v), (n) * sizeof(t))
108 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
109 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
111 #define Safefree(d) safefree((char*)d)
112 #define Str_new(x,len) str_new(len)
115 char *safexrealloc();
117 #define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
118 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
119 #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
120 memzero((char*)(v), (n) * sizeof(t))
121 #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
122 #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
123 #define Safefree(d) safexfree((char*)d)
124 #define Str_new(x,len) str_new(x,len)
125 #define MAXXCOUNT 1200
126 long xcount[MAXXCOUNT];
127 long lastxcount[MAXXCOUNT];
128 #endif /* LEAKTEST */
129 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
130 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
131 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
133 #define New(x,v,n,s) (v = Null(s *))
134 #define Newc(x,v,n,s,c) (v = Null(s *))
135 #define Newz(x,v,n,s) (v = Null(s *))
136 #define Renew(v,n,s) (v = Null(s *))
137 #define Move(s,d,n,t)
138 #define Copy(s,d,n,t)
140 #define Safefree(d) d = d
144 #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
146 #define StructCopy(s,d,t) Copy(s,d,1,t)