summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-06-01 18:58:45 -0700
committerJohn Denker <jsd@av8n.com>2012-06-01 18:58:45 -0700
commitb732a73bc773789894466b0e5320b2f1fe42c7e9 (patch)
tree385358983f064a1f10a5080b33a3ba13010886db /commands.c
parent634d365a03cb0581a062cd3cf4db9ae69f1cde26 (diff)
original, as downloaded from http://www.qmail.org/netqmail-1.06.tar.gz
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/commands.c b/commands.c
new file mode 100644
index 0000000..b0d3f61
--- /dev/null
+++ b/commands.c
@@ -0,0 +1,40 @@
+#include "commands.h"
+#include "substdio.h"
+#include "stralloc.h"
+#include "str.h"
+#include "case.h"
+
+static stralloc cmd = {0};
+
+int commands(ss,c)
+substdio *ss;
+struct commands *c;
+{
+ int i;
+ char *arg;
+
+ for (;;) {
+ if (!stralloc_copys(&cmd,"")) return -1;
+
+ for (;;) {
+ if (!stralloc_readyplus(&cmd,1)) return -1;
+ i = substdio_get(ss,cmd.s + cmd.len,1);
+ if (i != 1) return i;
+ if (cmd.s[cmd.len] == '\n') break;
+ ++cmd.len;
+ }
+
+ if (cmd.len > 0) if (cmd.s[cmd.len - 1] == '\r') --cmd.len;
+
+ cmd.s[cmd.len] = 0;
+
+ i = str_chr(cmd.s,' ');
+ arg = cmd.s + i;
+ while (*arg == ' ') ++arg;
+ cmd.s[i] = 0;
+
+ for (i = 0;c[i].text;++i) if (case_equals(c[i].text,cmd.s)) break;
+ c[i].fun(arg);
+ if (c[i].flush) c[i].flush();
+ }
+}