]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/pkgdata/pkgtypes.c
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /**************************************************************************
5 * Copyright (C) 2000-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
8 ***************************************************************************
10 * encoding: ANSI X3.4 (1968)
11 * tab size: 8 (not used)
14 * created on: 2000may16
15 * created by: Steven \u24C7 Loomis
17 * common types for pkgdata
22 #include "unicode/utypes.h"
23 #include "unicode/putil.h"
29 const char *pkg_writeCharListWrap(FileStream
*s
, CharList
*l
, const char *delim
, const char *brk
, int32_t quote
)
37 uprv_strncpy(buffer
, l
->str
, 1020);
40 if(quote
< 0) { /* remove quotes */
41 if(buffer
[uprv_strlen(buffer
)-1] == '"') {
42 buffer
[uprv_strlen(buffer
)-1] = '\0';
44 if(buffer
[0] == '"') {
45 uprv_strcpy(buffer
, buffer
+1);
47 } else if(quote
> 0) { /* add quotes */
48 if(l
->str
[0] != '"') {
49 uprv_strcpy(buffer
, "\"");
50 uprv_strncat(buffer
, l
->str
,1020);
52 if(l
->str
[uprv_strlen(l
->str
)-1] != '"') {
53 uprv_strcat(buffer
, "\"");
56 T_FileStream_write(s
, buffer
, (int32_t)uprv_strlen(buffer
));
58 ln
+= (int32_t)uprv_strlen(l
->str
);
65 T_FileStream_write(s
, brk
, (int32_t)uprv_strlen(brk
));
67 T_FileStream_write(s
, delim
, (int32_t)uprv_strlen(delim
));
75 const char *pkg_writeCharList(FileStream
*s
, CharList
*l
, const char *delim
, int32_t quote
)
82 uprv_strncpy(buffer
, l
->str
, 1023);
84 if(uprv_strlen(l
->str
) >= 1023)
86 fprintf(stderr
, "%s:%d: Internal error, line too long (greater than 1023 chars)\n",
90 if(quote
< 0) { /* remove quotes */
91 if(buffer
[uprv_strlen(buffer
)-1] == '"') {
92 buffer
[uprv_strlen(buffer
)-1] = '\0';
94 if(buffer
[0] == '"') {
95 uprv_strcpy(buffer
, buffer
+1);
97 } else if(quote
> 0) { /* add quotes */
98 if(l
->str
[0] != '"') {
99 uprv_strcpy(buffer
, "\"");
100 uprv_strcat(buffer
, l
->str
);
102 if(l
->str
[uprv_strlen(l
->str
)-1] != '"') {
103 uprv_strcat(buffer
, "\"");
106 T_FileStream_write(s
, buffer
, (int32_t)uprv_strlen(buffer
));
111 T_FileStream_write(s
, delim
, (int32_t)uprv_strlen(delim
));
120 * Count items . 0 if null
122 uint32_t pkg_countCharList(CharList
*l
)
135 * Prepend string to CharList
137 CharList
*pkg_prependToList(CharList
*l
, const char *str
)
140 newList
= uprv_malloc(sizeof(CharList
));
143 if(newList
== NULL
) {
153 * append string to CharList. *end or even end can be null if you don't
157 CharList
*pkg_appendToList(CharList
*l
, CharList
** end
, const char *str
)
159 CharList
*endptr
= NULL
, *tmp
;
167 if((*end
== NULL
) && (l
!= NULL
))
178 /* Create a new empty list and append it */
181 l
= pkg_prependToList(NULL
, str
);
185 (*end
)->next
= pkg_prependToList(NULL
, str
);
188 /* Move the end pointer. */
191 (*end
) = (*end
)->next
;
201 char * convertToNativePathSeparators(char *path
) {
202 #if defined(U_MAKE_IS_NMAKE)
204 while ((itr
= uprv_strchr(path
, U_FILE_ALT_SEP_CHAR
))) {
205 *itr
= U_FILE_SEP_CHAR
;
211 CharList
*pkg_appendUniqueDirToList(CharList
*l
, CharList
** end
, const char *strAlias
) {
214 rPtr
= uprv_strrchr(strAlias
, U_FILE_SEP_CHAR
);
215 #if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
217 char *aPtr
= uprv_strrchr(strAlias
, U_FILE_ALT_SEP_CHAR
);
218 if(!rPtr
|| /* regular char wasn't found or.. */
219 (aPtr
&& (aPtr
> rPtr
)))
220 { /* alt ptr exists and is to the right of r ptr */
221 rPtr
= aPtr
; /* may copy NULL which is OK */
226 return l
; /* no dir path */
228 if((rPtr
-strAlias
) >= UPRV_LENGTHOF(aBuf
)) {
229 fprintf(stderr
, "## ERR: Path too long [%d chars]: %s\n", (int)sizeof(aBuf
), strAlias
);
232 strncpy(aBuf
, strAlias
,(rPtr
-strAlias
));
233 aBuf
[rPtr
-strAlias
]=0; /* no trailing slash */
234 convertToNativePathSeparators(aBuf
);
236 if(!pkg_listContains(l
, aBuf
)) {
237 return pkg_appendToList(l
, end
, uprv_strdup(aBuf
));
239 return l
; /* already found */
245 pkg_appendFromStrings(CharList
*l
, CharList
** end
, const char *s
, int32_t len
)
247 CharList
*endptr
= NULL
;
256 len
= uprv_strlen(s
);
260 while(*s
&& s
<targ
) {
261 while(s
<targ
&&isspace(*s
)) s
++;
262 for(p
=s
;s
<targ
&&!isspace(*p
);p
++);
264 t
= uprv_malloc(p
-s
+1);
265 uprv_strncpy(t
,s
,p
-s
);
267 l
=pkg_appendToList(l
,end
,t
);
268 fprintf(stderr
, " P %s\n", t
);
281 void pkg_deleteList(CharList
*l
)
286 uprv_free((void*)l
->str
);
293 UBool
pkg_listContains(CharList
*l
, const char *str
)
296 if(!uprv_strcmp(l
->str
, str
)) {