thermferm/rdconfig.c

Mon, 26 May 2014 23:25:48 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 26 May 2014 23:25:48 +0200
changeset 54
c06190a58f22
parent 53
37623517e0ef
child 55
11d7cc3bdf31
permissions
-rw-r--r--

More configuration changes. Writing settings implemented.

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

mercurial