2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
25 * $XConsortium: istr.h /main/4 1995/11/06 18:50:56 rswiston $
27 * @(#)istr.h 1.27 11 Feb 1994 cde_app_builder/src/libAButil
29 * RESTRICTED CONFIDENTIAL INFORMATION:
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
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
44 * istr.h - string allocater
46 * empty value for an ISTRING is NULL.
52 #define _POSIX_SOURCE 1 /* we want to be POSIX-compliant */
56 #include <ab_private/AB.h>
57 #include <ab/util_types.h>
58 #include <ab_private/util.h>
62 BYTE you_dont_want_to_use_this_field;
65 typedef ISTRING_PUBLIC_REC *ISTRING;
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
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
78 extern ISTRING istr_create_const(
83 * Identical to istr_create_const (shortcut)
85 extern ISTRING istr_const(
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
97 extern ISTRING istr_create_alloced(
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
109 extern ISTRING istr_create(
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
118 extern int istr_destroy(
123 * Return the string value, and increment counter
126 extern ISTRING istr_dup(
131 * Return (STRING) for istring, return NULL if error
133 extern STRING istr_string(
138 * Won't return NULL - returns string associated with istring,
140 * Note: printable string returned
142 extern STRING istr_string_safe(
147 * Finds the existing ISTRING value for string, returns NULL if string
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.
153 extern ISTRING istr_dup_existing(
158 * Moves the istring in "from" to the istring in "to" and
159 * sets "from" to NULL
162 extern int istr_move(
168 * Returns the length of the string, returns NULL if the
176 * Compare the two strings, returns the same as strcmp
184 * Compare the two istrings, returns TRUE if equal
186 extern BOOL istr_equal(
192 * Compare the two strings, returns the same as strcmp
194 extern int istr_cmpstr(
200 * Compare the two strings, returns TRUE if equal
202 extern BOOL istr_equalstr(
208 * Verifies that the given ISTRING is valid (e.g., that it exists, and that
209 * it is not corrupted.
211 * Returns < 0 if an error is detected
213 int istr_verify(ISTRING);
216 * Checks all the ISTRINGS and internal data structures to see if anything
217 * has become corrupted.
219 * Returns < 0 if an error is detected
221 int istr_verify_all(void);
224 /*************************************************************************
226 ** Internal functions - clients must not call these! **
228 **************************************************************************/
234 unsigned int read_const : 1;
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;
247 /*************************************************************************
249 ** Inline implementation **
251 **************************************************************************/
253 #define istr_equal(a,b) ((a) == (b))
254 #define istr_len(s) ((s)==NULL? 0:strlen(istr_string(s)))
256 #define istr_destroy(s) \
257 (istrP_destroy_impl518283652PrivF(&(s)))
259 #define istr_create_alloced(s) \
260 (istrP_create_alloced_impl9726039350PrivF(&(s)))
262 #define istr_move(a,b) ((int)((a)=(b), (b)=NULL))
264 #define istr_cmp(a,b) (util_strcmp(istr_string(a),istr_string(b)))
266 #define istr_cmpstr(a,b) (util_strcmp(istr_string(a),(b)))
268 #define istr_equalstr(a,b) (istr_cmpstr(a,b)==0)
270 #define istr_const(s) (istr_create_const(s))
272 #define istr_string_safe(s) ((s) == NULL? Istr_null_string:istr_string(s))
274 #define istrP_get_string_fast3718930164PrivF(istring) \
275 (istrP_int_array1809065681PrivD[((int)istring)].str)
277 /* istr_string - if debugging is turned on, checks ISTRINGS for validity */
279 #define istr_string(istring) \
281 istrP_get_string_fast3718930164PrivF(istring) \
283 istrP_get_string_verify4521632085PrivF(istring) \
286 #define istr_string(istring) \
287 (istrP_get_string_fast3718930164PrivF(istring))