mash/rdconfig.c

Sat, 12 Jul 2014 21:59:19 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 12 Jul 2014 21:59:19 +0200
changeset 103
99c47a8a61cb
child 143
54f9b5d39e4c
permissions
-rw-r--r--

Added the mash sourcecode, this does nothing useful yet.

103
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2014
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with EC-65K; see the file COPYING. If not, write to the Free
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "mash.h"
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 #include "xutil.h"
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 bool debug = FALSE;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 static char *mypath;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 static char *k, *v;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 static int linecnt = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 sys_config Config; /* System configuration */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 //static int getstr(char **);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 static int getint(char **);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 static int getw1(char **);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 //static int getuch(char **);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 //static int getfloat(char **);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 //static int getbyt(char **);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 //static int gethex(char **);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 #define XSTR(x) #x
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 #define STR(x) XSTR(x)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 * System configuration table
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 key_list keytab[] = {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 {(char *)"w1therm", getw1, (char **)&Config.w1therms},
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols},
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows},
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 {NULL, NULL, NULL}
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 };
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 void killconfig(void)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 w1_therm *tmp1, *old1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 if (Config.name)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 free(Config.name);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 Config.name = NULL;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 old1 = tmp1->next;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 if (tmp1->master)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 free(tmp1->master);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 if (tmp1->name)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 free(tmp1->name);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 if (tmp1->alias)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 free(tmp1->alias);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 free(tmp1);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 Config.w1therms = NULL;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 Config.my_port = 6554;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 Config.lcd_cols = 16;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 Config.lcd_rows = 2;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 int wrconfig(char *config)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 int rc = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 FILE *fp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 w1_therm *tmp1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 if (getenv((char *)"USER") == NULL) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 mypath = xstrcpy((char *)"/root");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 } else {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 mypath = xstrcpy(getenv((char *)"HOME"));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 mypath = xstrcat(mypath, config);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 if (debug)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 fprintf(stdout, "Writing %s\n", mypath);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 if ((fp = fopen(mypath, "w")) == NULL) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 syslog(LOG_NOTICE, "could not rewrite %s", mypath);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 return 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 fprintf(fp, "\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 fprintf(fp, "# LCD display\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 fprintf(fp, "#\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 fprintf(fp, "\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 fprintf(fp, "#\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 fprintf(fp, "# kwd master bus name alias\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 fprintf(fp, "\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 fprintf(fp, "# End of generated configuration\n");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 fclose(fp);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 syslog(LOG_NOTICE, "Written %s rc=%d", mypath, rc);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 free(mypath);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 mypath = NULL;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 return rc;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 int rdconfig(char *config)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 char buf[256], *p;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 FILE *fp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 int i, rc = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 killconfig();
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 syslog(LOG_NOTICE, "HOME='%s' USER='%s' LOGNAME='%s'", MBSE_SS(getenv((char *)"HOME")), MBSE_SS(getenv((char *)"USER")), MBSE_SS(getenv((char *)"LOGNAME")));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 * Search config file
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 if (getenv((char *)"USER") == NULL) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 mypath = xstrcpy((char *)"/root");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 } else {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 mypath = xstrcpy(getenv((char *)"HOME"));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 mypath = xstrcat(mypath, config);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 if ((fp = fopen(mypath, "r")) == NULL) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 * Not in the users home directory
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 free(mypath);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 mypath = xstrcpy((char *)"/etc/mbsepi-apps/");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 mypath = xstrcat(mypath, config);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 if ((fp = fopen(mypath, "r")) == NULL) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 * Try /usr/local/etc
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 free(mypath);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/");
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 mypath = xstrcat(mypath, config);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 if ((fp = fopen(mypath, "r")) == NULL) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 syslog(LOG_NOTICE, "rdconfig: could find %s", config);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 return 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 syslog(LOG_NOTICE, "rdconfig: using %s", mypath);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 linecnt = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 while (fgets(buf, sizeof(buf) -1, fp)) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 linecnt++;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 if (*(p = buf + strlen(buf) -1) != '\n') {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 syslog(LOG_NOTICE, "rdconfig: %s(%d): \"%s\" - line too long", mypath, linecnt, buf);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 rc = 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 break;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 *p-- = '\0';
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 while ((p >= buf) && isspace(*p))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 *p-- = '\0';
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 k = buf;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 while (*k && isspace(*k))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 k++;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 p = k;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 while (*p && !isspace(*p))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 p++;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 *p++='\0';
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 v = p;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 while (*v && isspace(*v))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 v++;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 if ((*k == '\0') || (*k == '#')) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 continue;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 for (i = 0; keytab[i].key; i++)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 if (strcasecmp(k,keytab[i].key) == 0)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 break;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 if (keytab[i].key == NULL) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - unknown keyword", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 rc = 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 break;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 } else if ((keytab[i].prc(keytab[i].dest))) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 rc = 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 break;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 fclose(fp);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 free(mypath);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 mypath = NULL;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 return rc;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 static int getstr(char **dest)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 if (debug)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 *dest = xstrcpy(v);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 return 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 static int getint(char **dest)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 if (debug)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 if (strspn(v,"0123456789") != strlen(v))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 else
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 *((int*)dest)=atoi(v);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 return 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 static int getw1(char **dest)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 char *p, *q = NULL, *r = NULL;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 w1_therm **tmpm;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 int rc = 0, tmpp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 for (p = v; *p && !isspace(*p); p++);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 if (*p)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 *p++ = '\0';
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 while (*p && isspace(*p))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 p++;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 if (*p == '\0') {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 return 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 for (q = p; *q && !isspace(*q); q++);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 if (*q && isspace(*q)) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 if (*q)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 *q++ = '\0';
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 while (*q && isspace(*q))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 q++;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 for (r = q; *r && !isspace(*r); r++);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 if (*r)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 *r++ = '\0';
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 rc = sscanf(p, "%d", &tmpp);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 if (rc != 1) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280 syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s is not a integer value", mypath, linecnt, p);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 return 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 if (debug)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s %d %s %s", mypath, linecnt, v, tmpp, q, r);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 (*tmpm)->next = NULL;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 (*tmpm)->master = xstrcpy(v);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 (*tmpm)->bus = tmpp;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 (*tmpm)->name = xstrcpy(q);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 (*tmpm)->alias = xstrcpy(r);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 (*tmpm)->present = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 (*tmpm)->lastval = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 (*tmpm)->update = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 return 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 static int getuch(char **dest)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 if (debug)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 syslog(LOG_NOTICE, "rdconfig: getuch: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 if (isalnum(v[0])) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 *((unsigned char*)dest) = v[0];
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 } else {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad character", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313 return 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 static int getfloat(char **dest)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 float val = 0.0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 int rc;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 if (debug)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 syslog(LOG_NOTICE, "rdconfig: getfloat: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 rc = sscanf(v, "%f", &val);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 if (rc != 1) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad float value", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 return 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 *((float*)dest) = val;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 return 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 static int getbyt(char **dest)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 if (strspn(v,"0123456789") != strlen(v))
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 Log_Msg("[rdconfig] %s(%d): %s %s - bad numeric", mypath, linecnt, S(k), S(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 else
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 *((Uint8*)dest)=atoi(v);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 return 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 /*
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 static int gethex(char **dest)
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 unsigned int val = 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 int rc;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 Log_Msg("[rdconfig] gethex: %s(%d): %s %s", mypath, linecnt, k, v);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 rc = sscanf(v, "%08x", &val);
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 if (rc != 1) {
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 Log_Msg("[rdconfig] %s(%d): %s %s - bad hex value", mypath, linecnt, S(k), S(v));
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 return 1;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 *((int*)dest) = val;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 return 0;
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365 }
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 */
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367
99c47a8a61cb Added the mash sourcecode, this does nothing useful yet.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368

mercurial