-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplinter_cli.h
More file actions
148 lines (119 loc) · 4.24 KB
/
splinter_cli.h
File metadata and controls
148 lines (119 loc) · 4.24 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* Copyright 2025 Tim Post
* License: Apache 2 (MIT available upon request to timthepost@protonmail.com)
*
* @file splinter_cli.h
* @brief Splinter CLI global header
*/
#ifndef SPLINTER_CLI_H
#define SPLINTER_CLI_H
#include "splinter.h"
#include <stdbool.h>
#include <signal.h>
#include <termios.h>
// Hard cap on viewable history length
#define CLI_HISTORY_MAX_LEN 1024
// Types for module command entry and help
typedef int (*mod_entry_t)(int, char *[]);
typedef void (*mod_help_t)(unsigned int);
// A command (module)
typedef struct cli_module {
// correlates to array position for easy lookup
int id;
// name of the command, e.g. set / get / help
const char *name;
// computed length of the command to speed up linear probing
size_t name_len;
// What it does
const char *description;
// Is this just another name for another command? Set this to its id.
int alias_of;
// If alias, set these to null (we resolve the root entry points)
mod_entry_t entry;
mod_help_t help;
} cli_module_t;
// A utility to map "ctags-style" labels to bitmasks for bloom filtering
typedef struct {
char name[32];
uint64_t mask;
} label_map_t;
// A utility class to store user session quirks
typedef struct cli_user {
// name of the store connected to
char store[64];
// is the user connected to a store?
bool store_conn;
// does the user want to abort whatever we're doing?
volatile sig_atomic_t abort;
// user's terminal
struct termios term;
// exit status of the last run command
int lastexit;
// errno after last run command
int lasterrno;
// 64 assignable labels from .splinterrc
label_map_t labels[64];
// how many are actually there
int label_count;
} cli_user_t;
// We construct the user in cli_main
extern cli_user_t thisuser;
// Prototypes for runtime functions
char **cli_input_args(const char *prompt, int *argc);
char **cli_unroll_argv(const char *input, int *out_argc);
void cli_free_argv(char *argv[]);
int cli_find_module(const char *name);
int cli_find_alias(int idx);
int cli_run_module(int idx, int argc, char *argv[]);
void cli_show_module_help(int idx, unsigned int level);
char **cli_slice_args(char *const src[], int start_index, int count);
char *cli_rejoin_args(char *const src[]);
void cli_show_modules(void);
void cli_show_key_config(const char *key, const char *caller);
int cli_safer_atoi(const char *string);
char * cli_show_key_type(unsigned short flags);
uint16_t cli_type_to_bitmask(const char *type);
unsigned int cli_key_is_printable_unserialized(unsigned short flags);
void cli_load_config(void);
// Prototypes for individual command entry points
int cmd_help(int argc, char *argv[]);
void help_cmd_help(unsigned int level);
int cmd_clear(int argc, char *argv[]);
void help_cmd_clear(unsigned int level);
int cmd_config(int argc, char *argv[]);
void help_cmd_config(unsigned int level);
int cmd_use(int argc, char *argv[]);
void help_cmd_use(unsigned int level);
int cmd_watch(int argc, char *argv[]);
void help_cmd_watch(unsigned int level);
int cmd_unset(int argc, char *argv[]);
void help_cmd_unset(unsigned int level);
int cmd_set(int argc, char *argv[]);
void help_cmd_set(unsigned int level);
int cmd_get(int argc, char *argv[]);
void help_cmd_get(unsigned int level);
int cmd_list(int argc, char *argv[]);
void help_cmd_list(unsigned int level);
int cmd_hist(int argc, char *argv[]);
void help_cmd_hist(unsigned int level);
int cmd_head(int argc, char *argv[]);
void help_cmd_head(unsigned int level);
int cmd_init(int argc, char *argv[]);
void help_cmd_init(unsigned int level);
int cmd_export(int argc, char *argv[]);
void help_cmd_export(unsigned int level);
int cmd_type(int argc, char *argv[]);
void help_cmd_type(unsigned int level);
int cmd_math(int argc, char *argv[]);
void help_cmd_math(unsigned int level);
int cmd_label(int argc, char *argv[]);
void help_cmd_label(unsigned int level);
int cmd_lua(int argc, char *argv[]);
void help_cmd_lua(unsigned int level);
int cmd_orders(int argc, char *argv[]);
void help_cmd_orders(unsigned int level);
int cmd_bind(int argc, char *argv[]);
void help_cmd_bind(unsigned int level);
// And finally an array of modules to hold them all
extern cli_module_t command_modules[];
#endif // SPLINTER_CLI_H