4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.1 2008/02/07 01:02:52 james
14 * *** empty log message ***
16 * Revision 1.3 2008/02/06 17:53:28 james
17 * *** empty log message ***
19 * Revision 1.2 2008/02/04 02:05:06 james
20 * *** empty log message ***
22 * Revision 1.1 2008/02/04 01:32:39 james
23 * *** empty log message ***
30 set_nonblocking (int fd)
33 arg = fcntl (fd, F_GETFL, arg);
35 fcntl (fd, F_SETFL, arg);
42 arg = fcntl (fd, F_GETFL, arg);
44 fcntl (fd, F_SETFL, arg);
48 default_termios (struct termios *termios)
51 memset (termios, 0, sizeof (termios));
53 termios->c_iflag = ICRNL | IXON;
54 termios->c_oflag = OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
56 ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE;
58 termios->c_cc[VINTR] = 003;
59 termios->c_cc[VQUIT] = 034;
60 termios->c_cc[VERASE] = 0177;
61 termios->c_cc[VKILL] = 025;
62 termios->c_cc[VEOF] = 004;
63 termios->c_cc[VEOL] = 0;
64 termios->c_cc[VEOL2] = 0;
65 termios->c_cc[VSTART] = 021;
66 termios->c_cc[VSTOP] = 023;
67 termios->c_cc[VSUSP] = 032;
68 termios->c_cc[VLNEXT] = 026;
69 termios->c_cc[VWERASE] = 027;
70 termios->c_cc[VREPRINT] = 022;
71 termios->c_cc[VDISCARD] = 017;
73 termios->c_cflag = CS8 | CREAD | CLOCAL;
75 cfsetispeed (termios, B9600);
76 cfsetospeed (termios, B9600);
81 open_fd_to_bash (void) /*thump */
85 struct winsize winsize = { 0 };
86 struct termios termios;
88 default_termios (&termios);
90 winsize.ws_row = VT102_ROWS;
91 winsize.ws_col = VT102_COLS;
93 child = forkpty (&fd, NULL, &termios, &winsize);
97 case -1: /*boo hiss */
100 setenv ("TERM", "vt102", 1);
101 execl ("/bin/sh", "-", (char *) 0);
113 t = (TTY *) malloc (sizeof (TTY));
114 t->fd = open_fd_to_bash ();
116 set_nonblocking (t->fd);
122 wrap_read (int fd, void *buf, int len)
126 red = read (fd, buf, len);
130 if ((red < 0) && (errno == EAGAIN))
137 wrap_write (int fd, void *buf, int len)
141 writ = write (fd, buf, len);
145 if ((writ < 0) && (errno == -EAGAIN))
152 tty_read (TTY * t, void *buf, int len)
160 red = wrap_read (t->fd, buf, len);
178 tty_write (TTY * t, void *buf, int len)
186 for (i = 0; i < len; ++i)
187 fprintf (stderr, "vw: %03o %c\n", p[i], p[i] > 31 ? p[i] : 32);
194 writ = wrap_write (t->fd, buf, len);