Ignore:
File:
1 edited

Legend:

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

    rfeeac0d rdc0e41c  
    5959#include <putchar.h>
    6060#include <str.h>
     61#include <mm/slab.h>
    6162
    6263/** Simple kernel console.
     
    164165
    165166/** Try to find a command beginning with prefix */
    166 NO_TRACE static const char *cmdtab_search_one(const char *name,
    167     link_t **startpos)
    168 {
     167const char *cmdtab_enum(const char *name, const char **h, void **ctx)
     168{
     169        link_t **startpos = (link_t**)ctx;
    169170        size_t namelen = str_length(name);
    170171       
     
    182183               
    183184                if (str_lcmp(curname, name, namelen) == 0) {
     185                        *startpos = (*startpos)->next;
     186                        if (h) {
     187                                *h = hlp->description;
     188                        }
    184189                        spinlock_unlock(&cmd_lock);
    185190                        return (curname + str_lsize(curname, namelen));
     
    199204 *
    200205 */
    201 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)
    202208{
    203209        const char *name = input;
     
    211217        size_t max_match_len = size;
    212218        size_t max_match_len_tmp = size;
    213         size_t input_len = str_length(input);
    214         link_t *pos = NULL;
     219        void *pos = NULL;
    215220        const char *hint;
     221        const char *help;
    216222        char *output = malloc(MAX_CMDLINE, 0);
    217223        size_t hints_to_show = MAX_TAB_HINTS - 1;
     
    221227        output[0] = 0;
    222228       
    223         while ((hint = cmdtab_search_one(name, &pos))) {
    224                 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)))
    225231                        str_cpy(output, MAX_CMDLINE, hint);
    226232               
    227                 pos = pos->next;
    228233                found++;
    229234        }
     
    242247                printf("\n");
    243248                pos = NULL;
    244                 while (cmdtab_search_one(name, &pos)) {
    245                         cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
     249                while ((hint = hints_enum(name, &help, &pos))) {
    246250                       
    247251                        if (continue_showing_hints) {
    248                                 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                               
    249258                                --hints_to_show;
    250259                                ++total_hints_shown;
     
    257266                        }
    258267                       
    259                         pos = pos->next;
    260                        
    261268                        for (max_match_len_tmp = 0;
    262269                            (output[max_match_len_tmp] ==
    263                             hlp->name[input_len + max_match_len_tmp]) &&
     270                            hint[max_match_len_tmp]) &&
    264271                            (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
    265272                       
     
    276283        free(output);
    277284        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;
    278322}
    279323
     
    337381                        if (beg == 0) {
    338382                                /* Command completion */
    339                                 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
     383                                found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev,
     384                                    cmdtab_enum);
    340385                        } else {
    341                                 /* Symbol completion */
    342                                 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);
    343392                        }
    344393                       
Note: See TracChangeset for help on using the changeset viewer.