diff options
| author | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
| commit | 69aec538b456402170dc723af417ba5c05389c32 (patch) | |
| tree | e6f34c543f17c6392447ea337b2e2868212424d1 /commands.c | |
| download | qmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2 qmail-69aec538b456402170dc723af417ba5c05389c32.zip | |
qmail 1.03 import
Diffstat (limited to 'commands.c')
| -rw-r--r-- | commands.c | 40 |
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 @@ | |||
| 1 | #include "commands.h" | ||
| 2 | #include "substdio.h" | ||
| 3 | #include "stralloc.h" | ||
| 4 | #include "str.h" | ||
| 5 | #include "case.h" | ||
| 6 | |||
| 7 | static stralloc cmd = {0}; | ||
| 8 | |||
| 9 | int commands(ss,c) | ||
| 10 | substdio *ss; | ||
| 11 | struct commands *c; | ||
| 12 | { | ||
| 13 | int i; | ||
| 14 | char *arg; | ||
| 15 | |||
| 16 | for (;;) { | ||
| 17 | if (!stralloc_copys(&cmd,"")) return -1; | ||
| 18 | |||
| 19 | for (;;) { | ||
| 20 | if (!stralloc_readyplus(&cmd,1)) return -1; | ||
| 21 | i = substdio_get(ss,cmd.s + cmd.len,1); | ||
| 22 | if (i != 1) return i; | ||
| 23 | if (cmd.s[cmd.len] == '\n') break; | ||
| 24 | ++cmd.len; | ||
| 25 | } | ||
| 26 | |||
| 27 | if (cmd.len > 0) if (cmd.s[cmd.len - 1] == '\r') --cmd.len; | ||
| 28 | |||
| 29 | cmd.s[cmd.len] = 0; | ||
| 30 | |||
| 31 | i = str_chr(cmd.s,' '); | ||
| 32 | arg = cmd.s + i; | ||
| 33 | while (*arg == ' ') ++arg; | ||
| 34 | cmd.s[i] = 0; | ||
| 35 | |||
| 36 | for (i = 0;c[i].text;++i) if (case_equals(c[i].text,cmd.s)) break; | ||
| 37 | c[i].fun(arg); | ||
| 38 | if (c[i].flush) c[i].flush(); | ||
| 39 | } | ||
| 40 | } | ||
