wmix: created new file config.c to contain configuration related stuff
[dockapps.git] / wmix / config.c
blob9823949b33e8c1bfa3ff9d666db8f094fc86bbe7
1 /* WMix -- a mixer using the OSS mixer API.
2 * Copyright (C) 2014 Christophe CURIS for the WindowMaker Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * config.c: functions related to loading the configuration from file
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include <sys/soundcard.h>
28 #include "include/common.h"
29 #include "include/config.h"
32 /* The global configuration */
33 struct _Config config;
37 * Read configuration from a file
39 * The file name is taken from CLI if available, of falls back to
40 * a default name.
42 void config_read(void)
44 FILE *fp;
45 char buf[512];
46 char *ptr;
48 if (config.file == NULL)
49 return;
51 fp = fopen(config.file, "r");
52 if (!fp)
53 return;
55 while (fgets(buf, 512, fp)) {
56 if ((ptr = strstr(buf, "mousewheel="))) {
57 ptr += 11;
58 config.mousewheel = atoi(ptr);
60 if ((ptr = strstr(buf, "scrolltext="))) {
61 ptr += 11;
62 config.scrolltext = atoi(ptr);
64 if ((ptr = strstr(buf, "osd="))) {
65 ptr += 4;
66 config.osd = atoi(ptr);
68 if ((ptr = strstr(buf, "osdcolor="))) {
69 char *end;
70 ptr += 9;
71 end = strchr(ptr, '\n');
72 ptr[end - ptr] = '\0';
73 if (config.osd_color)
74 free(config.osd_color);
75 config.osd_color = strdup(ptr);
77 if ((ptr = strstr(buf, "wheelstep="))) {
78 ptr += 10;
79 /* detect old style config */
80 if (atoi(ptr) > 1)
81 config.scrollstep = (float)atoi(ptr) / 100.0;
82 else
83 config.scrollstep = atof(ptr);
85 if ((ptr = strstr(buf, "wheelbtn1="))) {
86 ptr += 10;
87 config.wheel_button_up = atoi(ptr);
89 if ((ptr = strstr(buf, "wheelbtn2="))) {
90 ptr += 10;
91 config.wheel_button_down = atoi(ptr);
94 fclose(fp);