#pragma once #include #include typedef struct { FILE *in; // stdin stream for reading further command data FILE *out; // stdout stream for command results /* Rest of the fields are filled in during command execution. */ const char *cmd; // command name char *saveptr; // argument to strtok_r for fetching command arguments int status; // numeric result status of command } cmdargs_t; bool cmd_string_arg(cmdargs_t *args, char **dest); bool cmd_signed_arg(cmdargs_t *args, signed *dest); bool cmd_unsigned_arg(cmdargs_t *args, unsigned *dest); bool cmd_last_arg(cmdargs_t *args); void cmd_result(cmdargs_t *args, int status, const char *info); void cmd_resultf(cmdargs_t *args, int status, const char *info, ...); void cmd_run(cmdargs_t *args, char *cmdline); void cmd_chat(FILE *stream, int cmdbuf_size);