comparison target-utils/libcommon/cmdentry.c @ 12:165040ce4929

terget-utils: command entry implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 01 May 2013 20:01:41 +0000
parents
children 17c1e2a38418
comparison
equal deleted inserted replaced
11:40f607bb0a2c 12:165040ce4929
1 /*
2 * This module implements ASCII command entry via the serial port,
3 * with normal echo and minimal editing (rubout and kill).
4 *
5 * The command string buffer is bss-allocated here as well. It is
6 * sized to allow a maximum-size S-record to be sent as a command,
7 * as that is how we expect flash loading and XRAM chain-loading
8 * to be done.
9 */
10
11 #define MAXCMD 527
12
13 char command[MAXCMD+1];
14
15 /*
16 * The command_entry() function takes no arguments, and begins by waiting
17 * for serial input - hence the prompt should be printed before calling it.
18 *
19 * This function returns when one of the following characters is received:
20 * CR - accepts the command
21 * ^C or ^U - cancels the command
22 *
23 * The return value is non-zero if a non-empty command was accepted with CR,
24 * or 0 if the user hit CR with no input or if the command was canceled
25 * with ^C or ^U. In any case a CRLF is sent out the serial port
26 * to close the input echo line before this function returns.
27 */
28 command_entry()
29 {
30 int inlen, ch;
31
32 for (inlen = 0; ; ) {
33 ch = mygetchar();
34 if (ch >= ' ' && ch <= '~') {
35 if (inlen < MAXCMD) {
36 command[inlen++] = ch;
37 putchar(ch);
38 } else
39 putchar(7);
40 continue;
41 }
42 switch (ch) {
43 case '\r':
44 case '\n':
45 command[inlen] = '\0';
46 putchar('\n');
47 return(inlen);
48 case '\b': /* BS */
49 case 0x7F: /* DEL */
50 if (inlen) {
51 putchar('\b');
52 putchar(' ');
53 putchar('\b');
54 inlen--;
55 } else
56 putchar(7);
57 continue;
58 case 0x03: /* ^C */
59 putchar('^');
60 putchar('C');
61 putchar('\n');
62 return(0);
63 case 0x15: /* ^U */
64 putchar('^');
65 putchar('U');
66 putchar('\n');
67 return(0);
68 default:
69 putchar(7);
70 }
71 }
72 }