[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
The attached patch (config-unix.patch) changes UNIX systems to read
/etc/allegrorc, as well as ~/.allegrorc, as well as allegro.cfg. I
specifically opted not to use _unix_find_resource because all three
config files are loaded (in the listed order, with later settings
overriding the previous) rather than only the most specific one.
It also adds a configuration function: al_config_merge_into. This is
actually the code from that static add_config. I justify it because
there will, in many cases, be no need to keep the original
configuration around after a merge, therefore this function is be
faster, use less memory, and provide a simpler API.
The second patch (alsa-configuration.patch) changes the alsa module to
support configurable devices.
--
Regards,
Ryan Patterson <mailto:cgamesplay@xxxxxxxxxx>
Index: src/system_new.c
===================================================================
--- src/system_new.c (revision 11026)
+++ src/system_new.c (working copy)
@@ -89,6 +89,11 @@
*/
bool al_install_system(int (*atexit_ptr)(void (*)(void)))
{
+#ifdef ALLEGRO_UNIX
+ ALLEGRO_CONFIG *temp;
+ char buf[256], tmp[256];
+#endif
+
if (active_sysdrv) {
return true;
}
@@ -113,8 +118,41 @@
return false;
}
- /* FIXME: On UNIX this should read /etc/allegro.cfg too and merge the two */
+#ifdef ALLEGRO_UNIX
+ active_sysdrv->config = al_config_read("/etc/allegrorc");
+ if(active_sysdrv->config) {
+ TRACE("Applying system settings from /etc/allegrorc\n");
+ }
+
+ ustrzcpy(buf, sizeof(buf) - ucwidth(OTHER_PATH_SEPARATOR), uconvert_ascii(getenv("HOME"), tmp));
+ put_backslash(buf);
+ ustrzcat(buf, sizeof(buf), uconvert_ascii(".allegrorc", tmp));
+ temp = al_config_read(buf);
+ if(temp) {
+ TRACE("Applying system settings from %s\n", buf);
+ if(active_sysdrv->config) {
+ al_config_merge_into(active_sysdrv->config, temp);
+ al_config_destroy(temp);
+ }
+ else {
+ active_sysdrv->config = temp;
+ }
+ }
+
+ temp = al_config_read("allegro.cfg");
+ if(temp) {
+ TRACE("Applying system settings from allegro.cfg\n");
+ if(active_sysdrv->config) {
+ al_config_merge_into(active_sysdrv->config, temp);
+ al_config_destroy(temp);
+ }
+ else {
+ active_sysdrv->config = temp;
+ }
+ }
+#else
active_sysdrv->config = al_config_read("allegro.cfg");
+#endif
_al_add_exit_func(shutdown_system_driver, "shutdown_system_driver");
Index: src/config.c
===================================================================
--- src/config.c (revision 11026)
+++ src/config.c (working copy)
@@ -351,11 +351,16 @@
}
-static void add_config(ALLEGRO_CONFIG *master, ALLEGRO_CONFIG *add)
+void al_config_merge_into(ALLEGRO_CONFIG *master, ALLEGRO_CONFIG *add)
{
ALLEGRO_CONFIG_SECTION *s = add->head;
ALLEGRO_CONFIG_ENTRY *e;
+ ASSERT(master);
+ if(!add) {
+ return;
+ }
+
/* Save globals */
e = add->globals;
while (e != NULL) {
@@ -380,8 +385,8 @@
{
ALLEGRO_CONFIG *config = local_calloc1(sizeof(ALLEGRO_CONFIG));
- add_config(config, cfg1);
- add_config(config, cfg2);
+ al_config_merge_into(config, cfg1);
+ al_config_merge_into(config, cfg2);
return config;
}
Index: include/allegro5/config.h
===================================================================
--- include/allegro5/config.h (revision 11026)
+++ include/allegro5/config.h (working copy)
@@ -15,6 +15,7 @@
AL_FUNC(AL_CONST char*, al_config_get_value, (ALLEGRO_CONFIG *config, AL_CONST char *section, AL_CONST char *key));
AL_FUNC(ALLEGRO_CONFIG*, al_config_read, (AL_CONST char *filename));
AL_FUNC(int, al_config_write, (ALLEGRO_CONFIG *config, AL_CONST char *filename));
+AL_FUNC(void, al_config_merge_into, (ALLEGRO_CONFIG *master, ALLEGRO_CONFIG *add));
AL_FUNC(ALLEGRO_CONFIG *, al_config_merge, (ALLEGRO_CONFIG *cfg1, ALLEGRO_CONFIG *cfg2));
AL_FUNC(void, al_config_destroy, (ALLEGRO_CONFIG *config));
Index: addons/kcm_audio/alsa.c
===================================================================
--- addons/kcm_audio/alsa.c (revision 11026)
+++ addons/kcm_audio/alsa.c (working copy)
@@ -22,6 +22,7 @@
#include "allegro5/allegro.h"
#include "allegro5/internal/aintern.h"
+#include "allegro5/internal/aintern_system.h"
#include "allegro5/internal/aintern_kcm_audio.h"
#include <alsa/asoundlib.h>
@@ -42,8 +43,8 @@
static snd_output_t *snd_output = NULL;
-/* TODO: add an API to make this configurable */
-static const char alsa_device[128] = "default";
+static char* default_device = "default";
+static char* alsa_device = NULL;
typedef struct ALSA_VOICE {
@@ -69,6 +70,16 @@
/* initialized output */
static int alsa_open(void)
{
+ alsa_device = default_device;
+
+ ALLEGRO_SYSTEM *sys = al_system_driver();
+ if(sys->config) {
+ const char* config_device;
+ config_device = al_config_get_value(sys->config, "sound", "alsa_device");
+ if(config_device)
+ alsa_device = strdup(config_device);
+ }
+
ALSA_CHECK(snd_output_stdio_attach(&snd_output, stdout, 0));
/* We need to check if alsa is available in this function. */
@@ -96,6 +107,11 @@
other processes to use the device */
static void alsa_close(void)
{
+ if(alsa_device != default_device)
+ free(alsa_device);
+
+ alsa_device = NULL;
+
snd_config_update_free_global();
}