perl5.000 patch.0e: fix various non-broken things in the x2p/ directory
[p5sagit/p5-mst-13.2.git] / x2p / handy.h
CommitLineData
9c8d0b29 1/* handy.h
a687059c 2 *
9c8d0b29 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
9c8d0b29 10#if !defined(__STDC__)
11#ifdef NULL
12#undef NULL
13#endif
14#ifndef I286
15# define NULL 0
16#else
17# define NULL 0L
18#endif
19#endif
20
21#define Null(type) ((type)NULL)
8d063cd8 22#define Nullch Null(char*)
23#define Nullfp Null(FILE*)
9c8d0b29 24#define Nullsv Null(SV*)
8d063cd8 25
9c8d0b29 26#ifdef UTS
27#define bool int
28#else
8d063cd8 29#define bool char
9c8d0b29 30#endif
31
1c3d792e 32#ifdef TRUE
33#undef TRUE
34#endif
35#ifdef FALSE
36#undef FALSE
37#endif
8d063cd8 38#define TRUE (1)
39#define FALSE (0)
40
9c8d0b29 41typedef char I8;
42typedef unsigned char U8;
43
44typedef short I16;
45typedef unsigned short U16;
46
47#if BYTEORDER > 0x4321
48 typedef int I32;
49 typedef unsigned int U32;
50#else
51 typedef long I32;
52 typedef unsigned long U32;
53#endif
54
8d063cd8 55#define Ctl(ch) (ch & 037)
56
57#define strNE(s1,s2) (strcmp(s1,s2))
58#define strEQ(s1,s2) (!strcmp(s1,s2))
59#define strLT(s1,s2) (strcmp(s1,s2) < 0)
60#define strLE(s1,s2) (strcmp(s1,s2) <= 0)
61#define strGT(s1,s2) (strcmp(s1,s2) > 0)
62#define strGE(s1,s2) (strcmp(s1,s2) >= 0)
63#define strnNE(s1,s2,l) (strncmp(s1,s2,l))
64#define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
9c8d0b29 65
66#ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
67# ifndef CTYPE256
68# define CTYPE256
69# endif
70#endif
71
72#ifdef USE_NEXT_CTYPE
73#define isALNUM(c) (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
74#define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
75#define isALPHA(c) NXIsAlpha((unsigned int)c)
76#define isSPACE(c) NXIsSpace((unsigned int)c)
77#define isDIGIT(c) NXIsDigit((unsigned int)c)
78#define isUPPER(c) NXIsUpper((unsigned int)c)
79#define isLOWER(c) NXIsLower((unsigned int)c)
80#define toUPPER(c) NXToUpper((unsigned int)c)
81#define toLOWER(c) NXToLower((unsigned int)c)
82#else /* USE_NEXT_CTYPE */
83#if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
84#define isALNUM(c) (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
85#define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
86#define isALPHA(c) isalpha((unsigned char)(c))
87#define isSPACE(c) isspace((unsigned char)(c))
88#define isDIGIT(c) isdigit((unsigned char)(c))
89#define isUPPER(c) isupper((unsigned char)(c))
90#define isLOWER(c) islower((unsigned char)(c))
91#define toUPPER(c) toupper((unsigned char)(c))
92#define toLOWER(c) tolower((unsigned char)(c))
93#else
94#define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
95#define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
96#define isALPHA(c) (isascii(c) && isalpha(c))
97#define isSPACE(c) (isascii(c) && isspace(c))
98#define isDIGIT(c) (isascii(c) && isdigit(c))
99#define isUPPER(c) (isascii(c) && isupper(c))
100#define isLOWER(c) (isascii(c) && islower(c))
101#define toUPPER(c) toupper(c)
102#define toLOWER(c) tolower(c)
103#endif
104#endif /* USE_NEXT_CTYPE */
105
106/* Line numbers are unsigned, 16 bits. */
107typedef U16 line_t;
108#ifdef lint
109#define NOLINE ((line_t)0)
110#else
111#define NOLINE ((line_t) 65535)
112#endif
113
114#ifndef lint
115#ifndef LEAKTEST
116#ifndef safemalloc
117char *safemalloc _((MEM_SIZE));
118char *saferealloc _((char *, MEM_SIZE));
119void safefree _((char *));
120#endif
121#ifndef MSDOS
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)))), \
125 memzero((char*)(v), (n) * sizeof(t))
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))))
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)))), \
132 memzero((char*)(v), (n) * sizeof(t))
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 */
136#define Safefree(d) safefree((char*)d)
137#define NEWSV(x,len) newSV(len)
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)))), \
145 memzero((char*)(v), (n) * sizeof(t))
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)
149#define NEWSV(x,len) newSV(x,len)
150#define MAXXCOUNT 1200
151long xcount[MAXXCOUNT];
152long lastxcount[MAXXCOUNT];
153#endif /* LEAKTEST */
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))
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 *))
162#define Move(s,d,n,t)
163#define Copy(s,d,n,t)
164#define Zero(d,n,t)
165#define Safefree(d) d = d
166#endif /* lint */
167
168#ifdef USE_STRUCT_COPY
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