Ignore:
File:
1 edited

Legend:

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

    ra7199c2 r563d6077  
    4545#include <print.h>
    4646#include <panic.h>
    47 #include <typedefs.h>
     47#include <arch/types.h>
    4848#include <adt/list.h>
    4949#include <arch.h>
     
    5151#include <debug.h>
    5252#include <func.h>
    53 #include <str.h>
     53#include <string.h>
    5454#include <macros.h>
    5555#include <sysinfo/sysinfo.h>
     
    5858#include <errno.h>
    5959#include <putchar.h>
    60 #include <str.h>
     60#include <string.h>
    6161
    6262/** Simple kernel console.
     
    160160
    161161/** Print count times a character */
    162 NO_TRACE static void print_cc(wchar_t ch, size_t count)
     162static 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 NO_TRACE static const char *cmdtab_search_one(const char *name,
    171     link_t **startpos)
     170static const char *cmdtab_search_one(const char *name, link_t **startpos)
    172171{
    173172        size_t namelen = str_length(name);
     
    203202 *
    204203 */
    205 NO_TRACE static int cmdtab_compl(char *input, size_t size)
     204static int cmdtab_compl(char *input, size_t size)
    206205{
    207206        const char *name = input;
     
    210209        link_t *pos = NULL;
    211210        const char *hint;
    212         char *output = malloc(MAX_CMDLINE, 0);
     211        char output[MAX_CMDLINE];
    213212       
    214213        output[0] = 0;
     
    225224                printf("\n");
    226225                pos = NULL;
    227                 while (cmdtab_search_one(name, &pos)) {
     226                while ((hint = cmdtab_search_one(name, &pos))) {
    228227                        cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
    229228                        printf("%s (%s)\n", hlp->name, hlp->description);
     
    235234                str_cpy(input, size, output);
    236235       
    237         free(output);
    238236        return found;
    239237}
    240238
    241 NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev)
     239static wchar_t *clever_readline(const char *prompt, indev_t *indev)
    242240{
    243241        printf("%s> ", prompt);
     
    246244        wchar_t *current = history[history_pos];
    247245        current[0] = 0;
    248         char *tmp = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    249246       
    250247        while (true) {
     
    291288                                beg++;
    292289                       
     290                        char tmp[STR_BOUNDS(MAX_CMDLINE)];
    293291                        wstr_to_str(tmp, position - beg + 1, current + beg);
    294292                       
     
    416414        }
    417415       
    418         free(tmp);
    419416        return current;
    420417}
     
    425422}
    426423
    427 NO_TRACE static bool parse_int_arg(const char *text, size_t len,
    428     unative_t *result)
     424static bool parse_int_arg(const char *text, size_t len, unative_t *result)
    429425{
    430426        bool isaddr = false;
     
    459455                        printf("No symbol information available.\n");
    460456                        return false;
    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                 }
     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);
    473465        } else {
    474466                /* It's a number - convert it */
    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                 }
     467                *result = atoi(text);
     468                if (isptr)
     469                        *result = *((unative_t *) *result);
    493470        }
    494471       
     
    511488 *
    512489 */
    513 NO_TRACE static bool parse_argument(const char *cmdline, size_t size,
    514     size_t *start, size_t *end)
     490static bool parse_argument(const char *cmdline, size_t size, size_t *start, size_t *end)
    515491{
    516492        ASSERT(start != NULL);
     
    548524 *
    549525 */
    550 NO_TRACE static cmd_info_t *parse_cmdline(const char *cmdline, size_t size)
     526static cmd_info_t *parse_cmdline(const char *cmdline, size_t size)
    551527{
    552528        size_t start = 0;
     
    595571        size_t i;
    596572        for (i = 0; i < cmd->argc; i++) {
    597                 char *buf;
    598                
    599573                start = end;
    600574                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                        
    607575                        printf("Too few arguments.\n");
    608576                        spinlock_unlock(&cmd->lock);
     
    610578                }
    611579               
     580                char *buf;
    612581                switch (cmd->argv[i].type) {
    613582                case ARG_TYPE_STRING:
    614                 case ARG_TYPE_STRING_OPTIONAL:
    615583                        buf = (char *) cmd->argv[i].buffer;
    616584                        str_ncpy(buf, cmd->argv[i].len, cmdline + start,
     
    632600                                        cmd->argv[i].vartype = ARG_TYPE_STRING;
    633601                                } else {
    634                                         printf("Wrong syntax.\n");
     602                                        printf("Wrong synxtax.\n");
    635603                                        error = true;
    636604                                }
     
    675643 *
    676644 */
    677 void kconsole(const char *prompt, const char *msg, bool kcon)
     645void kconsole(char *prompt, char *msg, bool kcon)
    678646{
    679647        if (!stdin) {
     
    690658                printf("Type \"exit\" to leave the console.\n");
    691659       
    692         char *cmdline = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    693660        while (true) {
    694661                wchar_t *tmp = clever_readline((char *) prompt, stdin);
     
    697664                        continue;
    698665               
     666                char cmdline[STR_BOUNDS(MAX_CMDLINE)];
    699667                wstr_to_str(cmdline, STR_BOUNDS(MAX_CMDLINE), tmp);
    700668               
     
    708676                (void) cmd_info->func(cmd_info->argv);
    709677        }
    710         free(cmdline);
    711678}
    712679
Note: See TracChangeset for help on using the changeset viewer.