Changeset ac2caecb in mainline


Ignore:
Timestamp:
2018-12-15T20:29:21Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f7817a9
Parents:
3301452
Message:

adding alias to completion

File:
1 edited

Legend:

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

    r3301452 rac2caecb  
    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"
     
    6264        /** Length of string prefix (number of characters) */
    6365        size_t prefix_len;
     66
     67        /* Pointer to the current alias */
     68        odlink_t *alias_link;
    6469
    6570        /** Pointer inside list of modules */
     
    227232        } else if (cs->is_command) {
    228233                /* Command without path */
     234                cs->alias_link = odict_first(&alias_dict);
    229235                cs->module = modules;
    230236                cs->builtin = builtins;
     
    305311        }
    306312
     313        /* Alias */
     314        if (cs->alias_link != NULL) {
     315                while (*compl == NULL && cs->alias_link != NULL) {
     316                        alias_t *data = odict_get_instance(cs->alias_link, alias_t, odict);
     317                        if (compl_match_prefix(cs, data->name)) {
     318                                asprintf(compl, "%s ", data->name);
     319                                cs->last_compl = *compl;
     320                                if (*compl == NULL)
     321                                        return ENOMEM;
     322                        }
     323                        cs->alias_link = odict_next(cs->alias_link, &alias_dict);
     324                }
     325        }
     326
    307327        /* Modules */
    308328        if (cs->module != NULL) {
    309329                while (*compl == NULL && cs->module->name != NULL) {
     330                        /* prevents multiple listing of an overriden cmd */
    310331                        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;
     332                                odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cs->module->name, NULL);
     333                                if (alias_link == NULL) {
     334                                        asprintf(compl, "%s ", cs->module->name);
     335                                        cs->last_compl = *compl;
     336                                        if (*compl == NULL)
     337                                                return ENOMEM;
     338                                }
    315339                        }
    316340                        cs->module++;
     
    322346                while (*compl == NULL && cs->builtin->name != NULL) {
    323347                        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;
     348                                /* prevents multiple listing of an overriden cmd */
     349                                odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cs->module->name, NULL);
     350                                if (alias_link == NULL) {
     351                                        asprintf(compl, "%s ", cs->builtin->name);
     352                                        cs->last_compl = *compl;
     353                                        if (*compl == NULL)
     354                                                return ENOMEM;
     355                                }
    328356                        }
    329357                        cs->builtin++;
     
    373401                                free(ent_path);
    374402
     403                                /* prevents multiple listing of an overriden cmd */
     404                                if (cs->is_command && !ent_stat.is_directory) {
     405                                        odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)dent->d_name, NULL);
     406                                        if (alias_link != NULL) {
     407                                                continue;
     408                                        }
     409                                }
     410                               
    375411                                asprintf(compl, "%s%c", dent->d_name,
    376412                                    ent_stat.is_directory ? '/' : ' ');
Note: See TracChangeset for help on using the changeset viewer.