Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / libAButil / istr.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23
24 /*
25  *      $XConsortium: istr.h /main/4 1995/11/06 18:50:56 rswiston $
26  *
27  * @(#)istr.h   1.27 11 Feb 1994        cde_app_builder/src/libAButil
28  *
29  *      RESTRICTED CONFIDENTIAL INFORMATION:
30  *      
31  *      The information in this document is subject to special
32  *      restrictions in a confidential disclosure agreement between
33  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
35  *      Sun's specific written approval.  This document and all copies
36  *      and derivative works thereof must be returned or destroyed at
37  *      Sun's request.
38  *
39  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  */
42
43 /*
44  * istr.h - string allocater
45  *
46  * empty value for an ISTRING is NULL.
47  */
48 #ifndef _ISTR_H
49 #define _ISTR_H
50
51 #ifndef _POSIX_SOURCE
52 #define _POSIX_SOURCE 1         /* we want to be POSIX-compliant */
53 #endif
54
55 #include <string.h>
56 #include <ab_private/AB.h>
57 #include <ab/util_types.h>
58 #include <ab_private/util.h>
59
60 typedef struct
61 {
62     BYTE        you_dont_want_to_use_this_field;
63 } ISTRING_PUBLIC_REC;
64
65 typedef ISTRING_PUBLIC_REC *ISTRING;
66
67 /* 
68  * Allocate a new istring for a given string and return the value,
69  * or if the string already exists return the value
70  * for an existing istring. If the string was previously allocated as
71  * a read only string change its status to const and its string 
72  * pointer.
73  * Returns -1 if error.  
74  * Note: This string is read only. The string sent in is already 
75  *       allocated and the destroy command will not deallocate the 
76  *       string 
77  */
78 extern ISTRING  istr_create_const(
79                     STRING string
80                 );
81
82 /* 
83  * Identical to istr_create_const (shortcut) 
84  */
85 extern ISTRING  istr_const(
86                     STRING string
87                 );
88
89 /* 
90  * Allocate a new istring for a given string and return the value, 
91  * or if the string already exists return the value
92  * for an existing istring. Returns -1 if error. 
93  * Note: This string is read only. The string sent in is already 
94  *       allocated and the destroy command will deallocate the 
95  *       string 
96  */
97 extern ISTRING  istr_create_alloced(
98                     STRING string
99                 );
100
101 /* 
102  * Allocate a new istring for a given string and return the value, 
103  * or if the string already exists return the value for an 
104  * existing istring. Returns -1 if error. 
105  * Note: This string is read only. The string sent in has not 
106  *       been allocated and the destroy command will deallocate 
107  *       the string.
108  */
109 extern ISTRING  istr_create(
110                     STRING string
111                 );
112
113 /* 
114  * Deallocate for the string if refcount=0 else decrement the refcount.
115  * If the string type is const then don't deallocate.
116  * returns -1 if error, else returns 1
117  */
118 extern int      istr_destroy(
119                     ISTRING istring
120                 );
121
122 /* 
123  * Return the string value, and increment counter 
124  * return -1 if error 
125  */
126 extern ISTRING  istr_dup(
127                     ISTRING istring
128                 );
129
130 /* 
131  * Return (STRING) for istring, return NULL if error
132  */
133 extern STRING   istr_string(
134                     ISTRING istring
135                 );
136
137 /* 
138  * Won't return NULL - returns string associated with istring,
139  * or "(nil)" 
140  * Note: printable string returned 
141  */
142 extern STRING   istr_string_safe(
143                     ISTRING istring
144                 );
145
146 /* 
147  * Finds the existing ISTRING value for string, returns NULL if string
148  * doesn't exist 
149  *
150  * Note that this dups the existing string, and istr_destroy() must
151  * be called on the returned ISTRING when it is no longer needed.
152  */
153 extern ISTRING  istr_dup_existing(
154                     STRING s
155                 );
156
157 /* 
158  * Moves the istring in "from" to the istring in "to" and 
159  * sets "from" to NULL
160  * always returns 0 
161  */
162 extern int      istr_move(
163                     ISTRING to, 
164                     ISTRING from
165                 );
166
167 /* 
168  * Returns the length of the string, returns NULL if the 
169  * string is empty 
170  */
171 extern int      istr_len(
172                     ISTRING s
173                 );
174  
175 /* 
176  * Compare the two strings, returns the same as strcmp 
177  */
178 extern int      istr_cmp(
179                     ISTRING s1, 
180                     ISTRING s2
181                 );
182
183 /* 
184  * Compare the two istrings, returns TRUE if equal 
185  */
186 extern BOOL     istr_equal(
187                     ISTRING s1, 
188                     ISTRING s2
189                 );
190
191 /* 
192  * Compare the two strings, returns the same as strcmp 
193  */
194 extern int      istr_cmpstr(
195                     ISTRING s1, 
196                     STRING s2
197                 );
198
199 /* 
200  * Compare the two strings, returns TRUE if equal 
201  */
202 extern BOOL     istr_equalstr(
203                     ISTRING s1, 
204                     STRING s2
205                 );
206
207 /*
208  * Verifies that the given ISTRING is valid (e.g., that it exists, and that
209  * it is not corrupted.
210  *
211  * Returns < 0 if an error is detected
212  */
213 int istr_verify(ISTRING);
214
215 /*
216  * Checks all the ISTRINGS and internal data structures to see if anything
217  * has become corrupted.
218  *
219  * Returns < 0 if an error is detected
220  */
221 int istr_verify_all(void);
222
223
224 /*************************************************************************
225 **                                                                      **
226 **              Internal functions - clients must not call these!       **
227 **                                                                      **
228 **************************************************************************/
229
230 typedef struct
231 {
232     int                 refcount;
233     STRING              str;
234     unsigned int        read_const : 1;
235 } ISTR_PRIVT_STRN;
236
237 extern STRING           Istr_null_string;
238 extern int              istrP_destroy_impl518283652PrivF(ISTRING*);
239 extern ISTRING          istrP_create_alloced_impl9726039350PrivF(STRING*);
240 extern int              istrP_notify_invalid2160413670PrivF(ISTRING);
241 extern STRING           istrP_get_string_fast3718930164PrivF(ISTRING);
242 extern STRING           istrP_get_string_verify4521632085PrivF(ISTRING);
243 extern int              istrP_num_count7608925912PrivD;
244 extern ISTR_PRIVT_STRN  *istrP_int_array1809065681PrivD;
245
246
247 /*************************************************************************
248 **                                                                      **
249 **              Inline implementation                                   **
250 **                                                                      **
251 **************************************************************************/
252
253 #define istr_equal(a,b) ((a) == (b))
254 #define istr_len(s)     ((s)==NULL? 0:strlen(istr_string(s)))
255
256 #define istr_destroy(s)                         \
257     (istrP_destroy_impl518283652PrivF(&(s)))
258
259 #define istr_create_alloced(s)                  \
260     (istrP_create_alloced_impl9726039350PrivF(&(s)))
261
262 #define istr_move(a,b)  ((int)((a)=(b), (b)=NULL))
263
264 #define istr_cmp(a,b)   (util_strcmp(istr_string(a),istr_string(b)))
265
266 #define istr_cmpstr(a,b)   (util_strcmp(istr_string(a),(b)))
267
268 #define istr_equalstr(a,b)   (istr_cmpstr(a,b)==0)
269
270 #define istr_const(s)   (istr_create_const(s))
271
272 #define istr_string_safe(s) ((s) == NULL? Istr_null_string:istr_string(s))
273
274 #define istrP_get_string_fast3718930164PrivF(istring) \
275     (istrP_int_array1809065681PrivD[((int)istring)].str)
276
277 /* istr_string - if debugging is turned on, checks ISTRINGS for validity */
278 #ifdef DEBUG
279     #define istr_string(istring) \
280         ((!debugging())? \
281             istrP_get_string_fast3718930164PrivF(istring) \
282         : \
283             istrP_get_string_verify4521632085PrivF(istring) \
284         )
285 #else
286     #define istr_string(istring) \
287             (istrP_get_string_fast3718930164PrivF(istring))
288 #endif /* DEBUG */
289
290 #endif /* _ISTR_H */