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
#ifndef __DADA_command_parse_h
#define __DADA_command_parse_h
#include <stdio.h>
/* pointer to a function that implements a command */
typedef int (*command) (void* context, FILE* reply, char* arguments);
#define COMMAND_PARSE_EXIT 13
typedef struct {
/* pointer to the command function */
command cmd;
/* additional context for the command */
void* context;
/* name of the command */
char* name;
/* help for the command */
char* help;
/* detailed description of the command */
char* more;
} command_t;
typedef struct {
/* an array of commands */
command_t* cmds;
/* size of the array */
unsigned ncmd;
/* I/O stream to be used when replying */
FILE* reply;
} command_parse_t;
/* create a new command parser */
command_parse_t* command_parse_create ();
/* destroy a command parser */
int command_parse_destroy (command_parse_t* parser);
/* set the stream to be used when replying */
int command_parse_reply (command_parse_t* parser, FILE* fptr);
/* add a command to the list of available commands */
int command_parse_add (command_parse_t* parser,
command cmd, void* context,
const char* command_name,
const char* short_help,
const char* long_help);
/* remove a command from the list of available commands */
int command_parse_remove (command_parse_t* parser, const char* command_name);
/* parse a command */
int command_parse (command_parse_t* parser, char* command);
/* parse a command; different output */
int command_parse_output (command_parse_t* parser, char* command, FILE* out);
#endif