Commit | Line | Data |
---|---|---|
79072805 | 1 | /* $RCSfile: handy.h,v $$Revision: 4.1 $$Date: 92/08/07 18:21:46 $ |
a687059c | 2 | * |
6e21c824 | 3 | * Copyright (c) 1991, Larry Wall |
a687059c | 4 | * |
6e21c824 LW |
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. | |
8d063cd8 LW |
7 | * |
8 | * $Log: handy.h,v $ | |
79072805 LW |
9 | * Revision 4.1 92/08/07 18:21:46 lwall |
10 | * | |
bee1dbe2 LW |
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 | |
14 | * | |
55204971 LW |
15 | * Revision 4.0.1.3 91/11/05 22:54:26 lwall |
16 | * patch11: erratum | |
17 | * | |
18 | * Revision 4.0.1.2 91/11/05 17:23:38 lwall | |
19 | * patch11: prepared for ctype implementations that don't define isascii() | |
20 | * | |
6e21c824 LW |
21 | * Revision 4.0.1.1 91/06/07 11:09:56 lwall |
22 | * patch4: new copyright notice | |
23 | * | |
fe14fcc3 LW |
24 | * Revision 4.0 91/03/20 01:22:15 lwall |
25 | * 4.0 baseline. | |
8d063cd8 LW |
26 | * |
27 | */ | |
28 | ||
85e6fe83 | 29 | #if !defined(__STDC__) |
378cc40b LW |
30 | #ifdef NULL |
31 | #undef NULL | |
32 | #endif | |
a687059c LW |
33 | #ifndef I286 |
34 | # define NULL 0 | |
35 | #else | |
36 | # define NULL 0L | |
37 | #endif | |
85e6fe83 LW |
38 | #endif |
39 | ||
378cc40b | 40 | #define Null(type) ((type)NULL) |
8d063cd8 LW |
41 | #define Nullch Null(char*) |
42 | #define Nullfp Null(FILE*) | |
79072805 | 43 | #define Nullsv Null(SV*) |
8d063cd8 | 44 | |
a687059c LW |
45 | #ifdef UTS |
46 | #define bool int | |
47 | #else | |
8d063cd8 | 48 | #define bool char |
a687059c | 49 | #endif |
0d3e774c LW |
50 | |
51 | #ifdef TRUE | |
52 | #undef TRUE | |
53 | #endif | |
54 | #ifdef FALSE | |
55 | #undef FALSE | |
56 | #endif | |
8d063cd8 LW |
57 | #define TRUE (1) |
58 | #define FALSE (0) | |
59 | ||
85e6fe83 LW |
60 | #ifdef UNICOS |
61 | #define I8 char | |
62 | #define U8 unsigned char | |
63 | #define I16 short | |
64 | #define U16 unsigned short | |
65 | #define I32 int | |
66 | #define U32 unsigned int | |
67 | ||
68 | #else | |
69 | ||
79072805 LW |
70 | typedef char I8; |
71 | typedef unsigned char U8; | |
72 | ||
73 | typedef short I16; | |
74 | typedef unsigned short U16; | |
75 | ||
76 | #if INTSIZE == 4 | |
85e6fe83 LW |
77 | typedef int I32; |
78 | typedef unsigned int U32; | |
79072805 | 79 | #else |
85e6fe83 LW |
80 | typedef long I32; |
81 | typedef unsigned long U32; | |
79072805 LW |
82 | #endif |
83 | ||
85e6fe83 LW |
84 | #endif /* UNICOS */ |
85 | ||
8d063cd8 LW |
86 | #define Ctl(ch) (ch & 037) |
87 | ||
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)) | |
378cc40b | 96 | |
2304df62 AD |
97 | #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */ |
98 | # ifndef CTYPE256 | |
99 | # define CTYPE256 | |
100 | # endif | |
101 | #endif | |
102 | ||
bee1dbe2 | 103 | #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII)) |
85e6fe83 LW |
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)) | |
55204971 | 111 | #else |
79072805 LW |
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)) | |
55204971 LW |
119 | #endif |
120 | ||
378cc40b | 121 | /* Line numbers are unsigned, 16 bits. */ |
79072805 | 122 | typedef U16 line_t; |
378cc40b LW |
123 | #ifdef lint |
124 | #define NOLINE ((line_t)0) | |
125 | #else | |
126 | #define NOLINE ((line_t) 65535) | |
127 | #endif | |
128 | ||
a687059c LW |
129 | #ifndef lint |
130 | #ifndef LEAKTEST | |
55204971 | 131 | #ifndef safemalloc |
a687059c LW |
132 | char *safemalloc(); |
133 | char *saferealloc(); | |
134 | void safefree(); | |
55204971 | 135 | #endif |
154e51a4 | 136 | #ifndef MSDOS |
a687059c LW |
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)))), \ | |
bee1dbe2 | 140 | memzero((char*)(v), (n) * sizeof(t)) |
a687059c LW |
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)))) | |
154e51a4 LW |
143 | #else |
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)))), \ | |
bee1dbe2 | 147 | memzero((char*)(v), (n) * sizeof(t)) |
154e51a4 LW |
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)))) | |
150 | #endif /* MSDOS */ | |
a687059c | 151 | #define Safefree(d) safefree((char*)d) |
79072805 | 152 | #define NEWSV(x,len) newSV(len) |
a687059c LW |
153 | #else /* LEAKTEST */ |
154 | char *safexmalloc(); | |
155 | char *safexrealloc(); | |
156 | void safexfree(); | |
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)))), \ | |
bee1dbe2 | 160 | memzero((char*)(v), (n) * sizeof(t)) |
a687059c LW |
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) | |
79072805 | 164 | #define NEWSV(x,len) newSV(x,len) |
a687059c LW |
165 | #define MAXXCOUNT 1200 |
166 | long xcount[MAXXCOUNT]; | |
167 | long lastxcount[MAXXCOUNT]; | |
168 | #endif /* LEAKTEST */ | |
bee1dbe2 LW |
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)) | |
a687059c LW |
172 | #else /* lint */ |
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 *)) | |
bee1dbe2 | 177 | #define Move(s,d,n,t) |
a687059c LW |
178 | #define Copy(s,d,n,t) |
179 | #define Zero(d,n,t) | |
180 | #define Safefree(d) d = d | |
181 | #endif /* lint */ | |
bee1dbe2 | 182 | |
2304df62 | 183 | #ifdef USE_STRUCT_COPY |
bee1dbe2 LW |
184 | #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s)) |
185 | #else | |
186 | #define StructCopy(s,d,t) Copy(s,d,1,t) | |
187 | #endif |