source: rtems/cpukit/libmisc/shell/shell.h @ cd4ed38

4.104.115
Last change on this file since cd4ed38 was 06f8e558, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 02/27/09 at 11:03:57
  • libmisc/shell/shell.c, libmisc/shell/shell.h: Changed type for boolean values from 'int' to 'bool'. Added option 'login' to enable or disable a login prompt. Changed intialization of global shell environment to static initialization. Changed stack size type to 'size_t' conforming to classic API.
  • libmisc/shell/shellconfig.h: Fixed some typos.
  • Property mode set to 100644
File size: 6.5 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 *  $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
29extern "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
57typedef int (*rtems_shell_command_t)(int argc, char **argv);
58
59struct rtems_shell_cmd_tt;
60typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
61
62struct rtems_shell_cmd_tt {
63  const char            *name;
64  const char            *usage;
65  const char            *topic;
66  rtems_shell_command_t  command;
67  rtems_shell_cmd_t     *alias;
68  rtems_shell_cmd_t     *next;
69};
70
71typedef struct {
72  const char *name;
73  const 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 */
80unsigned int rtems_shell_getchar(FILE *in);
81
82rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
83
84rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
85  rtems_shell_cmd_t *shell_cmd
86);
87
88rtems_shell_cmd_t * rtems_shell_add_cmd(
89  const char            *cmd,
90  const char            *topic,
91  const char            *usage,
92  rtems_shell_command_t  command
93);
94
95rtems_shell_cmd_t * rtems_shell_alias_cmd(
96  const char *cmd,
97  const char *alias
98);
99
100int rtems_shell_make_args(
101  char  *commandLine,
102  int   *argc_p,
103  char **argv_p,
104  int    max_args
105);
106
107int rtems_shell_scanline(
108  char *line,
109  int   size,
110  FILE *in,
111  FILE *out
112);
113
114int rtems_shell_cat_file(
115  FILE *out,
116  const char *name
117);
118
119void rtems_shell_write_file(
120  const char *name,
121  const char *content
122);
123
124int 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 * @param login Demand user login.
139 *
140 */
141rtems_status_code rtems_shell_init(
142  const char          *task_name,
143  size_t               task_stacksize,  /* 0 default*/
144  rtems_task_priority  task_priority,
145  const char          *devname,
146  bool                 forever,
147  bool                 wait,
148  bool                 login
149);
150
151/**
152 * Run a shell script creating a shell tasks to execute the command under.
153 *
154 * @param task_name Name of the shell task.
155 * @param task_stacksize The size of the stack. If 0 the default size is used.
156 * @param task_priority The priority the shell runs at.
157 * @param input The file of commands. Can be 'stdin' to use stdin.
158 * @param output The output file to write commands to. Can be 'stdout',
159 *              'stderr' or '/dev/null'.
160 * @param output_append Append the output to the file or truncate the file.
161 *                      Create if it does not exist.
162 * @param wait Wait for the script to finish.
163 */
164rtems_status_code rtems_shell_script(
165  const char          *task_name,
166  size_t               task_stacksize,  /* 0 default*/
167  rtems_task_priority  task_priority,
168  const char          *input,
169  const char          *output,
170  bool                 output_append,
171  bool                 wait,
172  bool                 echo
173);
174
175/*
176 *  Things that are useful to external entities developing commands and plugging
177 *  them in.
178 */
179int rtems_shell_str2int(const char * s);
180
181typedef struct  {
182  rtems_name  magic; /* 'S','E','N','V': Shell Environment */
183  const char *devname;
184  const char *taskname;
185  /* user extensions */
186  bool        exit_shell; /* logout */
187  bool        forever   ; /* repeat login */
188  int         errorlevel;
189  bool        echo;
190  char        cwd[256];
191  const char* input;
192  const char* output;
193  bool        output_append;
194  rtems_id    wake_on_end;
195  bool        login;
196} rtems_shell_env_t;
197
198bool rtems_shell_main_loop(
199  rtems_shell_env_t *rtems_shell_env
200);
201
202extern rtems_shell_env_t  rtems_global_shell_env;
203extern rtems_shell_env_t *rtems_current_shell_env;
204
205/*
206 * The types of file systems we can mount. We have them broken out
207 * out like this so they can be configured by shellconfig.h. The
208 * mount command needs special treatment due to some file systems
209 * being dependent on the network stack and some not. If we had
210 * all possible file systems being included it would force the
211 * networking stack into the applcation and this may not be
212 * required.
213 */
214struct rtems_shell_filesystems_tt;
215typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
216
217typedef int (*rtems_shell_filesystems_mounter_t)(
218  const char*                driver,
219  const char*                path,
220  rtems_shell_filesystems_t* fs,
221  rtems_filesystem_options_t options
222);
223
224struct rtems_shell_filesystems_tt {
225  const char*                        name;
226  int                                driver_needed;
227  rtems_filesystem_operations_table* fs_ops;
228  rtems_shell_filesystems_mounter_t  mounter;
229};
230
231/**
232 *  This method dynamically builds the command line prompt string
233 *  and places it in @a prompt.
234 *
235 *  @param[in] shell_env is the shell execution environment
236 *  @param[in] prompt is a pointer to a string buffer area
237 *  @param[in] size is length of the prompt buffer area
238 *
239 *  @return This method fills in the memory pointed to by @a prompt.
240 *
241 *  @note An application specific implementation can be provided
242 *        by the user.
243 */
244void rtems_shell_get_prompt(
245  rtems_shell_env_t *shell_env,
246  char              *prompt,
247  size_t             size
248);
249
250#ifdef __cplusplus
251}
252#endif
253
254#endif
Note: See TracBrowser for help on using the repository browser.