Subversion Repositories HelenOS

Rev

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

Rev 2787 Rev 3425
Line 167... Line 167...
167
        str[i] = str[i - 1];
167
        str[i] = str[i - 1];
168
    str[pos] = ch;
168
    str[pos] = ch;
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
    size_t 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);
Line 201... Line 201...
201
 * @param name - string to match, changed to hint on exit
201
 * @param name - string to match, changed to hint on exit
202
 * @return number of found matches
202
 * @return number of found matches
203
 */
203
 */
204
static int cmdtab_compl(char *name)
204
static int cmdtab_compl(char *name)
205
{
205
{
206
    static char output[MAX_SYMBOL_NAME+1];
206
    static char output[MAX_SYMBOL_NAME + 1];
207
    link_t *startpos = NULL;
207
    link_t *startpos = NULL;
208
    const char *foundtxt;
208
    const char *foundtxt;
209
    int found = 0;
209
    int found = 0;
210
    int i;
210
    int i;
211
 
211
 
212
    output[0] = '\0';
212
    output[0] = '\0';
213
    while ((foundtxt = cmdtab_search_one(name, &startpos))) {
213
    while ((foundtxt = cmdtab_search_one(name, &startpos))) {
214
        startpos = startpos->next;
214
        startpos = startpos->next;
215
        if (!found)
215
        if (!found)
216
            strncpy(output, foundtxt, strlen(foundtxt)+1);
216
            strncpy(output, foundtxt, strlen(foundtxt) + 1);
217
        else {
217
        else {
218
            for (i = 0; output[i] && foundtxt[i] &&
218
            for (i = 0; output[i] && foundtxt[i] &&
219
                output[i] == foundtxt[i]; i++)
219
                output[i] == foundtxt[i]; i++)
220
                ;
220
                ;
221
            output[i] = '\0';
221
            output[i] = '\0';
Line 238... Line 238...
238
    strncpy(name, output, MAX_SYMBOL_NAME);
238
    strncpy(name, output, MAX_SYMBOL_NAME);
239
    return found;
239
    return found;
240
   
240
   
241
}
241
}
242
 
242
 
243
static char * clever_readline(const char *prompt, chardev_t *input)
243
static char *clever_readline(const char *prompt, chardev_t *input)
244
{
244
{
245
    static int histposition = 0;
245
    static int histposition = 0;
246
 
246
 
247
    static char tmp[MAX_CMDLINE+1];
247
    static char tmp[MAX_CMDLINE + 1];
248
    int curlen = 0, position = 0;
248
    int curlen = 0, position = 0;
249
    char *current = history[histposition];
249
    char *current = history[histposition];
250
    int i;
250
    int i;
251
    char mod; /* Command Modifier */
251
    char mod; /* Command Modifier */
252
    char c;
252
    char c;
Line 255... Line 255...
255
    while (1) {
255
    while (1) {
256
        c = _getc(input);
256
        c = _getc(input);
257
        if (c == '\n') {
257
        if (c == '\n') {
258
            putchar(c);
258
            putchar(c);
259
            break;
259
            break;
-
 
260
        }
260
        } if (c == '\b') { /* Backspace */
261
        if (c == '\b') { /* Backspace */
261
            if (position == 0)
262
            if (position == 0)
262
                continue;
263
                continue;
263
            for (i = position; i < curlen; i++)
264
            for (i = position; i < curlen; i++)
264
                current[i - 1] = current[i];
265
                current[i - 1] = current[i];
265
            curlen--;
266
            curlen--;
Line 541... Line 542...
541
        switch (cmd->argv[i].type) {
542
        switch (cmd->argv[i].type) {
542
        case ARG_TYPE_STRING:
543
        case ARG_TYPE_STRING:
543
            buf = (char *) cmd->argv[i].buffer;
544
            buf = (char *) cmd->argv[i].buffer;
544
            strncpy(buf, (const char *) &cmdline[start],
545
            strncpy(buf, (const char *) &cmdline[start],
545
                min((end - start) + 2, cmd->argv[i].len));
546
                min((end - start) + 2, cmd->argv[i].len));
546
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
547
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] =
-
 
548
                '\0';
547
            break;
549
            break;
548
        case ARG_TYPE_INT:
550
        case ARG_TYPE_INT:
549
            if (parse_int_arg(cmdline + start, end - start + 1,
551
            if (parse_int_arg(cmdline + start, end - start + 1,
550
                &cmd->argv[i].intval))
552
                &cmd->argv[i].intval))
551
                error = 1;
553
                error = 1;
Line 558... Line 560...
558
                    min((end-start), cmd->argv[i].len));
560
                    min((end-start), cmd->argv[i].len));
559
                buf[min((end - start), cmd->argv[i].len - 1)] =
561
                buf[min((end - start), cmd->argv[i].len - 1)] =
560
                    '\0';
562
                    '\0';
561
                cmd->argv[i].intval = (unative_t) buf;
563
                cmd->argv[i].intval = (unative_t) buf;
562
                cmd->argv[i].vartype = ARG_TYPE_STRING;
564
                cmd->argv[i].vartype = ARG_TYPE_STRING;
563
            } else if (!parse_int_arg(cmdline + start, end - start + 1,
565
            } else if (!parse_int_arg(cmdline + start,
564
                &cmd->argv[i].intval)) {
566
                end - start + 1, &cmd->argv[i].intval)) {
565
                cmd->argv[i].vartype = ARG_TYPE_INT;
567
                cmd->argv[i].vartype = ARG_TYPE_INT;
566
            } else {
568
            } else {
567
                printf("Unrecognized variable argument.\n");
569
                printf("Unrecognized variable argument.\n");
568
                error = 1;
570
                error = 1;
569
            }
571
            }