Ignore:
Timestamp:
2012-08-08T08:46:22Z (13 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
30c0826
Parents:
bc216a0 (diff), 1d01cca (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:

Merged changes from mainline.

File:
1 edited

Legend:

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

    rbc216a0 rda68871a  
    4343#include <console/chardev.h>
    4444#include <console/cmd.h>
     45#include <console/prompt.h>
    4546#include <print.h>
    4647#include <panic.h>
     
    202203 *
    203204 */
    204 NO_TRACE static int cmdtab_compl(char *input, size_t size)
     205NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev)
    205206{
    206207        const char *name = input;
    207208       
    208209        size_t found = 0;
     210       
     211        /*
     212         * Maximum Match Length: Length of longest matching common
     213         * substring in case more than one match is found.
     214         */
     215        size_t max_match_len = size;
     216        size_t max_match_len_tmp = size;
     217        size_t input_len = str_length(input);
    209218        link_t *pos = NULL;
    210219        const char *hint;
    211220        char *output = malloc(MAX_CMDLINE, 0);
     221        size_t hints_to_show = MAX_TAB_HINTS - 1;
     222        size_t total_hints_shown = 0;
     223        bool continue_showing_hints = true;
    212224       
    213225        output[0] = 0;
     
    219231                pos = pos->next;
    220232                found++;
     233        }
     234       
     235        /*
     236         * If the number of possible completions is more than MAX_TAB_HINTS,
     237         * ask the user whether to display them or not.
     238         */
     239        if (found > MAX_TAB_HINTS) {
     240                printf("\n");
     241                continue_showing_hints =
     242                    console_prompt_display_all_hints(indev, found);
    221243        }
    222244       
     
    226248                while (cmdtab_search_one(name, &pos)) {
    227249                        cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
    228                         printf("%s (%s)\n", hlp->name, hlp->description);
     250                       
     251                        if (continue_showing_hints) {
     252                                printf("%s (%s)\n", hlp->name, hlp->description);
     253                                --hints_to_show;
     254                                ++total_hints_shown;
     255                               
     256                                if ((hints_to_show == 0) && (total_hints_shown != found)) {
     257                                        /* Ask user to continue */
     258                                        continue_showing_hints =
     259                                            console_prompt_more_hints(indev, &hints_to_show);
     260                                }
     261                        }
     262                       
    229263                        pos = pos->next;
    230                 }
     264                       
     265                        for (max_match_len_tmp = 0;
     266                            (output[max_match_len_tmp] ==
     267                            hlp->name[input_len + max_match_len_tmp]) &&
     268                            (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
     269                       
     270                        max_match_len = max_match_len_tmp;
     271                }
     272               
     273                /* Keep only the characters common in all completions */
     274                output[max_match_len] = 0;
    231275        }
    232276       
     
    281325                                continue;
    282326                       
    283                         /* Find the beginning of the word
    284                            and copy it to tmp */
     327                        /*
     328                         * Find the beginning of the word
     329                         * and copy it to tmp
     330                         */
    285331                        size_t beg;
    286332                        for (beg = position - 1; (beg > 0) && (!isspace(current[beg]));
     
    295341                        if (beg == 0) {
    296342                                /* Command completion */
    297                                 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
     343                                found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
    298344                        } else {
    299345                                /* Symbol completion */
    300                                 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
     346                                found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
    301347                        }
    302348                       
    303349                        if (found == 0)
    304350                                continue;
    305                        
    306                         if (found > 1) {
    307                                 /* No unique hint, list was printed */
    308                                 printf("%s> ", prompt);
    309                                 printf("%ls", current);
    310                                 print_cc('\b', wstr_length(current) - position);
    311                                 continue;
    312                         }
    313                        
    314                         /* We have a hint */
    315                        
     351
     352                        /*
     353                         * We have hints, possibly many. In case of more than one hint,
     354                         * tmp will contain the common prefix.
     355                         */
    316356                        size_t off = 0;
    317357                        size_t i = 0;
     
    319359                                if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE))
    320360                                        break;
     361                               
    321362                                i++;
    322363                        }
     364                       
     365                        if (found > 1) {
     366                                /* No unique hint, list was printed */
     367                                printf("%s> ", prompt);
     368                                printf("%ls", current);
     369                                position += str_length(tmp);
     370                                print_cc('\b', wstr_length(current) - position);
     371                                continue;
     372                        }
     373                       
     374                        /* We have a hint */
    323375                       
    324376                        printf("%ls", current + position);
     
    541593/** Parse command line.
    542594 *
    543  * @param cmdline Command line as read from input device. 
     595 * @param cmdline Command line as read from input device.
    544596 * @param size    Size (in bytes) of the string.
    545597 *
Note: See TracChangeset for help on using the changeset viewer.