[Pkg-wmaker-commits] [wmix] 17/44: wmix: created new file config.c to contain configuration related stuff
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 733b9024617134cce6363259fcf19b7cfcebbd70
Author: Christophe CURIS <christophe.curis at free.fr>
Date: Sat Jun 7 21:21:45 2014 +0200
wmix: created new file config.c to contain configuration related stuff
Management of the configuration is split in many places, the goal is to
regroup stuff together, starting with the loading from file stuff.
Signed-off-by: Christophe CURIS <christophe.curis at free.fr>
---
Makefile | 2 +-
config.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/common.h | 13 --------
include/config.h | 41 ++++++++++++++++++++++++
include/misc.h | 1 -
misc.c | 56 ---------------------------------
ui_x.c | 4 +--
wmix.c | 2 +-
8 files changed, 140 insertions(+), 74 deletions(-)
diff --git a/Makefile b/Makefile
index ffc1d5f..f7a44b7 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CC = gcc
CFLAGS = -O3 -W -Wall
LDFLAGS = -L/usr/X11R6/lib
LIBS = -lXpm -lXext -lX11 -lm
-OBJECTS = misc.o mixer-oss.o ui_x.o wmix.o
+OBJECTS = misc.o config.o mixer-oss.o ui_x.o wmix.o
# where to install this program (also for packaging stuff)
PREFIX = /usr/local
diff --git a/config.c b/config.c
new file mode 100644
index 0000000..9823949
--- /dev/null
+++ b/config.c
@@ -0,0 +1,95 @@
+/* WMix -- a mixer using the OSS mixer API.
+ * Copyright (C) 2014 Christophe CURIS for the WindowMaker Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+/*
+ * config.c: functions related to loading the configuration from file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/soundcard.h>
+
+#include "include/common.h"
+#include "include/config.h"
+
+
+/* The global configuration */
+struct _Config config;
+
+
+/*
+ * Read configuration from a file
+ *
+ * The file name is taken from CLI if available, of falls back to
+ * a default name.
+ */
+void config_read(void)
+{
+ FILE *fp;
+ char buf[512];
+ char *ptr;
+
+ if (config.file == NULL)
+ return;
+
+ fp = fopen(config.file, "r");
+ if (!fp)
+ return;
+
+ while (fgets(buf, 512, fp)) {
+ if ((ptr = strstr(buf, "mousewheel="))) {
+ ptr += 11;
+ config.mousewheel = atoi(ptr);
+ }
+ if ((ptr = strstr(buf, "scrolltext="))) {
+ ptr += 11;
+ config.scrolltext = atoi(ptr);
+ }
+ if ((ptr = strstr(buf, "osd="))) {
+ ptr += 4;
+ config.osd = atoi(ptr);
+ }
+ if ((ptr = strstr(buf, "osdcolor="))) {
+ char *end;
+ ptr += 9;
+ end = strchr(ptr, '\n');
+ ptr[end - ptr] = '\0';
+ if (config.osd_color)
+ free(config.osd_color);
+ config.osd_color = strdup(ptr);
+ }
+ if ((ptr = strstr(buf, "wheelstep="))) {
+ ptr += 10;
+ /* detect old style config */
+ if (atoi(ptr) > 1)
+ config.scrollstep = (float)atoi(ptr) / 100.0;
+ else
+ config.scrollstep = atof(ptr);
+ }
+ if ((ptr = strstr(buf, "wheelbtn1="))) {
+ ptr += 10;
+ config.wheel_button_up = atoi(ptr);
+ }
+ if ((ptr = strstr(buf, "wheelbtn2="))) {
+ ptr += 10;
+ config.wheel_button_down = atoi(ptr);
+ }
+ }
+ fclose(fp);
+}
diff --git a/include/common.h b/include/common.h
index 71aa8e6..4fdc857 100644
--- a/include/common.h
+++ b/include/common.h
@@ -35,16 +35,3 @@ typedef unsigned int bool;
#define MAX_DOUBLE_CLICK_TIME 0.5
#define BUTTON_WHEEL_UP 4
#define BUTTON_WHEEL_DOWN 5
-
-typedef struct _Config Config;
-
-struct _Config {
- char *file; /* full path to config file name */
- unsigned int osd : 1; /* show OSD? */
- unsigned int mousewheel : 1; /* mousewheel enabled? */
- unsigned int scrolltext : 1; /* scroll channel names? */
- unsigned int wheel_button_up; /* up button */
- unsigned int wheel_button_down; /* down button */
- float scrollstep; /* scroll mouse step adjustment */
- char *osd_color; /* osd color */
-};
diff --git a/include/config.h b/include/config.h
new file mode 100644
index 0000000..5d84ae9
--- /dev/null
+++ b/include/config.h
@@ -0,0 +1,41 @@
+/* WMix -- a mixer using the OSS mixer API
+ * Copyright (C)2014 Christophe CURIS for the WindowMaker Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+/* include/config.h: functions related to setting the configuration */
+
+#ifndef WMIX_CONFIG_H
+#define WMIX_CONFIG_H
+
+/* Global Configuration */
+extern struct _Config {
+ char *file; /* full path to config file name */
+
+ unsigned int osd : 1; /* show OSD? */
+ unsigned int mousewheel : 1; /* mousewheel enabled? */
+ unsigned int scrolltext : 1; /* scroll channel names? */
+
+ unsigned int wheel_button_up; /* up button */
+ unsigned int wheel_button_down; /* down button */
+
+ float scrollstep; /* scroll mouse step adjustment */
+ char *osd_color; /* osd color */
+} config;
+
+/* Read configuration from file */
+void config_read(void);
+
+#endif /* WMIX_CONFIG_H */
diff --git a/include/misc.h b/include/misc.h
index 7794111..0ad4d87 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -23,5 +23,4 @@ void vb_to_lr (float volume, float balance, float *left, float *right);
double get_current_time(void);
void add_region (int index, int x, int y, int width, int height);
int check_region (int x, int y);
-void config_read (void);
void create_pid_file (void);
diff --git a/misc.c b/misc.c
index 544a6e9..9120bd9 100644
--- a/misc.c
+++ b/misc.c
@@ -42,7 +42,6 @@ typedef struct {
} MRegion;
MRegion mr[16];
-extern Config config;
/* Converts separate left and right channel volumes (each in [0, 1]) to
* volume and balance values. (Volume is in [0, 1], balance is in [-1, 1])
@@ -109,61 +108,6 @@ int check_region(int x, int y)
return (i - 1);
}
-void config_read(void)
-{
- FILE *fp;
- char buf[512];
- char *ptr;
-
- if (config.file == NULL)
- return;
-
- fp = fopen(config.file, "r");
- if (!fp)
- return;
-
- while (fgets(buf, 512, fp)) {
- if ((ptr = strstr(buf, "mousewheel="))) {
- ptr += 11;
- config.mousewheel = atoi(ptr);
- }
- if ((ptr = strstr(buf, "scrolltext="))) {
- ptr += 11;
- config.scrolltext = atoi(ptr);
- }
- if ((ptr = strstr(buf, "osd="))) {
- ptr += 4;
- config.osd = atoi(ptr);
- }
- if ((ptr = strstr(buf, "osdcolor="))) {
- char *end;
- ptr += 9;
- end = strchr(ptr, '\n');
- ptr[end - ptr] = '\0';
- if (config.osd_color)
- free(config.osd_color);
- config.osd_color = strdup(ptr);
- }
- if ((ptr = strstr(buf, "wheelstep="))) {
- ptr += 10;
- /* detect old style config */
- if (atoi(ptr) > 1)
- config.scrollstep = (float)atoi(ptr) / 100.0;
- else
- config.scrollstep = atof(ptr);
- }
- if ((ptr = strstr(buf, "wheelbtn1="))) {
- ptr += 10;
- config.wheel_button_up = atoi(ptr);
- }
- if ((ptr = strstr(buf, "wheelbtn2="))) {
- ptr += 10;
- config.wheel_button_down = atoi(ptr);
- }
- }
- fclose(fp);
-}
-
/* handle writing PID file, silently ignore if we can't do it */
void create_pid_file(void)
{
diff --git a/ui_x.c b/ui_x.c
index 2b993bf..31a818a 100644
--- a/ui_x.c
+++ b/ui_x.c
@@ -44,6 +44,8 @@
#include "include/misc.h"
#include "include/mixer.h"
#include "include/ui_x.h"
+#include "include/config.h"
+
#ifndef PI
#define PI M_PI
@@ -72,8 +74,6 @@ struct _Dockapp {
};
-extern Config config;
-
static Pixmap led_on_pixmap;
static Pixmap led_on_mask;
static Pixmap led_off_pixmap;
diff --git a/wmix.c b/wmix.c
index 84b1e42..331c3b9 100644
--- a/wmix.c
+++ b/wmix.c
@@ -37,6 +37,7 @@
#include "include/mixer.h"
#include "include/misc.h"
#include "include/ui_x.h"
+#include "include/config.h"
#define VERSION "3.0"
@@ -49,7 +50,6 @@ static double prev_button_press_time = 0.0;
static float display_height;
static float display_width;
-Config config;
static int mouse_drag_home_x;
static int mouse_drag_home_y;
static int idle_loop;
--
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