Changeset 3e828ea in mainline for uspace/app/bdsh


Ignore:
Timestamp:
2019-09-23T12:49:29Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9be2358
Parents:
9259d20 (diff), 1a4ec93f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiri Svoboda <jiri@…> (2019-09-22 12:49:07)
git-committer:
Jiri Svoboda <jiri@…> (2019-09-23 12:49:29)
Message:

Merge changes from master, especially Meson build

Location:
uspace/app/bdsh
Files:
8 added
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r9259d20 r3e828ea  
    4242#include <vfs/vfs.h>
    4343#include <str.h>
     44#include <cap.h>
    4445
    4546#include "ls.h"
     
    5859        { "unsort", no_argument, 0, 'u' },
    5960        { "recursive", no_argument, 0, 'r' },
     61        { "exact-size", no_argument, 0, 'e' },
     62        { "single-column", no_argument, 0, '1' },
    6063        { 0, 0, 0, 0 }
    6164};
     
    6366/* Prototypes for the ls command, excluding entry points. */
    6467static unsigned int ls_start(ls_job_t *);
    65 static void ls_print(struct dir_elem_t *);
    66 static int ls_cmp(const void *, const void *);
     68static errno_t ls_print(struct dir_elem_t *);
     69static errno_t ls_print_single_column(struct dir_elem_t *);
     70static int ls_cmp_type_name(const void *, const void *);
     71static int ls_cmp_name(const void *, const void *);
    6772static signed int ls_scan_dir(const char *, DIR *, struct dir_elem_t **);
    6873static unsigned int ls_recursive(const char *, DIR *);
     
    7479        ls->sort = 1;
    7580
     81        ls->exact_size = false;
     82        ls->single_column = false;
     83        ls->printer = ls_print;
    7684        return 1;
    7785}
     
    8896 * @param de            Directory element.
    8997 */
    90 static void ls_print(struct dir_elem_t *de)
    91 {
    92         if (de->s.is_file)
    93                 printf("%-40s\t%llu\n", de->name, (long long) de->s.size);
    94         else if (de->s.is_directory)
    95                 printf("%-40s\t<dir>\n", de->name);
     98static errno_t ls_print(struct dir_elem_t *de)
     99{
     100        int width = 13;
     101
     102        if (de->s.is_file) {
     103                if (ls.exact_size) {
     104                        printf("%-40s\t%*llu\n", de->name, width, (long long) de->s.size);
     105                        return EOK;
     106                }
     107
     108                cap_spec_t cap;
     109                cap_from_blocks(de->s.size, 1, &cap);
     110                cap_simplify(&cap);
     111
     112                char *rptr;
     113                errno_t rc = cap_format(&cap, &rptr);
     114                if (rc != EOK) {
     115                        return rc;
     116                }
     117
     118                char *sep = str_rchr(rptr, ' ');
     119                if (sep == NULL) {
     120                        free(rptr);
     121                        return ENOENT;
     122                }
     123
     124                *sep = '\0';
     125
     126                printf("%-40s\t%*s %2s\n", de->name, width - 3, rptr, sep + 1);
     127                free(rptr);
     128        } else if (de->s.is_directory)
     129                printf("%-40s\t%*s\n", de->name, width, "<dir>");
    96130        else
    97131                printf("%-40s\n", de->name);
     132
     133        return EOK;
     134}
     135
     136static errno_t ls_print_single_column(struct dir_elem_t *de)
     137{
     138        if (de->s.is_file) {
     139                printf("%s\n", de->name);
     140        } else {
     141                printf("%s/\n", de->name);
     142        }
     143
     144        return EOK;
    98145}
    99146
     
    109156 * @return              -1 if a < b, 1 otherwise.
    110157 */
    111 static int ls_cmp(const void *a, const void *b)
     158static int ls_cmp_type_name(const void *a, const void *b)
    112159{
    113160        struct dir_elem_t const *da = a;
     
    120167        else
    121168                return 1;
     169}
     170
     171/** Compare directories/files per name
     172 *
     173 * This comparision ignores the type of
     174 * the node. Sorted will strictly by name.
     175 *
     176 */
     177static int ls_cmp_name(const void *a, const void *b)
     178{
     179        struct dir_elem_t const *da = a;
     180        struct dir_elem_t const *db = b;
     181
     182        return str_cmp(da->name, db->name);
    122183}
    123184
     
    192253        }
    193254
    194         if (ls.sort)
    195                 qsort(&tosort[0], nbdirs, sizeof(struct dir_elem_t), ls_cmp);
    196 
    197         for (i = 0; i < nbdirs; i++)
    198                 ls_print(&tosort[i]);
     255        if (ls.sort) {
     256                int (*compar)(const void *, const void *);
     257                compar = ls.single_column ? ls_cmp_name : ls_cmp_type_name;
     258                qsort(&tosort[0], nbdirs, sizeof(struct dir_elem_t), compar);
     259        }
     260
     261        for (i = 0; i < nbdirs; i++) {
     262                if (ls.printer(&tosort[i]) != EOK) {
     263                        cli_error(CL_ENOMEM, "%s: Out of memory", cmdname);
     264                        goto out;
     265                }
     266        }
    199267
    200268        /* Populate the directory list. */
     
    333401                    "If not path is given, the current working directory is used.\n"
    334402                    "Options:\n"
    335                     "  -h, --help       A short option summary\n"
    336                     "  -u, --unsort     Do not sort directory entries\n"
    337                     "  -r, --recursive  List subdirectories recursively\n",
     403                    "  -h, --help            A short option summary\n"
     404                    "  -u, --unsort          Do not sort directory entries\n"
     405                    "  -r, --recursive       List subdirectories recursively\n"
     406                    "  -e, --exact-size      File sizes will be unformatted (raw bytes count)\n"
     407                    "  -1, --single-column   Only the names will be returned\n",
    338408                    cmdname);
    339409        }
     
    364434
    365435        while (c != -1) {
    366                 c = getopt_long(argc, argv, "hur", long_options, &opt_ind);
     436                c = getopt_long(argc, argv, "hure1", long_options, &opt_ind);
    367437                switch (c) {
    368438                case 'h':
     
    375445                        ls.recursive = 1;
    376446                        break;
     447                case 'e':
     448                        ls.exact_size = true;
     449                        break;
     450                case '1':
     451                        ls.single_column = true;
     452                        ls.printer = ls_print_single_column;
     453                        break;
    377454                }
    378455        }
     
    400477        switch (scope) {
    401478        case LS_FILE:
    402                 ls_print(&de);
     479                if (ls.printer(&de) != EOK) {
     480                        cli_error(CL_ENOMEM, "%s: Out of memory", cmdname);
     481                        return CMD_FAILURE;
     482                }
    403483                break;
    404484        case LS_DIR:
  • uspace/app/bdsh/cmds/modules/ls/ls.h

    r9259d20 r3e828ea  
    88#define LS_FILE  1
    99#define LS_DIR   2
    10 
    11 typedef struct {
    12         /* Options set at runtime. */
    13         unsigned int recursive;
    14         unsigned int sort;
    15 
    16 } ls_job_t;
    1710
    1811/** Structure to represent a directory entry.
     
    2619};
    2720
     21typedef struct {
     22        /* Options set at runtime. */
     23        unsigned int recursive;
     24        unsigned int sort;
     25
     26        bool single_column;
     27        bool exact_size;
     28
     29        errno_t (*printer)(struct dir_elem_t *);
     30} ls_job_t;
     31
    2832#endif
  • uspace/app/bdsh/cmds/modules/modules.c

    r9259d20 r3e828ea  
    6363#include "echo/entry.h"
    6464#include "cmp/entry.h"
     65#include "alias/entry.h"
     66#include "unalias/entry.h"
    6567
    6668/*
     
    8890#include "echo/echo_def.inc"
    8991#include "cmp/cmp_def.inc"
     92#include "alias/alias_def.inc"
     93#include "unalias/unalias_def.inc"
    9094
    9195        { NULL, NULL, NULL, NULL }
  • uspace/app/bdsh/cmds/modules/modules.h

    r9259d20 r3e828ea  
    3131
    3232#include "../cmds.h"
    33 #include "modules.h"
    3433
    3534extern module_t modules[];
  • uspace/app/bdsh/compl.c

    r9259d20 r3e828ea  
    3535#include <vfs/vfs.h>
    3636#include <str.h>
    37 
     37#include <adt/odict.h>
     38
     39#include "scli.h"
    3840#include "cmds/cmds.h"
    3941#include "compl.h"
    4042#include "exec.h"
    4143#include "tok.h"
     44#include "util.h"
    4245
    4346static errno_t compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state);
     
    6265        /** Length of string prefix (number of characters) */
    6366        size_t prefix_len;
     67
     68        /* Pointer to the current alias */
     69        odlink_t *alias_link;
    6470
    6571        /** Pointer inside list of modules */
     
    209215                }
    210216                *cstart += rpath_sep + 1 - prefix;
    211                 free(prefix);
    212                 prefix = NULL;
    213217
    214218                cs->path_list = malloc(sizeof(char *) * 2);
     
    217221                        goto error;
    218222                }
    219                 cs->path_list[0] = dirname;
     223
     224                if (!is_path(prefix) && cs->is_command) {
     225                        cs->path_list[0] = malloc(sizeof(char) * PATH_MAX);
     226                        if (cs->path_list[0] == NULL) {
     227                                retval = ENOMEM;
     228                                goto error;
     229                        }
     230
     231                        int ret = snprintf(cs->path_list[0], PATH_MAX, "%s/%s", search_dir[0], dirname);
     232                        if (ret < 0 || ret >= PATH_MAX) {
     233                                retval = ENOMEM;
     234                                goto error;
     235                        }
     236                } else {
     237                        cs->path_list[0] = dirname;
     238                }
     239
     240                free(prefix);
    220241                cs->path_list[1] = NULL;
    221242                /*
     
    227248        } else if (cs->is_command) {
    228249                /* Command without path */
     250                cs->alias_link = odict_first(&alias_dict);
    229251                cs->module = modules;
    230252                cs->builtin = builtins;
     
    305327        }
    306328
     329        /* Alias */
     330        if (cs->alias_link != NULL) {
     331                while (*compl == NULL && cs->alias_link != NULL) {
     332                        alias_t *data = odict_get_instance(cs->alias_link, alias_t, odict);
     333                        if (compl_match_prefix(cs, data->name)) {
     334                                asprintf(compl, "%s ", data->name);
     335                                cs->last_compl = *compl;
     336                                if (*compl == NULL)
     337                                        return ENOMEM;
     338                        }
     339                        cs->alias_link = odict_next(cs->alias_link, &alias_dict);
     340                }
     341        }
     342
    307343        /* Modules */
    308344        if (cs->module != NULL) {
    309345                while (*compl == NULL && cs->module->name != NULL) {
     346                        /* prevents multiple listing of an overriden cmd */
    310347                        if (compl_match_prefix(cs, cs->module->name)) {
    311                                 asprintf(compl, "%s ", cs->module->name);
    312                                 cs->last_compl = *compl;
    313                                 if (*compl == NULL)
    314                                         return ENOMEM;
     348                                odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cs->module->name, NULL);
     349                                if (alias_link == NULL) {
     350                                        asprintf(compl, "%s ", cs->module->name);
     351                                        cs->last_compl = *compl;
     352                                        if (*compl == NULL)
     353                                                return ENOMEM;
     354                                }
    315355                        }
    316356                        cs->module++;
     
    322362                while (*compl == NULL && cs->builtin->name != NULL) {
    323363                        if (compl_match_prefix(cs, cs->builtin->name)) {
    324                                 asprintf(compl, "%s ", cs->builtin->name);
    325                                 cs->last_compl = *compl;
    326                                 if (*compl == NULL)
    327                                         return ENOMEM;
     364                                /* prevents multiple listing of an overriden cmd */
     365                                odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cs->module->name, NULL);
     366                                if (alias_link == NULL) {
     367                                        asprintf(compl, "%s ", cs->builtin->name);
     368                                        cs->last_compl = *compl;
     369                                        if (*compl == NULL)
     370                                                return ENOMEM;
     371                                }
    328372                        }
    329373                        cs->builtin++;
     
    373417                                free(ent_path);
    374418
     419                                /* prevents multiple listing of an overriden cmd */
     420                                if (cs->is_command && !ent_stat.is_directory) {
     421                                        odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)dent->d_name, NULL);
     422                                        if (alias_link != NULL) {
     423                                                continue;
     424                                        }
     425                                }
     426
    375427                                asprintf(compl, "%s%c", dent->d_name,
    376428                                    ent_stat.is_directory ? '/' : ' ');
  • uspace/app/bdsh/config.h

    r9259d20 r3e828ea  
    4242#endif
    4343
     44/* define maximal nested aliases */
     45#ifndef HUBS_MAX
     46#define HUBS_MAX 20
     47#endif
     48
    4449/* Used in many places */
    4550#define SMALL_BUFLEN 256
  • uspace/app/bdsh/exec.c

    r9259d20 r3e828ea  
    4747#include "errors.h"
    4848
    49 /* FIXME: Just have find_command() return an allocated string */
    50 static char *found;
    51 
    52 static char *find_command(char *);
     49static errno_t find_command(char *, char **);
    5350static int try_access(const char *);
    5451
     
    6865}
    6966
    70 /** Returns the full path of "cmd" if cmd is found
     67/** Returns EOK if no internal failure or else ENOMEM
    7168 *
    72  * else just hand back cmd as it was presented
     69 * When the parameter `cmd` can be found then the absolute path will be set in `found`.
     70 * Or else `found` will be NULL.
     71 * `found` will be newly allocated and must be freed by the caller
    7372 */
    74 static char *find_command(char *cmd)
     73static errno_t find_command(char *cmd, char **found)
    7574{
    76         size_t i;
     75        /* The user has specified a full or relative path, just give it back. */
     76        if (is_path(cmd)) {
     77                if (-1 != try_access(cmd)) {
     78                        *found = str_dup(cmd);
     79                        return EOK;
     80                }
    7781
    78         found = (char *)malloc(PATH_MAX);
     82                *found = NULL;
     83                return EOK;
     84        }
    7985
    80         /* The user has specified a full or relative path, just give it back. */
    81         if (-1 != try_access(cmd)) {
    82                 return (char *) cmd;
     86        *found = (char *)malloc(PATH_MAX);
     87        if (*found == NULL) {
     88                return ENOMEM;
    8389        }
    8490
    8591        /* We now have n places to look for the command */
     92        size_t i;
     93        size_t cmd_length = str_length(cmd);
    8694        for (i = 0; search_dir[i] != NULL; i++) {
    87                 memset(found, 0, PATH_MAX);
    88                 snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd);
    89                 if (-1 != try_access(found)) {
    90                         return (char *) found;
     95                if (str_length(search_dir[i]) + cmd_length + 2 > PATH_MAX) {
     96                        free(*found);
     97                        return ENOMEM;
     98                }
     99
     100                memset(*found, 0, PATH_MAX);
     101                snprintf(*found, PATH_MAX, "%s/%s", search_dir[i], cmd);
     102                if (-1 != try_access(*found)) {
     103                        return EOK;
    91104                }
    92105        }
     106        free(*found);
     107        *found = NULL;
    93108
    94         /* We didn't find it, just give it back as-is. */
    95         return (char *) cmd;
     109        /* We didn't find it, return NULL */
     110        return EOK;
    96111}
    97112
     
    107122        FILE *files[3];
    108123
    109         tmp = str_dup(find_command(cmd));
    110         free(found);
     124        rc = find_command(cmd, &tmp);
     125        if (rc != EOK) {
     126                cli_error(CL_ENOMEM, "%s: failure executing find_command()", progname);
     127                return 1;
     128        }
     129
     130        if (tmp == NULL) {
     131                cli_error(CL_EEXEC, "%s: Command not found '%s'", progname, cmd);
     132                return 1;
     133        }
    111134
    112135        files[0] = io->stdin;
  • uspace/app/bdsh/input.c

    r9259d20 r3e828ea  
    33 * Copyright (c) 2011 Jiri Svoboda
    44 * Copyright (c) 2011 Martin Sucha
     5 * Copyright (c) 2018 Matthieu Riolo
    56 * All rights reserved.
    67 *
     
    4344#include <stdbool.h>
    4445#include <tinput.h>
     46#include <adt/odict.h>
     47#include <adt/list.h>
    4548
    4649#include "config.h"
     
    6265static void print_pipe_usage(void);
    6366
     67typedef struct {
     68        link_t alias_hup_link;
     69        alias_t *alias;
     70} alias_hup_t;
     71
     72static bool find_alias_hup(alias_t *alias, list_t *alias_hups)
     73{
     74        list_foreach(*alias_hups, alias_hup_link, alias_hup_t, link) {
     75                if (alias == link->alias) {
     76                        return true;
     77                }
     78        }
     79
     80        return false;
     81}
     82
    6483/*
    6584 * Tokenizes input from console, sees if the first word is a built-in, if so
     
    6786 * the handler
    6887 */
    69 errno_t process_input(cliuser_t *usr)
    70 {
     88static errno_t process_input_nohup(cliuser_t *usr, list_t *alias_hups, size_t count_executed_hups)
     89{
     90        if (count_executed_hups >= HUBS_MAX) {
     91                cli_error(CL_EFAIL, "%s: maximal alias hubs reached\n", PACKAGE_NAME);
     92                return ELIMIT;
     93        }
     94
    7195        token_t *tokens_buf = calloc(WORD_MAX, sizeof(token_t));
    7296        if (tokens_buf == NULL)
     
    171195        }
    172196
     197        /* test if the passed cmd is an alias */
     198        odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cmd[0], NULL);
     199        if (alias_link != NULL) {
     200                alias_t *data = odict_get_instance(alias_link, alias_t, odict);
     201                /* check if the alias already has been resolved once */
     202                if (!find_alias_hup(data, alias_hups)) {
     203                        alias_hup_t *hup = (alias_hup_t *)calloc(1, sizeof(alias_hup_t));
     204                        if (hup == NULL) {
     205                                cli_error(CL_EFAIL, "%s: cannot allocate alias structure\n", PACKAGE_NAME);
     206                                rc = ENOMEM;
     207                                goto finit;
     208                        }
     209
     210                        hup->alias = data;
     211                        list_append(&hup->alias_hup_link, alias_hups);
     212
     213                        char *oldLine = usr->line;
     214                        const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1;
     215                        usr->line = (char *)malloc(input_length);
     216                        if (usr->line == NULL) {
     217                                cli_error(CL_EFAIL, "%s: cannot allocate input structure\n", PACKAGE_NAME);
     218                                rc = ENOMEM;
     219                                goto finit;
     220                        }
     221
     222                        usr->line[0] = '\0';
     223
     224                        unsigned int cmd_replace_index = cmd_token_start;
     225                        for (i = 0; i < tokens_length; i++) {
     226                                if (i == cmd_replace_index) {
     227                                        /* if there is a pipe symbol than cmd_token_start will point at the SPACE after the pipe symbol */
     228                                        if (tokens[i].type == TOKTYPE_SPACE) {
     229                                                cmd_replace_index++;
     230                                                str_append(usr->line, input_length, tokens[i].text);
     231                                                continue;
     232                                        }
     233
     234                                        str_append(usr->line, input_length, data->value);
     235                                } else {
     236                                        str_append(usr->line, input_length, tokens[i].text);
     237                                }
     238                        }
     239
     240                        /* reprocess input after string replace */
     241                        rc = process_input_nohup(usr, alias_hups, count_executed_hups + 1);
     242                        usr->line = oldLine;
     243                        goto finit;
     244                }
     245        }
     246
    173247        iostate_t new_iostate = {
    174248                .stdin = stdin,
     
    225299}
    226300
     301errno_t process_input(cliuser_t *usr)
     302{
     303        list_t alias_hups;
     304        list_initialize(&alias_hups);
     305
     306        errno_t rc = process_input_nohup(usr, &alias_hups, 0);
     307
     308        list_foreach_safe(alias_hups, cur_link, next_link) {
     309                alias_hup_t *cur_item = list_get_instance(cur_link, alias_hup_t, alias_hup_link);
     310                free(cur_item);
     311        }
     312
     313        return rc;
     314}
     315
    227316void print_pipe_usage(void)
    228317{
  • uspace/app/bdsh/meson.build

    r9259d20 r3e828ea  
    2828#
    2929
    30 USPACE_PREFIX = ../..
    31 LIBS = clui fmtutil
    32 EXTRA_CFLAGS = -I. -Icmds/ -Icmds/builtins -Icmds/modules
    33 BINARY = bdsh
     30deps = [ 'clui', 'fmtutil' ]
     31includes += include_directories('.', 'cmds', 'cmds/builtins', 'cmds/modules')
     32src = files(
     33        'cmds/builtin_cmds.c',
     34        'cmds/builtins/batch/batch.c',
     35        'cmds/builtins/builtin_aliases.c',
     36        'cmds/builtins/builtins.c',
     37        'cmds/builtins/cd/cd.c',
     38        'cmds/builtins/exit/exit.c',
     39        'cmds/mod_cmds.c',
     40        'cmds/modules/alias/alias.c',
     41        'cmds/modules/cat/cat.c',
     42        'cmds/modules/cmp/cmp.c',
     43        'cmds/modules/cp/cp.c',
     44        'cmds/modules/echo/echo.c',
     45        'cmds/modules/help/help.c',
     46        'cmds/modules/kcon/kcon.c',
     47        'cmds/modules/ls/ls.c',
     48        'cmds/modules/mkdir/mkdir.c',
     49        'cmds/modules/mkfile/mkfile.c',
     50        'cmds/modules/module_aliases.c',
     51        'cmds/modules/modules.c',
     52        'cmds/modules/mount/mount.c',
     53        'cmds/modules/mv/mv.c',
     54        'cmds/modules/printf/printf.c',
     55        'cmds/modules/pwd/pwd.c',
     56        'cmds/modules/rm/rm.c',
     57        'cmds/modules/sleep/sleep.c',
     58        'cmds/modules/touch/touch.c',
     59        'cmds/modules/unalias/unalias.c',
     60        'cmds/modules/unmount/unmount.c',
     61        'compl.c',
     62        'errors.c',
     63        'exec.c',
     64        'input.c',
     65        'scli.c',
     66        'tok.c',
     67        'util.c',
     68)
    3469
    35 SOURCES = \
    36         cmds/modules/module_aliases.c \
    37         cmds/modules/modules.c \
    38         cmds/modules/help/help.c \
    39         cmds/modules/mkdir/mkdir.c \
    40         cmds/modules/mkfile/mkfile.c \
    41         cmds/modules/rm/rm.c \
    42         cmds/modules/cat/cat.c \
    43         cmds/modules/touch/touch.c \
    44         cmds/modules/ls/ls.c \
    45         cmds/modules/pwd/pwd.c \
    46         cmds/modules/sleep/sleep.c \
    47         cmds/modules/cp/cp.c \
    48         cmds/modules/mv/mv.c \
    49         cmds/modules/printf/printf.c \
    50         cmds/modules/echo/echo.c \
    51         cmds/modules/mount/mount.c \
    52         cmds/modules/unmount/unmount.c \
    53         cmds/modules/kcon/kcon.c \
    54         cmds/modules/cmp/cmp.c \
    55         cmds/builtins/builtin_aliases.c \
    56         cmds/builtins/builtins.c \
    57         cmds/builtins/batch/batch.c \
    58         cmds/builtins/exit/exit.c \
    59         cmds/builtins/cd/cd.c \
    60         cmds/mod_cmds.c \
    61         cmds/builtin_cmds.c \
    62         compl.c \
    63         errors.c \
    64         input.c \
    65         util.c \
    66         exec.c \
    67         scli.c \
    68         tok.c
     70test_src = files(
     71        'tok.c',
     72        'test/toktest.c',
     73)
    6974
    70 TEST_SOURCES = \
    71         tok.c \
    72         test/toktest.c
    73 
    74 include $(USPACE_PREFIX)/Makefile.common
     75# TODO: install this file somewhere sane
     76installed_data += { 'name': 'demo.txt', 'dir': '/' }
  • uspace/app/bdsh/scli.c

    r9259d20 r3e828ea  
    11/*
    22 * Copyright (c) 2008 Tim Post
     3 * Copyright (c) 2018 Matthieu Riolo
    34 * All rights reserved.
    45 *
     
    3132#include <stddef.h>
    3233#include <str.h>
     34#include <adt/odict.h>
    3335#include "config.h"
    3436#include "scli.h"
     
    4244static iostate_t *iostate;
    4345static iostate_t stdiostate;
     46
     47odict_t alias_dict;
    4448
    4549/*
     
    5559 */
    5660const char *progname = PACKAGE_NAME;
     61
     62static int alias_cmp(void *a, void *b)
     63{
     64        return str_cmp((char *)a, (char *)b);
     65}
     66
     67static void *alias_key(odlink_t *odlink)
     68{
     69        return (void *)odict_get_instance(odlink, alias_t, odict)->name;
     70}
    5771
    5872/* These are not exposed, even to builtins */
     
    108122        iostate = &stdiostate;
    109123
     124        odict_initialize(&alias_dict, alias_key, alias_cmp);
     125
    110126        if (cli_init(&usr))
    111127                exit(EXIT_FAILURE);
  • uspace/app/bdsh/scli.h

    r9259d20 r3e828ea  
    11/*
    22 * Copyright (c) 2008 Tim Post
     3 * Copyright (c) 2018 Matthieu Riolo
    34 * All rights reserved.
    45 *
     
    3435#include <stdint.h>
    3536#include <stdio.h>
     37#include <types/adt/odict.h>
    3638
    3739typedef struct {
     
    5456extern void set_iostate(iostate_t *);
    5557
     58extern odict_t alias_dict;
     59
     60typedef struct {
     61        odlink_t odict;
     62        char *name;
     63        char *value;
     64} alias_t;
     65
    5666#endif
  • uspace/app/bdsh/util.c

    r9259d20 r3e828ea  
    7474        return 0;
    7575}
     76
     77/*
     78 * Returns true if the string is a relative or an absolute path
     79 */
     80bool is_path(const char *cmd)
     81{
     82
     83        bool ret = str_lcmp(cmd, "/", 1) == 0;
     84        ret = ret || str_lcmp(cmd, "./", 2) == 0;
     85        ret = ret || str_lcmp(cmd, "../", 3) == 0;
     86
     87        return ret;
     88}
  • uspace/app/bdsh/util.h

    r9259d20 r3e828ea  
    3131
    3232#include "scli.h"
     33#include <stdbool.h>
    3334
    3435/* Utility functions */
    3536extern unsigned int cli_count_args(char **);
    3637extern unsigned int cli_set_prompt(cliuser_t *usr);
     38extern bool is_path(const char *cmd);
    3739
    3840#endif
Note: See TracChangeset for help on using the changeset viewer.