lib/rdconfig.c

changeset 9
91218bc77abc
parent 8
e584bc0177df
child 17
b802305046dc
--- a/lib/rdconfig.c	Wed Apr 23 17:19:00 2014 +0200
+++ b/lib/rdconfig.c	Wed Apr 23 21:17:44 2014 +0200
@@ -34,6 +34,7 @@
 
 static int getstr(char **);
 static int getint(char **);
+static int getw1(char **);
 //static int getbyt(char **);
 //static int gethex(char **);
 
@@ -46,6 +47,7 @@
 key_list keytab[] = {
     {(char *)"mosq_host",	getstr,		&Config.mosq_host},
     {(char *)"mosq_port",	getint,		(char **)&Config.mosq_port},
+    {(char *)"w1therm",		getw1,		(char **)&Config.w1therms},
     {NULL,			NULL,		NULL}
 };
 
@@ -53,6 +55,8 @@
 
 void killconfig(void)
 {
+    w1_therm	*tmp1, *old1;
+
     if (Config.name)
 	free(Config.name);
     Config.name = NULL;
@@ -61,6 +65,18 @@
 	free(Config.mosq_host);
     Config.mosq_host= (char *)"localhost";
     Config.mosq_port = 1883;
+
+    for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
+	old1 = tmp1->next;
+	if (tmp1->master)
+	    free(tmp1->master);
+	if (tmp1->name)
+	    free(tmp1->name);
+	if (tmp1->alias)
+	    free(tmp1->alias);
+	free(tmp1);
+    }
+    Config.w1therms = NULL;
 }
 
 
@@ -158,6 +174,57 @@
 }
 
 
+
+static int getw1(char **dest)
+{
+    char	*p, *q = NULL, *r = NULL;
+    w1_therm	**tmpm;
+    int		rc = 0, tmpp;
+
+    for (p = v; *p && !isspace(*p); p++);
+    if (*p)
+	*p++ = '\0';
+    while (*p && isspace(*p))
+	p++;
+    if (*p == '\0') {
+	syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt);
+	return 1;
+    }
+
+    for (q = p; *q && !isspace(*q); q++);
+    if (*q && isspace(*q)) {
+	if (*q)
+	    *q++ = '\0';
+	while (*q && isspace(*q))
+	    q++;
+
+	for (r = q; *r && !isspace(*r); r++);
+	if (*r)
+	    *r++ = '\0';
+	rc = sscanf(p, "%d", &tmpp);
+	if (rc != 1) {
+	    syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s is not a integer value", mypath, linecnt, p);
+	    return 1;
+	}
+	if (debug)
+	    syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s %d %s %s", mypath, linecnt, v, tmpp, q, r);
+    }
+
+    for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next));
+    (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm));
+    (*tmpm)->next = NULL;
+    (*tmpm)->master = xstrcpy(v);
+    (*tmpm)->bus = tmpp;
+    (*tmpm)->name = xstrcpy(q);
+    (*tmpm)->alias = xstrcpy(r);
+    (*tmpm)->present = 0;
+    (*tmpm)->lastval = 0;
+
+    return 0;
+}
+
+
+
 /*
 static int getbyt(char **dest)
 {

mercurial