commit 575f1cc2d0c4b9e1b78a4c321f782404a6278684
parent bf956991e6e86000ab257922390f5ccd74b105cf
Author: Andrew Kloet <andrew@kloet.net>
Date: Fri, 1 May 2026 14:06:40 -0400
srd: do message parsing with strsep()
Diffstat:
| M | cio.c | | | 29 | +++++++++++------------------ |
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/cio.c b/cio.c
@@ -189,30 +189,23 @@ srd(void)
return 1;
if (s > l && s[-1] == '\r') s[-1] = 0;
*s++ = 0;
- char *tok = l;
+ char *line = l, *token;
usr = NULL;
- if (*tok == ':') {
- usr = tok + 1;
- if (!(tok = strchr(tok, ' '))) goto lskip;
- *tok++ = 0;
- }
- while (*tok == ' ') tok++;
- cmd = tok;
- if ((tok = strchr(tok, ' ')))
- *tok++ = 0;
argc = 0;
- while (tok && *tok && argc < MaxParams) {
- while (*tok == ' ') tok++;
- if (*tok == ':') {
- argv[argc++] = tok + 1;
+ if (*line == ':') {
+ usr = line + 1;
+ strsep(&line, " ");
+ }
+ cmd = strsep(&line, " ");
+ while (line && argc < MaxParams) {
+ if (*line == ':') {
+ argv[argc++] = line + 1;
break;
}
- argv[argc++] = tok;
- if ((tok = strchr(tok, ' ')))
- *tok++ = 0;
+ token = strsep(&line, " ");
+ if (*token) argv[argc++] = token;
}
if (cmd) scmd(usr, cmd, argc, argv);
- lskip:
memmove(l, s, p - s);
p -= s - l;
}