]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/pkgtypes.c
1 /**************************************************************************
3 * Copyright (C) 2000-2006, 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
)
35 uprv_strncpy(buffer
, l
->str
, 1020);
38 if(quote
< 0) { /* remove quotes */
39 if(buffer
[uprv_strlen(buffer
)-1] == '"') {
40 buffer
[uprv_strlen(buffer
)-1] = '\0';
42 if(buffer
[0] == '"') {
43 uprv_strcpy(buffer
, buffer
+1);
45 } else if(quote
> 0) { /* add quotes */
46 if(l
->str
[0] != '"') {
47 uprv_strcpy(buffer
, "\"");
48 uprv_strncat(buffer
, l
->str
,1020);
50 if(l
->str
[uprv_strlen(l
->str
)-1] != '"') {
51 uprv_strcat(buffer
, "\"");
54 T_FileStream_write(s
, buffer
, (int32_t)uprv_strlen(buffer
));
56 ln
+= (int32_t)uprv_strlen(l
->str
);
63 T_FileStream_write(s
, brk
, (int32_t)uprv_strlen(brk
));
65 T_FileStream_write(s
, delim
, (int32_t)uprv_strlen(delim
));
73 const char *pkg_writeCharList(FileStream
*s
, CharList
*l
, const char *delim
, int32_t quote
)
80 uprv_strncpy(buffer
, l
->str
, 1023);
82 if(uprv_strlen(l
->str
) >= 1023)
84 fprintf(stderr
, "%s:%d: Internal error, line too long (greater than 1023 chars)\n",
88 if(quote
< 0) { /* remove quotes */
89 if(buffer
[uprv_strlen(buffer
)-1] == '"') {
90 buffer
[uprv_strlen(buffer
)-1] = '\0';
92 if(buffer
[0] == '"') {
93 uprv_strcpy(buffer
, buffer
+1);
95 } else if(quote
> 0) { /* add quotes */
96 if(l
->str
[0] != '"') {
97 uprv_strcpy(buffer
, "\"");
98 uprv_strcat(buffer
, l
->str
);
100 if(l
->str
[uprv_strlen(l
->str
)-1] != '"') {
101 uprv_strcat(buffer
, "\"");
104 T_FileStream_write(s
, buffer
, (int32_t)uprv_strlen(buffer
));
109 T_FileStream_write(s
, delim
, (int32_t)uprv_strlen(delim
));
118 * Count items . 0 if null
120 uint32_t pkg_countCharList(CharList
*l
)
133 * Prepend string to CharList
135 CharList
*pkg_prependToList(CharList
*l
, const char *str
)
138 newList
= uprv_malloc(sizeof(CharList
));
141 if(newList
== NULL
) {
151 * append string to CharList. *end or even end can be null if you don't
155 CharList
*pkg_appendToList(CharList
*l
, CharList
** end
, const char *str
)
157 CharList
*endptr
= NULL
, *tmp
;
165 if((*end
== NULL
) && (l
!= NULL
))
176 /* Create a new empty list and append it */
179 l
= pkg_prependToList(NULL
, str
);
183 (*end
)->next
= pkg_prependToList(NULL
, str
);
186 /* Move the end pointer. */
189 (*end
) = (*end
)->next
;
199 char * convertToNativePathSeparators(char *path
) {
200 #if defined(U_MAKE_IS_NMAKE)
202 while ((itr
= uprv_strchr(path
, U_FILE_ALT_SEP_CHAR
))) {
203 *itr
= U_FILE_SEP_CHAR
;
209 CharList
*pkg_appendUniqueDirToList(CharList
*l
, CharList
** end
, const char *strAlias
) {
212 rPtr
= uprv_strrchr(strAlias
, U_FILE_SEP_CHAR
);
213 #if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
215 char *aPtr
= uprv_strrchr(strAlias
, U_FILE_ALT_SEP_CHAR
);
216 if(!rPtr
|| /* regular char wasn't found or.. */
217 (aPtr
&& (aPtr
> rPtr
)))
218 { /* alt ptr exists and is to the right of r ptr */
219 rPtr
= aPtr
; /* may copy NULL which is OK */
224 return l
; /* no dir path */
226 if((rPtr
-strAlias
) > (sizeof(aBuf
)/sizeof(aBuf
[0]))) {
227 fprintf(stderr
, "## ERR: Path too long [%d chars]: %s\n", (int)sizeof(aBuf
), strAlias
);
230 strncpy(aBuf
, strAlias
,(rPtr
-strAlias
));
231 aBuf
[rPtr
-strAlias
]=0; /* no trailing slash */
232 convertToNativePathSeparators(aBuf
);
234 if(!pkg_listContains(l
, aBuf
)) {
235 return pkg_appendToList(l
, end
, uprv_strdup(aBuf
));
237 return l
; /* already found */
243 pkg_appendFromStrings(CharList
*l
, CharList
** end
, const char *s
, int32_t len
)
245 CharList
*endptr
= NULL
;
254 len
= uprv_strlen(s
);
258 while(*s
&& s
<targ
) {
259 while(s
<targ
&&isspace(*s
)) s
++;
260 for(p
=s
;s
<targ
&&!isspace(*p
);p
++);
262 t
= uprv_malloc(p
-s
+1);
263 uprv_strncpy(t
,s
,p
-s
);
265 l
=pkg_appendToList(l
,end
,t
);
266 fprintf(stderr
, " P %s\n", t
);
279 void pkg_deleteList(CharList
*l
)
284 uprv_free((void*)l
->str
);
289 UBool
pkg_listContains(CharList
*l
, const char *str
)
292 if(!uprv_strcmp(l
->str
, str
)) {