4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.2 2008/02/07 11:11:14 staffcvs
14 * *** empty log message ***
16 * Revision 1.1 2008/02/07 01:02:52 james
17 * *** empty log message ***
19 * Revision 1.3 2008/02/06 17:53:28 james
20 * *** empty log message ***
22 * Revision 1.2 2008/02/04 02:05:06 james
23 * *** empty log message ***
25 * Revision 1.1 2008/02/04 01:32:39 james
26 * *** empty log message ***
33 set_nonblocking (int fd)
36 arg = fcntl (fd, F_GETFL, arg);
38 fcntl (fd, F_SETFL, arg);
45 arg = fcntl (fd, F_GETFL, arg);
47 fcntl (fd, F_SETFL, arg);
51 default_termios (struct termios *termios)
54 memset (termios, 0, sizeof (termios));
56 termios->c_iflag = ICRNL | IXON;
57 termios->c_oflag = OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
59 ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE;
61 termios->c_cc[VINTR] = 003;
62 termios->c_cc[VQUIT] = 034;
63 termios->c_cc[VERASE] = 0177;
64 termios->c_cc[VKILL] = 025;
65 termios->c_cc[VEOF] = 004;
66 termios->c_cc[VEOL] = 0;
67 termios->c_cc[VEOL2] = 0;
68 termios->c_cc[VSTART] = 021;
69 termios->c_cc[VSTOP] = 023;
70 termios->c_cc[VSUSP] = 032;
71 termios->c_cc[VLNEXT] = 026;
72 termios->c_cc[VWERASE] = 027;
73 termios->c_cc[VREPRINT] = 022;
74 termios->c_cc[VDISCARD] = 017;
76 termios->c_cflag = CS8 | CREAD | CLOCAL;
78 cfsetispeed (termios, B9600);
79 cfsetospeed (termios, B9600);
84 open_fd_to_bash (void) /*thump */
88 struct winsize winsize = { 0 };
89 struct termios termios;
91 default_termios (&termios);
93 winsize.ws_row = VT102_ROWS;
94 winsize.ws_col = VT102_COLS;
96 child = forkpty (&fd, NULL, &termios, &winsize);
100 case -1: /*boo hiss */
103 setenv ("TERM", "vt102", 1);
104 setenv ("LANG", "C", 1);
105 execl ("/bin/sh", "-", (char *) 0);
117 t = (TTY *) malloc (sizeof (TTY));
118 t->fd = open_fd_to_bash ();
120 set_nonblocking (t->fd);
126 wrap_read (int fd, void *buf, int len)
130 red = read (fd, buf, len);
134 if ((red < 0) && (errno == EAGAIN))
141 wrap_write (int fd, void *buf, int len)
145 writ = write (fd, buf, len);
149 if ((writ < 0) && (errno == -EAGAIN))
156 tty_read (TTY * t, void *buf, int len)
164 red = wrap_read (t->fd, buf, len);
182 tty_write (TTY * t, void *buf, int len)
190 for (i = 0; i < len; ++i)
191 fprintf (stderr, "vw: %03o %c\n", p[i], p[i] > 31 ? p[i] : 32);
198 writ = wrap_write (t->fd, buf, len);