annotate rvinterf/libasync/ttymagic.c @ 951:eb27543ce18e

c139explore: elementary operation commands lcdcmd and lcdpix added
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Wed, 04 Nov 2015 03:03:38 +0000
parents 40b8557b9d04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the tty "magic" code for fc-tmsh.
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <string.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <strings.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <stdlib.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <unistd.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <termios.h>
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern int ttyhacks;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 struct termios orig_termios, our_termios;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 #define MAX_USER_CMD 78
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 char usercmd[MAX_USER_CMD+1];
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 int usercmd_len;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 tty_init()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 if (!ttyhacks)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 return;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 tcgetattr(0, &orig_termios);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 bcopy(&orig_termios, &our_termios, sizeof(struct termios));
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 our_termios.c_oflag &= ~(OCRNL | ONOCR | ONLRET);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 our_termios.c_lflag &= ~(ICANON | ECHO);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 our_termios.c_cc[VMIN] = 1;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 our_termios.c_cc[VTIME] = 0;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 tcsetattr(0, TCSAFLUSH, &our_termios);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 putchar('>');
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 fflush(stdout);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 tty_cleanup()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 if (!ttyhacks)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 return;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 tcsetattr(0, TCSAFLUSH, &orig_termios);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 void
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 handle_tty_input()
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 char buf[256];
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 int i, c, cc;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 cc = read(0, buf, sizeof buf);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 if (cc <= 0) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 tty_cleanup();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 exit(0);
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 for (i = 0; i < cc; i++) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 c = buf[i];
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 if (c >= ' ' && c <= '~') {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (usercmd_len >= MAX_USER_CMD)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 continue;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 usercmd[usercmd_len++] = c;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 if (ttyhacks)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 putchar(c); /* echo */
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 continue;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 switch (c) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 case '\b':
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 case 0x7F:
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 if (!usercmd_len)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 continue;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 usercmd_len--;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 if (ttyhacks) {
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 putchar('\b');
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 putchar(' ');
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 putchar('\b');
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 continue;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 case '\n':
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 case '\r':
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 usercmd[usercmd_len] = '\0';
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 if (ttyhacks)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 putchar('\n'); /* echo */
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 dispatch_user_cmd();
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 usercmd_len = 0;
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 if (ttyhacks)
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 putchar('>'); /* new prompt */
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 }
13a0348ffce4 rvinterf/etm: checkpointing not-yet-compilable code
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 }
183
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
90
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
91 void
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
92 async_msg_output(msg)
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
93 char *msg;
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
94 {
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
95 int msglen, i;
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
96
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
97 msglen = strlen(msg);
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
98 if (ttyhacks)
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
99 putchar('\r');
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
100 fputs(msg, stdout);
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
101 if (ttyhacks)
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
102 for (i = msglen; i < usercmd_len + 1; i++)
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
103 putchar(' ');
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
104 putchar('\n');
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
105 if (!ttyhacks)
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
106 return;
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
107 /* reprint the input line */
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
108 putchar('>');
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
109 if (!usercmd_len)
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
110 return;
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
111 fwrite(usercmd, 1, usercmd_len, stdout);
85222710dc92 rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 182
diff changeset
112 }