source: rtems/cpukit/libmisc/shell/shell.h @ 8916bdc7

4.104.11
Last change on this file since 8916bdc7 was 8916bdc7, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Mar 26, 2009 at 2:11:53 PM
  • libmisc/shell/shell.h: Pointer to oparations table for mount command is now const.
  • libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h: Rewrite of the FTP file system which implements now the trivial command state machines of RFC 959. For the data transfer passive (= default) and active (= fallback) modes are now supported.
  • libmisc/shell/main_mount_ftp.c: Update for FTP file system changes.
  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[cbd7691]1/**
2 * @file rtems/shell.h
[70d689a]3 *
4 *  Instantatiate a new terminal shell.
[cbd7691]5 */
6
7/*
[aed742c]8 *  Author:
[70d689a]9 *
[aed742c]10 *   WORK: fernando.ruiz@ctv.es
[70d689a]11 *   HOME: correo@fernando-ruiz.com
12 *
13 *   Thanks at:
[2eeb648c]14 *    Chris Johns
[70d689a]15 *
[dd74e612]16 *  $Id$
17 */
18
[2eeb648c]19#ifndef __RTEMS_SHELL_H__
20#define __RTEMS_SHELL_H__
[dd74e612]21
[aed742c]22#include <rtems.h>
23#include <stdio.h>
24#include <termios.h>
[2eeb648c]25#include <rtems/fs.h>
26#include <rtems/libio.h>
[dd74e612]27
[714f06c]28#ifdef __cplusplus
29extern "C" {
30#endif
31
[ea90df23]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
[e41eaa88]57typedef int (*rtems_shell_command_t)(int argc, char **argv);
[dd74e612]58
[2eeb648c]59struct rtems_shell_cmd_tt;
60typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
[dd74e612]61
[2eeb648c]62struct rtems_shell_cmd_tt {
[e41eaa88]63  const char            *name;
64  const char            *usage;
65  const char            *topic;
[2eeb648c]66  rtems_shell_command_t  command;
67  rtems_shell_cmd_t     *alias;
68  rtems_shell_cmd_t     *next;
[dd74e612]69};
70
[4e5299f]71typedef struct {
[e41eaa88]72  const char *name;
73  const char *alias;
[2eeb648c]74} rtems_shell_alias_t;
[4e5299f]75
[ea90df23]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
[e41eaa88]82rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
[dd74e612]83
[2eeb648c]84rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
85  rtems_shell_cmd_t *shell_cmd
[4e5299f]86);
[dd74e612]87
[2eeb648c]88rtems_shell_cmd_t * rtems_shell_add_cmd(
[e41eaa88]89  const char            *cmd,
90  const char            *topic,
91  const char            *usage,
[2eeb648c]92  rtems_shell_command_t  command
[4e5299f]93);
94
[2eeb648c]95rtems_shell_cmd_t * rtems_shell_alias_cmd(
[e41eaa88]96  const char *cmd,
97  const char *alias
[4e5299f]98);
99
[2eeb648c]100int rtems_shell_make_args(
[814d9588]101  char  *commandLine,
102  int   *argc_p, 
103  char **argv_p, 
104  int    max_args
[4e5299f]105);
[dd74e612]106
[a3ddb08b]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,
[e41eaa88]116  const char *name
[a3ddb08b]117);
118
119void rtems_shell_write_file(
120  const char *name,
121  const char *content
122);
123
124int rtems_shell_script_file(
[e41eaa88]125  int    argc,
126  char **argv
[a3ddb08b]127);
[aed742c]128
[dec8f84]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.
[06f8e558]137 * @param wait Caller should block until shell exits.
138 * @param login Demand user login.
[dec8f84]139 *
140 */
[2eeb648c]141rtems_status_code rtems_shell_init(
[e41eaa88]142  const char          *task_name,
[06f8e558]143  size_t               task_stacksize,  /* 0 default*/
[6dd411aa]144  rtems_task_priority  task_priority,
[e41eaa88]145  const char          *devname,
[06f8e558]146  bool                 forever,
147  bool                 wait,
148  bool                 login
[6dd411aa]149);
150
[1ff9922]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(
[e41eaa88]165  const char          *task_name,
[06f8e558]166  size_t               task_stacksize,  /* 0 default*/
[1ff9922]167  rtems_task_priority  task_priority,
168  const char          *input,
169  const char          *output,
[06f8e558]170  bool                 output_append,
171  bool                 wait,
172  bool                 echo
[1ff9922]173);
174
[4e5299f]175/*
176 *  Things that are useful to external entities developing commands and plugging
177 *  them in.
178 */
[e41eaa88]179int rtems_shell_str2int(const char * s);
[4e5299f]180
181typedef struct  {
182  rtems_name  magic; /* 'S','E','N','V': Shell Environment */
[e41eaa88]183  const char *devname;
184  const char *taskname;
[4e5299f]185  /* user extensions */
[1167235]186  bool        exit_shell; /* logout */
187  bool        forever   ; /* repeat login */
[4e5299f]188  int         errorlevel;
[06f8e558]189  bool        echo;
[55c64fc]190  char        cwd[256];
[1ff9922]191  const char* input;
192  const char* output;
[06f8e558]193  bool        output_append;
[1ff9922]194  rtems_id    wake_on_end;
[06f8e558]195  bool        login;
[2eeb648c]196} rtems_shell_env_t;
[4e5299f]197
[1167235]198bool rtems_shell_main_loop(
[2eeb648c]199  rtems_shell_env_t *rtems_shell_env
[6dd411aa]200);
201
[2eeb648c]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;
[8e30a269]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
[2eeb648c]224struct rtems_shell_filesystems_tt {
[8916bdc7]225  const char                              *name;
226  int                                      driver_needed;
227  const rtems_filesystem_operations_table *fs_ops;
228  rtems_shell_filesystems_mounter_t        mounter;
[2eeb648c]229};
[dd74e612]230
[f3db4ac8]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
[dd74e612]250#ifdef __cplusplus
251}
[aed742c]252#endif
[dd74e612]253
254#endif
Note: See TracBrowser for help on using the repository browser.