From b7c05ad942fb303ee0f509e0e0cbe21d1b85fb2d Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 8 Jun 2001 10:15:25 +0000 Subject: [PATCH] Removed snd_defaults_ functions. Updated the syntax of configuration file to substitute values from the environment space. Updated alsa.conf to replace old snd_defaults_ functions. --- doc/asoundrc.doc | 7 +++ include/control.h | 7 --- src/alsa.conf | 26 ++++++-- src/conf.c | 63 +++++++++++++++---- src/control/Makefile.am | 2 +- src/control/defaults.c | 131 ---------------------------------------- utils/alsa.m4 | 2 +- 7 files changed, 80 insertions(+), 158 deletions(-) delete mode 100644 src/control/defaults.c diff --git a/doc/asoundrc.doc b/doc/asoundrc.doc index 3cc0afaf..86569321 100644 --- a/doc/asoundrc.doc +++ b/doc/asoundrc.doc @@ -1,3 +1,10 @@ +# Include a new configuration file + + +# Replace with an environment variable +# (default value is used if envvar is not present or empty) +<@envvar[,envvar1][,envvar2...]:defaultval@> + # Server definition server.NAME { host STR # host where the server is located (if map to local address diff --git a/include/control.h b/include/control.h index 4c6eb8e1..311aaad0 100644 --- a/include/control.h +++ b/include/control.h @@ -266,13 +266,6 @@ int snd_card_get_index(const char *name); int snd_card_get_name(int card, char **name); int snd_card_get_longname(int card, char **name); -int snd_defaults_card(void); -int snd_defaults_mixer_card(void); -int snd_defaults_pcm_card(void); -int snd_defaults_pcm_device(void); -int snd_defaults_rawmidi_card(void); -int snd_defaults_rawmidi_device(void); - int snd_card_type_string_to_enum(const char *strid, snd_card_type_t *enumid); int snd_card_type_enum_to_string(snd_card_type_t enumid, char **strid); diff --git a/src/alsa.conf b/src/alsa.conf index 0df89916..323bd66f 100644 --- a/src/alsa.conf +++ b/src/alsa.conf @@ -1,10 +1,13 @@ +# +# ALSA library configuration file +# pcm.default { type plug slave.pcm { type hw - card 0 - device 0 + card <@ALSA_PCM_CARD,ALSA_CARD:0@> + device <@ALSA_PCM_DEVICE:0@> } } @@ -115,10 +118,11 @@ pcm.surround40 { $.1 DEV $.CARD { type integer + default <@ALSA_SURROUND40_CARD,ALSA_PCM_CARD,ALSA_CARD:0@> } $.DEV { type integer - default 0 + default <@ALSA_SURROUND40_DEVICE:0@> } type surround card $CARD @@ -131,10 +135,11 @@ pcm.surround51 { $.1 DEV $.CARD { type integer + default <@ALSA_SURROUND51_CARD,ALSA_PCM_CARD,ALSA_CARD:0@> } $.DEV { type integer - default 0 + default <@ALSA_SURROUND51_DEVICE:0@> } type surround card $CARD @@ -148,7 +153,7 @@ pcm.null { ctl.default { type hw - card 0 + card <@ALSA_CARD:0@> } ctl.hw { @@ -174,6 +179,12 @@ ctl.shm { ctl $PCM } +rawmidi.default { + type hw + card <@ALSA_RAWMIDI_CARD,ALSA_CARD:0@> + device <@ALSA_RAWMIDI_DEVICE:0@> +} + rawmidi.hw { $.0 CARD $.1 DEV @@ -194,6 +205,10 @@ rawmidi.hw { subdevice $SUBDEV } +seq.default { + type hw +} + seq.hw { type hw } @@ -242,4 +257,3 @@ pcm.iec958 { } } } - diff --git a/src/conf.c b/src/conf.c index b09a7f71..361339fc 100644 --- a/src/conf.c +++ b/src/conf.c @@ -59,6 +59,7 @@ typedef struct { UNTERMINATED_QUOTE = -2, UNEXPECTED_CHAR = -3, UNEXPECTED_EOF = -4, + BAD_ENV_DEFAULT = -5, } error; } input_t; @@ -112,19 +113,54 @@ static int get_char_skip_comments(input_t *input) while (1) { c = get_char(input); if (c == '<') { - char *file; + char *str; snd_input_t *in; struct filedesc *fd; - int err = get_delimstring(&file, '>', input); - if (err < 0) - return err; - err = snd_input_stdio_open(&in, file, "r"); + int err = get_delimstring(&str, '>', input); if (err < 0) return err; + if (strlen(str) < 3 || + str[0] != '@' || + str[strlen(str)-1] != '@' || + strchr(str, ':') == NULL) { + err = snd_input_stdio_open(&in, str, "r"); + if (err < 0) + return err; + } else { + char *envvar = str + 1; + char *envdef = strchr(str, ':'); + char *env, *end; + + str[strlen(str)-1] = '\0'; + *envdef++ = '\0'; + if (*envdef == '\0') { + free(str); + input->error = BAD_ENV_DEFAULT; + return -EINVAL; + } + while (1) { + end = strchr(envvar, ','); + if (end) + *end = '\0'; + env = getenv(envvar); + if (env != NULL && *env != '\0') + break; + if (end) { + *end = ','; /* repair for fd->name */ + envvar = end + 1; + } else { + env = envdef; + break; + } + } + err = snd_input_buffer_open(&in, env, strlen(env)); + if (err < 0) + return err; + } fd = malloc(sizeof(*fd)); if (!fd) return -ENOMEM; - fd->name = file; + fd->name = str; fd->in = in; fd->next = input->current; fd->line = 1; @@ -839,6 +875,9 @@ int snd_config_load(snd_config_t *config, snd_input_t *in) case UNEXPECTED_EOF: str = "Unexpected end of file"; break; + case BAD_ENV_DEFAULT: + str = "Bad environment default value"; + break; default: assert(0); break; @@ -1196,10 +1235,10 @@ int snd_config_search_alias(snd_config_t *config, } /** Environment variable containing files list for #snd_config_update */ -#define ASOUND_CONFIGS_VAR "ASOUND_CONFIGS" +#define ALSA_CONFIG_PATH_VAR "ALSA_CONFIG_PATH" /** Default files used by #snd_config_update */ -#define ASOUND_CONFIGS_DEFAULT DATADIR "/alsa/alsa.conf:/etc/asound.conf:~/.asoundrc" +#define ALSA_CONFIG_PATH_DEFAULT DATADIR "/alsa/alsa.conf:/etc/asound.conf:~/.asoundrc" /** \ingroup Config * Config top node */ @@ -1216,7 +1255,7 @@ static unsigned int files_info_count = 0; /** * \brief Update #snd_config rereading (if needed) files specified in - * environment variable ASOUND_CONFIGS. If it's not set the default value is + * environment variable ALSA_CONFIG_PATH. If it's not set the default value is * "/usr/share/alsa/alsa.conf:/etc/asound.conf:~/.asoundrc" * \return 0 if no action is needed, 1 if tree has been rebuilt otherwise a negative error code * @@ -1232,9 +1271,9 @@ int snd_config_update() size_t l; struct finfo *fi; unsigned int fi_count; - configs = getenv(ASOUND_CONFIGS_VAR); + configs = getenv(ALSA_CONFIG_PATH_VAR); if (!configs) - configs = ASOUND_CONFIGS_DEFAULT; + configs = ALSA_CONFIG_PATH_DEFAULT; for (k = 0, c = configs; (l = strcspn(c, ": ")) > 0; ) { c += l; k++; @@ -1351,7 +1390,7 @@ snd_config_iterator_t snd_config_iterator_first(snd_config_t *node) } /** - * \brief Return an iterator pointing to next leaf +q * \brief Return an iterator pointing to next leaf * \param iterator Config node iterator * \return iterator value for next leaf */ diff --git a/src/control/Makefile.am b/src/control/Makefile.am index 57d61769..0b28efcd 100644 --- a/src/control/Makefile.am +++ b/src/control/Makefile.am @@ -1,6 +1,6 @@ EXTRA_LTLIBRARIES = libcontrol.la -libcontrol_la_SOURCES = cards.c cards_id.c hcontrol.c defaults.c \ +libcontrol_la_SOURCES = cards.c cards_id.c hcontrol.c \ control.c control_hw.c control_shm.c \ setup.c diff --git a/src/control/defaults.c b/src/control/defaults.c deleted file mode 100644 index 1e785b81..00000000 --- a/src/control/defaults.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Control Interface - defaults - * Copyright (c) 1998 by Jaroslav Kysela - * - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program 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 Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include -#include -#include "local.h" - -static int defaults_card(const char *env) -{ - char *e; - - e = getenv(env); - if (!e) - return -ENOENT; - return snd_card_get_index(e); -} - -static int defaults_device(const char *env) -{ - char *e; - int dev; - - e = getenv(env); - if (e) { - dev = atoi(env); - if (dev >= 0 && dev < 1024 * 1024) - return dev; - } - return 0; -} - -int snd_defaults_card(void) -{ - int result; - - result = defaults_card("ALSA_CARD"); - if (result >= 0) - return result; - result = -1; - if (snd_card_next(&result)) - return -ENOENT; - return result; -} - -int snd_defaults_mixer_card(void) -{ - int result; - - result = defaults_card("ALSA_MIXER_CARD"); - if (result >= 0) - return result; - return snd_defaults_card(); -} - -int snd_defaults_pcm_card(void) -{ - int result; - - result = defaults_card("ALSA_PCM_CARD"); - if (result >= 0) - return result; - return snd_defaults_card(); -} - -int snd_defaults_pcm_device(void) -{ - snd_ctl_t *handle; - char id[16]; - int result; - - result = defaults_device("ALSA_PCM_DEVICE"); - if (result >= 0) - return result; - sprintf(id, "hw:%i", snd_defaults_pcm_card()); - if (snd_ctl_open(&handle, id, 0) < 0) - return -ENOENT; - result = -1; - if (snd_ctl_pcm_next_device(handle, &result) < 0) { - snd_ctl_close(handle); - return -ENOENT; - } - return result; -} - -int snd_defaults_rawmidi_card(void) -{ - int result; - - result = defaults_card("ALSA_RAWMIDI_CARD"); - if (result >= 0) - return result; - return snd_defaults_card(); -} - -int snd_defaults_rawmidi_device(void) -{ - snd_ctl_t *handle; - char id[16]; - int result; - - result = defaults_device("ALSA_RAWMIDI_DEVICE"); - if (result >= 0) - return result; - sprintf(id, "hw:%i", snd_defaults_rawmidi_card()); - if (snd_ctl_open(&handle, id, 0) < 0) - return -ENOENT; - result = -1; - if (snd_ctl_rawmidi_next_device(handle, &result) < 0) { - snd_ctl_close(handle); - return -ENOENT; - } - return result; -} diff --git a/utils/alsa.m4 b/utils/alsa.m4 index 0c3ea11d..76400f97 100644 --- a/utils/alsa.m4 +++ b/utils/alsa.m4 @@ -118,7 +118,7 @@ exit(0); AC_LANG_RESTORE dnl Now that we know that we have the right version, let's see if we have the library and not just the headers. -AC_CHECK_LIB([asound], [snd_defaults_card],, +AC_CHECK_LIB([asound], [snd_seq_create_event],, [ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)]) alsa_found=no] ) -- 2.47.1