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 3 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, see <http://www.gnu.org/licenses/>.
26 #include "libjnlib-config.h"
28 #ifdef JNLIB_NEED_UTF8CONV
33 free_strlist( strlist_t sl
)
37 for(; sl
; sl
= sl2
) {
45 add_to_strlist( strlist_t
*list
, const char *string
)
49 sl
= jnlib_xmalloc( sizeof *sl
+ strlen(string
));
51 strcpy(sl
->d
, string
);
58 /* Same as add_to_strlist() but if is_utf8 is *not* set, a conversion
60 #ifdef JNLIB_NEED_UTF8CONV
62 add_to_strlist2( strlist_t
*list
, const char *string
, int is_utf8
)
67 sl
= add_to_strlist( list
, string
);
70 char *p
= native_to_utf8( string
);
71 sl
= add_to_strlist( list
, p
);
76 #endif /* JNLIB_NEED_UTF8CONV*/
79 append_to_strlist( strlist_t
*list
, const char *string
)
83 sl
= jnlib_xmalloc( sizeof *sl
+ strlen(string
));
85 strcpy(sl
->d
, string
);
90 for( r
= *list
; r
->next
; r
= r
->next
)
98 #ifdef JNLIB_NEED_UTF8CONV
100 append_to_strlist2( strlist_t
*list
, const char *string
, int is_utf8
)
105 sl
= append_to_strlist( list
, string
);
108 char *p
= native_to_utf8 (string
);
109 sl
= append_to_strlist( list
, p
);
114 #endif /* JNLIB_NEED_UTF8CONV */
117 /* Return a copy of LIST. */
119 strlist_copy (strlist_t list
)
121 strlist_t newlist
= NULL
, sl
, *last
;
124 for (; list
; list
= list
->next
)
126 sl
= jnlib_xmalloc (sizeof *sl
+ strlen (list
->d
));
127 sl
->flags
= list
->flags
;
128 strcpy(sl
->d
, list
->d
);
139 strlist_prev( strlist_t head
, strlist_t node
)
143 for(n
=NULL
; head
&& head
!= node
; head
= head
->next
)
149 strlist_last( strlist_t node
)
152 for( ; node
->next
; node
= node
->next
)
159 strlist_pop (strlist_t
*list
)
166 str
=jnlib_xmalloc(strlen(sl
->d
)+1);