diff options
| author | Aargh Rai <aargh.rai+git@gmail.com> | 2026-06-19 23:11:10 +0530 |
|---|---|---|
| committer | Aargh Rai <aargh.rai+git@gmail.com> | 2026-06-19 23:11:10 +0530 |
| commit | b5d53cd4210a74c65a42b6387dd78c4e5bc9c17f (patch) | |
| tree | 6f9c2e56b70a3a69d3c44d14e6947ffc07731136 /src/uci.c | |
| parent | 058f12c699c9183f93f280ad7eb54c8a1b25f523 (diff) | |
license & uci
Diffstat (limited to 'src/uci.c')
| -rw-r--r-- | src/uci.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/uci.c b/src/uci.c new file mode 100644 index 0000000..3c45765 --- /dev/null +++ b/src/uci.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include "uci/command.h" +#include "uci/response.h" + +void load_from_message(ucicmd* cmd, const char* message) { + char token[MAX_TOKEN_SIZE]; + int i = 0, k = 0; + + while ( + message[i] != 0 && + message[i] != '\n' && + message[i] != '\r' + ) { + if (message[i] != ' ') { + token[k++] = message[i++]; + continue; + } + if (k == 0) { + i++; + continue; + } + i++; + token[k] = 0; + ucicmd_add(cmd, token); + k = 0; + } + token[k] = 0; + ucicmd_add(cmd, token); +} + +int main() { + // https://stackoverflow.com/a/41559081 + fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); + + ucicmd cmd = ucicmd_init(); + size_t n; + char buf[1024]; + while (true) { + cmd.empty = true; + cmd.args_count = 0; + ssize_t n = read(STDIN_FILENO, buf, sizeof(buf)); + if (n > 0) { + load_from_message(&cmd, buf); + } + handle_uci(cmd); + } +} + +#include "uci/command.c" +#include "uci/response.c" |
