Changeset b781cc49 in mainline for uspace/app/bdsh/compl.c


Ignore:
Timestamp:
2019-07-05T18:37:31Z (5 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fa603e99
Parents:
53afa639 (diff), 46288ee (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:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-07-05 18:37:31)
git-committer:
GitHub <noreply@…> (2019-07-05 18:37:31)
Message:

Merge pull request #135 from matthieuriolo/bdsh_alias

Implements alias/unalias commands in bdsh.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/compl.c

    r53afa639 rb781cc49  
    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"
     
    6365        /** Length of string prefix (number of characters) */
    6466        size_t prefix_len;
     67
     68        /* Pointer to the current alias */
     69        odlink_t *alias_link;
    6570
    6671        /** Pointer inside list of modules */
     
    243248        } else if (cs->is_command) {
    244249                /* Command without path */
     250                cs->alias_link = odict_first(&alias_dict);
    245251                cs->module = modules;
    246252                cs->builtin = builtins;
     
    321327        }
    322328
     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
    323343        /* Modules */
    324344        if (cs->module != NULL) {
    325345                while (*compl == NULL && cs->module->name != NULL) {
     346                        /* prevents multiple listing of an overriden cmd */
    326347                        if (compl_match_prefix(cs, cs->module->name)) {
    327                                 asprintf(compl, "%s ", cs->module->name);
    328                                 cs->last_compl = *compl;
    329                                 if (*compl == NULL)
    330                                         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                                }
    331355                        }
    332356                        cs->module++;
     
    338362                while (*compl == NULL && cs->builtin->name != NULL) {
    339363                        if (compl_match_prefix(cs, cs->builtin->name)) {
    340                                 asprintf(compl, "%s ", cs->builtin->name);
    341                                 cs->last_compl = *compl;
    342                                 if (*compl == NULL)
    343                                         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                                }
    344372                        }
    345373                        cs->builtin++;
     
    389417                                free(ent_path);
    390418
     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
    391427                                asprintf(compl, "%s%c", dent->d_name,
    392428                                    ent_stat.is_directory ? '/' : ' ');
Note: See TracChangeset for help on using the changeset viewer.