]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/pkgtypes.c
1 /**************************************************************************
3 * Copyright (C) 2000-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
6 ***************************************************************************
8 * encoding: ANSI X3.4 (1968)
9 * tab size: 8 (not used)
12 * created on: 2000may16
13 * created by: Steven \u24C7 Loomis
15 * common types for pkgdata
20 #include "unicode/utypes.h"
21 #include "unicode/putil.h"
27 const char *pkg_writeCharListWrap(FileStream
*s
, CharList
*l
, const char *delim
, const char *brk
, int32_t quote
)
31 const CharList
*ol
= NULL
;
36 uprv_strncpy(buffer
, l
->str
, 1020);
39 if(quote
< 0) { /* remove quotes */
40 if(buffer
[uprv_strlen(buffer
)-1] == '"') {
41 buffer
[uprv_strlen(buffer
)-1] = '\0';
43 if(buffer
[0] == '"') {
44 uprv_strcpy(buffer
, buffer
+1);
46 } else if(quote
> 0) { /* add quotes */
47 if(l
->str
[0] != '"') {
48 uprv_strcpy(buffer
, "\"");
49 uprv_strncat(buffer
, l
->str
,1020);
51 if(l
->str
[uprv_strlen(l
->str
)-1] != '"') {
52 uprv_strcat(buffer
, "\"");
55 T_FileStream_write(s
, buffer
, (int32_t)uprv_strlen(buffer
));
58 ln
+= (int32_t)uprv_strlen(l
->str
);
66 T_FileStream_write(s
, brk
, (int32_t)uprv_strlen(brk
));
68 T_FileStream_write(s
, delim
, (int32_t)uprv_strlen(delim
));
76 const char *pkg_writeCharList(FileStream
*s
, CharList
*l
, const char *delim
, int32_t quote
)
83 uprv_strncpy(buffer
, l
->str
, 1023);
85 if(uprv_strlen(l
->str
) >= 1023)
87 fprintf(stderr
, "%s:%d: Internal error, line too long (greater than 1023 chars)\n",
91 if(quote
< 0) { /* remove quotes */
92 if(buffer
[uprv_strlen(buffer
)-1] == '"') {
93 buffer
[uprv_strlen(buffer
)-1] = '\0';
95 if(buffer
[0] == '"') {
96 uprv_strcpy(buffer
, buffer
+1);
98 } else if(quote
> 0) { /* add quotes */
99 if(l
->str
[0] != '"') {
100 uprv_strcpy(buffer
, "\"");
101 uprv_strcat(buffer
, l
->str
);
103 if(l
->str
[uprv_strlen(l
->str
)-1] != '"') {
104 uprv_strcat(buffer
, "\"");
107 T_FileStream_write(s
, buffer
, (int32_t)uprv_strlen(buffer
));
112 T_FileStream_write(s
, delim
, (int32_t)uprv_strlen(delim
));
121 * Count items . 0 if null
123 uint32_t pkg_countCharList(CharList
*l
)
136 * Prepend string to CharList
138 CharList
*pkg_prependToList(CharList
*l
, const char *str
)
141 newList
= uprv_malloc(sizeof(CharList
));
144 if(newList
== NULL
) {
154 * append string to CharList. *end or even end can be null if you don't
158 CharList
*pkg_appendToList(CharList
*l
, CharList
** end
, const char *str
)
160 CharList
*endptr
= NULL
, *tmp
;
168 if((*end
== NULL
) && (l
!= NULL
))
179 /* Create a new empty list and append it */
182 l
= pkg_prependToList(NULL
, str
);
186 (*end
)->next
= pkg_prependToList(NULL
, str
);
189 /* Move the end pointer. */
192 (*end
) = (*end
)->next
;
202 CharList
*pkg_appendUniqueDirToList(CharList
*l
, CharList
** end
, const char *strAlias
) {
205 rPtr
= uprv_strrchr(strAlias
, U_FILE_SEP_CHAR
);
206 #if defined(U_FILE_ALT_SEP_CHAR) && (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
208 char *aPtr
= uprv_strrchr(strAlias
, U_FILE_ALT_SEP_CHAR
);
209 if(!rPtr
|| /* regular char wasn't found or.. */
210 (aPtr
&& (aPtr
> rPtr
)))
211 { /* alt ptr exists and is to the right of r ptr */
212 rPtr
= aPtr
; /* may copy NULL which is OK */
217 return l
; /* no dir path */
219 if((rPtr
-strAlias
) > (sizeof(aBuf
)/sizeof(aBuf
[0]))) {
220 fprintf(stderr
, "## ERR: Path too long [%d chars]: %s\n", sizeof(aBuf
), strAlias
);
223 strncpy(aBuf
, strAlias
,(rPtr
-strAlias
));
224 aBuf
[rPtr
-strAlias
]=0; /* no trailing slash */
226 if(!pkg_listContains(l
, aBuf
)) {
227 return pkg_appendToList(l
, end
, uprv_strdup(aBuf
));
229 return l
; /* already found */
235 pkg_appendFromStrings(CharList
*l
, CharList
** end
, const char *s
, int32_t len
)
237 CharList
*endptr
= NULL
;
246 len
= uprv_strlen(s
);
250 while(*s
&& s
<targ
) {
251 while(s
<targ
&&isspace(*s
)) s
++;
252 for(p
=s
;s
<targ
&&!isspace(*p
);p
++);
254 t
= uprv_malloc(p
-s
+1);
255 uprv_strncpy(t
,s
,p
-s
);
257 l
=pkg_appendToList(l
,end
,t
);
258 fprintf(stderr
, " P %s\n", t
);
271 void pkg_deleteList(CharList
*l
)
276 uprv_free((void*)l
->str
);
281 UBool
pkg_listContains(CharList
*l
, const char *str
)
284 if(!uprv_strcmp(l
->str
, str
)) {