mess822x 1.23
mess822x
Loading...
Searching...
No Matches
commands.c
Go to the documentation of this file.
1#include "commands.h"
2#include "buffer.h"
3#include "stralloc.h"
4#include "str.h"
5#include "case.h"
6
7static stralloc cmd = {0};
8
9int commands(buffer *b,struct commands *c)
10{
11 int i;
12 char *arg;
13
14 for (;;) {
15 if (!stralloc_copys(&cmd,"")) return -1;
16
17 for (;;) {
18 if (!stralloc_readyplus(&cmd,1)) return -1;
19 i = buffer_get(b,cmd.s + cmd.len,1);
20 if (i != 1) return i;
21 if (cmd.s[cmd.len] == '\n') break;
22 if (!cmd.s[cmd.len]) cmd.s[cmd.len] = '\n';
23 ++cmd.len;
24 }
25
26 if (cmd.len > 0)
27 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].verb; ++i)
37 if (case_equals(c[i].verb,cmd.s)) break;
38 c[i].action(arg);
39 if (c[i].flush) c[i].flush();
40 }
41}
void c(char *, char *, char *, int, int, int)
Definition: install.c:46