1 | /* cli.h: |
---|
2 | * Header file for Command Line Interface related stuff. |
---|
3 | * |
---|
4 | * General notice: |
---|
5 | * This code is part of a boot-monitor package developed as a generic base |
---|
6 | * platform for embedded system designs. As such, it is likely to be |
---|
7 | * distributed to various projects beyond the control of the original |
---|
8 | * author. Please notify the author of any enhancements made or bugs found |
---|
9 | * so that all may benefit from the changes. In addition, notification back |
---|
10 | * to the author will allow the new user to pick up changes that may have |
---|
11 | * been made by other users after this version of the code was distributed. |
---|
12 | * |
---|
13 | * Note1: the majority of this code was edited with 4-space tabs. |
---|
14 | * Note2: as more and more contributions are accepted, the term "author" |
---|
15 | * is becoming a mis-representation of credit. |
---|
16 | * |
---|
17 | * Original author: Ed Sutter |
---|
18 | * Email: esutter@lucent.com |
---|
19 | * Phone: 908-582-2351 |
---|
20 | */ |
---|
21 | #ifndef _cli_h |
---|
22 | #define _cli_h |
---|
23 | |
---|
24 | #ifdef __cplusplus |
---|
25 | extern "C" { |
---|
26 | #endif |
---|
27 | |
---|
28 | /* Command table structure used by the monitor: |
---|
29 | */ |
---|
30 | struct monCommand { |
---|
31 | char *name; /* Name of command seen by user. */ |
---|
32 | int (*func)(int,char **); /* Called when command is invoked. */ |
---|
33 | char **helptxt; /* Help text (see notes below). */ |
---|
34 | long flags; /* Single-bit flags for various uses */ |
---|
35 | /* (see the CMDFLAG_XXX macros). */ |
---|
36 | }; |
---|
37 | |
---|
38 | #ifdef __cplusplus |
---|
39 | } |
---|
40 | #endif |
---|
41 | |
---|
42 | /* Bits currently assigned to command flags used in the monCommand |
---|
43 | * structure... |
---|
44 | */ |
---|
45 | #define CMDFLAG_NOMONRC 1 |
---|
46 | |
---|
47 | /* Maximum size of a command line: |
---|
48 | */ |
---|
49 | #ifndef CMDLINESIZE |
---|
50 | #define CMDLINESIZE 128 |
---|
51 | #endif |
---|
52 | |
---|
53 | /* Maximum number of arguments in a command line: |
---|
54 | */ |
---|
55 | #define ARGCNT 24 |
---|
56 | |
---|
57 | /* Definitions for docommand() return values: |
---|
58 | * |
---|
59 | * Note that the CMD_SUCCESS, CMD_FAILURE and CMD_PARAM_ERROR are return |
---|
60 | * values used by the local command code also. The remaining errors |
---|
61 | * (CMD_LINE_ERROR, CMD_ULVL_DENIED and CMD_NOT_FOUND) are used only by |
---|
62 | # the docommand() function. |
---|
63 | * |
---|
64 | * CMD_SUCCESS: |
---|
65 | * Everything worked ok. |
---|
66 | * CMD_FAILURE: |
---|
67 | * Command parameters were valid, but command itself failed for some other |
---|
68 | * reason. The docommand() function does not print a message here, it |
---|
69 | * is assumed that the error message was printed by the local function. |
---|
70 | * CMD_PARAM_ERROR: |
---|
71 | * Command line did not parse properly. Control was passed to a |
---|
72 | * local command function, but argument syntax caused it to choke. |
---|
73 | * In this case docommand() will print out the generic CLI syntax error |
---|
74 | * message. |
---|
75 | * CMD_LINE_ERROR: |
---|
76 | * Command line itself was invalid. Too many args, invalid shell var |
---|
77 | * syntax, etc.. Somekind of command line error prior to checking for |
---|
78 | * the command name-to-function match. |
---|
79 | * CMD_ULVL_DENIED: |
---|
80 | * Command's user level is higher than current user level, so access |
---|
81 | * is denied. |
---|
82 | * CMD_NOT_FOUND: |
---|
83 | * Since these same return values are used for each command function |
---|
84 | * plus the docommand() function, this error indicates that docommand() |
---|
85 | * could not even find the command in the command table. |
---|
86 | * CMD_MONRC_DENIED: |
---|
87 | * The command cannot execute because it is considered illegal |
---|
88 | * when run from within the monrc file. |
---|
89 | */ |
---|
90 | #define CMD_SUCCESS 0 |
---|
91 | #define CMD_FAILURE -1 |
---|
92 | #define CMD_PARAM_ERROR -2 |
---|
93 | #define CMD_LINE_ERROR -3 |
---|
94 | #define CMD_ULVL_DENIED -4 |
---|
95 | #define CMD_NOT_FOUND -5 |
---|
96 | #define CMD_MONRC_DENIED -6 |
---|
97 | |
---|
98 | /* Notes on help text array: |
---|
99 | * The monitor's CLI processor assumes that every command's help text |
---|
100 | * array abides by a few basic rules... |
---|
101 | * First of all, it assumes that every array has AT LEAST two strings. |
---|
102 | * The first string in the array of strings is assumed to be a one-line |
---|
103 | * abstract describing the command. |
---|
104 | * The second string in the array of strings is assumed to be a usage |
---|
105 | * message that describes the syntax of the arguments needed by the command. |
---|
106 | * If this second string is an empty string (""), the docommand() prints out |
---|
107 | * a generic usage string indicating that there are no options or arguements |
---|
108 | * to apply to the command. |
---|
109 | * All remaining lines are formatted based on the needs of the individual |
---|
110 | * command and the final string is a null pointer to let the CLI processor |
---|
111 | * know where the end is. |
---|
112 | * Following is an example help text array... |
---|
113 | * |
---|
114 | * char *HelpHelp[] = { |
---|
115 | * "Display command set", |
---|
116 | * "-[d] [commandname]", |
---|
117 | * "Options:", |
---|
118 | * " -d list commands and descriptions", |
---|
119 | * 0, |
---|
120 | * }; |
---|
121 | * |
---|
122 | */ |
---|
123 | #endif |
---|