This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 25: patch #20, continued
[perl5.git] / handy.h
CommitLineData
55204971 1/* $RCSfile: handy.h,v $$Revision: 4.0.1.3 $$Date: 91/11/05 22:54:26 $
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 $
55204971
LW
9 * Revision 4.0.1.3 91/11/05 22:54:26 lwall
10 * patch11: erratum
11 *
12 * Revision 4.0.1.2 91/11/05 17:23:38 lwall
13 * patch11: prepared for ctype implementations that don't define isascii()
14 *
6e21c824
LW
15 * Revision 4.0.1.1 91/06/07 11:09:56 lwall
16 * patch4: new copyright notice
17 *
fe14fcc3
LW
18 * Revision 4.0 91/03/20 01:22:15 lwall
19 * 4.0 baseline.
8d063cd8
LW
20 *
21 */
22
378cc40b
LW
23#ifdef NULL
24#undef NULL
25#endif
a687059c
LW
26#ifndef I286
27# define NULL 0
28#else
29# define NULL 0L
30#endif
378cc40b 31#define Null(type) ((type)NULL)
8d063cd8
LW
32#define Nullch Null(char*)
33#define Nullfp Null(FILE*)
34
a687059c
LW
35#ifdef UTS
36#define bool int
37#else
8d063cd8 38#define bool char
a687059c 39#endif
0d3e774c
LW
40
41#ifdef TRUE
42#undef TRUE
43#endif
44#ifdef FALSE
45#undef FALSE
46#endif
8d063cd8
LW
47#define TRUE (1)
48#define FALSE (0)
49
50#define Ctl(ch) (ch & 037)
51
52#define strNE(s1,s2) (strcmp(s1,s2))
53#define strEQ(s1,s2) (!strcmp(s1,s2))
54#define strLT(s1,s2) (strcmp(s1,s2) < 0)
55#define strLE(s1,s2) (strcmp(s1,s2) <= 0)
56#define strGT(s1,s2) (strcmp(s1,s2) > 0)
57#define strGE(s1,s2) (strcmp(s1,s2) >= 0)
58#define strnNE(s1,s2,l) (strncmp(s1,s2,l))
59#define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
378cc40b 60
55204971
LW
61#if defined(CTYPE256) || !defined(isascii)
62#define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
63#define isALPHA(c) isalpha(c)
64#define isSPACE(c) isspace(c)
65#define isDIGIT(c) isdigit(c)
66#define isUPPER(c) isupper(c)
67#define isLOWER(c) islower(c)
68#else
69#define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
70#define isALPHA(c) (isascii(c) && isalpha(c))
71#define isSPACE(c) (isascii(c) && isspace(c))
72#define isDIGIT(c) (isascii(c) && isdigit(c))
73#define isUPPER(c) (isascii(c) && isupper(c))
74#define isLOWER(c) (isascii(c) && islower(c))
75#endif
76
378cc40b
LW
77#define MEM_SIZE unsigned int
78
79/* Line numbers are unsigned, 16 bits. */
80typedef unsigned short line_t;
81#ifdef lint
82#define NOLINE ((line_t)0)
83#else
84#define NOLINE ((line_t) 65535)
85#endif
86
a687059c
LW
87#ifndef lint
88#ifndef LEAKTEST
55204971 89#ifndef safemalloc
a687059c
LW
90char *safemalloc();
91char *saferealloc();
92void safefree();
55204971 93#endif
154e51a4 94#ifndef MSDOS
a687059c
LW
95#define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
96#define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
97#define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
98 bzero((char*)(v), (n) * sizeof(t))
99#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
100#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
154e51a4
LW
101#else
102#define New(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
103#define Newc(x,v,n,t,c) (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
104#define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
105 bzero((char*)(v), (n) * sizeof(t))
106#define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
107#define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
108#endif /* MSDOS */
a687059c
LW
109#define Safefree(d) safefree((char*)d)
110#define Str_new(x,len) str_new(len)
111#else /* LEAKTEST */
112char *safexmalloc();
113char *safexrealloc();
114void safexfree();
115#define New(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
116#define Newc(x,v,n,t,c) (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
117#define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
118 bzero((char*)(v), (n) * sizeof(t))
119#define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
120#define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
121#define Safefree(d) safexfree((char*)d)
122#define Str_new(x,len) str_new(x,len)
123#define MAXXCOUNT 1200
124long xcount[MAXXCOUNT];
125long lastxcount[MAXXCOUNT];
126#endif /* LEAKTEST */
127#define Copy(s,d,n,t) (void)bcopy((char*)(s),(char*)(d), (n) * sizeof(t))
128#define Zero(d,n,t) (void)bzero((char*)(d), (n) * sizeof(t))
129#else /* lint */
130#define New(x,v,n,s) (v = Null(s *))
131#define Newc(x,v,n,s,c) (v = Null(s *))
132#define Newz(x,v,n,s) (v = Null(s *))
133#define Renew(v,n,s) (v = Null(s *))
134#define Copy(s,d,n,t)
135#define Zero(d,n,t)
136#define Safefree(d) d = d
137#endif /* lint */