Changes in / [b781cc49:53afa639] in mainline


Ignore:
Location:
uspace/app/bdsh
Files:
8 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    rb781cc49 r53afa639  
    3636        cmds/modules/module_aliases.c \
    3737        cmds/modules/modules.c \
    38         cmds/modules/alias/alias.c \
    39         cmds/modules/unalias/unalias.c \
    4038        cmds/modules/help/help.c \
    4139        cmds/modules/mkdir/mkdir.c \
  • uspace/app/bdsh/cmds/modules/modules.c

    rb781cc49 r53afa639  
    6363#include "echo/entry.h"
    6464#include "cmp/entry.h"
    65 #include "alias/entry.h"
    66 #include "unalias/entry.h"
    6765
    6866/*
     
    9088#include "echo/echo_def.inc"
    9189#include "cmp/cmp_def.inc"
    92 #include "alias/alias_def.inc"
    93 #include "unalias/unalias_def.inc"
    9490
    9591        { NULL, NULL, NULL, NULL }
  • uspace/app/bdsh/cmds/modules/modules.h

    rb781cc49 r53afa639  
    3131
    3232#include "../cmds.h"
     33#include "modules.h"
    3334
    3435extern module_t modules[];
  • uspace/app/bdsh/compl.c

    rb781cc49 r53afa639  
    3535#include <vfs/vfs.h>
    3636#include <str.h>
    37 #include <adt/odict.h>
    38 
    39 #include "scli.h"
     37
    4038#include "cmds/cmds.h"
    4139#include "compl.h"
     
    6563        /** Length of string prefix (number of characters) */
    6664        size_t prefix_len;
    67 
    68         /* Pointer to the current alias */
    69         odlink_t *alias_link;
    7065
    7166        /** Pointer inside list of modules */
     
    248243        } else if (cs->is_command) {
    249244                /* Command without path */
    250                 cs->alias_link = odict_first(&alias_dict);
    251245                cs->module = modules;
    252246                cs->builtin = builtins;
     
    327321        }
    328322
    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);
     323        /* Modules */
     324        if (cs->module != NULL) {
     325                while (*compl == NULL && cs->module->name != NULL) {
     326                        if (compl_match_prefix(cs, cs->module->name)) {
     327                                asprintf(compl, "%s ", cs->module->name);
    335328                                cs->last_compl = *compl;
    336329                                if (*compl == NULL)
    337330                                        return ENOMEM;
    338                         }
    339                         cs->alias_link = odict_next(cs->alias_link, &alias_dict);
    340                 }
    341         }
    342 
    343         /* Modules */
    344         if (cs->module != NULL) {
    345                 while (*compl == NULL && cs->module->name != NULL) {
    346                         /* prevents multiple listing of an overriden cmd */
    347                         if (compl_match_prefix(cs, cs->module->name)) {
    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                                 }
    355331                        }
    356332                        cs->module++;
     
    362338                while (*compl == NULL && cs->builtin->name != NULL) {
    363339                        if (compl_match_prefix(cs, cs->builtin->name)) {
    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                                 }
     340                                asprintf(compl, "%s ", cs->builtin->name);
     341                                cs->last_compl = *compl;
     342                                if (*compl == NULL)
     343                                        return ENOMEM;
    372344                        }
    373345                        cs->builtin++;
     
    417389                                free(ent_path);
    418390
    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 
    427391                                asprintf(compl, "%s%c", dent->d_name,
    428392                                    ent_stat.is_directory ? '/' : ' ');
  • uspace/app/bdsh/config.h

    rb781cc49 r53afa639  
    4242#endif
    4343
    44 /* define maximal nested aliases */
    45 #ifndef HUBS_MAX
    46 #define HUBS_MAX 20
    47 #endif
    48 
    4944/* Used in many places */
    5045#define SMALL_BUFLEN 256
  • uspace/app/bdsh/input.c

    rb781cc49 r53afa639  
    33 * Copyright (c) 2011 Jiri Svoboda
    44 * Copyright (c) 2011 Martin Sucha
    5  * Copyright (c) 2018 Matthieu Riolo
    65 * All rights reserved.
    76 *
     
    4443#include <stdbool.h>
    4544#include <tinput.h>
    46 #include <adt/odict.h>
    47 #include <adt/list.h>
    4845
    4946#include "config.h"
     
    6562static void print_pipe_usage(void);
    6663
    67 typedef struct {
    68         link_t alias_hup_link;
    69         alias_t *alias;
    70 } alias_hup_t;
    71 
    72 static 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 
    8364/*
    8465 * Tokenizes input from console, sees if the first word is a built-in, if so
     
    8667 * the handler
    8768 */
    88 static 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 
     69errno_t process_input(cliuser_t *usr)
     70{
    9571        token_t *tokens_buf = calloc(WORD_MAX, sizeof(token_t));
    9672        if (tokens_buf == NULL)
     
    195171        }
    196172
    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 
    247173        iostate_t new_iostate = {
    248174                .stdin = stdin,
     
    299225}
    300226
    301 errno_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 
    316227void print_pipe_usage(void)
    317228{
  • uspace/app/bdsh/scli.c

    rb781cc49 r53afa639  
    11/*
    22 * Copyright (c) 2008 Tim Post
    3  * Copyright (c) 2018 Matthieu Riolo
    43 * All rights reserved.
    54 *
     
    3231#include <stddef.h>
    3332#include <str.h>
    34 #include <adt/odict.h>
    3533#include "config.h"
    3634#include "scli.h"
     
    4442static iostate_t *iostate;
    4543static iostate_t stdiostate;
    46 
    47 odict_t alias_dict;
    4844
    4945/*
     
    5955 */
    6056const char *progname = PACKAGE_NAME;
    61 
    62 static int alias_cmp(void *a, void *b)
    63 {
    64         return str_cmp((char *)a, (char *)b);
    65 }
    66 
    67 static void *alias_key(odlink_t *odlink)
    68 {
    69         return (void *)odict_get_instance(odlink, alias_t, odict)->name;
    70 }
    7157
    7258/* These are not exposed, even to builtins */
     
    122108        iostate = &stdiostate;
    123109
    124         odict_initialize(&alias_dict, alias_key, alias_cmp);
    125 
    126110        if (cli_init(&usr))
    127111                exit(EXIT_FAILURE);
  • uspace/app/bdsh/scli.h

    rb781cc49 r53afa639  
    11/*
    22 * Copyright (c) 2008 Tim Post
    3  * Copyright (c) 2018 Matthieu Riolo
    43 * All rights reserved.
    54 *
     
    3534#include <stdint.h>
    3635#include <stdio.h>
    37 #include <types/adt/odict.h>
    3836
    3937typedef struct {
     
    5654extern void set_iostate(iostate_t *);
    5755
    58 extern odict_t alias_dict;
    59 
    60 typedef struct {
    61         odlink_t odict;
    62         char *name;
    63         char *value;
    64 } alias_t;
    65 
    6656#endif
Note: See TracChangeset for help on using the changeset viewer.