1 /*-----------------------------------------------------------------------
2 
3 File  : clb_dstrings.h
4 
5 Author: Stephan Schulz
6 
7   Declarations for dynamic, arbitrary length strings
8   (i.e. 0-terminated arrays of characters). The conversion between
9   DStrs and C-strings is as simple and efficient as possible. This
10   implementation is optimized for strings with a certain behaviour,
11   usually experienced when reading input: Most strings are fairly
12   small, and for each set of strings the length distribution is fairly
13   similar.
14 
15   DStrings can also be used as a primitive form of reference-counted
16   strings - functions for obtaining counted reference, releasing it,
17   and delayed destruction of a still referenced object are
18   provided. The use of these functions is optional and requires user
19   discipline!
20 
21   Copyright 1998, 1999 by the author.
22   This code is released under the GNU General Public Licence and
23   the GNU Lesser General Public License.
24   See the file COPYING in the main E directory for details..
25   Run "eprover -h" for contact information.
26 
27   Changes
28 
29   Created: Aug 15 17:01:33 MET DST 1997 - New
30 
31 -----------------------------------------------------------------------*/
32 
33 #ifndef CLB_DSTRINGS
34 
35 #define CLB_DSTRINGS
36 
37 #include "clb_memory.h"
38 
39 /*---------------------------------------------------------------------*/
40 /*                    Data type declarations                           */
41 /*---------------------------------------------------------------------*/
42 
43 typedef struct dstrcell
44 {
45    char* string;
46    long  len;
47    long  mem;
48    long  refs;
49 }DStrCell, *DStr_p;
50 
51 #define DSTRGROW 64
52 
53 /*---------------------------------------------------------------------*/
54 /*                Exported Functions and Variables                     */
55 /*---------------------------------------------------------------------*/
56 
57 extern char NullStr[];
58 
59 #define DStrCellAlloc() (DStrCell*)SizeMalloc(sizeof(DStrCell))
60 #define DStrCellFree(junk)         SizeFree(junk, sizeof(DStrCell))
61 
62 DStr_p DStrAlloc(void);
63 void   DStrFree(DStr_p junk);
64 
65 char*   DStrAppendStr(DStr_p strdes, char* newpart);
66 char*   DStrAppendChar(DStr_p strdes, char newch);
67 char*   DStrAppendBuffer(DStr_p strdes, char* buf, int len);
68 char*   DStrAppendInt(DStr_p strdes, long newpart);
69 char*   DStrAppendStrArray(DStr_p strdes, char* array[], char*
70                            separator);
71 #define DStrAppendDStr(strdes, str)             \
72         DStrAppendStr((strdes), DStrView(str))
73 char    DStrDeleteLastChar(DStr_p strdes);
74 #define DStrLastChar(strdes) (DStrLen(strdes)?DStrView(strdes)[DStrLen(strdes)-1]:'\0')
75 char*   DStrView(DStr_p strdes);
76 char*   DStrAddress(DStr_p strdes, int index);
77 char*   DStrCopy(DStr_p strdes);
78 char*   DStrCopyCore(DStr_p strdes);
79 char*   DStrSet(DStr_p strdes, char* string);
80 long    DStrLen(DStr_p strdes);
81 void    DStrReset(DStr_p strdes);
82 void    DStrMinimize(DStr_p strdes);
83 
84 #define DStrGetRef(strdes)     (((strdes)?((strdes)->refs++):0),strdes)
85 #define DStrReleaseRef(strdes) if(strdes){DStrFree(strdes);}
86 
87 #endif
88 
89 /*---------------------------------------------------------------------*/
90 /*                        End of File                                  */
91 /*---------------------------------------------------------------------*/
92