source: rtems/cpukit/libmisc/shell/shell.h @ 2649eef

4.104.115
Last change on this file since 2649eef was 8a775c27, checked in by Joel Sherrill <joel.sherrill@…>, on 03/27/09 at 13:45:31

2009-03-27 Sebastian Huber <sebastian.huber@…>

  • Makefile.am, preinstall.am, libmisc/Makefile.am, libmisc/shell/shell.c, libmisc/shell/shell.h, telnetd/check_passwd.c, telnetd/telnetd.c, telnetd/telnetd.h: Generalized login check.
  • libmisc/shell/login.h, libmisc/shell/login_check.c, libmisc/shell/login_prompt.c: New files.
  • libmisc/stackchk/check.c: Changed format for blown stack message.
  • libcsupport/src/libio_sockets.c: Removed superfluous cast.
  • libnetworking/rtems/ftpfs.h: Documentation.
  • 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#include <rtems/login.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*
34 * Some key labels to define special keys.
35 */
36
37#define RTEMS_SHELL_KEYS_EXTENDED    (0x8000)
38#define RTEMS_SHELL_KEYS_NORMAL_MASK (0x00ff)
39#define RTEMS_SHELL_KEYS_INS         (0)
40#define RTEMS_SHELL_KEYS_DEL         (1)
41#define RTEMS_SHELL_KEYS_UARROW      (2)
42#define RTEMS_SHELL_KEYS_DARROW      (3)
43#define RTEMS_SHELL_KEYS_LARROW      (4)
44#define RTEMS_SHELL_KEYS_RARROW      (5)
45#define RTEMS_SHELL_KEYS_HOME        (6)
46#define RTEMS_SHELL_KEYS_END         (7)
47#define RTEMS_SHELL_KEYS_F1          (8)
48#define RTEMS_SHELL_KEYS_F2          (9)
49#define RTEMS_SHELL_KEYS_F3          (10)
50#define RTEMS_SHELL_KEYS_F4          (11)
51#define RTEMS_SHELL_KEYS_F5          (12)
52#define RTEMS_SHELL_KEYS_F6          (13)
53#define RTEMS_SHELL_KEYS_F7          (14)
54#define RTEMS_SHELL_KEYS_F8          (15)
55#define RTEMS_SHELL_KEYS_F9          (16)
56#define RTEMS_SHELL_KEYS_F10         (17)
57
58typedef int (*rtems_shell_command_t)(int argc, char **argv);
59
60struct rtems_shell_cmd_tt;
61typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
62
63struct rtems_shell_cmd_tt {
64  const char            *name;
65  const char            *usage;
66  const char            *topic;
67  rtems_shell_command_t  command;
68  rtems_shell_cmd_t     *alias;
69  rtems_shell_cmd_t     *next;
70};
71
72typedef struct {
73  const char *name;
74  const char *alias;
75} rtems_shell_alias_t;
76
77/*
78 * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
79 * is extended, ie a special key.
80 */
81unsigned int rtems_shell_getchar(FILE *in);
82
83rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
84
85rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
86  rtems_shell_cmd_t *shell_cmd
87);
88
89rtems_shell_cmd_t * rtems_shell_add_cmd(
90  const char            *cmd,
91  const char            *topic,
92  const char            *usage,
93  rtems_shell_command_t  command
94);
95
96rtems_shell_cmd_t * rtems_shell_alias_cmd(
97  const char *cmd,
98  const char *alias
99);
100
101int rtems_shell_make_args(
102  char  *commandLine,
103  int   *argc_p,
104  char **argv_p,
105  int    max_args
106);
107
108int rtems_shell_cat_file(
109  FILE *out,
110  const char *name
111);
112
113void rtems_shell_write_file(
114  const char *name,
115  const char *content
116);
117
118int rtems_shell_script_file(
119  int    argc,
120  char **argv
121);
122
123/**
124 * Initialise the shell creating tasks to login and run the shell
125 * sessions.
126 *
127 * @param task_name Name of the shell task.
128 * @param task_stacksize The size of the stack. If 0 the default size is used.
129 * @param task_priority The priority the shell runs at.
130 * @param forever Repeat logins.
131 * @param wait Caller should block until shell exits.
132 * @param login_check User login check function, NULL disables login checks.
133 *
134 */
135rtems_status_code rtems_shell_init(
136  const char          *task_name,
137  size_t               task_stacksize,  /* 0 default*/
138  rtems_task_priority  task_priority,
139  const char          *devname,
140  bool                 forever,
141  bool                 wait,
142  rtems_login_check    login_check
143);
144
145/**
146 * Run a shell script creating a shell tasks to execute the command under.
147 *
148 * @param task_name Name of the shell task.
149 * @param task_stacksize The size of the stack. If 0 the default size is used.
150 * @param task_priority The priority the shell runs at.
151 * @param input The file of commands. Can be 'stdin' to use stdin.
152 * @param output The output file to write commands to. Can be 'stdout',
153 *              'stderr' or '/dev/null'.
154 * @param output_append Append the output to the file or truncate the file.
155 *                      Create if it does not exist.
156 * @param wait Wait for the script to finish.
157 */
158rtems_status_code rtems_shell_script(
159  const char          *task_name,
160  size_t               task_stacksize,  /* 0 default*/
161  rtems_task_priority  task_priority,
162  const char          *input,
163  const char          *output,
164  bool                 output_append,
165  bool                 wait,
166  bool                 echo
167);
168
169/*
170 *  Things that are useful to external entities developing commands and plugging
171 *  them in.
172 */
173int rtems_shell_str2int(const char * s);
174
175typedef struct  {
176  rtems_name         magic; /* 'S','E','N','V': Shell Environment */
177  const char        *devname;
178  const char        *taskname;
179  /* user extensions */
180  bool               exit_shell; /* logout */
181  bool               forever; /* repeat login */
182  int                errorlevel;
183  bool               echo;
184  char               cwd[256];
185  const char        *input;
186  const char        *output;
187  bool               output_append;
188  rtems_id           wake_on_end;
189  rtems_login_check  login_check;
190} rtems_shell_env_t;
191
192bool rtems_shell_main_loop(
193  rtems_shell_env_t *rtems_shell_env
194);
195
196extern rtems_shell_env_t  rtems_global_shell_env;
197extern rtems_shell_env_t *rtems_current_shell_env;
198
199/*
200 * The types of file systems we can mount. We have them broken out
201 * out like this so they can be configured by shellconfig.h. The
202 * mount command needs special treatment due to some file systems
203 * being dependent on the network stack and some not. If we had
204 * all possible file systems being included it would force the
205 * networking stack into the applcation and this may not be
206 * required.
207 */
208struct rtems_shell_filesystems_tt;
209typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
210
211typedef int (*rtems_shell_filesystems_mounter_t)(
212  const char*                driver,
213  const char*                path,
214  rtems_shell_filesystems_t* fs,
215  rtems_filesystem_options_t options
216);
217
218struct rtems_shell_filesystems_tt {
219  const char                              *name;
220  int                                      driver_needed;
221  const rtems_filesystem_operations_table *fs_ops;
222  rtems_shell_filesystems_mounter_t        mounter;
223};
224
225/**
226 *  This method dynamically builds the command line prompt string
227 *  and places it in @a prompt.
228 *
229 *  @param[in] shell_env is the shell execution environment
230 *  @param[in] prompt is a pointer to a string buffer area
231 *  @param[in] size is length of the prompt buffer area
232 *
233 *  @return This method fills in the memory pointed to by @a prompt.
234 *
235 *  @note An application specific implementation can be provided
236 *        by the user.
237 */
238void rtems_shell_get_prompt(
239  rtems_shell_env_t *shell_env,
240  char              *prompt,
241  size_t             size
242);
243
244#ifdef __cplusplus
245}
246#endif
247
248#endif
Note: See TracBrowser for help on using the repository browser.