New config. file parsing
The "set", "alias" and "bind" keywords can now be used in config files.
--- a/mcabber/src/main.c Mon Jul 18 18:57:50 2005 +0100
+++ b/mcabber/src/main.c Mon Jul 18 20:02:38 2005 +0100
@@ -178,7 +178,7 @@
int optval, optval2;
int key;
unsigned int ping;
- int ret = 0;
+ int ret;
unsigned int refresh = 0;
credits();
@@ -209,13 +209,19 @@
}
}
+ /* Initialize commands system */
+ cmd_init();
+
if (configFile)
ut_WriteLog("Setting config file: %s\n", configFile);
/* Parsing config file... */
ut_WriteLog("Parsing config file...\n");
- cfg_file(configFile);
+ ret = cfg_file(configFile);
if (configFile) g_free(configFile);
+ /* Leave if there was an error in the config. file */
+ if (ret)
+ exit(EXIT_FAILURE);
optstring = settings_opt_get("debug");
if (optstring) ut_InitDebug(1, optstring);
@@ -256,13 +262,10 @@
else
scr_LogPrint("Can't connect: no password supplied");
- /* Initialize commands system */
- cmd_init();
-
ut_WriteLog("Entering into main loop...\n\n");
ut_WriteLog("Ready to send/receive messages...\n");
- while (ret != 255) {
+ for (ret = 0 ; ret != 255 ; ) {
key = scr_Getch();
/* The refresh is really an ugly hack, but we need to call doupdate()
--- a/mcabber/src/parsecfg.c Mon Jul 18 18:57:50 2005 +0100
+++ b/mcabber/src/parsecfg.c Mon Jul 18 20:02:38 2005 +0100
@@ -6,7 +6,9 @@
#include <glib.h>
#include "settings.h"
+#include "commands.h"
#include "utils.h"
+#include "screen.h"
// cfg_file(filename)
// Read and parse config file "filename". If filename is NULL,
@@ -18,14 +20,16 @@
FILE *fp;
char *buf;
char *line;
- char *value;
+ unsigned int ln = 0;
+ int err = 0;
if (!filename) {
// Use default config file locations
char *home = getenv("HOME");
if (!home) {
ut_WriteLog("Can't find home dir!\n");
- exit(EXIT_FAILURE);
+ fprintf(stderr, "Can't find home dir!\n");
+ return -1;
}
filename = g_new(char, strlen(home)+24);
sprintf(filename, "%s/.mcabber/mcabberrc", home);
@@ -34,48 +38,51 @@
sprintf(filename, "%s/.mcabberrc", home);
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "Cannot open config file!\n");
- exit(EXIT_FAILURE);
+ return -1;
}
}
g_free(filename);
}
else if ((fp = fopen(filename, "r")) == NULL) {
perror("fopen (parsecfg.c:46)");
- exit(EXIT_FAILURE);
+ return -1;
}
- buf = g_new(char, 256);
+ // This should be fully rewritten...
+ buf = g_new(char, 512);
- while (fgets(buf, 256, fp) != NULL) {
- line = buf;
+ while (fgets(buf+1, 511, fp) != NULL) {
+ line = buf+1;
+ ln++;
- while (isspace((int) *line))
+ while (isspace(*line))
line++;
- while ((strlen(line) > 0)
- && isspace((int) line[strlen(line) - 1]))
+ while ((strlen(line) > 0) && isspace((int) line[strlen(line) - 1]))
line[strlen(line) - 1] = '\0';
if ((*line == '\n') || (*line == '\0') || (*line == '#'))
continue;
if ((strchr(line, '=') != NULL)) {
- value = strchr(line, '=');
- *value = '\0';
- value++;
-
- while (isspace((int) *value))
- value++;
-
- while ((strlen(line) > 0)
- && isspace((int) line[strlen(line) - 1]))
+ while ((strlen(line) > 0) && isspace(line[strlen(line) - 1]))
line[strlen(line) - 1] = '\0';
- settings_set(SETTINGS_TYPE_OPTION, line, value);
- continue;
+ if (strncmp(line, "set ", 4) &&
+ strncmp(line, "bind ", 5) &&
+ strncmp(line, "alias ", 6)) {
+ scr_LogPrint("Error in configuration file (l. %d)", ln);
+ err++;
+ continue;
+ }
+ *(--line) = '/';
+ process_command(line);
+ } else {
+ scr_LogPrint("Error in configuration file (l. %d)", ln);
+ err++;
}
- fprintf(stderr, "CFG: orphaned line \"%s\"\n", line);
}
g_free(buf);
- return 1;
+ fclose(fp);
+ return err;
}