1 | /* $RCSfile: str.h,v $$Revision: 1.1.1.1 $$Date: 1996-10-02 06:39:59 $ |
---|
2 | * |
---|
3 | * Copyright (c) 1991, Larry Wall |
---|
4 | * |
---|
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. |
---|
7 | * |
---|
8 | * $Log: not supported by cvs2svn $ |
---|
9 | * Revision 4.0.1.4 92/06/08 15:41:45 lwall |
---|
10 | * patch20: fixed confusion between a *var's real name and its effective name |
---|
11 | * patch20: removed implicit int declarations on functions |
---|
12 | * |
---|
13 | * Revision 4.0.1.3 91/11/05 18:41:47 lwall |
---|
14 | * patch11: random cleanup |
---|
15 | * patch11: solitary subroutine references no longer trigger typo warnings |
---|
16 | * |
---|
17 | * Revision 4.0.1.2 91/06/07 11:58:33 lwall |
---|
18 | * patch4: new copyright notice |
---|
19 | * |
---|
20 | * Revision 4.0.1.1 91/04/12 09:16:12 lwall |
---|
21 | * patch1: you may now use "die" and "caller" in a signal handler |
---|
22 | * |
---|
23 | * Revision 4.0 91/03/20 01:40:04 lwall |
---|
24 | * 4.0 baseline. |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | struct string { |
---|
29 | char * str_ptr; /* pointer to malloced string */ |
---|
30 | STRLEN str_len; /* allocated size */ |
---|
31 | union { |
---|
32 | double str_nval; /* numeric value, if any */ |
---|
33 | long str_useful; /* is this search optimization effective? */ |
---|
34 | ARG *str_args; /* list of args for interpreted string */ |
---|
35 | HASH *str_hash; /* string represents an assoc array (stab?) */ |
---|
36 | ARRAY *str_array; /* string represents an array */ |
---|
37 | CMD *str_cmd; /* command for this source line */ |
---|
38 | struct { |
---|
39 | STAB *stb_stab; /* magic stab for magic "key" string */ |
---|
40 | HASH *stb_stash; /* which symbol table this stab is in */ |
---|
41 | } stb_u; |
---|
42 | } str_u; |
---|
43 | STRLEN str_cur; /* length of str_ptr as a C string */ |
---|
44 | STR *str_magic; /* while free, link to next free str */ |
---|
45 | /* while in use, ptr to "key" for magic items */ |
---|
46 | unsigned char str_pok; /* state of str_ptr */ |
---|
47 | unsigned char str_nok; /* state of str_nval */ |
---|
48 | unsigned char str_rare; /* used by search strings */ |
---|
49 | unsigned char str_state; /* one of SS_* below */ |
---|
50 | /* also used by search strings for backoff */ |
---|
51 | #ifdef TAINT |
---|
52 | bool str_tainted; /* 1 if possibly under control of $< */ |
---|
53 | #endif |
---|
54 | }; |
---|
55 | |
---|
56 | struct stab { /* should be identical, except for str_ptr */ |
---|
57 | STBP * str_ptr; /* pointer to malloced string */ |
---|
58 | STRLEN str_len; /* allocated size */ |
---|
59 | union { |
---|
60 | double str_nval; /* numeric value, if any */ |
---|
61 | long str_useful; /* is this search optimization effective? */ |
---|
62 | ARG *str_args; /* list of args for interpreted string */ |
---|
63 | HASH *str_hash; /* string represents an assoc array (stab?) */ |
---|
64 | ARRAY *str_array; /* string represents an array */ |
---|
65 | CMD *str_cmd; /* command for this source line */ |
---|
66 | struct { |
---|
67 | STAB *stb_stab; /* magic stab for magic "key" string */ |
---|
68 | HASH *stb_stash; /* which symbol table this stab is in */ |
---|
69 | } stb_u; |
---|
70 | } str_u; |
---|
71 | STRLEN str_cur; /* length of str_ptr as a C string */ |
---|
72 | STR *str_magic; /* while free, link to next free str */ |
---|
73 | /* while in use, ptr to "key" for magic items */ |
---|
74 | unsigned char str_pok; /* state of str_ptr */ |
---|
75 | unsigned char str_nok; /* state of str_nval */ |
---|
76 | unsigned char str_rare; /* used by search strings */ |
---|
77 | unsigned char str_state; /* one of SS_* below */ |
---|
78 | /* also used by search strings for backoff */ |
---|
79 | #ifdef TAINT |
---|
80 | bool str_tainted; /* 1 if possibly under control of $< */ |
---|
81 | #endif |
---|
82 | }; |
---|
83 | |
---|
84 | #define str_stab stb_u.stb_stab |
---|
85 | #define str_stash stb_u.stb_stash |
---|
86 | |
---|
87 | /* some extra info tacked to some lvalue strings */ |
---|
88 | |
---|
89 | struct lstring { |
---|
90 | struct string lstr; |
---|
91 | STRLEN lstr_offset; |
---|
92 | STRLEN lstr_len; |
---|
93 | }; |
---|
94 | |
---|
95 | /* These are the values of str_pok: */ |
---|
96 | #define SP_VALID 1 /* str_ptr is valid */ |
---|
97 | #define SP_FBM 2 /* string was compiled for fbm search */ |
---|
98 | #define SP_STUDIED 4 /* string was studied */ |
---|
99 | #define SP_CASEFOLD 8 /* case insensitive fbm search */ |
---|
100 | #define SP_INTRP 16 /* string was compiled for interping */ |
---|
101 | #define SP_TAIL 32 /* fbm string is tail anchored: /foo$/ */ |
---|
102 | #define SP_MULTI 64 /* symbol table entry probably isn't a typo */ |
---|
103 | #define SP_TEMP 128 /* string slated to die, so can be plundered */ |
---|
104 | |
---|
105 | #define Nullstr Null(STR*) |
---|
106 | |
---|
107 | /* These are the values of str_state: */ |
---|
108 | #define SS_NORM 0 /* normal string */ |
---|
109 | #define SS_INCR 1 /* normal string, incremented ptr */ |
---|
110 | #define SS_SARY 2 /* array on save stack */ |
---|
111 | #define SS_SHASH 3 /* associative array on save stack */ |
---|
112 | #define SS_SINT 4 /* integer on save stack */ |
---|
113 | #define SS_SLONG 5 /* long on save stack */ |
---|
114 | #define SS_SSTRP 6 /* STR* on save stack */ |
---|
115 | #define SS_SHPTR 7 /* HASH* on save stack */ |
---|
116 | #define SS_SNSTAB 8 /* non-stab on save stack */ |
---|
117 | #define SS_SCSV 9 /* callsave structure on save stack */ |
---|
118 | #define SS_SAPTR 10 /* ARRAY* on save stack */ |
---|
119 | #define SS_HASH 253 /* carrying an hash */ |
---|
120 | #define SS_ARY 254 /* carrying an array */ |
---|
121 | #define SS_FREE 255 /* in free list */ |
---|
122 | /* str_state may have any value 0-255 when used to hold fbm pattern, in which */ |
---|
123 | /* case it indicates offset to rarest character in screaminstr key */ |
---|
124 | |
---|
125 | /* the following macro updates any magic values this str is associated with */ |
---|
126 | |
---|
127 | #ifdef TAINT |
---|
128 | #define STABSET(x) \ |
---|
129 | (x)->str_tainted |= tainted; \ |
---|
130 | if ((x)->str_magic) \ |
---|
131 | stabset((x)->str_magic,(x)) |
---|
132 | #else |
---|
133 | #define STABSET(x) \ |
---|
134 | if ((x)->str_magic) \ |
---|
135 | stabset((x)->str_magic,(x)) |
---|
136 | #endif |
---|
137 | |
---|
138 | #define STR_SSET(dst,src) if (dst != src) str_sset(dst,src) |
---|
139 | |
---|
140 | EXT STR **tmps_list; |
---|
141 | EXT int tmps_max INIT(-1); |
---|
142 | EXT int tmps_base INIT(-1); |
---|
143 | |
---|
144 | char *str_2ptr(); |
---|
145 | double str_2num(); |
---|
146 | STR *str_mortal(); |
---|
147 | STR *str_2mortal(); |
---|
148 | STR *str_make(); |
---|
149 | STR *str_nmake(); |
---|
150 | STR *str_smake(); |
---|
151 | int str_cmp(); |
---|
152 | int str_eq(); |
---|
153 | void str_magic(); |
---|
154 | void str_insert(); |
---|
155 | void str_numset(); |
---|
156 | void str_sset(); |
---|
157 | void str_nset(); |
---|
158 | void str_set(); |
---|
159 | void str_chop(); |
---|
160 | void str_cat(); |
---|
161 | void str_scat(); |
---|
162 | void str_ncat(); |
---|
163 | void str_reset(); |
---|
164 | void str_taintproper(); |
---|
165 | void str_taintenv(); |
---|
166 | STRLEN str_len(); |
---|
167 | |
---|
168 | #define MULTI (3) |
---|