From 59067e6a925eab5690f455b65d9f2b4d45301115 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 3 Jan 2009 13:20:12 +0100 Subject: ao: use g_strsplit() instead of strtok_r() g_strsplit() is more portable than strtok_r(). --- src/output/ao_plugin.c | 52 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) (limited to 'src/output/ao_plugin.c') diff --git a/src/output/ao_plugin.c b/src/output/ao_plugin.c index 798a188e8..fcbc52dc4 100644 --- a/src/output/ao_plugin.c +++ b/src/output/ao_plugin.c @@ -79,12 +79,6 @@ static void *audioOutputAo_initDriver(struct audio_output *ao, ConfigParam * param) { ao_info *ai; - char *duplicated; - char *stk1; - char *stk2; - char *n1; - char *key; - char *value; char *test; AoData *ad = newAoData(); BlockParam *blockParam; @@ -121,40 +115,24 @@ static void *audioOutputAo_initDriver(struct audio_output *ao, audio_output_get_name(ao)); blockParam = getBlockParam(param, "options"); - if (blockParam) { - duplicated = g_strdup(blockParam->value); - } else - duplicated = g_strdup(""); - - if (strlen(duplicated)) { - stk1 = NULL; - n1 = strtok_r(duplicated, ";", &stk1); - while (n1) { - stk2 = NULL; - key = strtok_r(n1, "=", &stk2); - if (!key) - g_error("problems parsing options \"%s\"\n", n1); - /*found = 0; - for(i=0;ioption_count;i++) { - if(strcmp(ai->options[i],key)==0) { - found = 1; - break; - } - } - if(!found) { - FATAL("\"%s\" is not an option for " - "\"%s\" ao driver\n",key, - ai->short_name); - } */ - value = strtok_r(NULL, "", &stk2); - if (!value) - g_error("problems parsing options \"%s\"\n", n1); - ao_append_option(&ad->options, key, value); - n1 = strtok_r(NULL, ";", &stk1); + gchar **options = g_strsplit(blockParam->value, ";", 0); + + for (unsigned i = 0; options[i] != NULL; ++i) { + gchar **key_value = g_strsplit(options[i], "=", 2); + + if (key_value[0] == NULL || key_value[1] == NULL) + g_error("problems parsing options \"%s\"\n", + options[i]); + + ao_append_option(&ad->options, key_value[0], + key_value[1]); + + g_strfreev(key_value); } + + g_strfreev(options); } - free(duplicated); return ad; } -- cgit v1.2.3