chiark / gitweb /
2cef3e0bda8e59956cbf74a32118ab3eeca23dee
[sympathy.git] / src / testtty.c
1 /*
2  * testtty.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] = "$Id$";
10
11 /*
12  * $Log$
13  * Revision 1.1  2008/02/04 01:32:39  james
14  * *** empty log message ***
15  *
16  */
17
18 #include "project.h"
19
20 static void  default_termios(struct termios *termios)
21 {
22
23 memset(termios,0,sizeof(termios));
24
25 termios->c_iflag=ICRNL|IXON;
26 termios->c_oflag=OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
27 termios->c_lflag=ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE;
28
29 termios->c_cc[VINTR]=003;
30 termios->c_cc[VQUIT]=034;
31 termios->c_cc[VERASE]=0177;
32 termios->c_cc[VKILL]=025;
33 termios->c_cc[VEOF]=004;
34 termios->c_cc[VEOL]=0;
35 termios->c_cc[VEOL2]=0;
36 termios->c_cc[VSTART]=021;
37 termios->c_cc[VSTOP]=023;
38 termios->c_cc[VSUSP]=032;
39 termios->c_cc[VLNEXT]=026;
40 termios->c_cc[VWERASE]=027;
41 termios->c_cc[VREPRINT]=022;
42 termios->c_cc[VDISCARD]=017;
43
44 termios->c_cflag=CS8 | CREAD | CLOCAL;
45
46 cfsetispeed(termios,B9600);
47 cfsetospeed(termios,B9600);
48 }
49
50
51 int open_fd_to_bash(void) /*thump*/
52 {
53 pid_t child;
54 int fd;
55 struct winsize winsize={0};
56 struct termios termios;
57
58 default_termios(&termios);
59
60 winsize.ws_row=CRT_ROWS;
61 winsize.ws_col=CRT_COLS;
62
63 child=forkpty(&fd,NULL,&termios,&winsize);
64
65 switch (child) 
66 {
67 case -1:/*boo hiss*/
68         return -1;
69 case 0: /*waaah*/
70         setenv("TERM","vt102",1);
71         execl("/bin/sh","-",(char *) 0);
72         _exit(-1);
73 }
74
75 return fd;
76 }