Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:19

0001 /*
0002  * Copyright (c) 2014 embedded brains GmbH & Co. KG
0003  *
0004  * The license and distribution terms for this file may be
0005  * found in the file LICENSE in this distribution or at
0006  * http://www.rtems.org/license/LICENSE.
0007  */
0008 
0009 #ifdef HAVE_CONFIG_H
0010 #include "config.h"
0011 #endif
0012 
0013 #include <errno.h>
0014 #include <stdio.h>
0015 #include <string.h>
0016 
0017 #include <rtems/shellconfig.h>
0018 
0019 #include "internal.h"
0020 
0021 static void error(const char *s, int eno)
0022 {
0023   printf("%s: %s\n", s, strerror(eno));
0024 }
0025 
0026 static void print_cmd(const rtems_shell_cmd_t *shell_cmd)
0027 {
0028   if (rtems_shell_can_see_cmd(shell_cmd)) {
0029     mode_t m = shell_cmd->mode;
0030 
0031     printf(
0032       "%c%c%c%c%c%c%c%c%c %5u %5u %s\n",
0033       (m & S_IRUSR) != 0 ? 'r' : '-',
0034       (m & S_IWUSR) != 0 ? 'w' : '-',
0035       (m & S_IXUSR) != 0 ? 'x' : '-',
0036       (m & S_IRGRP) != 0 ? 'r' : '-',
0037       (m & S_IWGRP) != 0 ? 'w' : '-',
0038       (m & S_IXGRP) != 0 ? 'x' : '-',
0039       (m & S_IROTH) != 0 ? 'r' : '-',
0040       (m & S_IWOTH) != 0 ? 'w' : '-',
0041       (m & S_IXOTH) != 0 ? 'x' : '-',
0042       (unsigned) shell_cmd->uid,
0043       (unsigned) shell_cmd->gid,
0044       shell_cmd->name
0045     );
0046   }
0047 }
0048 
0049 static int rtems_shell_main_cmdls(int argc, char **argv)
0050 {
0051   const rtems_shell_cmd_t *shell_cmd;
0052 
0053   if (argc <= 1) {
0054     shell_cmd = rtems_shell_first_cmd;
0055 
0056     while (shell_cmd != NULL) {
0057       print_cmd(shell_cmd);
0058 
0059       shell_cmd = shell_cmd->next;
0060     }
0061   } else {
0062     int i;
0063 
0064     for (i = 1; i < argc; ++i) {
0065       const char *cmd = argv[i];
0066 
0067       shell_cmd = rtems_shell_lookup_cmd(cmd);
0068 
0069       if (shell_cmd != NULL) {
0070         print_cmd(shell_cmd);
0071       } else {
0072         error(cmd, ENOENT);
0073       }
0074     }
0075   }
0076 
0077   return 0;
0078 }
0079 
0080 rtems_shell_cmd_t rtems_shell_CMDLS_Command = {
0081   .name = "cmdls",
0082   .usage = "cmdls COMMAND...",
0083   .topic = "misc",
0084   .command = rtems_shell_main_cmdls
0085 };