Subversion Repositories HelenOS

Rev

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

Rev 4180 Rev 4207
Line 135... Line 135...
135
            spinlock_lock(&cmd->lock);
135
            spinlock_lock(&cmd->lock);
136
        } else {
136
        } else {
137
            spinlock_lock(&cmd->lock);
137
            spinlock_lock(&cmd->lock);
138
            spinlock_lock(&hlp->lock);
138
            spinlock_lock(&hlp->lock);
139
        }
139
        }
140
        if ((strncmp(hlp->name, cmd->name, max(strlen(cmd->name),
140
        if ((strncmp(hlp->name, cmd->name, max(str_size(cmd->name),
141
            strlen(hlp->name))) == 0)) {
141
            str_size(hlp->name))) == 0)) {
142
            /* The command is already there. */
142
            /* The command is already there. */
143
            spinlock_unlock(&hlp->lock);
143
            spinlock_unlock(&hlp->lock);
144
            spinlock_unlock(&cmd->lock);
144
            spinlock_unlock(&cmd->lock);
145
            spinlock_unlock(&cmd_lock);
145
            spinlock_unlock(&cmd_lock);
146
            return 0;
146
            return 0;
Line 170... Line 170...
170
/** Insert character to string */
170
/** Insert character to string */
171
static void insert_char(char *str, char ch, int pos)
171
static void insert_char(char *str, char ch, int pos)
172
{
172
{
173
    int i;
173
    int i;
174
   
174
   
175
    for (i = strlen(str); i > pos; i--)
175
    for (i = str_size(str); i > pos; i--)
176
        str[i] = str[i - 1];
176
        str[i] = str[i - 1];
177
    str[pos] = ch;
177
    str[pos] = ch;
178
}
178
}
179
 
179
 
180
/** Try to find a command beginning with prefix */
180
/** Try to find a command beginning with prefix */
181
static const char *cmdtab_search_one(const char *name,link_t **startpos)
181
static const char *cmdtab_search_one(const char *name,link_t **startpos)
182
{
182
{
183
    size_t namelen = strlen(name);
183
    size_t namelen = str_size(name);
184
    const char *curname;
184
    const char *curname;
185
 
185
 
186
    spinlock_lock(&cmd_lock);
186
    spinlock_lock(&cmd_lock);
187
 
187
 
188
    if (!*startpos)
188
    if (!*startpos)
Line 191... Line 191...
191
    for (; *startpos != &cmd_head; *startpos = (*startpos)->next) {
191
    for (; *startpos != &cmd_head; *startpos = (*startpos)->next) {
192
        cmd_info_t *hlp;
192
        cmd_info_t *hlp;
193
        hlp = list_get_instance(*startpos, cmd_info_t, link);
193
        hlp = list_get_instance(*startpos, cmd_info_t, link);
194
 
194
 
195
        curname = hlp->name;
195
        curname = hlp->name;
196
        if (strlen(curname) < namelen)
196
        if (str_size(curname) < namelen)
197
            continue;
197
            continue;
198
        if (strncmp(curname, name, namelen) == 0) {
198
        if (strncmp(curname, name, namelen) == 0) {
199
            spinlock_unlock(&cmd_lock);
199
            spinlock_unlock(&cmd_lock);
200
            return curname+namelen;
200
            return curname+namelen;
201
        }
201
        }
Line 220... Line 220...
220
 
220
 
221
    output[0] = '\0';
221
    output[0] = '\0';
222
    while ((foundtxt = cmdtab_search_one(name, &startpos))) {
222
    while ((foundtxt = cmdtab_search_one(name, &startpos))) {
223
        startpos = startpos->next;
223
        startpos = startpos->next;
224
        if (!found)
224
        if (!found)
225
            strncpy(output, foundtxt, strlen(foundtxt) + 1);
225
            strncpy(output, foundtxt, str_size(foundtxt) + 1);
226
        else {
226
        else {
227
            for (i = 0; output[i] && foundtxt[i] &&
227
            for (i = 0; output[i] && foundtxt[i] &&
228
                output[i] == foundtxt[i]; i++)
228
                output[i] == foundtxt[i]; i++)
229
                ;
229
                ;
230
            output[i] = '\0';
230
            output[i] = '\0';
Line 232... Line 232...
232
        found++;
232
        found++;
233
    }
233
    }
234
    if (!found)
234
    if (!found)
235
        return 0;
235
        return 0;
236
 
236
 
237
    if (found > 1 && !strlen(output)) {
237
    if (found > 1 && !str_size(output)) {
238
        printf("\n");
238
        printf("\n");
239
        startpos = NULL;
239
        startpos = NULL;
240
        while ((foundtxt = cmdtab_search_one(name, &startpos))) {
240
        while ((foundtxt = cmdtab_search_one(name, &startpos))) {
241
            cmd_info_t *hlp;
241
            cmd_info_t *hlp;
242
            hlp = list_get_instance(startpos, cmd_info_t, link);
242
            hlp = list_get_instance(startpos, cmd_info_t, link);
Line 307... Line 307...
307
                continue;
307
                continue;
308
            for (i = 0; tmp[i] && curlen < MAX_CMDLINE;
308
            for (i = 0; tmp[i] && curlen < MAX_CMDLINE;
309
                i++, curlen++)
309
                i++, curlen++)
310
                insert_char(current, tmp[i], i + position);
310
                insert_char(current, tmp[i], i + position);
311
 
311
 
312
            if (strlen(tmp) || found == 1) { /* If we have a hint */
312
            if (str_size(tmp) || found == 1) { /* If we have a hint */
313
                for (i = position; i < curlen; i++)
313
                for (i = position; i < curlen; i++)
314
                    putchar(current[i]);
314
                    putchar(current[i]);
315
                position += strlen(tmp);
315
                position += str_size(tmp);
316
                /* Add space to end */
316
                /* Add space to end */
317
                if (found == 1 && position == curlen &&
317
                if (found == 1 && position == curlen &&
318
                    curlen < MAX_CMDLINE) {
318
                    curlen < MAX_CMDLINE) {
319
                    current[position] = ' ';
319
                    current[position] = ' ';
320
                    curlen++;
320
                    curlen++;
Line 323... Line 323...
323
                }
323
                }
324
            } else { /* No hint, table was printed */
324
            } else { /* No hint, table was printed */
325
                printf("%s> ", prompt);
325
                printf("%s> ", prompt);
326
                for (i = 0; i < curlen; i++)
326
                for (i = 0; i < curlen; i++)
327
                    putchar(current[i]);
327
                    putchar(current[i]);
328
                position += strlen(tmp);
328
                position += str_size(tmp);
329
            }
329
            }
330
            rdln_print_c('\b', curlen - position);
330
            rdln_print_c('\b', curlen - position);
331
            continue;
331
            continue;
332
        }
332
        }
333
        if (c == 0x1b) { /* Special command */
333
        if (c == 0x1b) { /* Special command */
Line 382... Line 382...
382
                    histposition =
382
                    histposition =
383
                        histposition % KCONSOLE_HISTORY;
383
                        histposition % KCONSOLE_HISTORY;
384
                }
384
                }
385
                current = history[histposition];
385
                current = history[histposition];
386
                printf("%s", current);
386
                printf("%s", current);
387
                curlen = strlen(current);
387
                curlen = str_size(current);
388
                position = curlen;
388
                position = curlen;
389
                continue;
389
                continue;
390
            }
390
            }
391
            continue;
391
            continue;
392
        }
392
        }
Line 441... Line 441...
441
    else
441
    else
442
        printf("Type \"exit\" to leave the console.\n");
442
        printf("Type \"exit\" to leave the console.\n");
443
   
443
   
444
    while (true) {
444
    while (true) {
445
        cmdline = clever_readline((char *) prompt, stdin);
445
        cmdline = clever_readline((char *) prompt, stdin);
446
        len = strlen(cmdline);
446
        len = str_size(cmdline);
447
        if (!len)
447
        if (!len)
448
            continue;
448
            continue;
449
       
449
       
450
        if ((!kcon) && (len == 4) && (strncmp(cmdline, "exit", 4) == 0))
450
        if ((!kcon) && (len == 4) && (strncmp(cmdline, "exit", 4) == 0))
451
            break;
451
            break;
Line 542... Line 542...
542
        cmd_info_t *hlp;
542
        cmd_info_t *hlp;
543
       
543
       
544
        hlp = list_get_instance(cur, cmd_info_t, link);
544
        hlp = list_get_instance(cur, cmd_info_t, link);
545
        spinlock_lock(&hlp->lock);
545
        spinlock_lock(&hlp->lock);
546
       
546
       
547
        if (strncmp(hlp->name, &cmdline[start], max(strlen(hlp->name),
547
        if (strncmp(hlp->name, &cmdline[start], max(str_size(hlp->name),
548
            end - start + 1)) == 0) {
548
            end - start + 1)) == 0) {
549
            cmd = hlp;
549
            cmd = hlp;
550
            break;
550
            break;
551
        }
551
        }
552
       
552