1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**************************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
383a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius*   Copyright (C) 2000-2011, International Business Machines
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru***************************************************************************
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   file name:  pkgdata.c
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   encoding:   ANSI X3.4 (1968)
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   tab size:   8 (not used)
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   indentation:4
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   created on: 2000may16
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   created by: Steven \u24C7 Loomis
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*  common types for pkgdata
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/putil.h"
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h"
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cstring.h"
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "pkgtypes.h"
2583a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius#include "putilimp.h"
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char *pkg_writeCharListWrap(FileStream *s, CharList *l, const char *delim, const char *brk, int32_t quote)
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t ln = 0;
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char buffer[1024];
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(l != NULL)
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(l->str)
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            uprv_strncpy(buffer, l->str, 1020);
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            buffer[1019]=0;
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(quote < 0) { /* remove quotes */
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(buffer[uprv_strlen(buffer)-1] == '"') {
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    buffer[uprv_strlen(buffer)-1] = '\0';
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(buffer[0] == '"') {
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strcpy(buffer, buffer+1);
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            } else if(quote > 0) { /* add quotes */
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(l->str[0] != '"') {
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strcpy(buffer, "\"");
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strncat(buffer, l->str,1020);
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(l->str[uprv_strlen(l->str)-1] != '"') {
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strcat(buffer, "\"");
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            T_FileStream_write(s, buffer, (int32_t)uprv_strlen(buffer));
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ln += (int32_t)uprv_strlen(l->str);
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(l->next && delim)
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(ln > 60 && brk) {
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                ln  = 0;
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                T_FileStream_write(s, brk, (int32_t)uprv_strlen(brk));
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            T_FileStream_write(s, delim, (int32_t)uprv_strlen(delim));
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        l = l->next;
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return NULL;
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst char *pkg_writeCharList(FileStream *s, CharList *l, const char *delim, int32_t quote)
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char buffer[1024];
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(l != NULL)
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(l->str)
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            uprv_strncpy(buffer, l->str, 1023);
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            buffer[1023]=0;
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(uprv_strlen(l->str) >= 1023)
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            {
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                fprintf(stderr, "%s:%d: Internal error, line too long (greater than 1023 chars)\n",
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        __FILE__, __LINE__);
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                exit(0);
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(quote < 0) { /* remove quotes */
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(buffer[uprv_strlen(buffer)-1] == '"') {
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    buffer[uprv_strlen(buffer)-1] = '\0';
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(buffer[0] == '"') {
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strcpy(buffer, buffer+1);
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            } else if(quote > 0) { /* add quotes */
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(l->str[0] != '"') {
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strcpy(buffer, "\"");
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strcat(buffer, l->str);
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(l->str[uprv_strlen(l->str)-1] != '"') {
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    uprv_strcat(buffer, "\"");
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            T_FileStream_write(s, buffer, (int32_t)uprv_strlen(buffer));
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
10685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(l->next && delim)
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            T_FileStream_write(s, delim, (int32_t)uprv_strlen(delim));
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        l = l->next;
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return NULL;
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Count items . 0 if null
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruuint32_t pkg_countCharList(CharList *l)
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  uint32_t c = 0;
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  while(l != NULL)
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  {
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    c++;
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    l = l->next;
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  return c;
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
13285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/*
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Prepend string to CharList
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCharList *pkg_prependToList(CharList *l, const char *str)
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  CharList *newList;
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  newList = uprv_malloc(sizeof(CharList));
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* test for NULL */
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(newList == NULL) {
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return NULL;
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  newList->str = str;
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  newList->next = l;
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  return newList;
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
15085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/*
15185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * append string to CharList. *end or even end can be null if you don't
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * know it.[slow]
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Str is adopted!
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCharList *pkg_appendToList(CharList *l, CharList** end, const char *str)
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  CharList *endptr = NULL, *tmp;
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(end == NULL)
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  {
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    end = &endptr;
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
16385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* FIND the end */
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if((*end == NULL) && (l != NULL))
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  {
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    tmp = l;
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(tmp->next)
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      tmp = tmp->next;
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    *end = tmp;
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* Create a new empty list and append it */
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(l == NULL)
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      l = pkg_prependToList(NULL, str);
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  else
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      (*end)->next = pkg_prependToList(NULL, str);
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* Move the end pointer. */
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(*end)
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      (*end) = (*end)->next;
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  else
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      *end = l;
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  return l;
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruchar * convertToNativePathSeparators(char *path) {
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if defined(U_MAKE_IS_NMAKE)
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *itr;
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while ((itr = uprv_strchr(path, U_FILE_ALT_SEP_CHAR))) {
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *itr = U_FILE_SEP_CHAR;
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return path;
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCharList *pkg_appendUniqueDirToList(CharList *l, CharList** end, const char *strAlias) {
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char aBuf[1024];
21185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char *rPtr;
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rPtr = uprv_strrchr(strAlias, U_FILE_SEP_CHAR);
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR)
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char *aPtr = uprv_strrchr(strAlias, U_FILE_ALT_SEP_CHAR);
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(!rPtr || /* regular char wasn't found or.. */
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            (aPtr && (aPtr > rPtr)))
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { /* alt ptr exists and is to the right of r ptr */
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            rPtr = aPtr; /* may copy NULL which is OK */
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!rPtr) {
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return l; /* no dir path */
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if((rPtr-strAlias) >= (sizeof(aBuf)/sizeof(aBuf[0]))) {
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        fprintf(stderr, "## ERR: Path too long [%d chars]: %s\n", (int)sizeof(aBuf), strAlias);
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return l;
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    strncpy(aBuf, strAlias,(rPtr-strAlias));
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    aBuf[rPtr-strAlias]=0;  /* no trailing slash */
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    convertToNativePathSeparators(aBuf);
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!pkg_listContains(l, aBuf)) {
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return pkg_appendToList(l, end, uprv_strdup(aBuf));
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return l; /* already found */
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic CharList *
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupkg_appendFromStrings(CharList *l, CharList** end, const char *s, int32_t len)
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  CharList *endptr = NULL;
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  const char *p;
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  char *t;
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  const char *targ;
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(end == NULL) {
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    end = &endptr;
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(len==-1) {
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    len = uprv_strlen(s);
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  targ = s+len;
25785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  while(*s && s<targ) {
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(s<targ&&isspace(*s)) s++;
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(p=s;s<targ&&!isspace(*p);p++);
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(p!=s) {
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      t = uprv_malloc(p-s+1);
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      uprv_strncpy(t,s,p-s);
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      t[p-s]=0;
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      l=pkg_appendToList(l,end,t);
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      fprintf(stderr, " P %s\n", t);
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    s=p;
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
27085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  return l;
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
27785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Delete list
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid pkg_deleteList(CharList *l)
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
28185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  CharList *tmp;
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  while(l != NULL)
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  {
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprv_free((void*)l->str);
28585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    tmp = l;
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    l = l->next;
28785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uprv_free(tmp);
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUBool  pkg_listContains(CharList *l, const char *str)
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  for(;l;l=l->next){
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!uprv_strcmp(l->str, str)) {
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return TRUE;
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  return FALSE;
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
301