Ignore:
File:
1 edited

Legend:

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

    r563d6077 ra7199c2  
    4545#include <print.h>
    4646#include <panic.h>
    47 #include <arch/types.h>
     47#include <typedefs.h>
    4848#include <adt/list.h>
    4949#include <arch.h>
     
    5151#include <debug.h>
    5252#include <func.h>
    53 #include <string.h>
     53#include <str.h>
    5454#include <macros.h>
    5555#include <sysinfo/sysinfo.h>
     
    5858#include <errno.h>
    5959#include <putchar.h>
    60 #include <string.h>
     60#include <str.h>
    6161
    6262/** Simple kernel console.
     
    160160
    161161/** Print count times a character */
    162 static void print_cc(wchar_t ch, size_t count)
     162NO_TRACE static void print_cc(wchar_t ch, size_t count)
    163163{
    164164        size_t i;
     
    168168
    169169/** Try to find a command beginning with prefix */
    170 static const char *cmdtab_search_one(const char *name, link_t **startpos)
     170NO_TRACE static const char *cmdtab_search_one(const char *name,
     171    link_t **startpos)
    171172{
    172173        size_t namelen = str_length(name);
     
    202203 *
    203204 */
    204 static int cmdtab_compl(char *input, size_t size)
     205NO_TRACE static int cmdtab_compl(char *input, size_t size)
    205206{
    206207        const char *name = input;
     
    209210        link_t *pos = NULL;
    210211        const char *hint;
    211         char output[MAX_CMDLINE];
     212        char *output = malloc(MAX_CMDLINE, 0);
    212213       
    213214        output[0] = 0;
     
    224225                printf("\n");
    225226                pos = NULL;
    226                 while ((hint = cmdtab_search_one(name, &pos))) {
     227                while (cmdtab_search_one(name, &pos)) {
    227228                        cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
    228229                        printf("%s (%s)\n", hlp->name, hlp->description);
     
    234235                str_cpy(input, size, output);
    235236       
     237        free(output);
    236238        return found;
    237239}
    238240
    239 static wchar_t *clever_readline(const char *prompt, indev_t *indev)
     241NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev)
    240242{
    241243        printf("%s> ", prompt);
     
    244246        wchar_t *current = history[history_pos];
    245247        current[0] = 0;
     248        char *tmp = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    246249       
    247250        while (true) {
     
    288291                                beg++;
    289292                       
    290                         char tmp[STR_BOUNDS(MAX_CMDLINE)];
    291293                        wstr_to_str(tmp, position - beg + 1, current + beg);
    292294                       
     
    414416        }
    415417       
     418        free(tmp);
    416419        return current;
    417420}
     
    422425}
    423426
    424 static bool parse_int_arg(const char *text, size_t len, unative_t *result)
     427NO_TRACE static bool parse_int_arg(const char *text, size_t len,
     428    unative_t *result)
    425429{
    426430        bool isaddr = false;
     
    455459                        printf("No symbol information available.\n");
    456460                        return false;
    457                 }
    458                
    459                 if (isaddr)
    460                         *result = (unative_t) symaddr;
    461                 else if (isptr)
    462                         *result = **((unative_t **) symaddr);
    463                 else
    464                         *result = *((unative_t *) symaddr);
     461                case EOK:
     462                        if (isaddr)
     463                                *result = (unative_t) symaddr;
     464                        else if (isptr)
     465                                *result = **((unative_t **) symaddr);
     466                        else
     467                                *result = *((unative_t *) symaddr);
     468                        break;
     469                default:
     470                        printf("Unknown error.\n");
     471                        return false;
     472                }
    465473        } else {
    466474                /* It's a number - convert it */
    467                 *result = atoi(text);
    468                 if (isptr)
    469                         *result = *((unative_t *) *result);
     475                uint64_t value;
     476                int rc = str_uint64(text, NULL, 0, true, &value);
     477                switch (rc) {
     478                case EINVAL:
     479                        printf("Invalid number.\n");
     480                        return false;
     481                case EOVERFLOW:
     482                        printf("Integer overflow.\n");
     483                        return false;
     484                case EOK:
     485                        *result = (unative_t) value;
     486                        if (isptr)
     487                                *result = *((unative_t *) *result);
     488                        break;
     489                default:
     490                        printf("Unknown error.\n");
     491                        return false;
     492                }
    470493        }
    471494       
     
    488511 *
    489512 */
    490 static bool parse_argument(const char *cmdline, size_t size, size_t *start, size_t *end)
     513NO_TRACE static bool parse_argument(const char *cmdline, size_t size,
     514    size_t *start, size_t *end)
    491515{
    492516        ASSERT(start != NULL);
     
    524548 *
    525549 */
    526 static cmd_info_t *parse_cmdline(const char *cmdline, size_t size)
     550NO_TRACE static cmd_info_t *parse_cmdline(const char *cmdline, size_t size)
    527551{
    528552        size_t start = 0;
     
    571595        size_t i;
    572596        for (i = 0; i < cmd->argc; i++) {
     597                char *buf;
     598               
    573599                start = end;
    574600                if (!parse_argument(cmdline, size, &start, &end)) {
     601                        if (cmd->argv[i].type == ARG_TYPE_STRING_OPTIONAL) {
     602                                buf = (char *) cmd->argv[i].buffer;
     603                                str_cpy(buf, cmd->argv[i].len, "");
     604                                continue;
     605                        }
     606                       
    575607                        printf("Too few arguments.\n");
    576608                        spinlock_unlock(&cmd->lock);
     
    578610                }
    579611               
    580                 char *buf;
    581612                switch (cmd->argv[i].type) {
    582613                case ARG_TYPE_STRING:
     614                case ARG_TYPE_STRING_OPTIONAL:
    583615                        buf = (char *) cmd->argv[i].buffer;
    584616                        str_ncpy(buf, cmd->argv[i].len, cmdline + start,
     
    600632                                        cmd->argv[i].vartype = ARG_TYPE_STRING;
    601633                                } else {
    602                                         printf("Wrong synxtax.\n");
     634                                        printf("Wrong syntax.\n");
    603635                                        error = true;
    604636                                }
     
    643675 *
    644676 */
    645 void kconsole(char *prompt, char *msg, bool kcon)
     677void kconsole(const char *prompt, const char *msg, bool kcon)
    646678{
    647679        if (!stdin) {
     
    658690                printf("Type \"exit\" to leave the console.\n");
    659691       
     692        char *cmdline = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    660693        while (true) {
    661694                wchar_t *tmp = clever_readline((char *) prompt, stdin);
     
    664697                        continue;
    665698               
    666                 char cmdline[STR_BOUNDS(MAX_CMDLINE)];
    667699                wstr_to_str(cmdline, STR_BOUNDS(MAX_CMDLINE), tmp);
    668700               
     
    676708                (void) cmd_info->func(cmd_info->argv);
    677709        }
     710        free(cmdline);
    678711}
    679712
Note: See TracChangeset for help on using the changeset viewer.