]> andersk Git - splint.git/blob - src/Headers/cstring.h
Fixed bug in string initialization checking.
[splint.git] / src / Headers / cstring.h
1 /*
2 ** Copyright (C) University of Virginia, Massachusetts Institue of Technology 1994-2001.
3 ** See ../LICENSE for license information.
4 **
5 */
6 /*
7 ** cstring.h
8 */
9
10 # ifndef CSTRING_H
11 # define CSTRING_H
12
13 /* does this cause problems on Solaris?  linux?  */
14 /* sgi's don't like it */
15 # ifndef IRIX
16 # ifdef NULL   /* hack so <strings.h> works */
17 # undef NULL
18 # endif
19 # endif
20
21 /* typedefs in forwardTypes */
22
23 extern /*@notnull@*/ cstring cstring_create (int p_n) /*@*/ /*@ensures maxSet(result) == p_n @*/ ;
24 extern /*@only@*/ /*@notnull@*/  cstring cstring_newEmpty (void) ;
25 extern /*@notnull@*/ cstring cstring_appendChar (/*@only@*/ cstring p_s1, char p_c);
26
27 extern cstring cstring_concatLength (/*@only@*/ cstring p_s1, char *p_s2, int p_len) /*@*/  /*@requires maxSet(p_s2) >= (p_len - 1) @*/;
28
29 extern /*@notnull@*/ cstring cstring_prependChar (char p_c, /*@temp@*/ cstring p_s1);
30 extern /*@notnull@*/ cstring cstring_prependCharO (char p_c, /*@only@*/ cstring p_s1);
31 extern cstring cstring_downcase (cstring p_s) /*@*/ ;
32 extern cstring cstring_copy (cstring p_s) /*@*/  /*@ensures maxSet(result) == maxRead(p_s) /\ maxRead(result) == maxRead(p_s) @*/ ;
33 extern cstring cstring_copyLength (char *p_s, int p_len) /*@*/  /*@requires maxSet(p_s) >= (p_len - 1) @*/;
34
35 extern int cstring_toPosInt (cstring p_s) /*@*/ ;
36
37 typedef enum {
38   CGE_SAME,     /* no differences */
39   CGE_DISTINCT, /* significant differences */
40   CGE_CASE,     /* case differences */
41   CGE_LOOKALIKE /* lookalike differences */
42 } cmpcode;
43
44 extern cmpcode cstring_genericEqual (cstring p_s, cstring p_t,
45                                      int p_nchars,
46                                      bool p_caseinsensitive,
47                                      bool p_lookalike) /*@*/   /*@requires maxRead(p_s) >= p_nchars /\ maxRead(p_t) >= p_nchars @*/ ;
48
49 /* evans 2001-09-09 - removed conditional compilation on this (for WIN32, OS2) */
50 extern void cstring_replaceAll (cstring p_s, char p_old, char p_snew) /*@modifies p_s@*/ ;
51
52 extern void cstring_replaceLit (/*@unique@*/ cstring p_s, char *p_old, char *p_snew) 
53    /*@modifies p_s@*/
54    /*@requires maxRead(p_snew) >= 0 /\ maxRead(p_old) >= 0 /\ maxRead(p_old) >= maxRead(p_snew) @*/;
55
56 extern char cstring_firstChar (cstring p_s) /*@*/ ;
57 extern char cstring_secondChar (cstring p_s) /*@*/ ;
58 extern char cstring_lastChar (cstring p_s) /*@*/ ;
59 extern char cstring_getChar (cstring p_s, int p_n);
60 extern void cstring_setChar (cstring p_s, int p_n, char p_c) /*@requires maxRead(p_s) >= (p_n - 1) /\ maxSet(p_s) >= (p_n - 1) @*/ ;
61
62 # define cstring_secondChar(s) cstring_getChar (s, 2)
63
64 extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/ char *
65   cstring_toCharsSafe (/*@temp@*/ /*@exposed@*/ /*@returned@*/ cstring p_s)
66      /*@*/ ;
67
68      extern int cstring_length (cstring p_s) /*@*/ /*@ensures result == maxRead(p_s) @*/;
69 extern bool cstring_contains (/*@unique@*/ cstring p_c, cstring p_sub) /*@*/ ;
70 extern bool cstring_containsChar (cstring p_c, char p_ch) /*@*/ ;
71 extern bool cstring_equal (cstring p_c1, cstring p_c2) /*@*/ ;
72 extern bool cstring_equalCaseInsensitive (cstring p_c1, cstring p_c2) /*@*/ ;
73 extern bool cstring_equalLen (cstring p_c1, cstring p_c2, int p_len) /*@*/ ;
74 extern bool cstring_equalLenCaseInsensitive (cstring p_c1, cstring p_c2, int p_len) /*@*/ ;
75 extern bool cstring_equalPrefix (cstring p_c1, cstring p_c2) /*@*/ ;
76 extern bool cstring_equalPrefixLit (cstring p_c1, /*@observer@*/ const char *p_c2) /*@*/ ;
77 extern bool cstring_equalLit (cstring p_c1, char *p_c2) /*@*/ ;
78 extern int cstring_compare (cstring p_c1, cstring p_c2) /*@*/ ;
79 extern int cstring_xcompare (cstring *p_c1, cstring *p_c2) /*@*/ ;
80
81 # ifndef NOLCL
82 extern bool cstring_hasNonAlphaNumBar (cstring p_s) /*@*/ ;
83 # endif
84
85 extern cstring cstring_elide (cstring p_s, int p_len) /*@*/ ;
86 extern cstring cstring_clip (/*@returned@*/ cstring p_s, int p_len) 
87    /*@modifies p_s@*/ ;
88 extern void cstring_stripChars (cstring p_s, const char *p_clist) /*@modifies p_s@*/ ;
89
90 extern /*@dependent@*/ cstring 
91   cstring_bsearch (cstring p_key,
92                    char **p_table,
93                    int p_nentries);
94
95 extern bool cstring_lessthan (cstring p_s1, cstring p_s2) /*@*/ ;
96 # define cstring_lessthan(s1, s2) (cstring_compare (s1, s2) < 0)
97
98 # define cstring_equalLit(s, lit) \
99   (mstring_equal (cstring_toCharsSafe (s), lit))
100
101 extern bool cstring_equalFree (/*@only@*/ cstring p_c1, /*@only@*/ cstring p_c2);
102
103 /* really exposed! */
104
105 /*
106 ** Don't allow tainted cstring's
107 */
108
109 extern /*@untained@*/ cstring 
110   cstring_fromChars (/*@returned@*/ /*@null@*/ 
111                      const /*:untainted@*/ /*@exposed@*/ /*@temp@*/ char *p_cp) /*@*/ ;
112
113 extern cstring
114    cstring_fromCharsO (/*@null@*/ /*:untainted@*/ /*@only@*/ char *p_cp) /*@*/ ;
115 /*@-mustfree@*/
116 # define cstring_fromCharsO(s) cstring_fromChars(s)
117 /*@=mustfree@*/
118
119 extern cstring cstring_fromCharsNew (/*:untainted@*/ /*@null@*/ char *p_s) /*@*/ ;
120 # define cstring_fromCharsNew(s) cstring_copy(cstring_fromChars(s))
121
122 # ifndef NOLCL
123 extern /*@exposed@*/ /*@notnull@*/ /*@untainted@*/
124   char *cstring_toCharsSafeO (/*@only@*/ /*@exposed@*/ /*@returned@*/ cstring p_s);
125 /*@-mustfree@*/
126 # define cstring_toCharsSafeO(s) cstring_toCharsSafe(s)
127 /*@=mustfree@*/
128 # endif
129
130 extern void cstring_free (/*@only@*/ cstring p_s);
131
132 /*@constant null cstring cstring_undefined;@*/
133 # define cstring_undefined     ((cstring)NULL)
134
135 extern /*@falsewhennull@*/ bool cstring_isDefined (cstring p_s) /*@*/ ;
136 extern /*@nullwhentrue@*/ bool cstring_isUndefined (cstring p_s) /*@*/ ;
137
138 extern /*@nullwhentrue@*/ bool cstring_isEmpty (cstring p_s) /*@*/ ;
139 extern /*@falsewhennull@*/ bool cstring_isNonEmpty (cstring p_s) /*@*/ ;
140
141 # define cstring_isDefined(s)   ((s) != cstring_undefined)
142 # define cstring_isUndefined(s) (!cstring_isDefined(s))
143
144 # define cstring_isEmpty(s)     (cstring_length(s) == 0)
145 # define cstring_isNonEmpty(s)  (!cstring_isEmpty(s))
146
147 extern cstring cstring_makeLiteral (char *) /*@*/ ;
148 extern /*@observer@*/ /*@dependent@*/ cstring 
149   cstring_makeLiteralTemp (char *) /*@*/ ;
150
151 # define cstring_makeLiteral(s) (cstring_copy (cstring_fromChars (s)))
152 # define cstring_makeLiteralTemp(s) (cstring_fromChars (s))
153
154 extern cstring cstring_capitalize (cstring p_s) /*@*/  /*@requires maxSet(p_s) >= 0 @*/ ;
155 extern cstring cstring_capitalizeFree (/*@only@*/ cstring p_s) /*@modifies p_s@*/  /*@requires maxSet(p_s) >= 0 /\ maxRead(p_s) >= 0 @*/ ;
156 extern cstring cstring_fill (cstring p_s, int p_n) /*@*/ /*@requires p_n >= 0 @*/;
157 extern cstring cstring_prefix (cstring p_s, int p_n) /*@*/ /*@requires maxRead(p_s) >= p_n /\ maxSet(p_s) >= p_n @*/ /*@ensures maxRead(result) == p_n /\ maxSet(result) == p_n @*/;
158 extern /*@observer@*/ cstring cstring_suffix (cstring p_s, int p_n) /*@*/ ;
159 extern cstring cstring_concat (cstring p_s, cstring p_t) /*@*/ /*@requires maxSet(p_s) >= 0 @*/;
160
161 extern cstring 
162   cstring_concatFree (/*@only@*/ cstring p_s, /*@only@*/ cstring p_t)
163   /*@modifies p_s, p_t@*/ ;
164
165 extern cstring 
166   cstring_concatFree1 (/*@only@*/ cstring p_s, cstring p_t) 
167   /*@modifies p_s@*/ ;
168
169 # ifndef NOLCL
170 extern cstring 
171   cstring_concatChars (/*@only@*/ cstring p_s, char *p_t)
172   /*@modifies p_s@*/ ;
173
174 extern lsymbol cstring_toSymbol (/*@only@*/ cstring p_s) /*@*/ ;
175 # endif
176
177 extern void cstring_markOwned (/*@owned@*/ cstring p_s) /*@modifies p_s@*/ ;
178
179 extern cstring cstring_beforeChar (cstring p_s, char p_c) /*@*/ ;
180 extern /*@exposed@*/ cstring cstring_afterChar (cstring p_s, char p_c) /*@*/ ;
181
182 /*@iter cstring_chars (sef cstring s, yield char c);@*/
183 # define cstring_chars(s, m_c) \
184   if (cstring_isDefined (s)) \
185     { char *m_current = (char *) (s); \
186       char m_c; \
187       for (; (m_c = *m_current) != '\0'; m_current++) {
188 # define end_cstring_chars }}
189
190 extern /*@observer@*/ cstring cstring_advanceWhiteSpace (cstring) /*@*/ ;
191
192 extern /*@only@*/ /*@notnull@*/ cstring
193 cstring_copySegment (cstring p_s, int p_findex, int p_tindex) /*@*/ ;
194
195 /*drl added 01/22/2001  Expands the escape squences i.e "\\n\\t\\000"
196  becomes "\n\t0"  */
197 extern cstring  cstring_expandEscapes (cstring p_s);
198
199 /*drl added 01/23/2001  Gives you the number of characters in an
200   expanded escape squences.  This can be different from strlen bc/ of
201   escaped nulls.  */
202 int  cstring_lengthExpandEscapes (cstring p_s);
203
204
205 extern bool cstring_containsLit (/*@unique@*/ cstring p_c, char *p_sub) /*@*/ ;
206 # define cstring_containsLit(c,sub) \
207   (cstring_contains (c, cstring_fromChars (sub)))
208
209 /*drl added July 2, 001 */
210 extern int cstring_compareLit (/*@unique@*/ cstring p_c, char *p_sub) /*@*/ ;
211 # define cstring_compareLit(c,sub) \
212   (cstring_compare (c, cstring_fromChars (sub)))
213
214 # else
215 # error "Multiple include"
216 # endif
217
218
219
This page took 0.132386 seconds and 5 git commands to generate.