chiark / gitweb /
e86c088098a87a4b78860bf40d64be0e723a88b1
[sympathy.git] / src / libsympathy.c
1 /*
2  * libsympathy.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] =
10   "$Id$";
11
12 /*
13  * $Log$
14  * Revision 1.4  2008/02/04 20:23:55  james
15  * *** empty log message ***
16  *
17  * Revision 1.3  2008/02/04 05:45:55  james
18  * ::
19  *
20  * Revision 1.2  2008/02/04 02:05:06  james
21  * *** empty log message ***
22  *
23  * Revision 1.1  2008/02/03 16:20:24  james
24  * *** empty log message ***
25  *
26  *
27  */
28
29 #include "project.h"
30
31 struct termios old = { 0 };
32
33 static void
34 foo (int not)
35 {
36   tcsetattr (0, TCSANOW, &old);
37   exit (1);
38 }
39
40
41 void
42 testy (void)
43 {
44   struct termios raw = { 0 };
45   VT102 v = { 0 };
46   ANSI a = { 0 };
47   fd_set rfd;
48   int fd;
49   char c;
50
51
52   signal (SIGINT, foo);
53
54   tcgetattr (0, &old);
55   tcgetattr (0, &raw);
56   cfmakeraw (&raw);
57   tcsetattr (0, TCSANOW, &raw);
58
59   a.fd = 1;
60
61   vt102_reset (&v);
62   ansi_reset (&a);
63
64
65   fd = open_fd_to_bash ();
66
67   FD_ZERO (&rfd);
68
69
70   for (;;)
71     {
72       FD_SET (fd, &rfd);
73       FD_SET (0, &rfd);
74       if (select (fd + 1, &rfd, NULL, NULL, NULL) <= 0)
75         continue;
76       if (FD_ISSET (0, &rfd))
77         {
78           if ((read (0, &c, 1) <= 0) || (c == 3))
79             break;
80
81           write (fd, &c, 1);
82         }
83       if (FD_ISSET (fd, &rfd))
84         {
85           if ((read (fd, &c, 1) <= 0))
86             break;
87           //write (1, &c, 1);
88           vt102_parse_char (&v, c);
89           ansi_draw (&a, &v.crt);
90         }
91     }
92   tcsetattr (0, TCSANOW, &old);
93   printf ("QUAT\n");
94 }