This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 1: (combined patch)
[perl5.git] / str.h
CommitLineData
fe14fcc3 1/* $Header: str.h,v 4.0 91/03/20 01:40:04 lwall Locked $
a687059c
LW
2 *
3 * Copyright (c) 1989, Larry Wall
4 *
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
8d063cd8
LW
7 *
8 * $Log: str.h,v $
fe14fcc3
LW
9 * Revision 4.0 91/03/20 01:40:04 lwall
10 * 4.0 baseline.
8d063cd8
LW
11 *
12 */
13
14struct string {
15 char * str_ptr; /* pointer to malloced string */
e929a76b 16 STRLEN str_len; /* allocated size */
a687059c
LW
17 union {
18 double str_nval; /* numeric value, if any */
19 STAB *str_stab; /* magic stab for magic "key" string */
20 long str_useful; /* is this search optimization effective? */
21 ARG *str_args; /* list of args for interpreted string */
22 HASH *str_hash; /* string represents an assoc array (stab?) */
23 ARRAY *str_array; /* string represents an array */
395c3793 24 CMD *str_cmd; /* command for this source line */
a687059c 25 } str_u;
e929a76b
LW
26 STRLEN str_cur; /* length of str_ptr as a C string */
27 STR *str_magic; /* while free, link to next free str */
a687059c
LW
28 /* while in use, ptr to "key" for magic items */
29 char str_pok; /* state of str_ptr */
30 char str_nok; /* state of str_nval */
31 unsigned char str_rare; /* used by search strings */
32 unsigned char str_state; /* one of SS_* below */
33 /* also used by search strings for backoff */
34#ifdef TAINT
35 bool str_tainted; /* 1 if possibly under control of $< */
36#endif
37};
38
39struct stab { /* should be identical, except for str_ptr */
40 STBP * str_ptr; /* pointer to malloced string */
e929a76b 41 STRLEN str_len; /* allocated size */
8d063cd8 42 union {
a687059c
LW
43 double str_nval; /* numeric value, if any */
44 STAB *str_stab; /* magic stab for magic "key" string */
45 long str_useful; /* is this search optimization effective? */
46 ARG *str_args; /* list of args for interpreted string */
47 HASH *str_hash; /* string represents an assoc array (stab?) */
48 ARRAY *str_array; /* string represents an array */
395c3793 49 CMD *str_cmd; /* command for this source line */
a687059c 50 } str_u;
e929a76b
LW
51 STRLEN str_cur; /* length of str_ptr as a C string */
52 STR *str_magic; /* while free, link to next free str */
a687059c 53 /* while in use, ptr to "key" for magic items */
8d063cd8
LW
54 char str_pok; /* state of str_ptr */
55 char str_nok; /* state of str_nval */
a687059c
LW
56 unsigned char str_rare; /* used by search strings */
57 unsigned char str_state; /* one of SS_* below */
58 /* also used by search strings for backoff */
59#ifdef TAINT
60 bool str_tainted; /* 1 if possibly under control of $< */
61#endif
62};
63
64/* some extra info tacked to some lvalue strings */
65
66struct lstring {
67 struct string lstr;
e929a76b
LW
68 STRLEN lstr_offset;
69 STRLEN lstr_len;
8d063cd8
LW
70};
71
a687059c
LW
72/* These are the values of str_pok: */
73#define SP_VALID 1 /* str_ptr is valid */
74#define SP_FBM 2 /* string was compiled for fbm search */
75#define SP_STUDIED 4 /* string was studied */
76#define SP_CASEFOLD 8 /* case insensitive fbm search */
77#define SP_INTRP 16 /* string was compiled for interping */
78#define SP_TAIL 32 /* fbm string is tail anchored: /foo$/ */
79#define SP_MULTI 64 /* symbol table entry probably isn't a typo */
34de22dd 80#define SP_TEMP 128 /* string slated to die, so can be plundered */
a687059c 81
8d063cd8
LW
82#define Nullstr Null(STR*)
83
a687059c
LW
84/* These are the values of str_state: */
85#define SS_NORM 0 /* normal string */
86#define SS_INCR 1 /* normal string, incremented ptr */
87#define SS_SARY 2 /* array on save stack */
88#define SS_SHASH 3 /* associative array on save stack */
89#define SS_SINT 4 /* integer on save stack */
90#define SS_SLONG 5 /* long on save stack */
91#define SS_SSTRP 6 /* STR* on save stack */
92#define SS_SHPTR 7 /* HASH* on save stack */
93#define SS_SNSTAB 8 /* non-stab on save stack */
395c3793 94#define SS_SCSV 9 /* callsave structure on save stack */
a687059c
LW
95#define SS_HASH 253 /* carrying an hash */
96#define SS_ARY 254 /* carrying an array */
97#define SS_FREE 255 /* in free list */
98/* str_state may have any value 0-255 when used to hold fbm pattern, in which */
99/* case it indicates offset to rarest character in screaminstr key */
100
8d063cd8
LW
101/* the following macro updates any magic values this str is associated with */
102
a687059c
LW
103#ifdef TAINT
104#define STABSET(x) \
105 (x)->str_tainted |= tainted; \
106 if ((x)->str_magic) \
107 stabset((x)->str_magic,(x))
108#else
109#define STABSET(x) \
110 if ((x)->str_magic) \
111 stabset((x)->str_magic,(x))
112#endif
113
114#define STR_SSET(dst,src) if (dst != src) str_sset(dst,src)
8d063cd8
LW
115
116EXT STR **tmps_list;
378cc40b
LW
117EXT int tmps_max INIT(-1);
118EXT int tmps_base INIT(-1);
8d063cd8
LW
119
120char *str_2ptr();
121double str_2num();
fe14fcc3
LW
122STR *str_mortal();
123STR *str_2mortal();
8d063cd8
LW
124STR *str_make();
125STR *str_nmake();
a687059c
LW
126STR *str_smake();
127int str_cmp();
128int str_eq();
129void str_magic();
130void str_insert();
e929a76b 131STRLEN str_len();