Commit | Line | Data |
---|---|---|
bee1dbe2 | 1 | /* $RCSfile: handy.h,v $$Revision: 4.0.1.4 $$Date: 92/06/08 13:23:17 $ |
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 $ | |
bee1dbe2 LW |
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 | |
12 | * | |
55204971 LW |
13 | * Revision 4.0.1.3 91/11/05 22:54:26 lwall |
14 | * patch11: erratum | |
15 | * | |
16 | * Revision 4.0.1.2 91/11/05 17:23:38 lwall | |
17 | * patch11: prepared for ctype implementations that don't define isascii() | |
18 | * | |
6e21c824 LW |
19 | * Revision 4.0.1.1 91/06/07 11:09:56 lwall |
20 | * patch4: new copyright notice | |
21 | * | |
fe14fcc3 LW |
22 | * Revision 4.0 91/03/20 01:22:15 lwall |
23 | * 4.0 baseline. | |
8d063cd8 LW |
24 | * |
25 | */ | |
26 | ||
378cc40b LW |
27 | #ifdef NULL |
28 | #undef NULL | |
29 | #endif | |
a687059c LW |
30 | #ifndef I286 |
31 | # define NULL 0 | |
32 | #else | |
33 | # define NULL 0L | |
34 | #endif | |
378cc40b | 35 | #define Null(type) ((type)NULL) |
8d063cd8 LW |
36 | #define Nullch Null(char*) |
37 | #define Nullfp Null(FILE*) | |
38 | ||
a687059c LW |
39 | #ifdef UTS |
40 | #define bool int | |
41 | #else | |
8d063cd8 | 42 | #define bool char |
a687059c | 43 | #endif |
0d3e774c LW |
44 | |
45 | #ifdef TRUE | |
46 | #undef TRUE | |
47 | #endif | |
48 | #ifdef FALSE | |
49 | #undef FALSE | |
50 | #endif | |
8d063cd8 LW |
51 | #define TRUE (1) |
52 | #define FALSE (0) | |
53 | ||
54 | #define Ctl(ch) (ch & 037) | |
55 | ||
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)) | |
378cc40b | 64 | |
bee1dbe2 | 65 | #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII)) |
55204971 LW |
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) | |
72 | #else | |
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)) | |
79 | #endif | |
80 | ||
378cc40b LW |
81 | /* Line numbers are unsigned, 16 bits. */ |
82 | typedef unsigned short line_t; | |
83 | #ifdef lint | |
84 | #define NOLINE ((line_t)0) | |
85 | #else | |
86 | #define NOLINE ((line_t) 65535) | |
87 | #endif | |
88 | ||
a687059c LW |
89 | #ifndef lint |
90 | #ifndef LEAKTEST | |
55204971 | 91 | #ifndef safemalloc |
a687059c LW |
92 | char *safemalloc(); |
93 | char *saferealloc(); | |
94 | void safefree(); | |
55204971 | 95 | #endif |
154e51a4 | 96 | #ifndef MSDOS |
a687059c LW |
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)))), \ | |
bee1dbe2 | 100 | memzero((char*)(v), (n) * sizeof(t)) |
a687059c LW |
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)))) | |
154e51a4 LW |
103 | #else |
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)))), \ | |
bee1dbe2 | 107 | memzero((char*)(v), (n) * sizeof(t)) |
154e51a4 LW |
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)))) | |
110 | #endif /* MSDOS */ | |
a687059c LW |
111 | #define Safefree(d) safefree((char*)d) |
112 | #define Str_new(x,len) str_new(len) | |
113 | #else /* LEAKTEST */ | |
114 | char *safexmalloc(); | |
115 | char *safexrealloc(); | |
116 | void safexfree(); | |
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)))), \ | |
bee1dbe2 | 120 | memzero((char*)(v), (n) * sizeof(t)) |
a687059c LW |
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 */ | |
bee1dbe2 LW |
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)) | |
a687059c LW |
132 | #else /* lint */ |
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 *)) | |
bee1dbe2 | 137 | #define Move(s,d,n,t) |
a687059c LW |
138 | #define Copy(s,d,n,t) |
139 | #define Zero(d,n,t) | |
140 | #define Safefree(d) d = d | |
141 | #endif /* lint */ | |
bee1dbe2 LW |
142 | |
143 | #ifdef STRUCTCOPY | |
144 | #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s)) | |
145 | #else | |
146 | #define StructCopy(s,d,t) Copy(s,d,1,t) | |
147 | #endif |