source: rtems/cpukit/libmisc/shell/main_cmdls.c @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#endif
12
13#include <errno.h>
14#include <stdio.h>
15#include <string.h>
16
17#include <rtems/shellconfig.h>
18
19#include "internal.h"
20
21static void error(const char *s, int eno)
22{
23  printf("%s: %s\n", s, strerror(eno));
24}
25
26static void print_cmd(const rtems_shell_cmd_t *shell_cmd)
27{
28  if (rtems_shell_can_see_cmd(shell_cmd)) {
29    mode_t m = shell_cmd->mode;
30
31    printf(
32      "%c%c%c%c%c%c%c%c%c %5u %5u %s\n",
33      (m & S_IRUSR) != 0 ? 'r' : '-',
34      (m & S_IWUSR) != 0 ? 'w' : '-',
35      (m & S_IXUSR) != 0 ? 'x' : '-',
36      (m & S_IRGRP) != 0 ? 'r' : '-',
37      (m & S_IWGRP) != 0 ? 'w' : '-',
38      (m & S_IXGRP) != 0 ? 'x' : '-',
39      (m & S_IROTH) != 0 ? 'r' : '-',
40      (m & S_IWOTH) != 0 ? 'w' : '-',
41      (m & S_IXOTH) != 0 ? 'x' : '-',
42      (unsigned) shell_cmd->uid,
43      (unsigned) shell_cmd->gid,
44      shell_cmd->name
45    );
46  }
47}
48
49static int rtems_shell_main_cmdls(int argc, char **argv)
50{
51  const rtems_shell_cmd_t *shell_cmd;
52
53  if (argc <= 1) {
54    shell_cmd = rtems_shell_first_cmd;
55
56    while (shell_cmd != NULL) {
57      print_cmd(shell_cmd);
58
59      shell_cmd = shell_cmd->next;
60    }
61  } else {
62    int i;
63
64    for (i = 1; i < argc; ++i) {
65      const char *cmd = argv[i];
66
67      shell_cmd = rtems_shell_lookup_cmd(cmd);
68
69      if (shell_cmd != NULL) {
70        print_cmd(shell_cmd);
71      } else {
72        error(cmd, ENOENT);
73      }
74    }
75  }
76
77  return 0;
78}
79
80rtems_shell_cmd_t rtems_shell_CMDLS_Command = {
81  .name = "cmdls",
82  .usage = "cmdls COMMAND...",
83  .topic = "misc",
84  .command = rtems_shell_main_cmdls
85};
Note: See TracBrowser for help on using the repository browser.