Ignore:
Timestamp:
2016-03-08T09:16:26Z (8 years ago)
Author:
Aurelio Colosimo <aurelio@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
83b2e73
Parents:
b6bbc74
Message:

kernel: cmdtab_compl rewritten by using a enum callback

This is the first step to obtain a multi-purpose tab completion function,
based on enum callbacks; a typedef for them, called hints_enum_func_t,
is defined in kernel/generic/include/console/kconsole.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/kconsole.c

    rb6bbc74 r36b0490e  
    165165
    166166/** Try to find a command beginning with prefix */
    167 NO_TRACE static const char *cmdtab_search_one(const char *name,
    168     link_t **startpos)
    169 {
     167NO_TRACE static const char *cmdtab_enum(const char *name,
     168    const char **h, void **ctx)
     169{
     170        link_t **startpos = (link_t**)ctx;
    170171        size_t namelen = str_length(name);
    171172       
     
    183184               
    184185                if (str_lcmp(curname, name, namelen) == 0) {
     186                        *startpos = (*startpos)->next;
     187                        if (h) {
     188                                *h = hlp->description;
     189                        }
    185190                        spinlock_unlock(&cmd_lock);
    186191                        return (curname + str_lsize(curname, namelen));
     
    200205 *
    201206 */
    202 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev)
     207NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev,
     208    hints_enum_func_t hints_enum)
    203209{
    204210        const char *name = input;
     
    212218        size_t max_match_len = size;
    213219        size_t max_match_len_tmp = size;
    214         size_t input_len = str_length(input);
    215         link_t *pos = NULL;
     220        void *pos = NULL;
    216221        const char *hint;
     222        const char *help;
    217223        char *output = malloc(MAX_CMDLINE, 0);
    218224        size_t hints_to_show = MAX_TAB_HINTS - 1;
     
    222228        output[0] = 0;
    223229       
    224         while ((hint = cmdtab_search_one(name, &pos))) {
     230        while ((hint = hints_enum(name, NULL, &pos))) {
    225231                if ((found == 0) || (str_length(output) > str_length(hint)))
    226232                        str_cpy(output, MAX_CMDLINE, hint);
    227233               
    228                 pos = pos->next;
    229234                found++;
    230235        }
     
    243248                printf("\n");
    244249                pos = NULL;
    245                 while (cmdtab_search_one(name, &pos)) {
    246                         cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
     250                while ((hint = hints_enum(name, &help, &pos))) {
    247251                       
    248252                        if (continue_showing_hints) {
    249                                 printf("%s (%s)\n", hlp->name, hlp->description);
     253                               
     254                                if (help)
     255                                        printf("%s%s (%s)\n", name, hint, help);
     256                                else
     257                                        printf("%s%s\n", name, hint);
     258                               
    250259                                --hints_to_show;
    251260                                ++total_hints_shown;
     
    258267                        }
    259268                       
    260                         pos = pos->next;
    261                        
    262269                        for (max_match_len_tmp = 0;
    263270                            (output[max_match_len_tmp] ==
    264                             hlp->name[input_len + max_match_len_tmp]) &&
     271                            hint[max_match_len_tmp]) &&
    265272                            (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
    266273                       
     
    338345                        if (beg == 0) {
    339346                                /* Command completion */
    340                                 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
     347                                found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev, cmdtab_enum);
    341348                        } else {
    342349                                /* Symbol completion */
Note: See TracChangeset for help on using the changeset viewer.