This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 6
[perl5.git] / handy.h
CommitLineData
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
378cc40b
LW
29#ifdef NULL
30#undef NULL
31#endif
a687059c
LW
32#ifndef I286
33# define NULL 0
34#else
35# define NULL 0L
36#endif
378cc40b 37#define Null(type) ((type)NULL)
8d063cd8
LW
38#define Nullch Null(char*)
39#define Nullfp Null(FILE*)
79072805 40#define Nullsv Null(SV*)
8d063cd8 41
a687059c
LW
42#ifdef UTS
43#define bool int
44#else
8d063cd8 45#define bool char
a687059c 46#endif
0d3e774c
LW
47
48#ifdef TRUE
49#undef TRUE
50#endif
51#ifdef FALSE
52#undef FALSE
53#endif
8d063cd8
LW
54#define TRUE (1)
55#define FALSE (0)
56
79072805
LW
57typedef char I8;
58typedef unsigned char U8;
59
60typedef short I16;
61typedef unsigned short U16;
62
63#if INTSIZE == 4
64typedef int I32;
65typedef unsigned int U32;
66#else
67typedef long I32;
68typedef unsigned long U32;
69#endif
70
8d063cd8
LW
71#define Ctl(ch) (ch & 037)
72
73#define strNE(s1,s2) (strcmp(s1,s2))
74#define strEQ(s1,s2) (!strcmp(s1,s2))
75#define strLT(s1,s2) (strcmp(s1,s2) < 0)
76#define strLE(s1,s2) (strcmp(s1,s2) <= 0)
77#define strGT(s1,s2) (strcmp(s1,s2) > 0)
78#define strGE(s1,s2) (strcmp(s1,s2) >= 0)
79#define strnNE(s1,s2,l) (strncmp(s1,s2,l))
80#define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
378cc40b 81
bee1dbe2 82#if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
79072805
LW
83#define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
84#define isIDFIRST(c) (isalpha(c) || (c) == '_')
85#define isALPHA(c) isalpha(c)
86#define isSPACE(c) isspace(c)
87#define isDIGIT(c) isdigit(c)
88#define isUPPER(c) isupper(c)
89#define isLOWER(c) islower(c)
55204971 90#else
79072805
LW
91#define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
92#define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
93#define isALPHA(c) (isascii(c) && isalpha(c))
94#define isSPACE(c) (isascii(c) && isspace(c))
95#define isDIGIT(c) (isascii(c) && isdigit(c))
96#define isUPPER(c) (isascii(c) && isupper(c))
97#define isLOWER(c) (isascii(c) && islower(c))
55204971
LW
98#endif
99
378cc40b 100/* Line numbers are unsigned, 16 bits. */
79072805 101typedef U16 line_t;
378cc40b
LW
102#ifdef lint
103#define NOLINE ((line_t)0)
104#else
105#define NOLINE ((line_t) 65535)
106#endif
107
a687059c
LW
108#ifndef lint
109#ifndef LEAKTEST
55204971 110#ifndef safemalloc
a687059c
LW
111char *safemalloc();
112char *saferealloc();
113void safefree();
55204971 114#endif
154e51a4 115#ifndef MSDOS
a687059c
LW
116#define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
117#define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
118#define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 119 memzero((char*)(v), (n) * sizeof(t))
a687059c
LW
120#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
121#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
154e51a4
LW
122#else
123#define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
124#define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
125#define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
bee1dbe2 126 memzero((char*)(v), (n) * sizeof(t))
154e51a4
LW
127#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
128#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
129#endif /* MSDOS */
a687059c 130#define Safefree(d) safefree((char*)d)
79072805 131#define NEWSV(x,len) newSV(len)
a687059c
LW
132#else /* LEAKTEST */
133char *safexmalloc();
134char *safexrealloc();
135void safexfree();
136#define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
137#define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
138#define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 139 memzero((char*)(v), (n) * sizeof(t))
a687059c
LW
140#define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
141#define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
142#define Safefree(d) safexfree((char*)d)
79072805 143#define NEWSV(x,len) newSV(x,len)
a687059c
LW
144#define MAXXCOUNT 1200
145long xcount[MAXXCOUNT];
146long lastxcount[MAXXCOUNT];
147#endif /* LEAKTEST */
bee1dbe2
LW
148#define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
149#define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
150#define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
a687059c
LW
151#else /* lint */
152#define New(x,v,n,s) (v = Null(s *))
153#define Newc(x,v,n,s,c) (v = Null(s *))
154#define Newz(x,v,n,s) (v = Null(s *))
155#define Renew(v,n,s) (v = Null(s *))
bee1dbe2 156#define Move(s,d,n,t)
a687059c
LW
157#define Copy(s,d,n,t)
158#define Zero(d,n,t)
159#define Safefree(d) d = d
160#endif /* lint */
bee1dbe2
LW
161
162#ifdef STRUCTCOPY
163#define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
164#else
165#define StructCopy(s,d,t) Copy(s,d,1,t)
166#endif