19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 *
21 * CDDL HEADER END
22 */
23 /*
24 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 #include <limits.h> /* MB_LEN_MAX */
29 #include <stdio.h>
30 #include <stdlib.h> /* wchar_t */
31 #include <string.h> /* strcmp() */
32 #include <sys/param.h> /* MAXPATHLEN */
33 #include <sys/types.h> /* time_t, caddr_t */
34 #include <vroot/vroot.h> /* pathpt */
35 #include <sys/time.h> /* timestruc_t */
36 #include <errno.h> /* errno */
37
38 #include <wctype.h>
39 #include <widec.h>
40
41
42 /*
43 * A type and some utilities for boolean values
44 */
45
46 #define false BOOLEAN_false
47 #define true BOOLEAN_true
48
49 typedef enum {
50 false = 0,
51 true = 1,
52 failed = 0,
53 succeeded = 1
54 } Boolean;
55 #define BOOLEAN(expr) ((expr) ? true : false)
56
57 /*
58 * Some random constants (in an enum so dbx knows their values)
59 */
60 enum {
141 };
142
143 /*
144 * CHAR_SEMANTICS_ENTRIES should be the number of entries above.
145 * The last entry in char_semantics[] should be blank.
146 */
147 #define CHAR_SEMANTICS_ENTRIES 27
148 /*
149 #define CHAR_SEMANTICS_STRING "&*@`\\|[]:$=!>-\n#()%+?;^<'\""
150 */
151
152 /*
153 * Some utility macros
154 */
155 #define ALLOC(x) ((struct _##x *)getmem(sizeof (struct _##x)))
156 #define ALLOC_WC(x) ((wchar_t *)getmem((x) * SIZEOFWCHAR_T))
157 #define FIND_LENGTH -1
158 #define GETNAME(a,b) getname_fn((a), (b), false)
159 #define IS_EQUAL(a,b) (!strcmp((a), (b)))
160 #define IS_EQUALN(a,b,n) (!strncmp((a), (b), (n)))
161 #define IS_WEQUAL(a,b) (!wscmp((a), (b)))
162 #define IS_WEQUALN(a,b,n) (!wsncmp((a), (b), (n)))
163 #define MBLEN(a) mblen((a), MB_LEN_MAX)
164 #define MBSTOWCS(a,b) (void) mbstowcs_with_check((a), (b), MAXPATHLEN)
165 #define MBTOWC(a,b) mbtowc((a), (b), MB_LEN_MAX)
166 #define SIZEOFWCHAR_T (sizeof (wchar_t))
167 #define VSIZEOF(v) (sizeof (v) / sizeof ((v)[0]))
168 #define WCSTOMBS(a,b) (void) wcstombs((a), (b), (MAXPATHLEN * MB_LEN_MAX))
169 #define WCTOMB(a,b) (void) wctomb((a), (b))
170 #define HASH(v, c) (v = (v)*31 + (unsigned int)(c))
171
172 extern void mbstowcs_with_check(wchar_t *pwcs, const char *s, size_t n);
173
174 /*
175 * Bits stored in funny vector to classify chars
176 */
177 enum {
178 dollar_sem = 0001,
179 meta_sem = 0002,
180 percent_sem = 0004,
181 wildcard_sem = 0010,
182 command_prefix_sem = 0020,
227 str.buffer.end = (buf) \
228 + (sizeof (buf)/SIZEOFWCHAR_T); \
229 str.free_after_use = false; \
230 }
231
232 #define APPEND_NAME(np, dest, len) append_string((np)->string_mb, (dest), (len));
233
234 class Wstring {
235 public:
236 struct _String string;
237 wchar_t string_buf[STRING_BUFFER_LENGTH];
238
239 public:
240 Wstring();
241 Wstring(struct _Name * name);
242 ~Wstring();
243
244 void init(struct _Name * name);
245 void init(wchar_t * name, unsigned length);
246 unsigned length() {
247 return wslen(string.buffer.start);
248 };
249 void append_to_str(struct _String * str, unsigned off, unsigned length);
250
251 wchar_t * get_string() {
252 return string.buffer.start;
253 };
254
255 wchar_t * get_string(unsigned off) {
256 return string.buffer.start + off;
257 };
258
259 Boolean equaln(wchar_t * str, unsigned length);
260 Boolean equal(wchar_t * str);
261 Boolean equal(wchar_t * str, unsigned off);
262 Boolean equal(wchar_t * str, unsigned off, unsigned length);
263
264 Boolean equaln(Wstring * str, unsigned length);
265 Boolean equal(Wstring * str);
266 Boolean equal(Wstring * str, unsigned off);
267 Boolean equal(Wstring * str, unsigned off, unsigned length);
|
19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 *
21 * CDDL HEADER END
22 */
23 /*
24 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 #include <limits.h> /* MB_LEN_MAX */
29 #include <stdio.h>
30 #include <stdlib.h> /* wchar_t */
31 #include <string.h> /* strcmp() */
32 #include <sys/param.h> /* MAXPATHLEN */
33 #include <sys/types.h> /* time_t, caddr_t */
34 #include <vroot/vroot.h> /* pathpt */
35 #include <sys/time.h> /* timestruc_t */
36 #include <errno.h> /* errno */
37
38 #include <wctype.h>
39
40 /*
41 * A type and some utilities for boolean values
42 */
43
44 #define false BOOLEAN_false
45 #define true BOOLEAN_true
46
47 typedef enum {
48 false = 0,
49 true = 1,
50 failed = 0,
51 succeeded = 1
52 } Boolean;
53 #define BOOLEAN(expr) ((expr) ? true : false)
54
55 /*
56 * Some random constants (in an enum so dbx knows their values)
57 */
58 enum {
139 };
140
141 /*
142 * CHAR_SEMANTICS_ENTRIES should be the number of entries above.
143 * The last entry in char_semantics[] should be blank.
144 */
145 #define CHAR_SEMANTICS_ENTRIES 27
146 /*
147 #define CHAR_SEMANTICS_STRING "&*@`\\|[]:$=!>-\n#()%+?;^<'\""
148 */
149
150 /*
151 * Some utility macros
152 */
153 #define ALLOC(x) ((struct _##x *)getmem(sizeof (struct _##x)))
154 #define ALLOC_WC(x) ((wchar_t *)getmem((x) * SIZEOFWCHAR_T))
155 #define FIND_LENGTH -1
156 #define GETNAME(a,b) getname_fn((a), (b), false)
157 #define IS_EQUAL(a,b) (!strcmp((a), (b)))
158 #define IS_EQUALN(a,b,n) (!strncmp((a), (b), (n)))
159 #define IS_WEQUAL(a,b) (!wcscmp((a), (b)))
160 #define IS_WEQUALN(a,b,n) (!wcsncmp((a), (b), (n)))
161 #define MBLEN(a) mblen((a), MB_LEN_MAX)
162 #define MBSTOWCS(a,b) (void) mbstowcs_with_check((a), (b), MAXPATHLEN)
163 #define MBTOWC(a,b) mbtowc((a), (b), MB_LEN_MAX)
164 #define SIZEOFWCHAR_T (sizeof (wchar_t))
165 #define VSIZEOF(v) (sizeof (v) / sizeof ((v)[0]))
166 #define WCSTOMBS(a,b) (void) wcstombs((a), (b), (MAXPATHLEN * MB_LEN_MAX))
167 #define WCTOMB(a,b) (void) wctomb((a), (b))
168 #define HASH(v, c) (v = (v)*31 + (unsigned int)(c))
169
170 extern void mbstowcs_with_check(wchar_t *pwcs, const char *s, size_t n);
171
172 /*
173 * Bits stored in funny vector to classify chars
174 */
175 enum {
176 dollar_sem = 0001,
177 meta_sem = 0002,
178 percent_sem = 0004,
179 wildcard_sem = 0010,
180 command_prefix_sem = 0020,
225 str.buffer.end = (buf) \
226 + (sizeof (buf)/SIZEOFWCHAR_T); \
227 str.free_after_use = false; \
228 }
229
230 #define APPEND_NAME(np, dest, len) append_string((np)->string_mb, (dest), (len));
231
232 class Wstring {
233 public:
234 struct _String string;
235 wchar_t string_buf[STRING_BUFFER_LENGTH];
236
237 public:
238 Wstring();
239 Wstring(struct _Name * name);
240 ~Wstring();
241
242 void init(struct _Name * name);
243 void init(wchar_t * name, unsigned length);
244 unsigned length() {
245 return wcslen(string.buffer.start);
246 };
247 void append_to_str(struct _String * str, unsigned off, unsigned length);
248
249 wchar_t * get_string() {
250 return string.buffer.start;
251 };
252
253 wchar_t * get_string(unsigned off) {
254 return string.buffer.start + off;
255 };
256
257 Boolean equaln(wchar_t * str, unsigned length);
258 Boolean equal(wchar_t * str);
259 Boolean equal(wchar_t * str, unsigned off);
260 Boolean equal(wchar_t * str, unsigned off, unsigned length);
261
262 Boolean equaln(Wstring * str, unsigned length);
263 Boolean equal(Wstring * str);
264 Boolean equal(Wstring * str, unsigned off);
265 Boolean equal(Wstring * str, unsigned off, unsigned length);
|