mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-13 13:29:58 -05:00
Store strings directly in strlst elements, other modernizations
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1536 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
98d36efa82
commit
8836396c77
1 changed files with 23 additions and 16 deletions
|
|
@ -26,26 +26,31 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <pulse/xmalloc.h>
|
#include <pulse/xmalloc.h>
|
||||||
|
|
||||||
#include <pulsecore/strbuf.h>
|
#include <pulsecore/strbuf.h>
|
||||||
|
#include <pulsecore/macro.h>
|
||||||
#include <pulsecore/core-util.h>
|
#include <pulsecore/core-util.h>
|
||||||
|
|
||||||
#include "strlist.h"
|
#include "strlist.h"
|
||||||
|
|
||||||
struct pa_strlist {
|
struct pa_strlist {
|
||||||
pa_strlist *next;
|
pa_strlist *next;
|
||||||
char *str;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define ITEM_TO_TEXT(c) ((char*) (c) + PA_ALIGN(sizeof(pa_strlist)))
|
||||||
|
|
||||||
pa_strlist* pa_strlist_prepend(pa_strlist *l, const char *s) {
|
pa_strlist* pa_strlist_prepend(pa_strlist *l, const char *s) {
|
||||||
pa_strlist *n;
|
pa_strlist *n;
|
||||||
assert(s);
|
size_t size;
|
||||||
n = pa_xmalloc(sizeof(pa_strlist));
|
|
||||||
n->str = pa_xstrdup(s);
|
pa_assert(s);
|
||||||
|
size = strlen(s);
|
||||||
|
n = pa_xmalloc(PA_ALIGN(sizeof(pa_strlist)) + size + 1);
|
||||||
|
memcpy(ITEM_TO_TEXT(n), s, size + 1);
|
||||||
n->next = l;
|
n->next = l;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +63,7 @@ char *pa_strlist_tostring(pa_strlist *l) {
|
||||||
if (!first)
|
if (!first)
|
||||||
pa_strbuf_puts(b, " ");
|
pa_strbuf_puts(b, " ");
|
||||||
first = 0;
|
first = 0;
|
||||||
pa_strbuf_puts(b, l->str);
|
pa_strbuf_puts(b, ITEM_TO_TEXT(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
return pa_strbuf_tostring_free(b);
|
return pa_strbuf_tostring_free(b);
|
||||||
|
|
@ -66,19 +71,20 @@ char *pa_strlist_tostring(pa_strlist *l) {
|
||||||
|
|
||||||
pa_strlist* pa_strlist_remove(pa_strlist *l, const char *s) {
|
pa_strlist* pa_strlist_remove(pa_strlist *l, const char *s) {
|
||||||
pa_strlist *ret = l, *prev = NULL;
|
pa_strlist *ret = l, *prev = NULL;
|
||||||
assert(l && s);
|
|
||||||
|
pa_assert(l);
|
||||||
|
pa_assert(s);
|
||||||
|
|
||||||
while (l) {
|
while (l) {
|
||||||
if (!strcmp(l->str, s)) {
|
if (!strcmp(ITEM_TO_TEXT(l), s)) {
|
||||||
pa_strlist *n = l->next;
|
pa_strlist *n = l->next;
|
||||||
|
|
||||||
if (!prev) {
|
if (!prev) {
|
||||||
assert(ret == l);
|
pa_assert(ret == l);
|
||||||
ret = n;
|
ret = n;
|
||||||
} else
|
} else
|
||||||
prev->next = n;
|
prev->next = n;
|
||||||
|
|
||||||
pa_xfree(l->str);
|
|
||||||
pa_xfree(l);
|
pa_xfree(l);
|
||||||
|
|
||||||
l = n;
|
l = n;
|
||||||
|
|
@ -96,22 +102,21 @@ void pa_strlist_free(pa_strlist *l) {
|
||||||
while (l) {
|
while (l) {
|
||||||
pa_strlist *c = l;
|
pa_strlist *c = l;
|
||||||
l = l->next;
|
l = l->next;
|
||||||
|
|
||||||
pa_xfree(c->str);
|
|
||||||
pa_xfree(c);
|
pa_xfree(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_strlist* pa_strlist_pop(pa_strlist *l, char **s) {
|
pa_strlist* pa_strlist_pop(pa_strlist *l, char **s) {
|
||||||
pa_strlist *r;
|
pa_strlist *r;
|
||||||
assert(s);
|
|
||||||
|
pa_assert(s);
|
||||||
|
|
||||||
if (!l) {
|
if (!l) {
|
||||||
*s = NULL;
|
*s = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*s = l->str;
|
*s = pa_xstrdup(ITEM_TO_TEXT(l));
|
||||||
r = l->next;
|
r = l->next;
|
||||||
pa_xfree(l);
|
pa_xfree(l);
|
||||||
return r;
|
return r;
|
||||||
|
|
@ -124,10 +129,12 @@ pa_strlist* pa_strlist_parse(const char *s) {
|
||||||
|
|
||||||
while ((r = pa_split_spaces(s, &state))) {
|
while ((r = pa_split_spaces(s, &state))) {
|
||||||
pa_strlist *n;
|
pa_strlist *n;
|
||||||
|
size_t size = strlen(r);
|
||||||
|
|
||||||
n = pa_xmalloc(sizeof(pa_strlist));
|
n = pa_xmalloc(PA_ALIGN(sizeof(pa_strlist)) + size + 1);
|
||||||
n->str = r;
|
|
||||||
n->next = NULL;
|
n->next = NULL;
|
||||||
|
memcpy(ITEM_TO_TEXT(n), r, size+1);
|
||||||
|
pa_xfree(r);
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
p->next = n;
|
p->next = n;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue