diff -r d820a6f3ec16 -r 873786a20a61 lib/rdconfig.c --- a/lib/rdconfig.c Mon May 05 10:33:26 2014 +0200 +++ b/lib/rdconfig.c Mon May 05 13:49:53 2014 +0200 @@ -35,6 +35,7 @@ static int getstr(char **); static int getint(char **); static int getw1(char **); +static int getrcs(char **); //static int getbyt(char **); //static int gethex(char **); @@ -51,6 +52,9 @@ #ifdef HAVE_WIRINGPI_H {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, + {(char *)"rx433", getint, (char **)&Config.rx433}, + {(char *)"tx433", getint, (char **)&Config.tx433}, + {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, #endif {NULL, NULL, NULL} }; @@ -60,6 +64,7 @@ void killconfig(void) { w1_therm *tmp1, *old1; + rc_switch *tmp2, *old2; if (Config.name) free(Config.name); @@ -85,12 +90,27 @@ #ifdef HAVE_WIRINGPI_H Config.lcd_cols = 16; Config.lcd_rows = 2; + Config.rx433 = -1; + Config.tx433 = -1; + + for (tmp2 = Config.rcswitch; tmp2; tmp2 = old2) { + old2 = tmp2->next; + if (tmp2->address) + free(tmp2->address); + tmp2->address = NULL; + if (tmp2->alias) + free(tmp2->alias); + tmp2->alias = NULL; + free(tmp2); + } + Config.rcswitch = NULL; + #endif } -int rdconfig(void) +int rdconfig(char *config) { char buf[256], *p; FILE *fp; @@ -99,14 +119,30 @@ killconfig(); /* - * Get config from the system path + * Search config file */ - mypath = xstrcpy((char *)STR(ETCDIR)); - mypath = xstrcat(mypath, (char *)"/mbsepi-apps.conf"); - + mypath = xstrcpy(getenv((char *)"HOME")); + mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); + mypath = xstrcat(mypath, config); if ((fp = fopen(mypath, "r")) == NULL) { - syslog(LOG_NOTICE, "rdconfig: could not open %s", mypath); - return 1; + /* + * Not in the users home directory + */ + free(mypath); + mypath = xstrcpy((char *)"/etc/mbsepi-apps/"); + mypath = xstrcat(mypath, config); + if ((fp = fopen(mypath, "r")) == NULL) { + /* + * Try /usr/local/etc + */ + free(mypath); + mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/"); + mypath = xstrcat(mypath, config); + if ((fp = fopen(mypath, "r")) == NULL) { + syslog(LOG_NOTICE, "rdconfig: could not open %s", mypath); + return 1; + } + } } linecnt = 0; @@ -234,6 +270,46 @@ +static int getrcs(char **dest) +{ + char *p, *q = NULL, *r = NULL; + rc_switch **tmpm; + + 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'; + if (debug) + syslog(LOG_NOTICE, "rdconfig: getrcs: %s(%d): %s %s", mypath, linecnt, v, p); + } + + for (tmpm = (rc_switch**)dest; *tmpm; tmpm=&((*tmpm)->next)); + (*tmpm) = (rc_switch *) xmalloc(sizeof(rc_switch)); + (*tmpm)->next = NULL; + (*tmpm)->address = xstrcpy(v); + (*tmpm)->alias = xstrcpy(p); + + return 0; +} + + + /* static int getbyt(char **dest) {