From 85135221f08d2e2d54269c8b8fc4325833c2fe9d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 19 Jun 2008 21:20:27 +0000 Subject: [PATCH] Handle commented lines. --- cfg.c | 16 +++++----------- cmd-command-prompt.c | 4 +++- cmd-string.c | 10 ++++++++-- 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 @@ -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 @@ -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 @@ -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;