Changes in / [1dbe465:e367f5b8] in mainline


Ignore:
Location:
uspace/app/bdsh/cmds/modules
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.h

    r1dbe465 re367f5b8  
    44/* Prototypes for the cat command, excluding entry points */
    55
     6static unsigned int cat_file(const char *, size_t, bool, off64_t, off64_t, bool);
     7
    68#endif /* CAT_H */
    79
  • uspace/app/bdsh/cmds/modules/help/help.h

    r1dbe465 re367f5b8  
    33
    44/* Prototypes for the help command (excluding entry points) */
     5static int is_mod_or_builtin(char *);
    56
    67#endif
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.h

    r1dbe465 re367f5b8  
    44/* Prototypes for the mkdir command, excluding entry points */
    55
     6static unsigned int create_directory(const char *, unsigned int);
    67#endif /* MKDIR_H */
    78
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    r1dbe465 re367f5b8  
    4646#define RM_VERSION "0.0.1"
    4747
     48static rm_job_t rm;
     49
    4850static struct option const long_options[] = {
    4951        { "help", no_argument, 0, 'h' },
     
    5557};
    5658
    57 /* Return values for rm_scope() */
    58 #define RM_BOGUS 0
    59 #define RM_FILE  1
    60 #define RM_DIR   2
    61 
    62 /* Flags for rm_update() */
    63 #define _RM_ENTRY   0
    64 #define _RM_ADVANCE 1
    65 #define _RM_REWIND  2
    66 #define _RM_EXIT    3
    67 
    68 /* A simple job structure */
    69 typedef struct {
    70         /* Options set at run time */
    71         unsigned int force;      /* -f option */
    72         unsigned int recursive;  /* -r option */
    73         unsigned int safe;       /* -s option */
    74 
    75         /* Keeps track of the job in progress */
    76         int advance; /* How far deep we've gone since entering */
    77         DIR *entry;  /* Entry point to the tree being removed */
    78         char *owd;   /* Where we were when we invoked rm */
    79         char *cwd;   /* Current directory being transversed */
    80         char *nwd;   /* Next directory to be transversed */
    81 
    82         /* Counters */
    83         int f_removed; /* Number of files unlinked */
    84         int d_removed; /* Number of directories unlinked */
    85 } rm_job_t;
    86 
    87 static rm_job_t rm;
    88 
    89 static unsigned int rm_recursive(const char *);
    90 
    9159static unsigned int rm_start(rm_job_t *rm)
    9260{
     
    12795        if (NULL != rm->cwd)
    12896                free(rm->cwd);
    129 }
    130 
    131 static unsigned int rm_single(const char *path)
    132 {
    133         if (unlink(path)) {
    134                 cli_error(CL_EFAIL, "rm: could not remove file %s", path);
    135                 return 1;
    136         }
    137         return 0;
    138 }
    139 
    140 static unsigned int rm_scope(const char *path)
    141 {
    142         int fd;
    143         DIR *dirp;
    144 
    145         dirp = opendir(path);
    146         if (dirp) {
    147                 closedir(dirp);
    148                 return RM_DIR;
    149         }
    150 
    151         fd = open(path, O_RDONLY);
    152         if (fd > 0) {
    153                 close(fd);
    154                 return RM_FILE;
    155         }
    156 
    157         return RM_BOGUS;
    15897}
    15998
     
    215154
    216155        return ret + 1;
     156}
     157
     158static unsigned int rm_single(const char *path)
     159{
     160        if (unlink(path)) {
     161                cli_error(CL_EFAIL, "rm: could not remove file %s", path);
     162                return 1;
     163        }
     164        return 0;
     165}
     166
     167static unsigned int rm_scope(const char *path)
     168{
     169        int fd;
     170        DIR *dirp;
     171
     172        dirp = opendir(path);
     173        if (dirp) {
     174                closedir(dirp);
     175                return RM_DIR;
     176        }
     177
     178        fd = open(path, O_RDONLY);
     179        if (fd > 0) {
     180                close(fd);
     181                return RM_FILE;
     182        }
     183
     184        return RM_BOGUS;
    217185}
    218186
  • uspace/app/bdsh/cmds/modules/rm/rm.h

    r1dbe465 re367f5b8  
    22#define RM_H
    33
     4/* Return values for rm_scope() */
     5#define RM_BOGUS 0
     6#define RM_FILE  1
     7#define RM_DIR   2
     8
     9/* Flags for rm_update() */
     10#define _RM_ENTRY   0
     11#define _RM_ADVANCE 1
     12#define _RM_REWIND  2
     13#define _RM_EXIT    3
     14
     15/* A simple job structure */
     16typedef struct {
     17        /* Options set at run time */
     18        unsigned int force;      /* -f option */
     19        unsigned int recursive;  /* -r option */
     20        unsigned int safe;       /* -s option */
     21
     22        /* Keeps track of the job in progress */
     23        int advance; /* How far deep we've gone since entering */
     24        DIR *entry;  /* Entry point to the tree being removed */
     25        char *owd;   /* Where we were when we invoked rm */
     26        char *cwd;   /* Current directory being transversed */
     27        char *nwd;   /* Next directory to be transversed */
     28
     29        /* Counters */
     30        int f_removed; /* Number of files unlinked */
     31        int d_removed; /* Number of directories unlinked */
     32} rm_job_t;
     33
     34
    435/* Prototypes for the rm command, excluding entry points */
     36static unsigned int rm_start(rm_job_t *);
     37static void rm_end(rm_job_t *rm);
     38static unsigned int rm_recursive(const char *);
     39static unsigned int rm_single(const char *);
     40static unsigned int rm_scope(const char *);
    541
    642#endif /* RM_H */
  • uspace/app/bdsh/cmds/modules/sleep/sleep.c

    r1dbe465 re367f5b8  
    2727 */
    2828
    29 #include <errno.h>
    3029#include <stdio.h>
    3130#include <stdlib.h>
    32 #include <unistd.h>
    3331#include "config.h"
    3432#include "util.h"
     
    4341void help_cmd_sleep(unsigned int level)
    4442{
    45         if (level == HELP_SHORT) {
    46                 printf("`%s' pauses for a given time interval\n", cmdname);
    47         } else {
    48                 help_cmd_sleep(HELP_SHORT);
    49                 printf(
    50                     "Usage:  %s <duration>\n"
    51                     "The duration is a decimal number of seconds.\n",
    52                     cmdname);
    53         }
    54 
     43        printf("This is the %s help for '%s'.\n",
     44                level ? EXT_HELP : SHORT_HELP, cmdname);
    5545        return;
    56 }
    57 
    58 /** Convert string containing decimal seconds to useconds_t.
    59  *
    60  * @param nptr   Pointer to string.
    61  * @param result Result of the conversion.
    62  * @return EOK if conversion was successful.
    63  */
    64 static int decimal_to_useconds(const char *nptr, useconds_t *result)
    65 {
    66         int ret;
    67         uint64_t whole_seconds;
    68         uint64_t frac_seconds;
    69         char *endptr;
    70 
    71         /* Check for whole seconds */
    72         if (*nptr == '.') {
    73                 whole_seconds = 0;
    74                 endptr = (char *)nptr;
    75         } else {
    76                 ret = str_uint64_t(nptr, &endptr, 10, false, &whole_seconds);
    77                 if (ret != EOK)
    78                         return ret;
    79         }
    80 
    81         /* Check for fractional seconds */
    82         if (*endptr == '\0') {
    83                 frac_seconds = 0;
    84         } else if (*endptr == '.' && endptr[1] == '\0') {
    85                 frac_seconds = 0;
    86         } else if (*endptr == '.') {
    87                 nptr = endptr + 1;
    88                 ret = str_uint64_t(nptr, &endptr, 10, true, &frac_seconds);
    89                 if (ret != EOK)
    90                         return ret;
    91 
    92                 int ndigits = endptr - nptr;
    93                 for (; ndigits < 6; ndigits++)
    94                         frac_seconds *= 10;
    95                 for (; ndigits > 6; ndigits--)
    96                         frac_seconds /= 10;
    97         } else {
    98                 return EINVAL;
    99         }
    100 
    101         /* Check for overflow */
    102         useconds_t total = whole_seconds * 1000000 + frac_seconds;
    103         if (total / 1000000 != whole_seconds)
    104                 return EOVERFLOW;
    105 
    106         *result = total;
    107 
    108         return EOK;
    10946}
    11047
     
    11249int cmd_sleep(char **argv)
    11350{
    114         int ret;
    11551        unsigned int argc;
    116         useconds_t duration;
     52        unsigned int i;
    11753
    11854        /* Count the arguments */
    119         argc = cli_count_args(argv);
     55        for (argc = 0; argv[argc] != NULL; argc ++);
    12056
    121         if (argc != 2) {
    122                 printf("%s - incorrect number of arguments. Try `help %s'\n",
    123                     cmdname, cmdname);
    124                 return CMD_FAILURE;
     57        printf("%s %s\n", TEST_ANNOUNCE, cmdname);
     58        printf("%d arguments passed to %s", argc - 1, cmdname);
     59
     60        if (argc < 2) {
     61                printf("\n");
     62                return CMD_SUCCESS;
    12563        }
    12664
    127         ret = decimal_to_useconds(argv[1], &duration);
    128         if (ret != EOK) {
    129                 printf("%s - invalid duration.\n", cmdname);
    130                 return CMD_FAILURE;
    131         }
    132 
    133         (void) usleep(duration);
     65        printf(":\n");
     66        for (i = 1; i < argc; i++)
     67                printf("[%d] -> %s\n", i, argv[i]);
    13468
    13569        return CMD_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.