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