source: rtems/cpukit/libmisc/shell/shell.h @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 8.0 KB
Line 
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
17#ifndef __RTEMS_SHELL_H__
18#define __RTEMS_SHELL_H__
19
20#include <rtems.h>
21#include <stdio.h>
22#include <termios.h>
23#include <rtems/fs.h>
24#include <rtems/libio.h>
25#include <rtems/chain.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/*
32 * Some key labels to define special keys.
33 */
34
35#define RTEMS_SHELL_KEYS_EXTENDED    (0x8000)
36#define RTEMS_SHELL_KEYS_NORMAL_MASK (0x00ff)
37#define RTEMS_SHELL_KEYS_INS         (0)
38#define RTEMS_SHELL_KEYS_DEL         (1)
39#define RTEMS_SHELL_KEYS_UARROW      (2)
40#define RTEMS_SHELL_KEYS_DARROW      (3)
41#define RTEMS_SHELL_KEYS_LARROW      (4)
42#define RTEMS_SHELL_KEYS_RARROW      (5)
43#define RTEMS_SHELL_KEYS_HOME        (6)
44#define RTEMS_SHELL_KEYS_END         (7)
45#define RTEMS_SHELL_KEYS_F1          (8)
46#define RTEMS_SHELL_KEYS_F2          (9)
47#define RTEMS_SHELL_KEYS_F3          (10)
48#define RTEMS_SHELL_KEYS_F4          (11)
49#define RTEMS_SHELL_KEYS_F5          (12)
50#define RTEMS_SHELL_KEYS_F6          (13)
51#define RTEMS_SHELL_KEYS_F7          (14)
52#define RTEMS_SHELL_KEYS_F8          (15)
53#define RTEMS_SHELL_KEYS_F9          (16)
54#define RTEMS_SHELL_KEYS_F10         (17)
55
56typedef bool (*rtems_shell_login_check_t)(
57  const char * /* user */,
58  const char * /* passphrase */
59);
60
61extern bool rtems_shell_login_prompt(
62  FILE *in,
63  FILE *out,
64  const char *device,
65  rtems_shell_login_check_t check
66);
67
68extern bool rtems_shell_login_check(
69  const char *user,
70  const char *passphrase
71);
72
73typedef int (*rtems_shell_command_t)(int argc, char **argv);
74
75struct rtems_shell_cmd_tt;
76typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
77
78struct rtems_shell_cmd_tt {
79  const char            *name;
80  const char            *usage;
81  const char            *topic;
82  rtems_shell_command_t  command;
83  rtems_shell_cmd_t     *alias;
84  rtems_shell_cmd_t     *next;
85};
86
87typedef struct {
88  const char *name;
89  const char *alias;
90} rtems_shell_alias_t;
91
92/*
93 * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
94 * is extended, ie a special key.
95 */
96extern unsigned int rtems_shell_getchar(FILE *in);
97
98extern rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
99
100extern rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
101  rtems_shell_cmd_t *shell_cmd
102);
103
104rtems_shell_cmd_t * rtems_shell_add_cmd(
105  const char            *cmd,
106  const char            *topic,
107  const char            *usage,
108  rtems_shell_command_t  command
109);
110
111extern rtems_shell_cmd_t * rtems_shell_alias_cmd(
112  const char *cmd,
113  const char *alias
114);
115
116extern int rtems_shell_make_args(
117  char  *commandLine,
118  int   *argc_p,
119  char **argv_p,
120  int    max_args
121);
122
123extern int rtems_shell_cat_file(
124  FILE *out,
125  const char *name
126);
127
128extern void rtems_shell_write_file(
129  const char *name,
130  const char *content
131);
132
133extern int rtems_shell_script_file(
134  int    argc,
135  char **argv
136);
137
138/**
139 * Initialise the shell creating tasks to login and run the shell
140 * sessions.
141 *
142 * @param task_name Name of the shell task.
143 * @param task_stacksize The size of the stack. If 0 the default size is used.
144 * @param task_priority The priority the shell runs at.
145 * @param forever Repeat logins.
146 * @param wait Caller should block until shell exits.
147 * @param login_check User login check function, NULL disables login checks.
148 *
149 */
150extern rtems_status_code rtems_shell_init(
151  const char *task_name,
152  size_t task_stacksize,
153  rtems_task_priority task_priority,
154  const char *devname,
155  bool forever,
156  bool wait,
157  rtems_shell_login_check_t login_check
158);
159
160/**
161 * Run a shell script creating a shell tasks to execute the command under.
162 *
163 * @param task_name Name of the shell task.
164 * @param task_stacksize The size of the stack. If 0 the default size is used.
165 * @param task_priority The priority the shell runs at.
166 * @param input The file of commands. Can be 'stdin' to use stdin.
167 * @param output The output file to write commands to. Can be 'stdout',
168 *              'stderr' or '/dev/null'.
169 * @param output_append Append the output to the file or truncate the file.
170 *                      Create if it does not exist.
171 * @param wait Wait for the script to finish.
172 */
173extern rtems_status_code rtems_shell_script(
174  const char          *task_name,
175  size_t               task_stacksize,  /* 0 default*/
176  rtems_task_priority  task_priority,
177  const char          *input,
178  const char          *output,
179  bool                 output_append,
180  bool                 wait,
181  bool                 echo
182);
183
184/**
185 *  Private environment associated with each shell instance.
186 */
187typedef struct {
188  /** 'S','E','N','V': Shell Environment */
189  rtems_name magic;
190  const char *devname;
191  const char *taskname;
192  bool exit_shell; /* logout */
193  bool forever; /* repeat login */
194  int errorlevel;
195  bool echo;
196  char cwd[256];
197  const char *input;
198  const char *output;
199  bool output_append;
200  rtems_id wake_on_end;
201  rtems_shell_login_check_t login_check;
202} rtems_shell_env_t;
203
204bool rtems_shell_main_loop(
205  rtems_shell_env_t *rtems_shell_env
206);
207
208extern rtems_shell_env_t  rtems_global_shell_env;
209extern rtems_shell_env_t *rtems_current_shell_env;
210
211/*
212 * The types of file systems we can mount. We have them broken out
213 * out like this so they can be configured by shellconfig.h. The
214 * mount command needs special treatment due to some file systems
215 * being dependent on the network stack and some not. If we had
216 * all possible file systems being included it would force the
217 * networking stack into the applcation and this may not be
218 * required.
219 */
220struct rtems_shell_filesystems_tt;
221typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
222
223typedef int (*rtems_shell_filesystems_mounter_t)(
224  const char*                driver,
225  const char*                path,
226  rtems_shell_filesystems_t* fs,
227  rtems_filesystem_options_t options
228);
229
230struct rtems_shell_filesystems_tt {
231  rtems_chain_node                         link;
232  const char                              *name;
233  int                                      driver_needed;
234  const rtems_filesystem_operations_table *fs_ops;
235  rtems_shell_filesystems_mounter_t        mounter;
236};
237
238/**
239 *  This method dynamically builds the command line prompt string
240 *  and places it in @a prompt.
241 *
242 *  @param[in] shell_env is the shell execution environment
243 *  @param[in] prompt is a pointer to a string buffer area
244 *  @param[in] size is length of the prompt buffer area
245 *
246 *  @return This method fills in the memory pointed to by @a prompt.
247 *
248 *  @note An application specific implementation can be provided
249 *        by the user.
250 */
251extern void rtems_shell_get_prompt(
252  rtems_shell_env_t *shell_env,
253  char              *prompt,
254  size_t             size
255);
256
257/**
258 * Helper for the mount command.
259 *
260 * @param[in] driver The path to the driver.
261 * @param[in] path The path to mount on.
262 * @param[in] fs The file system definition.
263 * @param[in] options Special file system options.
264 */
265extern int rtems_shell_libc_mounter(
266  const char*                driver,
267  const char*                path,
268  rtems_shell_filesystems_t* fs,
269  rtems_filesystem_options_t options
270);
271
272/**
273 * Add a new file system mount configuration to the mount command.
274 *
275 * @param[in] fs The file system mount data.
276 */
277extern void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs);
278
279/**
280 * Delete file system mount configuration from the mount command.
281 *
282 * @param[in] fs The file system mount data to remove.
283 */
284extern void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs);
285
286typedef void (*rtems_shell_wait_for_input_notification)(
287  int fd,
288  int seconds_remaining,
289  void *arg
290);
291
292/**
293 * @brief Waits for input.
294 *
295 * @retval RTEMS_SUCCESSFUL Input detected.
296 * @retval RTEMS_TIMEOUT Timeout expired.
297 * @retval RTEMS_UNSATISFIED Cannot change or restore termios attributes.
298 */
299extern rtems_status_code rtems_shell_wait_for_input(
300  int fd,
301  int timeout_in_seconds,
302  rtems_shell_wait_for_input_notification notification,
303  void *notification_arg
304);
305
306extern int rtems_shell_main_monitor(int argc, char **argv);
307
308
309#ifdef __cplusplus
310}
311#endif
312
313#endif
Note: See TracBrowser for help on using the repository browser.