RTEMS 6.1-rc6
Loading...
Searching...
No Matches
shell.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2001 Fernando Ruiz Casas <fruizcasas@gmail.com>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 *
14 */
15
16#ifndef __RTEMS_SHELL_H__
17#define __RTEMS_SHELL_H__
18
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <rtems.h>
22#include <stdio.h>
23#include <termios.h>
24#include <rtems/fs.h>
25#include <rtems/libio.h>
26#include <rtems/chain.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
62extern bool rtems_shell_login_prompt(
63 FILE *in,
64 FILE *out,
65 const char *device,
66 rtems_shell_login_check_t check
67);
68
69extern bool 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
78
80 const char *name;
81 const char *usage;
82 const char *topic;
83 rtems_shell_command_t command;
84 rtems_shell_cmd_t *alias;
86 mode_t mode;
87 uid_t uid;
88 gid_t gid;
89};
90
91typedef struct {
92 const char *name;
93 const char *alias;
95
98
100 const char *topic;
102};
103
104/*
105 * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
106 * is extended, ie a special key.
107 */
108extern unsigned int rtems_shell_getchar(FILE *in);
109
110extern rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
111
112extern rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
113 rtems_shell_cmd_t *shell_cmd
114);
115
116rtems_shell_cmd_t * rtems_shell_add_cmd(
117 const char *cmd,
118 const char *topic,
119 const char *usage,
120 rtems_shell_command_t command
121);
122
123extern rtems_shell_cmd_t * rtems_shell_alias_cmd(
124 const char *cmd,
125 const char *alias
126);
127
128extern int rtems_shell_make_args(
129 char *commandLine,
130 int *argc_p,
131 char **argv_p,
132 int max_args
133);
134
135extern rtems_shell_topic_t * rtems_shell_lookup_topic(
136 const char *topic
137);
138
139extern bool rtems_shell_can_see_cmd(
140 const rtems_shell_cmd_t *shell_cmd
141);
142
143extern int rtems_shell_execute_cmd(
144 const char *cmd, int argc, char *argv[]
145);
146
147/*
148 * Call to set up the shell environment if you need to execute commands before
149 * running a shell.
150 */
151extern void rtems_shell_init_environment(
152 void
153);
154
155extern int rtems_shell_cat_file(
156 FILE *out,
157 const char *name
158);
159
160extern void rtems_shell_write_file(
161 const char *name,
162 const char *content
163);
164
165extern int rtems_shell_script_file(
166 int argc,
167 char **argv
168);
169
183 const char *task_name,
184 size_t task_stacksize,
185 rtems_task_priority task_priority,
186 const char *devname,
187 bool forever,
188 bool wait,
189 rtems_shell_login_check_t login_check
190);
191
206 const char *task_name,
207 size_t task_stacksize, /* 0 default*/
208 rtems_task_priority task_priority,
209 const char *input,
210 const char *output,
211 bool output_append,
212 bool wait,
213 bool echo
214);
215
219typedef struct {
222 bool managed;
223 const char *devname;
224 const char *taskname;
225 bool exit_shell; /* logout */
226 bool forever; /* repeat login */
227 int *exit_code;
228 bool exit_on_error;
229 bool echo;
230 char cwd[256];
231 const char *input;
232 const char *output;
233 bool output_append;
234 FILE *parent_stdin;
235 FILE *parent_stdout;
236 FILE *parent_stderr;
237 rtems_id wake_on_end;
238 rtems_shell_login_check_t login_check;
239
244 uid_t uid;
245
250 gid_t gid;
252
253bool rtems_shell_main_loop(
254 rtems_shell_env_t *rtems_shell_env
255);
256
277 rtems_shell_env_t *shell_env,
278 bool interactive,
279 FILE *line_editor_output
280);
281
282extern const rtems_shell_env_t rtems_global_shell_env;
283
284rtems_shell_env_t *rtems_shell_get_current_env(void);
285void rtems_shell_dup_current_env(rtems_shell_env_t *);
286
287/*
288 * The types of file systems we can mount. We have them broken out
289 * out like this so they can be configured by shellconfig.h. The
290 * mount command needs special treatment due to some file systems
291 * being dependent on the network stack and some not. If we had
292 * all possible file systems being included it would force the
293 * networking stack into the applcation and this may not be
294 * required.
295 */
298
299typedef int (*rtems_shell_filesystems_mounter_t)(
300 const char* driver,
301 const char* path,
304);
305
307 rtems_chain_node link;
308 const char *name;
309 int driver_needed;
311 rtems_shell_filesystems_mounter_t mounter;
312};
313
327extern void rtems_shell_get_prompt(
328 rtems_shell_env_t *shell_env,
329 char *prompt,
330 size_t size
331);
332
342 const char* driver,
343 const char* path,
346);
347
354
361
362typedef void (*rtems_shell_wait_for_input_notification)(
363 int fd,
364 int seconds_remaining,
365 void *arg
366);
367
376 int fd,
377 int timeout_in_seconds,
378 rtems_shell_wait_for_input_notification notification,
379 void *notification_arg
380);
381
393 int fd,
394 int timeout_in_seconds,
395 rtems_shell_wait_for_input_notification notification,
396 void *notification_arg,
397 int desired_input
398);
399
400extern int rtems_shell_main_monitor(int argc, char **argv);
401
402/*
403 * Provide these commands for application use, as their implementation
404 * is tedious.
405 */
406int rtems_shell_main_mv(int argc, char *argv[]);
407int rtems_shell_main_cp(int argc, char *argv[]);
408int rtems_shell_main_rm(int argc, char *argv[]);
409
410#ifdef __cplusplus
411}
412#endif
413
414#endif
This header file provides the Chains API.
rtems_filesystem_options_t
File system options.
Definition: libio.h:1666
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
uint32_t rtems_name
This type represents Classic API object names.
Definition: types.h:226
uint32_t rtems_task_priority
This integer type represents task priorities of the Classic API.
Definition: types.h:257
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
Basic Filesystem Types.
Basic IO API.
This header file defines the RTEMS Classic API.
rtems_status_code rtems_shell_wait_for_input(int fd, int timeout_in_seconds, rtems_shell_wait_for_input_notification notification, void *notification_arg)
Waits for input.
Definition: shell-wait-for-input.c:83
int rtems_shell_libc_mounter(const char *driver, const char *path, rtems_shell_filesystems_t *fs, rtems_filesystem_options_t options)
bool rtems_shell_run_main_loop(rtems_shell_env_t *shell_env, bool interactive, FILE *line_editor_output)
Runs the shell main loop.
Definition: shell.c:1222
void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t *fs)
void rtems_shell_get_prompt(rtems_shell_env_t *shell_env, char *prompt, size_t size)
Definition: shell_getprompt.c:31
void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t *fs)
rtems_status_code rtems_shell_init(const char *task_name, size_t task_stacksize, rtems_task_priority task_priority, const char *devname, bool forever, bool wait, rtems_shell_login_check_t login_check)
Definition: shell.c:1480
rtems_status_code rtems_shell_script(const char *task_name, size_t task_stacksize, rtems_task_priority task_priority, const char *input, const char *output, bool output_append, bool wait, bool echo)
Definition: shell.c:1511
rtems_status_code rtems_shell_wait_for_explicit_input(int fd, int timeout_in_seconds, rtems_shell_wait_for_input_notification notification, void *notification_arg, int desired_input)
Waits for explicit input.
Definition: shell-wait-for-input.c:50
This structure represents a chain node.
Definition: chain.h:78
File system operations table.
Definition: libio.h:489
Definition: shell.h:91
Definition: shell.h:79
Definition: shell.h:219
gid_t gid
The real and effective GID of the shell task in case no login check is present.
Definition: shell.h:250
uid_t uid
The real and effective UID of the shell task in case no login check is present.
Definition: shell.h:244
rtems_name magic
Definition: shell.h:221
Definition: shell.h:306
Definition: shell.h:99