2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio 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 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulse/xmalloc.h>
30 #include <pulsecore/strbuf.h>
31 #include <pulsecore/macro.h>
32 #include <pulsecore/core-util.h>
40 #define ITEM_TO_TEXT(c) ((char*) (c) + PA_ALIGN(sizeof(pa_strlist)))
42 pa_strlist* pa_strlist_prepend(pa_strlist *l, const char *s) {
48 n = pa_xmalloc(PA_ALIGN(sizeof(pa_strlist)) + size + 1);
49 memcpy(ITEM_TO_TEXT(n), s, size + 1);
55 char *pa_strlist_tostring(pa_strlist *l) {
60 for (; l; l = l->next) {
62 pa_strbuf_puts(b, " ");
64 pa_strbuf_puts(b, ITEM_TO_TEXT(l));
67 return pa_strbuf_tostring_free(b);
70 pa_strlist* pa_strlist_remove(pa_strlist *l, const char *s) {
71 pa_strlist *ret = l, *prev = NULL;
77 if (!strcmp(ITEM_TO_TEXT(l), s)) {
78 pa_strlist *n = l->next;
99 void pa_strlist_free(pa_strlist *l) {
107 pa_strlist* pa_strlist_pop(pa_strlist *l, char **s) {
117 *s = pa_xstrdup(ITEM_TO_TEXT(l));
123 pa_strlist* pa_strlist_parse(const char *s) {
124 pa_strlist *head = NULL, *p = NULL;
125 const char *state = NULL;
128 while ((r = pa_split_spaces(s, &state))) {
130 size_t size = strlen(r);
132 n = pa_xmalloc(PA_ALIGN(sizeof(pa_strlist)) + size + 1);
134 memcpy(ITEM_TO_TEXT(n), r, size+1);
148 pa_strlist *pa_strlist_reverse(pa_strlist *l) {
149 pa_strlist *r = NULL;
163 pa_strlist *pa_strlist_next(pa_strlist *s) {
169 const char *pa_strlist_data(pa_strlist *s) {
172 return ITEM_TO_TEXT(s);