perl 5.002beta2 patch: toke.c
[p5sagit/p5-mst-13.2.git] / handy.h
CommitLineData
a0d0e21e 1/* handy.h
a687059c 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, Larry Wall
a687059c 4 *
6e21c824 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 8 */
9
85e6fe83 10#if !defined(__STDC__)
378cc40b 11#ifdef NULL
12#undef NULL
13#endif
a687059c 14#ifndef I286
15# define NULL 0
16#else
17# define NULL 0L
18#endif
85e6fe83 19#endif
20
378cc40b 21#define Null(type) ((type)NULL)
8d063cd8 22#define Nullch Null(char*)
23#define Nullfp Null(FILE*)
79072805 24#define Nullsv Null(SV*)
8d063cd8 25
232e078e 26/* bool is built-in for g++-2.6.3, which might be used for an extension.
5d94fbed 27 If the extension includes <_G_config.h> before this file then
28 _G_HAVE_BOOL will be properly set. If, however, the extension includes
29 this file first, then you will have to manually set -DHAS_BOOL in
30 your command line to avoid a conflict.
31*/
32#ifdef _G_HAVE_BOOL
33# if _G_HAVE_BOOL
34# ifndef HAS_BOOL
35# define HAS_BOOL 1
36# endif
37# endif
38#endif
39
40#ifndef HAS_BOOL
41# ifdef UTS
42# define bool int
43# else
44# define bool char
45# endif
a687059c 46#endif
0d3e774c 47
48#ifdef TRUE
49#undef TRUE
50#endif
51#ifdef FALSE
52#undef FALSE
53#endif
8d063cd8 54#define TRUE (1)
55#define FALSE (0)
56
79072805 57typedef char I8;
58typedef unsigned char U8;
59
60typedef short I16;
61typedef unsigned short U16;
62
a0d0e21e 63#if BYTEORDER > 0x4321
85e6fe83 64 typedef int I32;
65 typedef unsigned int U32;
79072805 66#else
85e6fe83 67 typedef long I32;
68 typedef unsigned long U32;
79072805 69#endif
70
8d063cd8 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 82#ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
83# ifndef CTYPE256
84# define CTYPE256
85# endif
86#endif
87
a0d0e21e 88#ifdef USE_NEXT_CTYPE
89#define isALNUM(c) (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
90#define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
91#define isALPHA(c) NXIsAlpha((unsigned int)c)
92#define isSPACE(c) NXIsSpace((unsigned int)c)
93#define isDIGIT(c) NXIsDigit((unsigned int)c)
94#define isUPPER(c) NXIsUpper((unsigned int)c)
95#define isLOWER(c) NXIsLower((unsigned int)c)
96#define toUPPER(c) NXToUpper((unsigned int)c)
97#define toLOWER(c) NXToLower((unsigned int)c)
98#else /* USE_NEXT_CTYPE */
bee1dbe2 99#if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
85e6fe83 100#define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
101#define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
102#define isALPHA(c) isalpha((unsigned char)(c))
103#define isSPACE(c) isspace((unsigned char)(c))
104#define isDIGIT(c) isdigit((unsigned char)(c))
105#define isUPPER(c) isupper((unsigned char)(c))
106#define isLOWER(c) islower((unsigned char)(c))
a0d0e21e 107#define toUPPER(c) toupper((unsigned char)(c))
108#define toLOWER(c) tolower((unsigned char)(c))
55204971 109#else
79072805 110#define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
111#define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
112#define isALPHA(c) (isascii(c) && isalpha(c))
113#define isSPACE(c) (isascii(c) && isspace(c))
114#define isDIGIT(c) (isascii(c) && isdigit(c))
115#define isUPPER(c) (isascii(c) && isupper(c))
116#define isLOWER(c) (isascii(c) && islower(c))
a0d0e21e 117#define toUPPER(c) toupper(c)
118#define toLOWER(c) tolower(c)
55204971 119#endif
a0d0e21e 120#endif /* USE_NEXT_CTYPE */
55204971 121
378cc40b 122/* Line numbers are unsigned, 16 bits. */
79072805 123typedef U16 line_t;
378cc40b 124#ifdef lint
125#define NOLINE ((line_t)0)
126#else
127#define NOLINE ((line_t) 65535)
128#endif
129
a687059c 130#ifndef lint
131#ifndef LEAKTEST
55204971 132#ifndef safemalloc
a0d0e21e 133char *safemalloc _((MEM_SIZE));
134char *saferealloc _((char *, MEM_SIZE));
135void safefree _((char *));
55204971 136#endif
154e51a4 137#ifndef MSDOS
a687059c 138#define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
139#define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
140#define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 141 memzero((char*)(v), (n) * sizeof(t))
a687059c 142#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
143#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
154e51a4 144#else
145#define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
146#define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
147#define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
bee1dbe2 148 memzero((char*)(v), (n) * sizeof(t))
154e51a4 149#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
150#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
151#endif /* MSDOS */
a687059c 152#define Safefree(d) safefree((char*)d)
79072805 153#define NEWSV(x,len) newSV(len)
a687059c 154#else /* LEAKTEST */
155char *safexmalloc();
156char *safexrealloc();
157void safexfree();
158#define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
159#define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
160#define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
bee1dbe2 161 memzero((char*)(v), (n) * sizeof(t))
a687059c 162#define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
163#define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
164#define Safefree(d) safexfree((char*)d)
79072805 165#define NEWSV(x,len) newSV(x,len)
a687059c 166#define MAXXCOUNT 1200
167long xcount[MAXXCOUNT];
168long lastxcount[MAXXCOUNT];
169#endif /* LEAKTEST */
bee1dbe2 170#define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
171#define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
172#define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
a687059c 173#else /* lint */
174#define New(x,v,n,s) (v = Null(s *))
175#define Newc(x,v,n,s,c) (v = Null(s *))
176#define Newz(x,v,n,s) (v = Null(s *))
177#define Renew(v,n,s) (v = Null(s *))
bee1dbe2 178#define Move(s,d,n,t)
a687059c 179#define Copy(s,d,n,t)
180#define Zero(d,n,t)
181#define Safefree(d) d = d
182#endif /* lint */
bee1dbe2 183
2304df62 184#ifdef USE_STRUCT_COPY
bee1dbe2 185#define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
186#else
187#define StructCopy(s,d,t) Copy(s,d,1,t)
188#endif