Changeset a363016 in mainline


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

kconsole tab completion: call* argument hints restored by using proper callback

Location:
kernel/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/symtab.h

    r6a75c134 ra363016  
    4040
    4141extern void symtab_print_search(const char *);
    42 extern int symtab_compl(char *, size_t, indev_t *);
     42extern const char* symtab_hints_enum(const char *, const char **, void **);
    4343
    4444#endif
  • kernel/generic/src/console/cmd.c

    r6a75c134 ra363016  
    303303        .func = cmd_call0,
    304304        .argc = 1,
    305         .argv = &call0_argv
     305        .argv = &call0_argv,
     306        .hints_enum = symtab_hints_enum
    306307};
    307308
     
    318319        .func = cmd_mcall0,
    319320        .argc = 1,
    320         .argv = &mcall0_argv
     321        .argv = &mcall0_argv,
     322        .hints_enum = symtab_hints_enum
    321323};
    322324
     
    340342        .func = cmd_call1,
    341343        .argc = 2,
    342         .argv = call1_argv
     344        .argv = call1_argv,
     345        .hints_enum = symtab_hints_enum
    343346};
    344347
     
    367370        .func = cmd_call2,
    368371        .argc = 3,
    369         .argv = call2_argv
     372        .argv = call2_argv,
     373        .hints_enum = symtab_hints_enum
    370374};
    371375
     
    400404        .func = cmd_call3,
    401405        .argc = 4,
    402         .argv = call3_argv
     406        .argv = call3_argv,
     407        .hints_enum = symtab_hints_enum
    403408};
    404409
  • kernel/generic/src/debug/symtab.c

    r6a75c134 ra363016  
    202202}
    203203
    204 /** Symtab completion
    205  *
    206  * @param input Search string, completes to symbol name
    207  * @param size  Input buffer size
    208  *
    209  * @return 0 - nothing found, 1 - success, >1 print duplicates
    210  *
    211  */
    212 int symtab_compl(char *input, size_t size, indev_t *indev)
    213 {
    214 #ifdef CONFIG_SYMTAB
    215         const char *name = input;
    216        
    217         /* Allow completion of pointers */
    218         if ((name[0] == '*') || (name[0] == '&'))
    219                 name++;
    220        
    221         /* Do not print all symbols */
    222         if (str_length(name) == 0)
    223                 return 0;
    224        
    225         size_t found = 0;
    226         size_t pos = 0;
    227         const char *hint;
    228         char output[MAX_SYMBOL_NAME];
    229        
    230         /*
    231          * Maximum Match Length: Length of longest matching common substring in
    232          * case more than one match is found.
    233          */
    234         size_t max_match_len = size;
    235         size_t max_match_len_tmp = size;
    236         size_t input_len = str_length(input);
    237         char *sym_name;
    238         size_t hints_to_show = MAX_TAB_HINTS - 1;
    239         size_t total_hints_shown = 0;
    240         bool continue_showing_hints = true;
    241        
    242         output[0] = 0;
    243        
    244         while ((hint = symtab_search_one(name, &pos)))
    245                 pos++;
    246        
    247         pos = 0;
    248        
    249         while ((hint = symtab_search_one(name, &pos))) {
    250                 if ((found == 0) || (str_length(output) > str_length(hint)))
    251                         str_cpy(output, MAX_SYMBOL_NAME, hint);
    252                
    253                 pos++;
    254                 found++;
    255         }
    256        
    257         /*
    258          * If the number of possible completions is more than MAX_TAB_HINTS,
    259          * ask the user whether to display them or not.
    260          */
    261         if (found > MAX_TAB_HINTS) {
    262                 printf("\n");
    263                 continue_showing_hints =
    264                     console_prompt_display_all_hints(indev, found);
    265         }
    266        
    267         if ((found > 1) && (str_length(output) != 0)) {
    268                 printf("\n");
    269                 pos = 0;
    270                 while (symtab_search_one(name, &pos)) {
    271                         sym_name = symbol_table[pos].symbol_name;
    272                         pos++;
    273                        
    274                         if (continue_showing_hints) {
    275                                 /* We are still showing hints */
    276                                 printf("%s\n", sym_name);
    277                                 --hints_to_show;
    278                                 ++total_hints_shown;
    279                                
    280                                 if ((hints_to_show == 0) && (total_hints_shown != found)) {
    281                                         /* Ask the user to continue */
    282                                         continue_showing_hints =
    283                                             console_prompt_more_hints(indev, &hints_to_show);
    284                                 }
    285                         }
    286                        
    287                         for (max_match_len_tmp = 0;
    288                             (output[max_match_len_tmp] ==
    289                             sym_name[input_len + max_match_len_tmp]) &&
    290                             (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
    291                        
    292                         max_match_len = max_match_len_tmp;
     204/** Symtab completion enum, see kernel/generic/include/kconsole.h */
     205const char* symtab_hints_enum(const char *input, const char **help,
     206    void **ctx)
     207{
     208#ifdef CONFIG_SYMTAB
     209        size_t len = str_length(input);
     210        struct symtab_entry **entry = (struct symtab_entry**)ctx;
     211       
     212        if (*entry == NULL)
     213                *entry = symbol_table;
     214       
     215        for (; (*entry)->address_le; (*entry)++) {
     216                const char *curname = (*entry)->symbol_name;
     217               
     218                /* Find a ':' in curname */
     219                const char *colon = str_chr(curname, ':');
     220                if (colon == NULL)
     221                        continue;
     222               
     223                if (str_length(curname) < len)
     224                        continue;
     225               
     226                if (str_lcmp(input, curname, len) == 0) {
     227                        (*entry)++;
     228                        if (help)
     229                                *help = NULL;
     230                        return (curname + str_lsize(curname, len));
    293231                }
    294                
    295                 /* Keep only the characters common in all completions */
    296                 output[max_match_len] = 0;
    297         }
    298        
    299         if (found > 0)
    300                 str_cpy(input, size, output);
    301        
    302         return found;
    303        
    304 #else
    305         return 0;
     232        }
     233       
     234        return NULL;
     235       
     236#else
     237        return NULL;
    306238#endif
    307239}
Note: See TracChangeset for help on using the changeset viewer.