summaryrefslogtreecommitdiff
path: root/include/hybbx/command.h
blob: 5d8ba5cd9a7e7204e816fd67a92b294ceef333fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
 *   /<verb>        or / <verb>              → command
 *   /command <verb> or /cmd <verb>          → same as / <verb>
 *
 * - 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 */
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com