From 20cb29c2f8c5c87bc590896854a20b1473ceb358 Mon Sep 17 00:00:00 2001 From: "info@mode42.com" Date: Sat, 8 Aug 2026 03:54:55 +0000 Subject: #2 --- include/hybbx/command.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 include/hybbx/command.h (limited to 'include/hybbx/command.h') diff --git a/include/hybbx/command.h b/include/hybbx/command.h new file mode 100644 index 0000000..5d8ba5c --- /dev/null +++ b/include/hybbx/command.h @@ -0,0 +1,71 @@ +#ifndef HYBBX_COMMAND_H +#define HYBBX_COMMAND_H + +#include "hybbx/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct hybbx_service; +struct hybbx_session; + +/** + * Input line routing scope. + * + * HyBBX accepts only lines starting with '/'. Valid forms: + * / or /command /cmd /commands → /help + * / or / → command + * /command or /cmd → same as / + * + * - COMMENT: starts with ';' or '#' — ignored (like empty line) + * - LOCAL: anything else — not HyBBX; silently ignored + */ +typedef enum hybbx_command_scope { + HYBBX_CMD_SCOPE_HYBBX = 1, + HYBBX_CMD_SCOPE_LOCAL = 2, + HYBBX_CMD_SCOPE_COMMENT = 3 +} hybbx_command_scope_t; + +typedef struct hybbx_parsed_command { + hybbx_command_scope_t scope; + char *line; + char *verb; + char **argv; + size_t argc; +} hybbx_parsed_command_t; + +/** + * Classify a single input line. + * Returns HYBBX_CMD_SCOPE_HYBBX only when the first non-whitespace + * character is '/'. + */ +hybbx_command_scope_t hybbx_command_classify(const char *line); + +/** Non-zero when @p line is a HyBBX system command (starts with '/'). */ +int hybbx_command_is_hybbx(const char *line); + +/** Non-zero when @p line is a local comment (';' or '#' after whitespace). */ +int hybbx_command_is_comment(const char *line); + +/** + * Parse a trimmed command line into verb and arguments. + * For HyBBX commands the leading '/' is stripped from the verb. + */ +hybbx_result_t hybbx_command_parse(const char *line, + hybbx_parsed_command_t *out); + +void hybbx_command_free(hybbx_parsed_command_t *cmd); + +/** + * Dispatch a parsed HyBBX command (scope must be HYBBX_CMD_SCOPE_HYBBX). + */ +hybbx_result_t hybbx_command_dispatch(struct hybbx_service *service, + struct hybbx_session *session, + const hybbx_parsed_command_t *cmd); + +#ifdef __cplusplus +} +#endif + +#endif /* HYBBX_COMMAND_H */ -- cgit v1.3.1