Ignore:
Timestamp:
2016-03-09T20:01:43Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1b8ad4
Parents:
df425da (diff), dc0e41c (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:

Merge from lp:~aurelio-x/helenos/kcon-devel

File:
1 edited

Legend:

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

    rdf425da rd4d8255  
    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 {
     167const char *cmdtab_enum(const char *name, const char **h, void **ctx)
     168{
     169        link_t **startpos = (link_t**)ctx;
    170170        size_t namelen = str_length(name);
    171171       
     
    183183               
    184184                if (str_lcmp(curname, name, namelen) == 0) {
     185                        *startpos = (*startpos)->next;
     186                        if (h) {
     187                                *h = hlp->description;
     188                        }
    185189                        spinlock_unlock(&cmd_lock);
    186190                        return (curname + str_lsize(curname, namelen));
     
    200204 *
    201205 */
    202 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev)
     206NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev,
     207    hints_enum_func_t hints_enum)
    203208{
    204209        const char *name = input;
     
    212217        size_t max_match_len = size;
    213218        size_t max_match_len_tmp = size;
    214         size_t input_len = str_length(input);
    215         link_t *pos = NULL;
     219        void *pos = NULL;
    216220        const char *hint;
     221        const char *help;
    217222        char *output = malloc(MAX_CMDLINE, 0);
    218223        size_t hints_to_show = MAX_TAB_HINTS - 1;
     
    222227        output[0] = 0;
    223228       
    224         while ((hint = cmdtab_search_one(name, &pos))) {
    225                 if ((found == 0) || (str_length(output) > str_length(hint)))
     229        while ((hint = hints_enum(name, NULL, &pos))) {
     230                if ((found == 0) || (str_length(hint) > str_length(output)))
    226231                        str_cpy(output, MAX_CMDLINE, hint);
    227232               
    228                 pos = pos->next;
    229233                found++;
    230234        }
     
    243247                printf("\n");
    244248                pos = NULL;
    245                 while (cmdtab_search_one(name, &pos)) {
    246                         cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
     249                while ((hint = hints_enum(name, &help, &pos))) {
    247250                       
    248251                        if (continue_showing_hints) {
    249                                 printf("%s (%s)\n", hlp->name, hlp->description);
     252                               
     253                                if (help)
     254                                        printf("%s%s (%s)\n", name, hint, help);
     255                                else
     256                                        printf("%s%s\n", name, hint);
     257                               
    250258                                --hints_to_show;
    251259                                ++total_hints_shown;
     
    258266                        }
    259267                       
    260                         pos = pos->next;
    261                        
    262268                        for (max_match_len_tmp = 0;
    263269                            (output[max_match_len_tmp] ==
    264                             hlp->name[input_len + max_match_len_tmp]) &&
     270                            hint[max_match_len_tmp]) &&
    265271                            (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
    266272                       
     
    277283        free(output);
    278284        return found;
     285}
     286
     287NO_TRACE static cmd_info_t *parse_cmd(const wchar_t *cmdline)
     288{
     289        size_t start = 0;
     290        size_t end;
     291        char *tmp;
     292       
     293        while (isspace(cmdline[start]))
     294                start++;
     295        end = start + 1;
     296        while (!isspace(cmdline[end]))
     297                end++;
     298       
     299        tmp = malloc(STR_BOUNDS(end - start + 1), 0);
     300       
     301        wstr_to_str(tmp, end - start + 1, &cmdline[start]);
     302       
     303        spinlock_lock(&cmd_lock);
     304       
     305        list_foreach(cmd_list, link, cmd_info_t, hlp) {
     306                spinlock_lock(&hlp->lock);
     307               
     308                if (str_cmp(hlp->name, tmp) == 0) {
     309                        spinlock_unlock(&hlp->lock);
     310                        spinlock_unlock(&cmd_lock);
     311                        free(tmp);
     312                        return hlp;
     313                }
     314               
     315                spinlock_unlock(&hlp->lock);
     316        }
     317       
     318        free(tmp);
     319        spinlock_unlock(&cmd_lock);
     320       
     321        return NULL;
    279322}
    280323
     
    338381                        if (beg == 0) {
    339382                                /* Command completion */
    340                                 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
     383                                found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev,
     384                                    cmdtab_enum);
    341385                        } else {
    342                                 /* Symbol completion */
    343                                 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
     386                                /* Arguments completion */
     387                                cmd_info_t *cmd = parse_cmd(current);
     388                                if (!cmd || !cmd->hints_enum)
     389                                        continue;
     390                                found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev,
     391                                    cmd->hints_enum);
    344392                        }
    345393                       
Note: See TracChangeset for help on using the changeset viewer.