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

4.104.11
Last change on this file since cbd1e87 was cbd1e87, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Apr 14, 2009 at 8:50:03 AM

adapt copyright statements

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