summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-19 21:20:27 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-19 21:20:27 +0000
commit85135221f08d2e2d54269c8b8fc4325833c2fe9d (patch)
tree60fc49fda53deff487ce4f2a3db6f4a6ad0d9ef0
parent0695db3889928969d4281859bbe676d7c8605f49 (diff)
Handle commented lines.
-rw-r--r--cfg.c16
-rw-r--r--cmd-command-prompt.c4
-rw-r--r--cmd-string.c10
3 files changed, 16 insertions, 14 deletions
diff --git a/cfg.c b/cfg.c
index 7bb4b488..be55c51d 100644
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.10 2008-06-19 21:13:56 nicm Exp $ */
+/* $Id: cfg.c,v 1.11 2008-06-19 21:20:24 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -78,17 +78,11 @@ load_cfg(const char *path, char **cause)
}
n++;
- /* Trim spaces from start and end. */
- while (*buf != '\0' && (*buf == ' ' || *buf == '\t'))
- *buf++ = '\0';
- len = strlen(buf);
- while (len > 0 && (buf[len - 1] == ' ' || buf[len - 1] == '\t'))
- buf[--len] = '\0';
- if (*buf == '\0')
- continue;
-
- if ((cmd = cmd_string_parse(buf, cause)) == NULL)
+ if ((cmd = cmd_string_parse(buf, cause)) == NULL) {
+ if (*cause == NULL)
+ continue;
goto error;
+ }
cfg_cause = NULL;
ctx.msgdata = NULL;
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index 96ca7199..2a93d730 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-command-prompt.c,v 1.1 2008-06-19 20:45:20 nicm Exp $ */
+/* $Id: cmd-command-prompt.c,v 1.2 2008-06-19 21:20:25 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -73,6 +73,8 @@ cmd_command_prompt_callback(void *data, char *s)
return;
if ((cmd = cmd_string_parse(s, &cause)) == NULL) {
+ if (cause == NULL)
+ return;
*cause = toupper((u_char) *cause);
server_set_client_message(c, cause);
xfree(cause);
diff --git a/cmd-string.c b/cmd-string.c
index 33496222..e28cef2d 100644
--- a/cmd-string.c
+++ b/cmd-string.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-string.c,v 1.2 2008-06-19 21:13:56 nicm Exp $ */
+/* $Id: cmd-string.c,v 1.3 2008-06-19 21:20:27 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,6 +39,10 @@ cmd_string_getc(const char *s, size_t *p)
return (s[(*p)++]);
}
+/*
+ * Parse command string. Return command or NULL on error. If returning NULL,
+ * cause is error string, or NULL for empty command.
+ */
struct cmd *
cmd_string_parse(const char *s, char **cause)
{
@@ -56,6 +60,8 @@ cmd_string_parse(const char *s, char **cause)
cmd = NULL;
+ *cause = NULL;
+
p = 0;
for (;;) {
ch = cmd_string_getc(s, &p);
@@ -94,7 +100,7 @@ cmd_string_parse(const char *s, char **cause)
if (ch != EOF)
break;
if (argc == 0)
- goto error;
+ goto out;
cmd = cmd_parse(argc, argv, cause);
goto out;