1 /* strlist.c - string helpers
2 * Copyright (C) 1998, 2000, 2001, 2006 Free Software Foundation, Inc.
4 * This file is part of JNLIB.
6 * JNLIB is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * JNLIB is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "libjnlib-config.h"
30 #ifdef JNLIB_NEED_UTF8CONV
35 free_strlist( strlist_t sl
)
39 for(; sl
; sl
= sl2
) {
47 add_to_strlist( strlist_t
*list
, const char *string
)
51 sl
= jnlib_xmalloc( sizeof *sl
+ strlen(string
));
53 strcpy(sl
->d
, string
);
60 /* Same as add_to_strlist() but if is_utf8 is *not* set, a conversion
62 #ifdef JNLIB_NEED_UTF8CONV
64 add_to_strlist2( strlist_t
*list
, const char *string
, int is_utf8
)
69 sl
= add_to_strlist( list
, string
);
72 char *p
= native_to_utf8( string
);
73 sl
= add_to_strlist( list
, p
);
78 #endif /* JNLIB_NEED_UTF8CONV*/
81 append_to_strlist( strlist_t
*list
, const char *string
)
85 sl
= jnlib_xmalloc( sizeof *sl
+ strlen(string
));
87 strcpy(sl
->d
, string
);
92 for( r
= *list
; r
->next
; r
= r
->next
)
100 #ifdef JNLIB_NEED_UTF8CONV
102 append_to_strlist2( strlist_t
*list
, const char *string
, int is_utf8
)
107 sl
= append_to_strlist( list
, string
);
110 char *p
= native_to_utf8 (string
);
111 sl
= append_to_strlist( list
, p
);
116 #endif /* JNLIB_NEED_UTF8CONV */
119 /* Return a copy of LIST. */
121 strlist_copy (strlist_t list
)
123 strlist_t newlist
= NULL
, sl
, *last
;
126 for (; list
; list
= list
->next
)
128 sl
= jnlib_xmalloc (sizeof *sl
+ strlen (list
->d
));
129 sl
->flags
= list
->flags
;
130 strcpy(sl
->d
, list
->d
);
141 strlist_prev( strlist_t head
, strlist_t node
)
145 for(n
=NULL
; head
&& head
!= node
; head
= head
->next
)
151 strlist_last( strlist_t node
)
154 for( ; node
->next
; node
= node
->next
)
161 strlist_pop (strlist_t
*list
)
168 str
=jnlib_xmalloc(strlen(sl
->d
)+1);