[Pkg-wmaker-commits] [wmix] 18/44: wmix: moved parsing of Command-Line options to the config handling file

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 9e2724592027c5b053a52c04c94df9867518da6c
Author: Christophe CURIS <christophe.curis at free.fr>
Date:   Sat Jun 7 21:21:46 2014 +0200

    wmix: moved parsing of Command-Line options to the config handling file
    
    Took opportunity to re-order them alphabetically so they are easier to
    work with, both for devs and for users.
    
    Signed-off-by: Christophe CURIS <christophe.curis at free.fr>
---
 config.c         | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 include/config.h | 15 ++++++++++++
 wmix.c           | 71 +++++---------------------------------------------------
 3 files changed, 89 insertions(+), 66 deletions(-)

diff --git a/config.c b/config.c
index 9823949..8a0419c 100644
--- a/config.c
+++ b/config.c
@@ -16,12 +16,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 /*
- * config.c: functions related to loading the configuration from file
+ * config.c: functions related to loading the configuration, both from
+ * command line options and from file
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <getopt.h>
 
 #include <sys/soundcard.h>
 
@@ -29,11 +31,76 @@
 #include "include/config.h"
 
 
+#define HELP_TEXT	  \
+	"WMixer " VERSION " by timecop at japan.co.jp + skunk at mit.edu\n" \
+	"usage:\n" \
+	"  -d <dsp>  connect to remote X display\n" \
+	"  -e <name> exclude channel, can be used many times\n" \
+	"  -f <file> parse this config [~/.wmixrc]\n" \
+	"  -h        print this help\n" \
+	"  -m <dev>  mixer device [/dev/mixer]\n" \
+	"  -v        verbose -> id, long name, name\n" \
+
 /* The global configuration */
 struct _Config config;
 
 
 /*
+ * Parse Command-Line options
+ *
+ * Supposed to be called before reading config file, as there's an
+ * option to change its name
+ */
+void parse_cli_options(int argc, char **argv)
+{
+	int opt;
+	int count_exclude = 0;
+
+	config.verbose = false;
+	while ((opt = getopt(argc, argv, "d:e:f:hm:v")) != EOF) {
+		switch (opt) {
+		case 'd':
+			if (optarg != NULL)
+				config.display_name = strdup(optarg);
+			break;
+
+		case 'e':
+			if (count_exclude < SOUND_MIXER_NRDEVICES) {
+				config.exclude_channel[count_exclude] = strdup(optarg);
+				count_exclude++;
+			} else
+				fprintf(stderr, "Warning: You can't exclude this many channels\n");
+			break;
+
+		case 'f':
+			if (optarg != NULL)
+				if (config.file != NULL)
+					free(config.file);
+			config.file = strdup(optarg);
+			break;
+
+		case 'h':
+			fputs(HELP_TEXT, stdout);
+			exit(0);
+			break;
+
+		case 'm':
+			if (optarg != NULL)
+				config.mixer_device = strdup(optarg);
+			break;
+
+		case 'v':
+			config.verbose = true;
+			break;
+
+		default:
+			break;
+		}
+	}
+	config.exclude_channel[count_exclude] = NULL;
+}
+
+/*
  * Read configuration from a file
  *
  * The file name is taken from CLI if available, of falls back to
diff --git a/include/config.h b/include/config.h
index 5d84ae9..71a79d4 100644
--- a/include/config.h
+++ b/include/config.h
@@ -20,10 +20,17 @@
 #ifndef WMIX_CONFIG_H
 #define WMIX_CONFIG_H
 
+/* Needed for SOUND_MIXER_NRDEVICES */
+#include <sys/soundcard.h>
+
+
 /* Global Configuration */
 extern struct _Config {
 	char        *file;				/* full path to config file name */
+	char        *display_name;		/* X Display to connect to */
+	char        *mixer_device;		/* device file to use for controlling Mixer volumes */
 
+	unsigned int verbose    : 1;	/* be Verbose when starting */
 	unsigned int osd        : 1;	/* show OSD? */
 	unsigned int mousewheel : 1;	/* mousewheel enabled? */
 	unsigned int scrolltext : 1;	/* scroll channel names? */
@@ -33,8 +40,16 @@ extern struct _Config {
 
 	float        scrollstep;		/* scroll mouse step adjustment */
 	char        *osd_color;			/* osd color */
+
+	char        *exclude_channel[SOUND_MIXER_NRDEVICES + 1];	/* Devices to exclude from GUI's list */
 } config;
 
+/* Current version of WMixer */
+#define VERSION "3.0"
+
+/* Sets configuration from command line */
+void parse_cli_options(int argc, char **argv);
+
 /* Read configuration from file */
 void config_read(void);
 
diff --git a/wmix.c b/wmix.c
index 331c3b9..94b3422 100644
--- a/wmix.c
+++ b/wmix.c
@@ -39,11 +39,8 @@
 #include "include/ui_x.h"
 #include "include/config.h"
 
-#define VERSION "3.0"
 
 static Display *display;
-static char *display_name = NULL;
-static char *mixer_device = NULL;
 static bool button_pressed = false;
 static bool slider_pressed = false;
 static double prev_button_press_time = 0.0;
@@ -53,69 +50,13 @@ static float display_width;
 static int mouse_drag_home_x;
 static int mouse_drag_home_y;
 static int idle_loop;
-static bool verbose;
-static char *exclude[SOUND_MIXER_NRDEVICES];
 
 /* local stuff */
-static void parse_cli_options(int argc, char **argv);
 static void signal_catch(int sig);
 static void button_press_event(XButtonEvent *event);
 static void button_release_event(XButtonEvent *event);
 static void motion_event(XMotionEvent *event);
 
-#define HELP_TEXT \
-	"WMixer " VERSION " by timecop at japan.co.jp + skunk at mit.edu\n" \
-	"usage:\n" \
-	"  -d <dsp>  connect to remote X display\n" \
-	"  -f <file> parse this config [~/.wmixrc]\n" \
-	"  -m <dev>  mixer device [/dev/mixer]\n" \
-	"  -h        print this help\n" \
-	"  -v        verbose -> id, long name, name\n" \
-	"  -e <name> exclude channel, can be used many times\n" \
-
-static void parse_cli_options(int argc, char **argv)
-{
-    int opt;
-    int count_exclude = 0 ;
-    verbose = false ;
-
-    while ((opt = getopt(argc, argv, "d:f:hm:ve:")) != EOF) {
-	switch (opt) {
-	    case 'd':
-		if (optarg != NULL)
-		    display_name = strdup(optarg);
-		break;
-	    case 'm':
-		if (optarg != NULL)
-		    mixer_device = strdup(optarg);
-		break;
-	    case 'f':
-		if (optarg != NULL)
-		    if (config.file != NULL)
-			free(config.file);
-		    config.file = strdup(optarg);
-		break;
-	    case 'h':
-		fputs(HELP_TEXT, stdout);
-		exit(0);
-		break;
-   	    case 'v':
-	        verbose = true;
-		break;
-   	    case 'e':
-		if (count_exclude < SOUND_MIXER_NRDEVICES) {
-		    exclude[count_exclude] = strdup(optarg);
-		    /* printf("exclude : %s\n", exclude[count_exclude]); */
-		    count_exclude++;
-		} else
-		    fprintf(stderr, "Warning: You can't exclude this many channels\n");
-		break;
-	    default:
-		break;
-	}
-    }
-    exclude[count_exclude] = NULL ;
-}
 
 int main(int argc, char **argv)
 {
@@ -143,18 +84,18 @@ int main(int argc, char **argv)
     parse_cli_options(argc, argv);
     config_read();
 
-    if (mixer_device == NULL)
-	mixer_device = "/dev/mixer";
+    if (config.mixer_device == NULL)
+	config.mixer_device = "/dev/mixer";
 
-    mixer_init(mixer_device, verbose, (const char **)exclude);
+    mixer_init(config.mixer_device, config.verbose, (const char **)config.exclude_channel);
     mixer_set_channel(0);
 
-    display = XOpenDisplay(display_name);
+    display = XOpenDisplay(config.display_name);
     if (display == NULL) {
 	const char *name;
 
-	if (display_name) {
-	    name = display_name;
+	if (config.display_name) {
+	    name = config.display_name;
 	} else {
 	    name = getenv("DISPLAY");
 	    if (name == NULL) {

-- 
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