]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/modargs.c
merge 'lennart' branch back into trunk.
[pulseaudio] / src / pulsecore / modargs.c
index 13a48785be8ecf4bba1ecbe568c7ad1037bdad54..1311af3c18b1c8839aca4f43fdb355b4d421f19c 100644 (file)
@@ -2,17 +2,19 @@
 
 /***
   This file is part of PulseAudio.
+
+  Copyright 2004-2006 Lennart Poettering
+
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2 of the License,
   or (at your option) any later version.
+
   PulseAudio is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
+
   You should have received a copy of the GNU Lesser General Public License
   along with PulseAudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -24,7 +26,6 @@
 #endif
 
 #include <ctype.h>
-#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -37,6 +38,7 @@
 #include <pulsecore/sink.h>
 #include <pulsecore/source.h>
 #include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
 
 #include "modargs.h"
 
@@ -46,7 +48,10 @@ struct entry {
 
 static int add_key_value(pa_hashmap *map, char *key, char *value, const char* const valid_keys[]) {
     struct entry *e;
-    assert(map && key && value);
+
+    pa_assert(map);
+    pa_assert(key);
+    pa_assert(value);
 
     if (valid_keys) {
         const char*const* v;
@@ -60,11 +65,12 @@ static int add_key_value(pa_hashmap *map, char *key, char *value, const char* co
             return -1;
         }
     }
-    
-    e = pa_xmalloc(sizeof(struct entry));
+
+    e = pa_xnew(struct entry, 1);
     e->key = key;
     e->value = value;
     pa_hashmap_put(map, key, e);
+
     return 0;
 }
 
@@ -72,13 +78,12 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
     pa_hashmap *map = NULL;
 
     map = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    assert(map);
 
     if (args) {
         enum { WHITESPACE, KEY, VALUE_START, VALUE_SIMPLE, VALUE_DOUBLE_QUOTES, VALUE_TICKS } state;
         const char *p, *key, *value;
         size_t key_len = 0, value_len = 0;
-        
+
         key = value = NULL;
         state = WHITESPACE;
         for (p = args; *p; p++) {
@@ -160,14 +165,14 @@ fail:
 
     if (map)
         pa_modargs_free((pa_modargs*) map);
-                      
+
     return NULL;
 }
 
-
 static void free_func(void *p, PA_GCC_UNUSED void*userdata) {
     struct entry *e = p;
-    assert(e);
+    pa_assert(e);
+
     pa_xfree(e->key);
     pa_xfree(e->value);
     pa_xfree(e);
@@ -190,7 +195,10 @@ const char *pa_modargs_get_value(pa_modargs *ma, const char *key, const char *de
 
 int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) {
     const char *v;
-    assert(ma && key && value);
+
+    pa_assert(ma);
+    pa_assert(key);
+    pa_assert(value);
 
     if (!(v = pa_modargs_get_value(ma, key, NULL)))
         return 0;
@@ -203,21 +211,27 @@ int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) {
 
 int pa_modargs_get_value_s32(pa_modargs *ma, const char *key, int32_t *value) {
     const char *v;
-    assert(ma && key && value);
+
+    pa_assert(ma);
+    pa_assert(key);
+    pa_assert(value);
 
     if (!(v = pa_modargs_get_value(ma, key, NULL)))
         return 0;
 
     if (pa_atoi(v, value) < 0)
         return -1;
-            
+
     return 0;
 }
 
 int pa_modargs_get_value_boolean(pa_modargs *ma, const char *key, int *value) {
     const char *v;
     int r;
-    assert(ma && key && value);
+
+    pa_assert(ma);
+    pa_assert(key);
+    pa_assert(value);
 
     if (!(v = pa_modargs_get_value(ma, key, NULL)))
         return 0;
@@ -236,10 +250,10 @@ int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) {
     const char *format;
     uint32_t channels;
     pa_sample_spec ss;
-    assert(ma && rss);
 
-/*    DEBUG_TRAP;*/
-    
+    pa_assert(ma);
+    pa_assert(rss);
+
     ss = *rss;
     if ((pa_modargs_get_value_u32(ma, "rate", &ss.rate)) < 0)
         return -1;
@@ -257,20 +271,20 @@ int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) {
         return -1;
 
     *rss = ss;
-    
+
     return 0;
 }
 
-int pa_modargs_get_channel_map(pa_modargs *ma, pa_channel_map *rmap) {
+int pa_modargs_get_channel_map(pa_modargs *ma, const char *name, pa_channel_map *rmap) {
     pa_channel_map map;
     const char *cm;
-    
-    assert(ma);
-    assert(rmap);
+
+    pa_assert(ma);
+    pa_assert(rmap);
 
     map = *rmap;
 
-    if ((cm = pa_modargs_get_value(ma, "channel_map", NULL)))
+    if ((cm = pa_modargs_get_value(ma, name ? name : "channel_map", NULL)))
         if (!pa_channel_map_parse(&map, cm))
             return -1;
 
@@ -284,10 +298,10 @@ int pa_modargs_get_channel_map(pa_modargs *ma, pa_channel_map *rmap) {
 int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *rss, pa_channel_map *rmap, pa_channel_map_def_t def) {
     pa_sample_spec ss;
     pa_channel_map map;
-    
-    assert(ma);
-    assert(rss);
-    assert(rmap);
+
+    pa_assert(ma);
+    pa_assert(rss);
+    pa_assert(rmap);
 
     ss = *rss;
 
@@ -297,7 +311,7 @@ int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *r
     if (!pa_channel_map_init_auto(&map, ss.channels, def))
         map.channels = 0;
 
-    if (pa_modargs_get_channel_map(ma, &map) < 0)
+    if (pa_modargs_get_channel_map(ma, NULL, &map) < 0)
         return -1;
 
     if (map.channels != ss.channels)