Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/debug/symtab.c

    r9d58539 raca4a04  
    4343#include <typedefs.h>
    4444#include <errno.h>
     45#include <console/prompt.h>
    4546
    4647/** Get name of a symbol that seems most likely to correspond to address.
     
    209210 *
    210211 */
    211 int symtab_compl(char *input, size_t size)
     212int symtab_compl(char *input, size_t size, indev_t * indev)
    212213{
    213214#ifdef CONFIG_SYMTAB
     
    226227        const char *hint;
    227228        char output[MAX_SYMBOL_NAME];
     229        /* Maximum Match Length : Length of longest matching common substring in
     230           case more than one match is found */
     231        size_t max_match_len = size;
     232        size_t max_match_len_tmp = size;
     233        size_t input_len = str_length(input);
     234        char *sym_name;
     235        size_t hints_to_show = MAX_TAB_HINTS - 1;
     236        size_t total_hints_shown = 0;
     237        bool continue_showing_hints = true;
    228238       
    229239        output[0] = 0;
     240
     241        while ((hint = symtab_search_one(name, &pos))) {
     242                ++pos;
     243        }
     244
     245        pos = 0;
    230246       
    231247        while ((hint = symtab_search_one(name, &pos))) {
     
    235251                pos++;
    236252                found++;
     253        }
     254       
     255        /* If possible completions are more than MAX_TAB_HINTS, ask user whether to display them or not. */
     256        if (found > MAX_TAB_HINTS) {
     257                printf("\n");
     258                continue_showing_hints = console_prompt_display_all_hints(indev, found);
    237259        }
    238260       
     
    241263                pos = 0;
    242264                while (symtab_search_one(name, &pos)) {
    243                         printf("%s\n", symbol_table[pos].symbol_name);
     265                        sym_name = symbol_table[pos].symbol_name;
    244266                        pos++;
     267
     268                        if (continue_showing_hints) { /* We are still showing hints */
     269                                printf("%s\n", sym_name);
     270                                --hints_to_show;
     271                                ++total_hints_shown;
     272
     273                                if (hints_to_show == 0 && total_hints_shown != found) { /* Time to ask user to continue */
     274                                        continue_showing_hints = console_prompt_more_hints(indev, &hints_to_show);
     275                                }
     276                        }
     277
     278                        for(max_match_len_tmp = 0; output[max_match_len_tmp] == sym_name[input_len + max_match_len_tmp]
     279                                        && max_match_len_tmp < max_match_len; ++max_match_len_tmp);
     280                        max_match_len = max_match_len_tmp;
    245281                }
     282                /* keep only the characters common in all completions */
     283                output[max_match_len] = 0;
    246284        }
    247285       
Note: See TracChangeset for help on using the changeset viewer.