#pragma once #ifdef __cplusplus extern "C" { #endif #define LIBSCOMP_VERSION "0.1.0" #include #define LIBSCOMP_MAXARG 32 #define LIBSCOMP_MAXBUF 1024 struct libscomp_line { size_t name; char *buf[LIBSCOMP_MAXARG]; size_t len; }; struct libscomp_input { int state; char intbuf[LIBSCOMP_MAXBUF]; size_t len; }; enum libscomp_input_r { LIBSCOMP_MORE, LIBSCOMP_OVERFLOW, LIBSCOMP_ARG_OVERFLOW, LIBSCOMP_COMPLETE }; void libscomp_reset(struct libscomp_input *); enum libscomp_input_r libscomp_read(struct libscomp_input *, char **, struct libscomp_line *); enum libscomp_cmd_r { LIBSCOMP_NOT_FOUND = -1, LIBSCOMP_CMD_OK = 0 }; struct libscomp_cmd { const char *name; int (*exec)(struct libscomp_line *, void *); }; struct libscomp_cmd_store { struct libscomp_cmd *arr; size_t len; }; #if defined(__STDC_VERSION__) #define libscomp_mkcmds(...) {(struct libscomp_cmd []){__VA_ARGS__}, \ sizeof((struct libscomp_cmd []){__VA_ARGS__}) / \ sizeof((struct libscomp_cmd []){__VA_ARGS__}[0])} #endif int libscomp_exec(const struct libscomp_cmd_store *cmds, struct libscomp_line *ln, void *ptr ); #ifdef __cplusplus } // extern "C" #endif