Changeset 3e828ea in mainline for uspace/app/bdsh/compl.c


Ignore:
Timestamp:
2019-09-23T12:49:29Z (6 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 ? '/' : ' ');
Note: See TracChangeset for help on using the changeset viewer.