perl 4.0 patch 24: patch #20, continued
[p5sagit/p5-mst-13.2.git] / handy.h
1 /* $RCSfile: handy.h,v $$Revision: 4.0.1.3 $$Date: 91/11/05 22:54:26 $
2  *
3  *    Copyright (c) 1991, Larry Wall
4  *
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.
7  *
8  * $Log:        handy.h,v $
9  * Revision 4.0.1.3  91/11/05  22:54:26  lwall
10  * patch11: erratum
11  * 
12  * Revision 4.0.1.2  91/11/05  17:23:38  lwall
13  * patch11: prepared for ctype implementations that don't define isascii()
14  * 
15  * Revision 4.0.1.1  91/06/07  11:09:56  lwall
16  * patch4: new copyright notice
17  * 
18  * Revision 4.0  91/03/20  01:22:15  lwall
19  * 4.0 baseline.
20  * 
21  */
22
23 #ifdef NULL
24 #undef NULL
25 #endif
26 #ifndef I286
27 #  define NULL 0
28 #else
29 #  define NULL 0L
30 #endif
31 #define Null(type) ((type)NULL)
32 #define Nullch Null(char*)
33 #define Nullfp Null(FILE*)
34
35 #ifdef UTS
36 #define bool int
37 #else
38 #define bool char
39 #endif
40
41 #ifdef TRUE
42 #undef TRUE
43 #endif
44 #ifdef FALSE
45 #undef FALSE
46 #endif
47 #define TRUE (1)
48 #define FALSE (0)
49
50 #define Ctl(ch) (ch & 037)
51
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))
60
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)
68 #else
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))
75 #endif
76
77 #define MEM_SIZE unsigned int
78
79 /* Line numbers are unsigned, 16 bits. */
80 typedef unsigned short line_t;
81 #ifdef lint
82 #define NOLINE ((line_t)0)
83 #else
84 #define NOLINE ((line_t) 65535)
85 #endif
86
87 #ifndef lint
88 #ifndef LEAKTEST
89 #ifndef safemalloc
90 char *safemalloc();
91 char *saferealloc();
92 void safefree();
93 #endif
94 #ifndef MSDOS
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))))
101 #else
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))))
108 #endif /* MSDOS */
109 #define Safefree(d) safefree((char*)d)
110 #define Str_new(x,len) str_new(len)
111 #else /* LEAKTEST */
112 char *safexmalloc();
113 char *safexrealloc();
114 void safexfree();
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))
129 #else /* lint */
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)
135 #define Zero(d,n,t)
136 #define Safefree(d) d = d
137 #endif /* lint */