chiark / gitweb /
*** empty log message ***
[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.8  2008/02/07 00:43:27  james
15  * *** empty log message ***
16  *
17  * Revision 1.7  2008/02/07 00:39:13  james
18  * *** empty log message ***
19  *
20  * Revision 1.6  2008/02/06 20:26:58  james
21  * *** empty log message ***
22  *
23  * Revision 1.5  2008/02/06 17:53:28  james
24  * *** empty log message ***
25  *
26  * Revision 1.4  2008/02/04 20:23:55  james
27  * *** empty log message ***
28  *
29  * Revision 1.3  2008/02/04 05:45:55  james
30  * ::
31  *
32  * Revision 1.2  2008/02/04 02:05:06  james
33  * *** empty log message ***
34  *
35  * Revision 1.1  2008/02/03 16:20:24  james
36  * *** empty log message ***
37  *
38  *
39  */
40
41 #include "project.h"
42
43 struct termios old = { 0 };
44 static int had_winch = 0;
45
46 static void
47 quit (int not)
48 {
49   tcsetattr (0, TCSANOW, &old);
50   exit (1);
51 }
52
53 static void
54 winch (int not)
55 {
56   had_winch++;
57 }
58
59
60 void
61 testy (void)
62 {
63   struct termios raw = { 0 };
64   ANSI a = { 0 };
65   fd_set rfd;
66   int fd;
67   char c;
68   TTY *t;
69   VT102 *v;
70
71
72   signal (SIGINT, quit);
73   {
74     struct sigaction sa = { 0 };
75
76     sa.sa_handler = winch;
77     sa.sa_flags = SA_RESTART;
78     sigaction (SIGWINCH, &sa, NULL);
79   }
80
81
82   tcgetattr (0, &old);
83   tcgetattr (0, &raw);
84   cfmakeraw (&raw);
85   tcsetattr (0, TCSANOW, &raw);
86
87   a.fd = 0;
88   ansi_reset (&a);
89
90
91   t = tty_new_test ();
92   v = vt102_new (t);
93
94   FD_ZERO (&rfd);
95   for (;;)
96     {
97       struct timeval tv = { 0, 100000 };
98
99       FD_SET (t->fd, &rfd);
100       FD_SET (a.fd, &rfd);
101       select (t->fd + 1, &rfd, NULL, NULL, &tv);
102
103 #if 0
104       if (FD_ISSET (a.fd, &rfd))
105         {
106         }
107 #endif
108       if (ansi_dispatch (&a, v))
109         break;
110
111       if (FD_ISSET (t->fd, &rfd))
112         {
113           if (vt102_dispatch (v))
114             break;
115         }
116
117       if (had_winch)
118         {
119           had_winch = 0;
120           ansi_getsize (&a);
121           ansi_reset (&a);
122           ansi_draw (&a, &v->crt);
123         }
124       ansi_draw (&a, &v->crt);
125     }
126   tcsetattr (0, TCSANOW, &old);
127   printf ("QUAT\n");
128 }