This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 8
[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
2304df62
AD
82#ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
83# ifndef CTYPE256
84# define CTYPE256
85# endif
86#endif
87
bee1dbe2 88#if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
79072805
LW
89#define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
90#define isIDFIRST(c) (isalpha(c) || (c) == '_')
91#define isALPHA(c) isalpha(c)
92#define isSPACE(c) isspace(c)
93#define isDIGIT(c) isdigit(c)
94#define isUPPER(c) isupper(c)
95#define isLOWER(c) islower(c)
55204971 96#else
79072805
LW
97#define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
98#define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
99#define isALPHA(c) (isascii(c) && isalpha(c))
100#define isSPACE(c) (isascii(c) && isspace(c))
101#define isDIGIT(c) (isascii(c) && isdigit(c))
102#define isUPPER(c) (isascii(c) && isupper(c))
103#define isLOWER(c) (isascii(c) && islower(c))
55204971
LW
104#endif
105
378cc40b 106/* Line numbers are unsigned, 16 bits. */
79072805 107typedef U16 line_t;
378cc40b
LW
108#ifdef lint
109#define NOLINE ((line_t)0)
110#else
111#define NOLINE ((line_t) 65535)
112#endif
113
a687059c
LW
114#ifndef lint
115#ifndef LEAKTEST
55204971 116#ifndef safemalloc
a687059c
LW
117char *safemalloc();
118char *saferealloc();
119void safefree();
55204971 120#endif
154e51a4 121#ifndef MSDOS
a687059c
LW
122#define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
123#define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
124#define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 125 memzero((char*)(v), (n) * sizeof(t))
a687059c
LW
126#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
127#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
154e51a4
LW
128#else
129#define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
130#define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
131#define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
bee1dbe2 132 memzero((char*)(v), (n) * sizeof(t))
154e51a4
LW
133#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
134#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
135#endif /* MSDOS */
a687059c 136#define Safefree(d) safefree((char*)d)
79072805 137#define NEWSV(x,len) newSV(len)
a687059c
LW
138#else /* LEAKTEST */
139char *safexmalloc();
140char *safexrealloc();
141void safexfree();
142#define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
143#define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
144#define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 145 memzero((char*)(v), (n) * sizeof(t))
a687059c
LW
146#define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
147#define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
148#define Safefree(d) safexfree((char*)d)
79072805 149#define NEWSV(x,len) newSV(x,len)
a687059c
LW
150#define MAXXCOUNT 1200
151long xcount[MAXXCOUNT];
152long lastxcount[MAXXCOUNT];
153#endif /* LEAKTEST */
bee1dbe2
LW
154#define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
155#define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
156#define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
a687059c
LW
157#else /* lint */
158#define New(x,v,n,s) (v = Null(s *))
159#define Newc(x,v,n,s,c) (v = Null(s *))
160#define Newz(x,v,n,s) (v = Null(s *))
161#define Renew(v,n,s) (v = Null(s *))
bee1dbe2 162#define Move(s,d,n,t)
a687059c
LW
163#define Copy(s,d,n,t)
164#define Zero(d,n,t)
165#define Safefree(d) d = d
166#endif /* lint */
bee1dbe2 167
2304df62 168#ifdef USE_STRUCT_COPY
bee1dbe2
LW
169#define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
170#else
171#define StructCopy(s,d,t) Copy(s,d,1,t)
172#endif