home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / perl / Source / H / Str < prev    next >
Encoding:
Text File  |  1990-11-13  |  5.7 KB  |  155 lines

  1. /* $Header: str.h,v 3.0.1.4 90/11/10 02:07:52 lwall Locked $
  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.
  7.  *
  8.  * $Log:    str.h,v $
  9.  * Revision 3.0.1.4  90/11/10  02:07:52  lwall
  10.  * patch38: temp string values are now copied less often
  11.  * 
  12.  * Revision 3.0.1.3  90/10/16  10:44:04  lwall
  13.  * patch29: added caller
  14.  * patch29: scripts now run at almost full speed under the debugger
  15.  * 
  16.  * Revision 3.0.1.2  90/08/09  05:23:24  lwall
  17.  * patch19: various MSDOS and OS/2 patches folded in
  18.  * 
  19.  * Revision 3.0.1.1  89/10/26  23:24:42  lwall
  20.  * patch1: rearranged some structures to align doubles better on Gould
  21.  * 
  22.  * Revision 3.0  89/10/18  15:23:49  lwall
  23.  * 3.0 baseline
  24.  * 
  25.  */
  26.  
  27. struct string {
  28.     char *    str_ptr;    /* pointer to malloced string */
  29.     STRLEN    str_len;    /* allocated size */
  30.     union {
  31.     double    str_nval;    /* numeric value, if any */
  32.     STAB    *str_stab;    /* magic stab for magic "key" string */
  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.     } str_u;
  39.     STRLEN    str_cur;    /* length of str_ptr as a C string */
  40.     STR        *str_magic;    /* while free, link to next free str */
  41.                 /* while in use, ptr to "key" for magic items */
  42.     char    str_pok;    /* state of str_ptr */
  43.     char    str_nok;    /* state of str_nval */
  44.     unsigned char str_rare;    /* used by search strings */
  45.     unsigned char str_state;    /* one of SS_* below */
  46.                 /* also used by search strings for backoff */
  47. #ifdef TAINT
  48.     bool    str_tainted;    /* 1 if possibly under control of $< */
  49. #endif
  50. };
  51.  
  52. struct stab {    /* should be identical, except for str_ptr */
  53.     STBP *    str_ptr;    /* pointer to malloced string */
  54.     STRLEN    str_len;    /* allocated size */
  55.     union {
  56.     double    str_nval;    /* numeric value, if any */
  57.     STAB    *str_stab;    /* magic stab for magic "key" string */
  58.     long    str_useful;    /* is this search optimization effective? */
  59.     ARG    *str_args;    /* list of args for interpreted string */
  60.     HASH    *str_hash;    /* string represents an assoc array (stab?) */
  61.     ARRAY    *str_array;    /* string represents an array */
  62.     CMD    *str_cmd;    /* command for this source line */
  63.     } str_u;
  64.     STRLEN    str_cur;    /* length of str_ptr as a C string */
  65.     STR        *str_magic;    /* while free, link to next free str */
  66.                 /* while in use, ptr to "key" for magic items */
  67.     char    str_pok;    /* state of str_ptr */
  68.     char    str_nok;    /* state of str_nval */
  69.     unsigned char str_rare;    /* used by search strings */
  70.     unsigned char str_state;    /* one of SS_* below */
  71.                 /* also used by search strings for backoff */
  72. #ifdef TAINT
  73.     bool    str_tainted;    /* 1 if possibly under control of $< */
  74. #endif
  75. };
  76.  
  77. /* some extra info tacked to some lvalue strings */
  78.  
  79. struct lstring {
  80.     struct string lstr;
  81.     STRLEN    lstr_offset;
  82.     STRLEN    lstr_len;
  83. };
  84.  
  85. /* These are the values of str_pok:        */
  86. #define SP_VALID    1    /* str_ptr is valid */
  87. #define SP_FBM        2    /* string was compiled for fbm search */
  88. #define SP_STUDIED    4    /* string was studied */
  89. #define SP_CASEFOLD    8    /* case insensitive fbm search */
  90. #define SP_INTRP    16    /* string was compiled for interping */
  91. #define SP_TAIL        32    /* fbm string is tail anchored: /foo$/  */
  92. #define SP_MULTI    64    /* symbol table entry probably isn't a typo */
  93. #define SP_TEMP        128    /* string slated to die, so can be plundered */
  94.  
  95. #define Nullstr Null(STR*)
  96.  
  97. /* These are the values of str_state:        */
  98. #define SS_NORM        0    /* normal string */
  99. #define SS_INCR        1    /* normal string, incremented ptr */
  100. #define SS_SARY        2    /* array on save stack */
  101. #define SS_SHASH    3    /* associative array on save stack */
  102. #define SS_SINT        4    /* integer on save stack */
  103. #define SS_SLONG    5    /* long on save stack */
  104. #define SS_SSTRP    6    /* STR* on save stack */
  105. #define SS_SHPTR    7    /* HASH* on save stack */
  106. #define SS_SNSTAB    8    /* non-stab on save stack */
  107. #define SS_SCSV        9    /* callsave structure on save stack */
  108. #define SS_HASH        253    /* carrying an hash */
  109. #define SS_ARY        254    /* carrying an array */
  110. #define SS_FREE        255    /* in free list */
  111. /* str_state may have any value 0-255 when used to hold fbm pattern, in which */
  112. /* case it indicates offset to rarest character in screaminstr key */
  113.  
  114. /* the following macro updates any magic values this str is associated with */
  115.  
  116. #ifdef TAINT
  117. #define STABSET(x) \
  118.     (x)->str_tainted |= tainted; \
  119.     if ((x)->str_magic) \
  120.     stabset((x)->str_magic,(x))
  121. #else
  122. #define STABSET(x) \
  123.     if ((x)->str_magic) \
  124.     stabset((x)->str_magic,(x))
  125. #endif
  126.  
  127. #define STR_SSET(dst,src) if (dst != src) str_sset(dst,src)
  128.  
  129. EXT STR **tmps_list;
  130. EXT int tmps_max INIT(-1);
  131. EXT int tmps_base INIT(-1);
  132.  
  133. extern char *str_2ptr PROTO((STR *));
  134. extern double str_2num PROTO((STR *));
  135. extern STR *str_static PROTO((STR *));
  136. extern STR *str_2static PROTO((STR *));
  137. extern STR *str_make PROTO((char *, STRLEN));
  138. extern STR *str_nmake PROTO((double));
  139. extern STR *str_smake PROTO((STR *));
  140. extern int str_cmp PROTO((STR *, STR *));
  141. extern int str_eq PROTO((STR *, STR *));
  142. extern void str_magic PROTO((STR *, STAB *, int, char *, STRLEN));
  143. extern void str_insert PROTO((STR *, STRLEN, STRLEN, char *, STRLEN));
  144. extern void str_numset PROTO((STR *, double));
  145. extern void str_sset PROTO((STR *, STR *));
  146. extern void str_nset PROTO((STR *, char *, STRLEN));
  147. extern void str_set PROTO((STR *, char *));
  148. extern void str_chop PROTO((STR *, char *));
  149. extern void str_ncat PROTO((STR *, char *, STRLEN));
  150. extern void str_scat PROTO((STR *, STR *));
  151. extern void str_cat PROTO((STR *, char *));
  152. extern STRLEN str_len PROTO((STR *));
  153. extern void str_reset PROTO((char *, HASH *));
  154. extern ARG *parselist PROTO((STR *));
  155.