[Pkg-wmaker-commits] [wmix] 20/44: wmix: be more verbose about the configuration file in use

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Sep 29 10:40:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository wmix.

commit 7490988bdd16401061de28ed77a3aa69adc01ac0
Author: Christophe CURIS <christophe.curis at free.fr>
Date:   Sat Jun 7 21:21:48 2014 +0200

    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 at free.fr>
---
 config.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/config.c b/config.c
index 9252657..42f9e6c 100644
--- a/config.c
+++ b/config.c
@@ -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="))) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmix.git



More information about the Pkg-wmaker-commits mailing list