Rev 4263 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4263 | Rev 4327 | ||
---|---|---|---|
Line 212... | Line 212... | ||
212 | 212 | ||
213 | output[0] = 0; |
213 | output[0] = 0; |
214 | 214 | ||
215 | while ((hint = cmdtab_search_one(name, &pos))) { |
215 | while ((hint = cmdtab_search_one(name, &pos))) { |
216 | if ((found == 0) || (str_length(output) > str_length(hint))) |
216 | if ((found == 0) || (str_length(output) > str_length(hint))) |
217 | str_ncpy(output, hint, MAX_CMDLINE); |
217 | str_cpy(output, MAX_CMDLINE, hint); |
218 | 218 | ||
219 | pos = pos->next; |
219 | pos = pos->next; |
220 | found++; |
220 | found++; |
221 | } |
221 | } |
222 | 222 | ||
Line 229... | Line 229... | ||
229 | pos = pos->next; |
229 | pos = pos->next; |
230 | } |
230 | } |
231 | } |
231 | } |
232 | 232 | ||
233 | if (found > 0) |
233 | if (found > 0) |
234 | str_ncpy(input, output, size); |
234 | str_cpy(input, size, output); |
235 | 235 | ||
236 | return found; |
236 | return found; |
237 | } |
237 | } |
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) |
Line 243... | Line 243... | ||
243 | count_t position = 0; |
243 | count_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 = _getc(indev); |
248 | wchar_t ch = indev_pop_character(indev); |
249 | 249 | ||
250 | if (ch == '\n') { |
250 | if (ch == '\n') { |
251 | /* Enter */ |
251 | /* Enter */ |
252 | putchar(ch); |
252 | putchar(ch); |
253 | break; |
253 | break; |
Line 300... | Line 300... | ||
300 | } |
300 | } |
301 | 301 | ||
302 | if (found == 0) |
302 | if (found == 0) |
303 | continue; |
303 | continue; |
304 | 304 | ||
- | 305 | if (found > 1) { |
|
- | 306 | /* No unique hint, list was printed */ |
|
- | 307 | printf("%s> ", prompt); |
|
- | 308 | printf("%ls", current); |
|
- | 309 | print_cc('\b', wstr_length(current) - position); |
|
- | 310 | continue; |
|
- | 311 | } |
|
- | 312 | ||
- | 313 | /* We have a hint */ |
|
- | 314 | ||
305 | size_t off = 0; |
315 | size_t off = 0; |
306 | count_t i = 0; |
316 | count_t i = 0; |
307 | while ((ch = str_decode(tmp, &off, STR_NO_LIMIT)) != 0) { |
317 | while ((ch = str_decode(tmp, &off, STR_NO_LIMIT)) != 0) { |
308 | if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE)) |
318 | if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE)) |
309 | break; |
319 | break; |
310 | i++; |
320 | i++; |
311 | } |
321 | } |
312 | 322 | ||
313 | if ((str_length(tmp) > 0) || (found == 1)) { |
- | |
314 | /* We have a hint */ |
- | |
315 | printf("%ls", current + position); |
323 | printf("%ls", current + position); |
316 | print_cc('\b', wstr_length(current) - position); |
324 | position += str_length(tmp); |
317 | position += str_length(tmp); |
325 | print_cc('\b', wstr_length(current) - position); |
318 | 326 | ||
319 | if ((found == 1) && (position == wstr_length(current))) { |
327 | if (position == wstr_length(current)) { |
- | 328 | /* Insert a space after the last completed argument */ |
|
320 | if (wstr_linsert(current, ' ', position, MAX_CMDLINE)) { |
329 | if (wstr_linsert(current, ' ', position, MAX_CMDLINE)) { |
321 | printf("%ls", current + position); |
330 | printf("%ls", current + position); |
322 | position++; |
331 | position++; |
323 | } |
- | |
324 | } |
332 | } |
325 | } else { |
- | |
326 | /* No unique hint, list was printed */ |
- | |
327 | printf("%s> ", prompt); |
- | |
328 | printf("%ls", current); |
- | |
329 | position += str_length(tmp); |
- | |
330 | } |
333 | } |
331 | - | ||
332 | print_cc('\b', wstr_length(current) - position); |
- | |
333 | continue; |
334 | continue; |
334 | } |
335 | } |
335 | 336 | ||
336 | if (ch == U_LEFT_ARROW) { |
337 | if (ch == U_LEFT_ARROW) { |
337 | /* Left */ |
338 | /* Left */ |
Line 436... | Line 437... | ||
436 | len--; |
437 | len--; |
437 | } |
438 | } |
438 | 439 | ||
439 | if ((text[0] < '0') || (text[0] > '9')) { |
440 | if ((text[0] < '0') || (text[0] > '9')) { |
440 | char symname[MAX_SYMBOL_NAME]; |
441 | char symname[MAX_SYMBOL_NAME]; |
441 | str_ncpy(symname, text, min(len + 1, MAX_SYMBOL_NAME)); |
442 | str_ncpy(symname, MAX_SYMBOL_NAME, text, len + 1); |
442 | 443 | ||
443 | uintptr_t symaddr; |
444 | uintptr_t symaddr; |
444 | int rc = symtab_addr_lookup(symname, &symaddr); |
445 | int rc = symtab_addr_lookup(symname, &symaddr); |
445 | switch (rc) { |
446 | switch (rc) { |
446 | case ENOENT: |
447 | case ENOENT: |
Line 578... | Line 579... | ||
578 | 579 | ||
579 | char *buf; |
580 | char *buf; |
580 | switch (cmd->argv[i].type) { |
581 | switch (cmd->argv[i].type) { |
581 | case ARG_TYPE_STRING: |
582 | case ARG_TYPE_STRING: |
582 | buf = (char *) cmd->argv[i].buffer; |
583 | buf = (char *) cmd->argv[i].buffer; |
583 | str_ncpy(buf, cmdline + start, |
584 | str_ncpy(buf, cmd->argv[i].len, cmdline + start, |
584 | min((end - start) + 1, cmd->argv[i].len)); |
585 | end - start); |
585 | break; |
586 | break; |
586 | case ARG_TYPE_INT: |
587 | case ARG_TYPE_INT: |
587 | if (!parse_int_arg(cmdline + start, end - start, |
588 | if (!parse_int_arg(cmdline + start, end - start, |
588 | &cmd->argv[i].intval)) |
589 | &cmd->argv[i].intval)) |
589 | error = true; |
590 | error = true; |
590 | break; |
591 | break; |
591 | case ARG_TYPE_VAR: |
592 | case ARG_TYPE_VAR: |
592 | if ((start < end - 1) && (cmdline[start] == '"')) { |
593 | if ((start < end - 1) && (cmdline[start] == '"')) { |
593 | if (cmdline[end - 1] == '"') { |
594 | if (cmdline[end - 1] == '"') { |
594 | buf = (char *) cmd->argv[i].buffer; |
595 | buf = (char *) cmd->argv[i].buffer; |
- | 596 | str_ncpy(buf, cmd->argv[i].len, |
|
595 | str_ncpy(buf, cmdline + start + 1, |
597 | cmdline + start + 1, |
596 | min((end - start) - 1, cmd->argv[i].len)); |
598 | (end - start) - 1); |
597 | cmd->argv[i].intval = (unative_t) buf; |
599 | cmd->argv[i].intval = (unative_t) buf; |
598 | cmd->argv[i].vartype = ARG_TYPE_STRING; |
600 | cmd->argv[i].vartype = ARG_TYPE_STRING; |
599 | } else { |
601 | } else { |
600 | printf("Wrong synxtax.\n"); |
602 | printf("Wrong synxtax.\n"); |
601 | error = true; |
603 | error = true; |
Line 649... | Line 651... | ||
649 | 651 | ||
650 | if (msg) |
652 | if (msg) |
651 | printf("%s", msg); |
653 | printf("%s", msg); |
652 | 654 | ||
653 | if (kcon) |
655 | if (kcon) |
654 | _getc(stdin); |
656 | indev_pop_character(stdin); |
655 | else |
657 | else |
656 | printf("Type \"exit\" to leave the console.\n"); |
658 | printf("Type \"exit\" to leave the console.\n"); |
657 | 659 | ||
658 | while (true) { |
660 | while (true) { |
659 | wchar_t *tmp = clever_readline((char *) prompt, stdin); |
661 | wchar_t *tmp = clever_readline((char *) prompt, stdin); |