1 /* $RCSfile: handy.h,v $$Revision: 4.0.1.3 $$Date: 91/11/05 22:54:26 $
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.3 91/11/05 22:54:26 lwall
12 * Revision 4.0.1.2 91/11/05 17:23:38 lwall
13 * patch11: prepared for ctype implementations that don't define isascii()
15 * Revision 4.0.1.1 91/06/07 11:09:56 lwall
16 * patch4: new copyright notice
18 * Revision 4.0 91/03/20 01:22:15 lwall
31 #define Null(type) ((type)NULL)
32 #define Nullch Null(char*)
33 #define Nullfp Null(FILE*)
50 #define Ctl(ch) (ch & 037)
52 #define strNE(s1,s2) (strcmp(s1,s2))
53 #define strEQ(s1,s2) (!strcmp(s1,s2))
54 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
55 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
56 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
57 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
58 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
59 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
61 #if defined(CTYPE256) || !defined(isascii)
62 #define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
63 #define isALPHA(c) isalpha(c)
64 #define isSPACE(c) isspace(c)
65 #define isDIGIT(c) isdigit(c)
66 #define isUPPER(c) isupper(c)
67 #define isLOWER(c) islower(c)
69 #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
70 #define isALPHA(c) (isascii(c) && isalpha(c))
71 #define isSPACE(c) (isascii(c) && isspace(c))
72 #define isDIGIT(c) (isascii(c) && isdigit(c))
73 #define isUPPER(c) (isascii(c) && isupper(c))
74 #define isLOWER(c) (isascii(c) && islower(c))
77 #define MEM_SIZE unsigned int
79 /* Line numbers are unsigned, 16 bits. */
80 typedef unsigned short line_t;
82 #define NOLINE ((line_t)0)
84 #define NOLINE ((line_t) 65535)
95 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
96 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
97 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
98 bzero((char*)(v), (n) * sizeof(t))
99 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
100 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
102 #define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
103 #define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
104 #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
105 bzero((char*)(v), (n) * sizeof(t))
106 #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
107 #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
109 #define Safefree(d) safefree((char*)d)
110 #define Str_new(x,len) str_new(len)
113 char *safexrealloc();
115 #define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
116 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
117 #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
118 bzero((char*)(v), (n) * sizeof(t))
119 #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
120 #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
121 #define Safefree(d) safexfree((char*)d)
122 #define Str_new(x,len) str_new(x,len)
123 #define MAXXCOUNT 1200
124 long xcount[MAXXCOUNT];
125 long lastxcount[MAXXCOUNT];
126 #endif /* LEAKTEST */
127 #define Copy(s,d,n,t) (void)bcopy((char*)(s),(char*)(d), (n) * sizeof(t))
128 #define Zero(d,n,t) (void)bzero((char*)(d), (n) * sizeof(t))
130 #define New(x,v,n,s) (v = Null(s *))
131 #define Newc(x,v,n,s,c) (v = Null(s *))
132 #define Newz(x,v,n,s) (v = Null(s *))
133 #define Renew(v,n,s) (v = Null(s *))
134 #define Copy(s,d,n,t)
136 #define Safefree(d) d = d