* Christmas edition *; fixed irc /os command; small cleanup in fd.c; improvements...
[ZeXOS.git] / apps / wm / config.c
blobe7dbe16029b9a599f30b3b8147476db15e3937f3
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include "config.h"
27 config_t *cfg;
29 void config_set (char *variable, char *value)
31 puts ("config -> ");
32 puts (variable);
33 puts (" : ");
34 puts (value);
35 puts ("\n");
37 if (!strcmp (variable, "wm_mouse"))
38 cfg->mouse = atoi (value);
41 void config_parse (char *cfgfile)
43 unsigned i = 0, y = strlen (cfgfile), z = 0;
44 unsigned a = 0;
46 while (i < y) {
47 if (cfgfile[i] == '\n') {
48 char var[16];
49 char val[32];
51 a = 0;
53 while (a < 16) {
54 if (cfgfile[a+z] == ' ')
55 break;
57 a ++;
60 if (a >= 15)
61 continue;
63 memcpy (var, cfgfile+z, a);
64 var[a] = '\0';
66 a ++;
68 memcpy (val, cfgfile+z+a, i-z-a);
69 val[i-z-a] = '\0';
71 config_set (var, val);
73 i ++;
75 z = i;
78 i ++;
82 unsigned init_config ()
84 char *cfgfile = (char *) malloc (sizeof (char) * 2048);
86 if (!cfgfile)
87 return 0;
89 // html web page
90 int fd = open ("config", O_RDONLY);
92 if (!fd) {
93 puts ("error -> file 'config' not found\n");
94 return 0;
97 if (!read (fd, cfgfile, 2048)) {
98 puts ("error -> something was wrong !\n");
99 return 0;
102 cfgfile[2048] = '\0';
104 cfg = (config_t *) malloc (sizeof (config_t));
106 if (!cfg)
107 return 0;
109 config_parse (cfgfile);
111 return 1;