This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5.001 patch.1b: [byacc deps fix, set*id fixes, x2p/walk.c emit_split()
[perl5.git] / handy.h
CommitLineData
a0d0e21e 1/* handy.h
a687059c 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, 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 7 *
8d063cd8
LW
8 */
9
85e6fe83 10#if !defined(__STDC__)
378cc40b
LW
11#ifdef NULL
12#undef NULL
13#endif
a687059c
LW
14#ifndef I286
15# define NULL 0
16#else
17# define NULL 0L
18#endif
85e6fe83
LW
19#endif
20
378cc40b 21#define Null(type) ((type)NULL)
8d063cd8
LW
22#define Nullch Null(char*)
23#define Nullfp Null(FILE*)
79072805 24#define Nullsv Null(SV*)
8d063cd8 25
1aef975c
AD
26/* bool is built-in for g++-2.6.3, which might be used for an extension. */
27#if !defined(HAS_BOOL) && !defined(_G_HAVE_BOOL)
a687059c
LW
28#ifdef UTS
29#define bool int
30#else
8d063cd8 31#define bool char
a687059c 32#endif
1aef975c 33#endif /* !defined(HAS_BOOL) && !defined(_G_HAVE_BOOL) */
0d3e774c
LW
34
35#ifdef TRUE
36#undef TRUE
37#endif
38#ifdef FALSE
39#undef FALSE
40#endif
8d063cd8
LW
41#define TRUE (1)
42#define FALSE (0)
43
79072805
LW
44typedef char I8;
45typedef unsigned char U8;
46
47typedef short I16;
48typedef unsigned short U16;
49
a0d0e21e 50#if BYTEORDER > 0x4321
85e6fe83
LW
51 typedef int I32;
52 typedef unsigned int U32;
79072805 53#else
85e6fe83
LW
54 typedef long I32;
55 typedef unsigned long U32;
79072805
LW
56#endif
57
8d063cd8
LW
58#define Ctl(ch) (ch & 037)
59
60#define strNE(s1,s2) (strcmp(s1,s2))
61#define strEQ(s1,s2) (!strcmp(s1,s2))
62#define strLT(s1,s2) (strcmp(s1,s2) < 0)
63#define strLE(s1,s2) (strcmp(s1,s2) <= 0)
64#define strGT(s1,s2) (strcmp(s1,s2) > 0)
65#define strGE(s1,s2) (strcmp(s1,s2) >= 0)
66#define strnNE(s1,s2,l) (strncmp(s1,s2,l))
67#define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
378cc40b 68
2304df62
AD
69#ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
70# ifndef CTYPE256
71# define CTYPE256
72# endif
73#endif
74
a0d0e21e
LW
75#ifdef USE_NEXT_CTYPE
76#define isALNUM(c) (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
77#define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
78#define isALPHA(c) NXIsAlpha((unsigned int)c)
79#define isSPACE(c) NXIsSpace((unsigned int)c)
80#define isDIGIT(c) NXIsDigit((unsigned int)c)
81#define isUPPER(c) NXIsUpper((unsigned int)c)
82#define isLOWER(c) NXIsLower((unsigned int)c)
83#define toUPPER(c) NXToUpper((unsigned int)c)
84#define toLOWER(c) NXToLower((unsigned int)c)
85#else /* USE_NEXT_CTYPE */
bee1dbe2 86#if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
85e6fe83
LW
87#define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
88#define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
89#define isALPHA(c) isalpha((unsigned char)(c))
90#define isSPACE(c) isspace((unsigned char)(c))
91#define isDIGIT(c) isdigit((unsigned char)(c))
92#define isUPPER(c) isupper((unsigned char)(c))
93#define isLOWER(c) islower((unsigned char)(c))
a0d0e21e
LW
94#define toUPPER(c) toupper((unsigned char)(c))
95#define toLOWER(c) tolower((unsigned char)(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))
a0d0e21e
LW
104#define toUPPER(c) toupper(c)
105#define toLOWER(c) tolower(c)
55204971 106#endif
a0d0e21e 107#endif /* USE_NEXT_CTYPE */
55204971 108
378cc40b 109/* Line numbers are unsigned, 16 bits. */
79072805 110typedef U16 line_t;
378cc40b
LW
111#ifdef lint
112#define NOLINE ((line_t)0)
113#else
114#define NOLINE ((line_t) 65535)
115#endif
116
a687059c
LW
117#ifndef lint
118#ifndef LEAKTEST
55204971 119#ifndef safemalloc
a0d0e21e
LW
120char *safemalloc _((MEM_SIZE));
121char *saferealloc _((char *, MEM_SIZE));
122void safefree _((char *));
55204971 123#endif
154e51a4 124#ifndef MSDOS
a687059c
LW
125#define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
126#define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
127#define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 128 memzero((char*)(v), (n) * sizeof(t))
a687059c
LW
129#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
130#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
154e51a4
LW
131#else
132#define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
133#define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
134#define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
bee1dbe2 135 memzero((char*)(v), (n) * sizeof(t))
154e51a4
LW
136#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
137#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
138#endif /* MSDOS */
a687059c 139#define Safefree(d) safefree((char*)d)
79072805 140#define NEWSV(x,len) newSV(len)
a687059c
LW
141#else /* LEAKTEST */
142char *safexmalloc();
143char *safexrealloc();
144void safexfree();
145#define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
146#define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
147#define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 148 memzero((char*)(v), (n) * sizeof(t))
a687059c
LW
149#define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
150#define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
151#define Safefree(d) safexfree((char*)d)
79072805 152#define NEWSV(x,len) newSV(x,len)
a687059c
LW
153#define MAXXCOUNT 1200
154long xcount[MAXXCOUNT];
155long lastxcount[MAXXCOUNT];
156#endif /* LEAKTEST */
bee1dbe2
LW
157#define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
158#define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
159#define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
a687059c
LW
160#else /* lint */
161#define New(x,v,n,s) (v = Null(s *))
162#define Newc(x,v,n,s,c) (v = Null(s *))
163#define Newz(x,v,n,s) (v = Null(s *))
164#define Renew(v,n,s) (v = Null(s *))
bee1dbe2 165#define Move(s,d,n,t)
a687059c
LW
166#define Copy(s,d,n,t)
167#define Zero(d,n,t)
168#define Safefree(d) d = d
169#endif /* lint */
bee1dbe2 170
2304df62 171#ifdef USE_STRUCT_COPY
bee1dbe2
LW
172#define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
173#else
174#define StructCopy(s,d,t) Copy(s,d,1,t)
175#endif