wmix: be more verbose about the configuration file in use

If the config file was set by user with '-f', it would be a good idea to
report him if we're not able to load it.
Took opportunity to report to user that the config file is loaded if he
asked for verbose operations, so he can see if the default file loaded
is the one he expected.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS 2014-06-07 21:21:48 +02:00 committed by Carlos R. Mafra
parent b394e0bdba
commit 676fc13cb2

View file

@ -50,17 +50,8 @@ struct _Config config;
*/
void config_init(void)
{
char *home;
memset(&config, 0, sizeof(config));
/* we can theoretically live without a config file */
home = getenv("HOME");
if (home) {
config.file = calloc(1, strlen(home) + 9);
sprintf(config.file, "%s/.wmixrc", home);
}
config.mousewheel = 1;
config.scrolltext = 1;
config.wheel_button_up = 4;
@ -133,16 +124,38 @@ void parse_cli_options(int argc, char **argv)
*/
void config_read(void)
{
const char *filename;
char buffer_fname[512];
FILE *fp;
char buf[512];
char *ptr;
if (config.file == NULL)
return;
if (config.file != NULL) {
filename = config.file;
} else {
const char *home;
fp = fopen(config.file, "r");
if (!fp)
home = getenv("HOME");
if (home == NULL) {
fprintf(stderr, "wmix: warning, could not get $HOME, can't load configuration file\n");
return;
}
snprintf(buffer_fname, sizeof(buffer_fname), "%s/.wmixrc", home);
filename = buffer_fname;
}
fp = fopen(filename, "r");
if (fp == NULL) {
if (config.file != NULL) {
/* The config file was explicitely specified by user, tell him there's a problem */
fprintf(stderr, "wmix: error, could not load configuration file \"%s\"\n", filename);
exit(EXIT_FAILURE);
}
/* Otherwise, it is acceptable if the file does not exist */
return;
}
if (config.verbose)
printf("Using configuration file: %s\n", filename);
while (fgets(buf, 512, fp)) {
if ((ptr = strstr(buf, "mousewheel="))) {