Subversion Repositories HelenOS

Rev

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

Rev 2108 Rev 2113
Line 169... Line 169...
169
}
169
}
170
 
170
 
171
/** Try to find a command beginning with prefix */
171
/** Try to find a command beginning with prefix */
172
static const char * cmdtab_search_one(const char *name,link_t **startpos)
172
static const char * cmdtab_search_one(const char *name,link_t **startpos)
173
{
173
{
174
    int namelen = strlen(name);
174
    size_t namelen = strlen(name);
175
    const char *curname;
175
    const char *curname;
176
 
176
 
177
    spinlock_lock(&cmd_lock);
177
    spinlock_lock(&cmd_lock);
178
 
178
 
179
    if (!*startpos)
179
    if (!*startpos)
Line 414... Line 414...
414
        printf("%s: no stdin\n", __FUNCTION__);
414
        printf("%s: no stdin\n", __FUNCTION__);
415
        return;
415
        return;
416
    }
416
    }
417
   
417
   
418
    while (true) {
418
    while (true) {
419
        cmdline = clever_readline(prompt, stdin);
419
        cmdline = clever_readline((char *) prompt, stdin);
420
        len = strlen(cmdline);
420
        len = strlen(cmdline);
421
        if (!len)
421
        if (!len)
422
            continue;
422
            continue;
423
        cmd_info = parse_cmdline(cmdline, len);
423
        cmd_info = parse_cmdline(cmdline, len);
424
        if (!cmd_info)
424
        if (!cmd_info)
Line 484... Line 484...
484
cmd_info_t *parse_cmdline(char *cmdline, size_t len)
484
cmd_info_t *parse_cmdline(char *cmdline, size_t len)
485
{
485
{
486
    index_t start = 0, end = 0;
486
    index_t start = 0, end = 0;
487
    cmd_info_t *cmd = NULL;
487
    cmd_info_t *cmd = NULL;
488
    link_t *cur;
488
    link_t *cur;
489
    int i;
489
    count_t i;
490
    int error = 0;
490
    int error = 0;
491
   
491
   
492
    if (!parse_argument(cmdline, len, &start, &end)) {
492
    if (!parse_argument(cmdline, len, &start, &end)) {
493
        /* Command line did not contain alphanumeric word. */
493
        /* Command line did not contain alphanumeric word. */
494
        return NULL;
494
        return NULL;
Line 538... Line 538...
538
        }
538
        }
539
       
539
       
540
        error = 0;
540
        error = 0;
541
        switch (cmd->argv[i].type) {
541
        switch (cmd->argv[i].type) {
542
        case ARG_TYPE_STRING:
542
        case ARG_TYPE_STRING:
543
                buf = cmd->argv[i].buffer;
543
            buf = (char *) cmd->argv[i].buffer;
544
                strncpy(buf, (const char *) &cmdline[start],
544
            strncpy(buf, (const char *) &cmdline[start],
545
                min((end - start) + 2, cmd->argv[i].len));
545
                min((end - start) + 2, cmd->argv[i].len));
546
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
546
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
547
            break;
547
            break;
548
        case ARG_TYPE_INT:
548
        case ARG_TYPE_INT:
549
            if (parse_int_arg(cmdline + start, end - start + 1,
549
            if (parse_int_arg(cmdline + start, end - start + 1,
Line 551... Line 551...
551
                error = 1;
551
                error = 1;
552
            break;
552
            break;
553
        case ARG_TYPE_VAR:
553
        case ARG_TYPE_VAR:
554
            if (start != end && cmdline[start] == '"' &&
554
            if (start != end && cmdline[start] == '"' &&
555
                cmdline[end] == '"') {
555
                cmdline[end] == '"') {
556
                buf = cmd->argv[i].buffer;
556
                buf = (char *) cmd->argv[i].buffer;
557
                strncpy(buf, (const char *) &cmdline[start + 1],
557
                strncpy(buf, (const char *) &cmdline[start + 1],
558
                    min((end-start), cmd->argv[i].len));
558
                    min((end-start), cmd->argv[i].len));
559
                buf[min((end - start), cmd->argv[i].len - 1)] =
559
                buf[min((end - start), cmd->argv[i].len - 1)] =
560
                    '\0';
560
                    '\0';
561
                cmd->argv[i].intval = (unative_t) buf;
561
                cmd->argv[i].intval = (unative_t) buf;
Line 606... Line 606...
606
 *
606
 *
607
 * @return false on failure, true on success.
607
 * @return false on failure, true on success.
608
 */
608
 */
609
bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end)
609
bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end)
610
{
610
{
611
    int i;
611
    index_t i;
612
    bool found_start = false;
612
    bool found_start = false;
613
   
613
   
614
    ASSERT(start != NULL);
614
    ASSERT(start != NULL);
615
    ASSERT(end != NULL);
615
    ASSERT(end != NULL);
616
   
616