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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#ifndef __CLI$ROUTINES__
#define __CLI$ROUTINES__ 1
#ifdef __cplusplus
extern "C" {
#endif
/*
**++
**
** FACILITY: Command Language Interface (CLI) Routines
**
** ABSTRACT: A portable API to implement command line parameters parsing, primary syntax checking,
** and dispatching of processing. This true story is based on the OpenVMS CDU/CLI facilities.
**
** DESCRIPTION: Command Language Interface (CLI) Routines - an API is supposed to be used to parse and
** dispatch processing.
**
** This set of routines help to implement a follows syntax:
**
** <verb> [p1 p2 ... p8] [/qualifiers[=<value> ...]
**
** ...
**
** DESIGN ISSUE:
** {tbs}
**
** AUTHORS: Ruslan R. Laishev (RRL)
**
** CREATION DATE: 22-AUG-2018
**
** MODIFICATION HISTORY:
**
**--
*/
/*
* Parameters (P1 - P8)
*/
#define CLI$K_P1 1 /* Position depended parameters */
#define CLI$K_P2 2
#define CLI$K_P3 3
#define CLI$K_P4 4
#define CLI$K_P5 5
#define CLI$K_P6 6
#define CLI$K_P7 7
#define CLI$K_P8 8
#define CLI$K_QUAL 9 /* Qualifier*/
/* Parameter/Value - types */
#define CLI$K_FILE 1
#define CLI$K_DATE 2
#define CLI$K_NUM 3 /* Number: Octal, Decimal, Hex */
#define CLI$K_IPV4 4 /* 212.129.97.4 */
#define CLI$K_IPV6 5
#define CLI$K_OPT 7 /* Options - no value */
#define CLI$K_QSTRING 8 /* Quoted string */
#define CLI$K_UUID 9 /* Fucken UUID */
#define CLI$K_DEVICE 0xa /* A device in the /dev/ */
#define CLI$K_KWD 0xb /* A predefined keyword */
#define CLI$M_NEGATABLE 1 /* Qualifier can be negatable */
#define CLI$M_LIST 2
#define CLI$M_PRESENT 4
#define CLI$S_MAXVERBL 32 /* Maximum verb's length */
#ifndef __ASC_TYPE__
typedef struct __asc__ {
unsigned char len,
sts[255];
} ASC;
#endif
typedef struct __cli_keyword__ {
ASC name; /* Keyword's string itself */
unsigned long long val; /* Associated value */
} CLI_KEYWORD;
typedef struct __cli_pqdesc__ {
ASC name; /* A short name of the parameter*/
unsigned short type; /* FILE, DATE ... */
unsigned char pn; /* P1, P2, ... P8 */
unsigned char flag; /* Reserved */
ASC defval; /* Default value string */
CLI_KEYWORD * kwd; /* A list of keywords */
} CLI_PQDESC;
typedef struct __cli__verb__ {
ASC name;
struct __cli__verb__ *next;
CLI_PQDESC *params;
CLI_PQDESC *quals;
int (*act_rtn) (__unknown_params);
void *act_arg;
} CLI_VERB;
typedef struct __cli_item__{
struct __cli_item__ *next;/* Linked list stuff */
unsigned type; /* 0 - verb, P1 - P8, QUAL */
union {
CLI_VERB *verb;
/* An address of the CLI's */
/* parameters or qualifiers */
/* definition structure */
CLI_PQDESC *pqdesc;
};
ASC val; /* Value string */
} CLI_ITEM;
/*
* A context to keep has been parsed command line:
* verb parameters, qualifiers
*/
/* Processing options */
#define CLI$M_OPTRACE 1
#define CLI$M_OPSIGNAL 2
typedef struct __cli_ctx__
{
int opts;
CLI_ITEM *vlist, /* A list of verbs' sequence for a command */
*avlist;/* A list of parameters' values and qualifiers */
} CLI_CTX;
/*
* CLI API Routines declaration section
*/
void cli$show_verbs (CLI_VERB *verbs, int level);
int cli$parse (CLI_VERB *verbs, int opts, int argc, char ** argv, void **clictx);
int cli$dispatch (CLI_CTX *clictx);
int cli$cleanup (CLI_CTX *clictx);
int cli$get_value (CLI_CTX *clictx, CLI_PQDESC *pq, ASC *val);
#ifdef __cplusplus
}
#endif
#endif /* __CLI$ROUTINES__ */
|