-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.h
81 lines (65 loc) · 2.26 KB
/
cli.h
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
#ifndef CLI_H
#define CLI_H
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "ctype.h"
#define MAX_PARAMETERS 15 /* Max no. of prameters in a command */
#define MAX_LEN_TOKEN 84 /* Max length of a token */
#define MIN_PWD_LEN 4
#define SPACE_SIZE 128
#define CLI_PROMPT_LEN 9
#define CMD_SIZE 120
#define MAX_LEN_ARGS 512 /* Max length of all args in a given tree */
#define MAX_USER_LEN 9
#define MAX_PWD_LEN 9
#define USER_MODE_ID "user"
#define ENGG_MODE_ID "engg"
#define ROOT_MODE_ID "root"
extern int echo_char;
#define ENABLEECHO() {echo_char = 1;}
#define DISABLEECHO() {echo_char = 0;}
typedef enum { CLI_FAILURE, CLI_SUCCESS, ERR_MULTI_TOKENS, EMPTY_STRING, BAD_MODE, EMPTY_TREE } cli_status_t;
typedef enum { MORE_ARGUMENTS = 100, FEWER_ARGUMENTS, MULTIPLE_TOKENS, UNKNOWN_TOKEN, NO_PERMISSION,
SUICIDAL, NOTHING, MEM_FAILURE } cli_error_t;
typedef enum { SUCC_CALLBACK = 200, SUCC_NEXTTREE, ERR_IMPLEMENTATION, ERR_PRIVILEGE } cli_avl_tree_t;
int setpasswd(char *, char *);
#define NMODES 3
#define USER_MODE 0x100
#define SUPERVISORY_MODE 0x200
#define ENGG_MODE 0x400
#define INPUT_MODE 0x2
#define START_MODE USER_MODE
#define SET_PASSWORD setpasswd
typedef int (*funcPtr)(char *str[]);
typedef struct CliTreeNode
{
char data[MAX_LEN_TOKEN];
int balFactor;
int status;
/* unsigned cmArrIdx; */
int (*callBackFn)(char **str);
struct CliTreeNode *lchild;
struct CliTreeNode *rchild;
struct CliTreeNode *nextTree;
} CliTreeNode;
/* Support for different privilage levels */
struct usermodes
{
int mode;
char userid[MAX_USER_LEN];
char passwd[MAX_PWD_LEN];
char name[20];
char prompt[CLI_PROMPT_LEN];
};
extern CliTreeNode *cli_root;
extern CliTreeNode *nextRoot;
extern char clrLine[SPACE_SIZE]; /*clrLine contains spaces*/
extern struct usermodes usermodes[NMODES];
extern char prompt[CLI_PROMPT_LEN], exit_flag;
extern int current_mode;
int init_cli();
void CliCleanup(void);
int InsertCommand(const char *cmd,int mode, funcPtr callBackFn);
int ParseACommand(const char *);
#endif // CLI_H