1 | /* |
---|
2 | * Copyright (c) 2014 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
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 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <errno.h> |
---|
20 | #include <stdio.h> |
---|
21 | #include <string.h> |
---|
22 | |
---|
23 | #include <rtems/shellconfig.h> |
---|
24 | |
---|
25 | #include "internal.h" |
---|
26 | |
---|
27 | static void error(const char *s, int eno) |
---|
28 | { |
---|
29 | printf("%s: %s\n", s, strerror(eno)); |
---|
30 | } |
---|
31 | |
---|
32 | static void print_cmd(const rtems_shell_cmd_t *shell_cmd) |
---|
33 | { |
---|
34 | if (rtems_shell_can_see_cmd(shell_cmd)) { |
---|
35 | mode_t m = shell_cmd->mode; |
---|
36 | |
---|
37 | printf( |
---|
38 | "%c%c%c%c%c%c%c%c%c %5u %5u %s\n", |
---|
39 | (m & S_IRUSR) != 0 ? 'r' : '-', |
---|
40 | (m & S_IWUSR) != 0 ? 'w' : '-', |
---|
41 | (m & S_IXUSR) != 0 ? 'x' : '-', |
---|
42 | (m & S_IRGRP) != 0 ? 'r' : '-', |
---|
43 | (m & S_IWGRP) != 0 ? 'w' : '-', |
---|
44 | (m & S_IXGRP) != 0 ? 'x' : '-', |
---|
45 | (m & S_IROTH) != 0 ? 'r' : '-', |
---|
46 | (m & S_IWOTH) != 0 ? 'w' : '-', |
---|
47 | (m & S_IXOTH) != 0 ? 'x' : '-', |
---|
48 | (unsigned) shell_cmd->uid, |
---|
49 | (unsigned) shell_cmd->gid, |
---|
50 | shell_cmd->name |
---|
51 | ); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | static int rtems_shell_main_cmdls(int argc, char **argv) |
---|
56 | { |
---|
57 | const rtems_shell_cmd_t *shell_cmd; |
---|
58 | |
---|
59 | if (argc <= 1) { |
---|
60 | shell_cmd = rtems_shell_first_cmd; |
---|
61 | |
---|
62 | while (shell_cmd != NULL) { |
---|
63 | print_cmd(shell_cmd); |
---|
64 | |
---|
65 | shell_cmd = shell_cmd->next; |
---|
66 | } |
---|
67 | } else { |
---|
68 | int i; |
---|
69 | |
---|
70 | for (i = 1; i < argc; ++i) { |
---|
71 | const char *cmd = argv[i]; |
---|
72 | |
---|
73 | shell_cmd = rtems_shell_lookup_cmd(cmd); |
---|
74 | |
---|
75 | if (shell_cmd != NULL) { |
---|
76 | print_cmd(shell_cmd); |
---|
77 | } else { |
---|
78 | error(cmd, ENOENT); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | return 0; |
---|
84 | } |
---|
85 | |
---|
86 | rtems_shell_cmd_t rtems_shell_CMDLS_Command = { |
---|
87 | .name = "cmdls", |
---|
88 | .usage = "cmdls COMMAND...", |
---|
89 | .topic = "misc", |
---|
90 | .command = rtems_shell_main_cmdls |
---|
91 | }; |
---|