Mercurial > ecos
comparison packages/redboot/current/src/io.c @ 195:67850532eebb
Merge from eCos master repository on 2001-11-02-06:43:03-GMT
| author | jlarmour |
|---|---|
| date | Fri, 02 Nov 2001 16:12:33 +0000 |
| parents | feb0fcf83327 |
| children | 9b55e9c69693 |
comparison
equal
deleted
inserted
replaced
| 194:feb0fcf83327 | 195:67850532eebb |
|---|---|
| 275 #endif | 275 #endif |
| 276 | 276 |
| 277 // | 277 // |
| 278 // Read a line of input from the user | 278 // Read a line of input from the user |
| 279 // Return: | 279 // Return: |
| 280 // n: 'n' valid characters received | 280 // _GETS_OK: 'n' valid characters received |
| 281 // 0: '$' (GDB lead-in) | 281 // _GETS_GDB: '$' (GDB lead-in) |
| 282 // -1: No input before timeout | 282 // _GETS_TIMEOUT: No input before timeout |
| 283 // -2: ^C typed | 283 // _GETS_CTRLC: ^C typed |
| 284 // | 284 // |
| 285 int | 285 int |
| 286 _rb_gets(char *buf, int buflen, int timeout) | 286 _rb_gets_preloaded(char *buf, int buflen, int timeout) |
| 287 { | 287 { |
| 288 char *ip = buf; // Insertion point | 288 char *ip = buf; // Insertion point |
| 289 char *eol = buf; // End of line | 289 char *eol = buf; // End of line |
| 290 char c; | 290 char c; |
| 291 bool res = false; | 291 bool res = false; |
| 305 static int _cl_index = -1; // Last known command line | 305 static int _cl_index = -1; // Last known command line |
| 306 static int _cl_max_index = -1; // Last command in buffers | 306 static int _cl_max_index = -1; // Last command in buffers |
| 307 int _index = _cl_index; // Last saved line | 307 int _index = _cl_index; // Last saved line |
| 308 char *xp; | 308 char *xp; |
| 309 #endif | 309 #endif |
| 310 | |
| 311 // Display current buffer data | |
| 312 while (*eol) { | |
| 313 mon_write_char(*eol++); | |
| 314 } | |
| 315 ip = eol; | |
| 310 | 316 |
| 311 while (true) { | 317 while (true) { |
| 312 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT | 318 #ifdef CYGFUN_REDBOOT_BOOT_SCRIPT |
| 313 if (getc_script(&c)) | 319 if (getc_script(&c)) |
| 314 do_idle(false); | 320 do_idle(false); |
| 421 mon_write_char('\b'); | 427 mon_write_char('\b'); |
| 422 } | 428 } |
| 423 eol = ip; | 429 eol = ip; |
| 424 } | 430 } |
| 425 break; | 431 break; |
| 432 case CTRL('D'): | |
| 433 // Erase the character under the cursor | |
| 434 if (ip != eol) { | |
| 435 xp = ip; | |
| 436 eol--; | |
| 437 while (xp != eol) { | |
| 438 *xp = *(xp+1); | |
| 439 mon_write_char(*xp++); | |
| 440 } | |
| 441 mon_write_char(' '); // Erases last character | |
| 442 mon_write_char('\b'); | |
| 443 while (xp-- != ip) { | |
| 444 mon_write_char('\b'); | |
| 445 } | |
| 446 } | |
| 447 break; | |
| 426 #endif // CYGNUM_REDBOOT_CMD_LINE_EDITING | 448 #endif // CYGNUM_REDBOOT_CMD_LINE_EDITING |
| 427 case CTRL('C'): // ^C | 449 case CTRL('C'): // ^C |
| 428 if (ip == buf) { | 450 // Abort current input |
| 429 diag_printf("^C\n"); | 451 diag_printf("^C\n"); |
| 430 return _GETS_CTRLC; | 452 return _GETS_CTRLC; |
| 431 } | |
| 432 *ip++ = c; | |
| 433 break; | |
| 434 case '\n': | 453 case '\n': |
| 435 case '\r': | 454 case '\r': |
| 436 // If previous character was the "other" end-of-line, ignore this one | 455 // If previous character was the "other" end-of-line, ignore this one |
| 437 if (((c == '\n') && (last_ch == '\r')) || | 456 if (((c == '\n') && (last_ch == '\r')) || |
| 438 ((c == '\r') && (last_ch == '\n'))) { | 457 ((c == '\r') && (last_ch == '\n'))) { |
| 444 mon_write_char('\r'); | 463 mon_write_char('\r'); |
| 445 mon_write_char('\n'); | 464 mon_write_char('\n'); |
| 446 } | 465 } |
| 447 last_ch = c; | 466 last_ch = c; |
| 448 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0 | 467 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0 |
| 449 // Save current line | 468 if (cmd_history) { |
| 450 if (++_cl_index == _CL_NUM_LINES) _cl_index = 0; | 469 // Save current line - only when enabled |
| 451 if (_cl_index > _cl_max_index) _cl_max_index = _cl_index; | 470 if (++_cl_index == _CL_NUM_LINES) _cl_index = 0; |
| 452 strcpy(_cl_lines[_cl_index], buf); | 471 if (_cl_index > _cl_max_index) _cl_max_index = _cl_index; |
| 472 strcpy(_cl_lines[_cl_index], buf); | |
| 473 } | |
| 453 #endif | 474 #endif |
| 454 return _GETS_OK; | 475 return _GETS_OK; |
| 455 case '\b': | 476 case '\b': |
| 456 case 0x7F: // DEL | 477 case 0x7F: // DEL |
| 457 if (ip != buf) { | 478 if (ip != buf) { |
| 552 if (ip == buf + buflen) // Buffer full | 573 if (ip == buf + buflen) // Buffer full |
| 553 return buflen; | 574 return buflen; |
| 554 } | 575 } |
| 555 } | 576 } |
| 556 | 577 |
| 578 int | |
| 579 _rb_gets(char *buf, int buflen, int timeout) | |
| 580 { | |
| 581 *buf = '\0'; // Empty buffer | |
| 582 return _rb_gets_preloaded(buf, buflen, timeout); | |
| 583 } | |
| 584 | |
| 557 bool | 585 bool |
| 558 verify_action(char *fmt, ...) | 586 verify_action(char *fmt, ...) |
| 559 { | 587 { |
| 560 va_list ap; | 588 va_list ap; |
| 561 char ans[8]; | 589 char ans[8]; |
