1 | /** |
---|
2 | * @file rtems/shell.h |
---|
3 | * |
---|
4 | * Instantatiate a new terminal shell. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * Author: |
---|
9 | * |
---|
10 | * WORK: fernando.ruiz@ctv.es |
---|
11 | * HOME: correo@fernando-ruiz.com |
---|
12 | * |
---|
13 | * Thanks at: |
---|
14 | * Chris Johns |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef __RTEMS_SHELL_H__ |
---|
20 | #define __RTEMS_SHELL_H__ |
---|
21 | |
---|
22 | #include <rtems.h> |
---|
23 | #include <stdio.h> |
---|
24 | #include <termios.h> |
---|
25 | #include <rtems/fs.h> |
---|
26 | #include <rtems/libio.h> |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | /* |
---|
33 | * Some key labels to define special keys. |
---|
34 | */ |
---|
35 | |
---|
36 | #define RTEMS_SHELL_KEYS_EXTENDED (0x8000) |
---|
37 | #define RTEMS_SHELL_KEYS_NORMAL_MASK (0x00ff) |
---|
38 | #define RTEMS_SHELL_KEYS_INS (0) |
---|
39 | #define RTEMS_SHELL_KEYS_DEL (1) |
---|
40 | #define RTEMS_SHELL_KEYS_UARROW (2) |
---|
41 | #define RTEMS_SHELL_KEYS_DARROW (3) |
---|
42 | #define RTEMS_SHELL_KEYS_LARROW (4) |
---|
43 | #define RTEMS_SHELL_KEYS_RARROW (5) |
---|
44 | #define RTEMS_SHELL_KEYS_HOME (6) |
---|
45 | #define RTEMS_SHELL_KEYS_END (7) |
---|
46 | #define RTEMS_SHELL_KEYS_F1 (8) |
---|
47 | #define RTEMS_SHELL_KEYS_F2 (9) |
---|
48 | #define RTEMS_SHELL_KEYS_F3 (10) |
---|
49 | #define RTEMS_SHELL_KEYS_F4 (11) |
---|
50 | #define RTEMS_SHELL_KEYS_F5 (12) |
---|
51 | #define RTEMS_SHELL_KEYS_F6 (13) |
---|
52 | #define RTEMS_SHELL_KEYS_F7 (14) |
---|
53 | #define RTEMS_SHELL_KEYS_F8 (15) |
---|
54 | #define RTEMS_SHELL_KEYS_F9 (16) |
---|
55 | #define RTEMS_SHELL_KEYS_F10 (17) |
---|
56 | |
---|
57 | typedef int (*rtems_shell_command_t)(int argc,char * argv[]); |
---|
58 | |
---|
59 | struct rtems_shell_cmd_tt; |
---|
60 | typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t; |
---|
61 | |
---|
62 | struct rtems_shell_cmd_tt { |
---|
63 | char *name; |
---|
64 | char *usage; |
---|
65 | char *topic; |
---|
66 | rtems_shell_command_t command; |
---|
67 | rtems_shell_cmd_t *alias; |
---|
68 | rtems_shell_cmd_t *next; |
---|
69 | }; |
---|
70 | |
---|
71 | typedef struct { |
---|
72 | char *name; |
---|
73 | char *alias; |
---|
74 | } rtems_shell_alias_t; |
---|
75 | |
---|
76 | /* |
---|
77 | * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key |
---|
78 | * is extended, ie a special key. |
---|
79 | */ |
---|
80 | unsigned int rtems_shell_getchar(FILE *in); |
---|
81 | |
---|
82 | rtems_shell_cmd_t * rtems_shell_lookup_cmd(char * cmd); |
---|
83 | |
---|
84 | rtems_shell_cmd_t *rtems_shell_add_cmd_struct( |
---|
85 | rtems_shell_cmd_t *shell_cmd |
---|
86 | ); |
---|
87 | |
---|
88 | rtems_shell_cmd_t * rtems_shell_add_cmd( |
---|
89 | char *cmd, |
---|
90 | char *topic, |
---|
91 | char *usage, |
---|
92 | rtems_shell_command_t command |
---|
93 | ); |
---|
94 | |
---|
95 | rtems_shell_cmd_t * rtems_shell_alias_cmd( |
---|
96 | char *cmd, |
---|
97 | char *alias |
---|
98 | ); |
---|
99 | |
---|
100 | int rtems_shell_make_args( |
---|
101 | char *commandLine, |
---|
102 | int *argc_p, |
---|
103 | char **argv_p, |
---|
104 | int max_args |
---|
105 | ); |
---|
106 | |
---|
107 | int rtems_shell_scanline( |
---|
108 | char *line, |
---|
109 | int size, |
---|
110 | FILE *in, |
---|
111 | FILE *out |
---|
112 | ); |
---|
113 | |
---|
114 | int rtems_shell_cat_file( |
---|
115 | FILE *out, |
---|
116 | char *name |
---|
117 | ); |
---|
118 | |
---|
119 | void rtems_shell_write_file( |
---|
120 | const char *name, |
---|
121 | const char *content |
---|
122 | ); |
---|
123 | |
---|
124 | int rtems_shell_script_file( |
---|
125 | int argc, |
---|
126 | char *argv[] |
---|
127 | ); |
---|
128 | |
---|
129 | /** |
---|
130 | * Initialise the shell creating tasks to login and run the shell |
---|
131 | * sessions. |
---|
132 | * |
---|
133 | * @param task_name Name of the shell task. |
---|
134 | * @param task_stacksize The size of the stack. If 0 the default size is used. |
---|
135 | * @param task_priority The priority the shell runs at. |
---|
136 | * @param forever Repeat logins. |
---|
137 | * @param wait Caller should block until shell exits |
---|
138 | * |
---|
139 | */ |
---|
140 | rtems_status_code rtems_shell_init( |
---|
141 | char *task_name, |
---|
142 | uint32_t task_stacksize, /*0 default*/ |
---|
143 | rtems_task_priority task_priority, |
---|
144 | char *devname, |
---|
145 | int forever, |
---|
146 | int wait |
---|
147 | ); |
---|
148 | |
---|
149 | /** |
---|
150 | * Run a shell script creating a shell tasks to execute the command under. |
---|
151 | * |
---|
152 | * @param task_name Name of the shell task. |
---|
153 | * @param task_stacksize The size of the stack. If 0 the default size is used. |
---|
154 | * @param task_priority The priority the shell runs at. |
---|
155 | * @param input The file of commands. Can be 'stdin' to use stdin. |
---|
156 | * @param output The output file to write commands to. Can be 'stdout', |
---|
157 | * 'stderr' or '/dev/null'. |
---|
158 | * @param output_append Append the output to the file or truncate the file. |
---|
159 | * Create if it does not exist. |
---|
160 | * @param wait Wait for the script to finish. |
---|
161 | */ |
---|
162 | rtems_status_code rtems_shell_script( |
---|
163 | char *task_name, |
---|
164 | uint32_t task_stacksize, /*0 default*/ |
---|
165 | rtems_task_priority task_priority, |
---|
166 | const char *input, |
---|
167 | const char *output, |
---|
168 | int output_append, |
---|
169 | int wait, |
---|
170 | int echo |
---|
171 | ); |
---|
172 | |
---|
173 | /* |
---|
174 | * Things that are useful to external entities developing commands and plugging |
---|
175 | * them in. |
---|
176 | */ |
---|
177 | int rtems_shell_str2int(char * s); |
---|
178 | |
---|
179 | typedef struct { |
---|
180 | rtems_name magic; /* 'S','E','N','V': Shell Environment */ |
---|
181 | char *devname; |
---|
182 | char *taskname; |
---|
183 | /* user extensions */ |
---|
184 | int exit_shell; /* logout */ |
---|
185 | int forever ; /* repeat login */ |
---|
186 | int errorlevel; |
---|
187 | int echo; |
---|
188 | char cwd[256]; |
---|
189 | const char* input; |
---|
190 | const char* output; |
---|
191 | int output_append; |
---|
192 | rtems_id wake_on_end; |
---|
193 | } rtems_shell_env_t; |
---|
194 | |
---|
195 | rtems_boolean rtems_shell_main_loop( |
---|
196 | rtems_shell_env_t *rtems_shell_env |
---|
197 | ); |
---|
198 | |
---|
199 | extern rtems_shell_env_t rtems_global_shell_env; |
---|
200 | extern rtems_shell_env_t *rtems_current_shell_env; |
---|
201 | |
---|
202 | /* |
---|
203 | * The types of file systems we can mount. We have them broken out |
---|
204 | * out like this so they can be configured by shellconfig.h. The |
---|
205 | * mount command needs special treatment due to some file systems |
---|
206 | * being dependent on the network stack and some not. If we had |
---|
207 | * all possible file systems being included it would force the |
---|
208 | * networking stack into the applcation and this may not be |
---|
209 | * required. |
---|
210 | */ |
---|
211 | struct rtems_shell_filesystems_tt; |
---|
212 | typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t; |
---|
213 | |
---|
214 | typedef int (*rtems_shell_filesystems_mounter_t)( |
---|
215 | const char* driver, |
---|
216 | const char* path, |
---|
217 | rtems_shell_filesystems_t* fs, |
---|
218 | rtems_filesystem_options_t options |
---|
219 | ); |
---|
220 | |
---|
221 | struct rtems_shell_filesystems_tt { |
---|
222 | const char* name; |
---|
223 | int driver_needed; |
---|
224 | rtems_filesystem_operations_table* fs_ops; |
---|
225 | rtems_shell_filesystems_mounter_t mounter; |
---|
226 | }; |
---|
227 | |
---|
228 | #ifdef __cplusplus |
---|
229 | } |
---|
230 | #endif |
---|
231 | |
---|
232 | #endif |
---|