Ignore:
Timestamp:
2012-07-20T13:51:28Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8fccd42
Parents:
c5bff3c (diff), 7030bc9 (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.
Message:

More mainline changes.

File:
1 edited

Legend:

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

    rc5bff3c r8013637  
    4343#include <console/chardev.h>
    4444#include <console/cmd.h>
     45#include <console/prompt.h>
    4546#include <print.h>
    4647#include <panic.h>
     
    201202 *
    202203 */
    203 NO_TRACE static int cmdtab_compl(char *input, size_t size)
     204NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev)
    204205{
    205206        const char *name = input;
    206207       
    207208        size_t found = 0;
     209       
     210        /*
     211         * Maximum Match Length: Length of longest matching common
     212         * substring in case more than one match is found.
     213         */
     214        size_t max_match_len = size;
     215        size_t max_match_len_tmp = size;
     216        size_t input_len = str_length(input);
    208217        link_t *pos = NULL;
    209218        const char *hint;
    210219        char *output = malloc(MAX_CMDLINE, 0);
     220        size_t hints_to_show = MAX_TAB_HINTS - 1;
     221        size_t total_hints_shown = 0;
     222        bool continue_showing_hints = true;
    211223       
    212224        output[0] = 0;
     
    218230                pos = pos->next;
    219231                found++;
     232        }
     233       
     234        /*
     235         * If the number of possible completions is more than MAX_TAB_HINTS,
     236         * ask the user whether to display them or not.
     237         */
     238        if (found > MAX_TAB_HINTS) {
     239                printf("\n");
     240                continue_showing_hints =
     241                    console_prompt_display_all_hints(indev, found);
    220242        }
    221243       
     
    225247                while (cmdtab_search_one(name, &pos)) {
    226248                        cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
    227                         printf("%s (%s)\n", hlp->name, hlp->description);
     249                       
     250                        if (continue_showing_hints) {
     251                                printf("%s (%s)\n", hlp->name, hlp->description);
     252                                --hints_to_show;
     253                                ++total_hints_shown;
     254                               
     255                                if ((hints_to_show == 0) && (total_hints_shown != found)) {
     256                                        /* Ask user to continue */
     257                                        continue_showing_hints =
     258                                            console_prompt_more_hints(indev, &hints_to_show);
     259                                }
     260                        }
     261                       
    228262                        pos = pos->next;
    229                 }
     263                       
     264                        for (max_match_len_tmp = 0;
     265                            (output[max_match_len_tmp] ==
     266                            hlp->name[input_len + max_match_len_tmp]) &&
     267                            (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
     268                       
     269                        max_match_len = max_match_len_tmp;
     270                }
     271               
     272                /* Keep only the characters common in all completions */
     273                output[max_match_len] = 0;
    230274        }
    231275       
     
    280324                                continue;
    281325                       
    282                         /* Find the beginning of the word
    283                            and copy it to tmp */
     326                        /*
     327                         * Find the beginning of the word
     328                         * and copy it to tmp
     329                         */
    284330                        size_t beg;
    285331                        for (beg = position - 1; (beg > 0) && (!isspace(current[beg]));
     
    294340                        if (beg == 0) {
    295341                                /* Command completion */
    296                                 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
     342                                found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
    297343                        } else {
    298344                                /* Symbol completion */
    299                                 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
     345                                found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
    300346                        }
    301347                       
    302348                        if (found == 0)
    303349                                continue;
    304                        
    305                         if (found > 1) {
    306                                 /* No unique hint, list was printed */
    307                                 printf("%s> ", prompt);
    308                                 printf("%ls", current);
    309                                 print_cc('\b', wstr_length(current) - position);
    310                                 continue;
    311                         }
    312                        
    313                         /* We have a hint */
    314                        
     350
     351                        /*
     352                         * We have hints, possibly many. In case of more than one hint,
     353                         * tmp will contain the common prefix.
     354                         */
    315355                        size_t off = 0;
    316356                        size_t i = 0;
     
    318358                                if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE))
    319359                                        break;
     360                               
    320361                                i++;
    321362                        }
     363                       
     364                        if (found > 1) {
     365                                /* No unique hint, list was printed */
     366                                printf("%s> ", prompt);
     367                                printf("%ls", current);
     368                                position += str_length(tmp);
     369                                print_cc('\b', wstr_length(current) - position);
     370                                continue;
     371                        }
     372                       
     373                        /* We have a hint */
    322374                       
    323375                        printf("%ls", current + position);
     
    540592/** Parse command line.
    541593 *
    542  * @param cmdline Command line as read from input device. 
     594 * @param cmdline Command line as read from input device.
    543595 * @param size    Size (in bytes) of the string.
    544596 *
Note: See TracChangeset for help on using the changeset viewer.