Handle commented lines.

This commit is contained in:
Nicholas Marriott 2008-06-19 21:20:27 +00:00
parent 0695db3889
commit 85135221f0
3 changed files with 16 additions and 14 deletions

14
cfg.c
View File

@ -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> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -78,17 +78,11 @@ load_cfg(const char *path, char **cause)
} }
n++; n++;
/* Trim spaces from start and end. */ if ((cmd = cmd_string_parse(buf, cause)) == NULL) {
while (*buf != '\0' && (*buf == ' ' || *buf == '\t')) if (*cause == NULL)
*buf++ = '\0';
len = strlen(buf);
while (len > 0 && (buf[len - 1] == ' ' || buf[len - 1] == '\t'))
buf[--len] = '\0';
if (*buf == '\0')
continue; continue;
if ((cmd = cmd_string_parse(buf, cause)) == NULL)
goto error; goto error;
}
cfg_cause = NULL; cfg_cause = NULL;
ctx.msgdata = NULL; ctx.msgdata = NULL;

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -73,6 +73,8 @@ cmd_command_prompt_callback(void *data, char *s)
return; return;
if ((cmd = cmd_string_parse(s, &cause)) == NULL) { if ((cmd = cmd_string_parse(s, &cause)) == NULL) {
if (cause == NULL)
return;
*cause = toupper((u_char) *cause); *cause = toupper((u_char) *cause);
server_set_client_message(c, cause); server_set_client_message(c, cause);
xfree(cause); xfree(cause);

View File

@ -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> * 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)++]); 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 * struct cmd *
cmd_string_parse(const char *s, char **cause) cmd_string_parse(const char *s, char **cause)
{ {
@ -56,6 +60,8 @@ cmd_string_parse(const char *s, char **cause)
cmd = NULL; cmd = NULL;
*cause = NULL;
p = 0; p = 0;
for (;;) { for (;;) {
ch = cmd_string_getc(s, &p); ch = cmd_string_getc(s, &p);
@ -94,7 +100,7 @@ cmd_string_parse(const char *s, char **cause)
if (ch != EOF) if (ch != EOF)
break; break;
if (argc == 0) if (argc == 0)
goto error; goto out;
cmd = cmd_parse(argc, argv, cause); cmd = cmd_parse(argc, argv, cause);
goto out; goto out;