Subversion Repositories HelenOS

Rev

Rev 4348 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4348 Rev 4691
Line 84... Line 84...
84
 
84
 
85
SPINLOCK_INITIALIZE(cmd_lock);  /**< Lock protecting command list. */
85
SPINLOCK_INITIALIZE(cmd_lock);  /**< Lock protecting command list. */
86
LIST_INITIALIZE(cmd_head);      /**< Command list. */
86
LIST_INITIALIZE(cmd_head);      /**< Command list. */
87
 
87
 
88
static wchar_t history[KCONSOLE_HISTORY][MAX_CMDLINE] = {};
88
static wchar_t history[KCONSOLE_HISTORY][MAX_CMDLINE] = {};
89
static count_t history_pos = 0;
89
static size_t history_pos = 0;
90
 
90
 
91
/** Initialize kconsole data structures
91
/** Initialize kconsole data structures
92
 *
92
 *
93
 * This is the most basic initialization, almost no
93
 * This is the most basic initialization, almost no
94
 * other kernel subsystem is ready yet.
94
 * other kernel subsystem is ready yet.
Line 157... Line 157...
157
    spinlock_unlock(&cmd_lock);
157
    spinlock_unlock(&cmd_lock);
158
    return true;
158
    return true;
159
}
159
}
160
 
160
 
161
/** Print count times a character */
161
/** Print count times a character */
162
static void print_cc(wchar_t ch, count_t count)
162
static void print_cc(wchar_t ch, size_t count)
163
{
163
{
164
    count_t i;
164
    size_t i;
165
    for (i = 0; i < count; i++)
165
    for (i = 0; i < count; i++)
166
        putchar(ch);
166
        putchar(ch);
167
}
167
}
168
 
168
 
169
/** Try to find a command beginning with prefix */
169
/** Try to find a command beginning with prefix */
170
static const char *cmdtab_search_one(const char *name, link_t **startpos)
170
static const char *cmdtab_search_one(const char *name, link_t **startpos)
171
{
171
{
172
    count_t namelen = str_length(name);
172
    size_t namelen = str_length(name);
173
   
173
   
174
    spinlock_lock(&cmd_lock);
174
    spinlock_lock(&cmd_lock);
175
   
175
   
176
    if (*startpos == NULL)
176
    if (*startpos == NULL)
177
        *startpos = cmd_head.next;
177
        *startpos = cmd_head.next;
Line 203... Line 203...
203
 */
203
 */
204
static int cmdtab_compl(char *input, size_t size)
204
static int cmdtab_compl(char *input, size_t size)
205
{
205
{
206
    const char *name = input;
206
    const char *name = input;
207
   
207
   
208
    count_t found = 0;
208
    size_t found = 0;
209
    link_t *pos = NULL;
209
    link_t *pos = NULL;
210
    const char *hint;
210
    const char *hint;
211
    char output[MAX_CMDLINE];
211
    char output[MAX_CMDLINE];
212
   
212
   
213
    output[0] = 0;
213
    output[0] = 0;
Line 238... Line 238...
238
 
238
 
239
static wchar_t *clever_readline(const char *prompt, indev_t *indev)
239
static wchar_t *clever_readline(const char *prompt, indev_t *indev)
240
{
240
{
241
    printf("%s> ", prompt);
241
    printf("%s> ", prompt);
242
   
242
   
243
    count_t position = 0;
243
    size_t position = 0;
244
    wchar_t *current = history[history_pos];
244
    wchar_t *current = history[history_pos];
245
    current[0] = 0;
245
    current[0] = 0;
246
   
246
   
247
    while (true) {
247
    while (true) {
248
        wchar_t ch = indev_pop_character(indev);
248
        wchar_t ch = indev_pop_character(indev);
Line 278... Line 278...
278
            if (position == 0)
278
            if (position == 0)
279
                continue;
279
                continue;
280
           
280
           
281
            /* Find the beginning of the word
281
            /* Find the beginning of the word
282
               and copy it to tmp */
282
               and copy it to tmp */
283
            count_t beg;
283
            size_t beg;
284
            for (beg = position - 1; (beg > 0) && (!isspace(current[beg]));
284
            for (beg = position - 1; (beg > 0) && (!isspace(current[beg]));
285
                beg--);
285
                beg--);
286
           
286
           
287
            if (isspace(current[beg]))
287
            if (isspace(current[beg]))
288
                beg++;
288
                beg++;
Line 311... Line 311...
311
            }
311
            }
312
           
312
           
313
            /* We have a hint */
313
            /* We have a hint */
314
           
314
           
315
            size_t off = 0;
315
            size_t off = 0;
316
            count_t i = 0;
316
            size_t i = 0;
317
            while ((ch = str_decode(tmp, &off, STR_NO_LIMIT)) != 0) {
317
            while ((ch = str_decode(tmp, &off, STR_NO_LIMIT)) != 0) {
318
                if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE))
318
                if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE))
319
                    break;
319
                    break;
320
                i++;
320
                i++;
321
            }
321
            }
Line 540... Line 540...
540
        cmd_info_t *hlp = list_get_instance(cur, cmd_info_t, link);
540
        cmd_info_t *hlp = list_get_instance(cur, cmd_info_t, link);
541
        spinlock_lock(&hlp->lock);
541
        spinlock_lock(&hlp->lock);
542
       
542
       
543
        if (str_lcmp(hlp->name, cmdline + start,
543
        if (str_lcmp(hlp->name, cmdline + start,
544
            max(str_length(hlp->name),
544
            max(str_length(hlp->name),
545
            str_nlength(cmdline + start, (count_t) (end - start) - 1))) == 0) {
545
            str_nlength(cmdline + start, (size_t) (end - start) - 1))) == 0) {
546
            cmd = hlp;
546
            cmd = hlp;
547
            break;
547
            break;
548
        }
548
        }
549
       
549
       
550
        spinlock_unlock(&hlp->lock);
550
        spinlock_unlock(&hlp->lock);
Line 566... Line 566...
566
     * converted to those specified in the cmd info
566
     * converted to those specified in the cmd info
567
     * structure.
567
     * structure.
568
     */
568
     */
569
   
569
   
570
    bool error = false;
570
    bool error = false;
571
    count_t i;
571
    size_t i;
572
    for (i = 0; i < cmd->argc; i++) {
572
    for (i = 0; i < cmd->argc; i++) {
573
        start = end;
573
        start = end;
574
        if (!parse_argument(cmdline, size, &start, &end)) {
574
        if (!parse_argument(cmdline, size, &start, &end)) {
575
            printf("Too few arguments.\n");
575
            printf("Too few arguments.\n");
576
            spinlock_unlock(&cmd->lock);
576
            spinlock_unlock(&cmd->lock);
Line 657... Line 657...
657
    else
657
    else
658
        printf("Type \"exit\" to leave the console.\n");
658
        printf("Type \"exit\" to leave the console.\n");
659
   
659
   
660
    while (true) {
660
    while (true) {
661
        wchar_t *tmp = clever_readline((char *) prompt, stdin);
661
        wchar_t *tmp = clever_readline((char *) prompt, stdin);
662
        count_t len = wstr_length(tmp);
662
        size_t len = wstr_length(tmp);
663
        if (!len)
663
        if (!len)
664
            continue;
664
            continue;
665
       
665
       
666
        char cmdline[STR_BOUNDS(MAX_CMDLINE)];
666
        char cmdline[STR_BOUNDS(MAX_CMDLINE)];
667
        wstr_nstr(cmdline, tmp, STR_BOUNDS(MAX_CMDLINE));
667
        wstr_nstr(cmdline, tmp, STR_BOUNDS(MAX_CMDLINE));