lib/rdconfig.c

changeset 8
e584bc0177df
parent 7
d74b26b2f217
child 9
91218bc77abc
--- a/lib/rdconfig.c	Wed Apr 23 14:25:09 2014 +0200
+++ b/lib/rdconfig.c	Wed Apr 23 17:19:00 2014 +0200
@@ -23,19 +23,11 @@
 #include "../config.h"
 #include "mbselib.h"
 
-// #define	DEBUG_CONFIG	1
 
-
-extern int	DebugEmu;
-extern char	*Private_Path;
-
+bool		debug = FALSE;
 static char	*mypath;
 static char	*k, *v;
 static int	linecnt = 0;
-
-extern int	MustSave;
-
-
 sys_config	Config;			/* System configuration		*/
 
 
@@ -45,14 +37,14 @@
 //static int getbyt(char **);
 //static int gethex(char **);
 
-
+#define XSTR(x) #x
+#define STR(x) XSTR(x)
 
 /*
  * System configuration table
  */
 key_list keytab[] = {
-    {(char *)"name",		getstr,		&Config.name},
-    {(char *)"mosq_server",	getstr,		&Config.mosq_server},
+    {(char *)"mosq_host",	getstr,		&Config.mosq_host},
     {(char *)"mosq_port",	getint,		(char **)&Config.mosq_port},
     {NULL,			NULL,		NULL}
 };
@@ -65,47 +57,15 @@
 	free(Config.name);
     Config.name = NULL;
 
+    if (Config.mosq_host)
+	free(Config.mosq_host);
+    Config.mosq_host= (char *)"localhost";
+    Config.mosq_port = 1883;
 }
 
 
 
-int wrconfig(char *machine)
-{
-    FILE	*fp;
-
-    /*
-     * Get config from the system path
-     */
-    mypath = xstrcpy(Private_Path);
-    mypath = xstrcat(mypath, (char *)"/data/machines/");
-    mypath = xstrcat(mypath, machine);
-    mypath = xstrcat(mypath, (char *)".conf");
-
-    if ((fp = fopen(mypath, "w")) == NULL) {
-//	Log_Msg("[rdconfig] could not rewrite %s", mypath);
-	return 1;
-    }
-
-    fprintf(fp, "# Configuration file for EC65K %s\n", VERSION);
-    fprintf(fp, "# Machine: `%s'\n", machine);
-    fprintf(fp, "#\n");
-//    fprintf(fp, "description        %s\n", Config.description);
-//    fprintf(fp, "\n");
-//    fprintf(fp, "# 65(C)02 CPU\n");
-//    fprintf(fp, "#\n");
-
-    fprintf(fp, "# End of generated configuration\n");
-    fclose(fp);
-    free(mypath);
-    mypath = NULL;
-    MustSave = FALSE;
-
-    return 0;
-}
-
-
-
-int rdconfig(char *machine) 
+int rdconfig(void) 
 {
     char	buf[256], *p;
     FILE	*fp;
@@ -116,13 +76,11 @@
     /*
      * Get config from the system path
      */
-    mypath = xstrcpy(Private_Path);
-    mypath = xstrcat(mypath, (char *)"/data/machines/");
-    mypath = xstrcat(mypath, machine);
-    mypath = xstrcat(mypath, (char *)".conf");
+    mypath = xstrcpy((char *)STR(ETCDIR));
+    mypath = xstrcat(mypath, (char *)"/mbsepi-apps.conf");
 
     if ((fp = fopen(mypath, "r")) == NULL) {
-//	Log_Msg("[rdconfig] could not open %s", mypath);
+	syslog(LOG_NOTICE, "rdconfig: could not open %s", mypath);
 	return 1;
     }
 
@@ -130,7 +88,7 @@
     while (fgets(buf, sizeof(buf) -1, fp)) {
 	linecnt++;
 	if (*(p = buf + strlen(buf) -1) != '\n') {
-//	    Log_Msg("[rdconfig] %s(%d): \"%s\" - line too long", mypath, linecnt, buf);
+	    syslog(LOG_NOTICE, "rdconfig: %s(%d): \"%s\" - line too long", mypath, linecnt, buf);
 	    rc = 1;
 	    break;
 	}
@@ -157,7 +115,7 @@
 		break;
 
 	if (keytab[i].key == NULL) {
-//	    Log_Msg("[rdconfig] %s(%d): %s %s - unknown keyword", mypath, linecnt, S(k), S(v));
+	    syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - unknown keyword", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
 	    rc = 1;
 	    break;
 	} else if ((keytab[i].prc(keytab[i].dest))) {
@@ -170,7 +128,6 @@
 
     free(mypath);
     mypath = NULL;
-    MustSave = FALSE;
 
     return rc;
 }
@@ -179,7 +136,9 @@
 
 static int getstr(char **dest)
 {
-//    Log_Msg("[rdconfig] getstr: %s(%d): %s %s", mypath, linecnt, S(k), S(v));
+    if (debug)
+	syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
+
     *dest = xstrcpy(v);
     return 0;
 }
@@ -188,10 +147,12 @@
 
 static int getint(char **dest)
 {
-//    Log_Msg("[rdconfig] getint: %s(%d): %s %s", mypath, linecnt, k, v);
-//    if (strspn(v,"0123456789") != strlen(v)) 
-//	Log_Msg("[rdconfig] %s(%d): %s %s - bad numeric", mypath, linecnt, S(k), S(v));
-//    else 
+    if (debug)
+	syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
+
+    if (strspn(v,"0123456789") != strlen(v)) 
+	syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
+    else 
 	*((int*)dest)=atoi(v);
     return 0;
 }

mercurial