0.0.7
[fbvnc.git] / vt52vnc.c
blob9a36806dd57873a39c3862c7e73c137aefa1f2b2
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <termios.h>
5 #include <sys/time.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8 #include <string.h>
10 #define byterate 1920
12 #include "vt52vnc.h"
14 int main(int argc, char * argv[])
16 int port = DEF_PORT;
17 char * host = "127.0.0.1";
18 int fd, retval;
19 struct termios ti1, ti2;
20 fd_set sel_in;
21 struct timeval tv;
22 unsigned long stat;
23 int already_requested = 0;
24 int must_draw = 0;
25 int must_redraw = 1;
27 if (argc>=2)
28 host = argv[1];
29 if (argc>=3)
30 port = atoi(argv[2]);
31 fd = vncproto_init(host, port);
32 if(fd==-1)
33 return -1;
35 tcgetattr (0, &ti1);
36 ti2 = ti1;
37 cfmakeraw(&ti2);
39 if (request_vnc_refresh(fd) == -1)
40 return -1;
41 tcsetattr(0, TCSANOW, &ti2);
43 tv.tv_sec = 0;
44 tv.tv_usec = 500000;
46 while(1) {
47 FD_ZERO(&sel_in);
48 FD_SET(fd, &sel_in);
49 FD_SET(0, &sel_in);
50 retval = select(fd+1, &sel_in, NULL, NULL, &tv);
51 if (retval == 0) {
52 if (!already_requested && !must_redraw && !must_draw) {
53 if (request_vnc_refresh(fd) == -1)
54 break;
55 already_requested = 1;
57 if (must_draw || must_redraw) {
58 must_draw = drawdelta();
59 if (!must_draw) {
60 must_draw=must_redraw;
61 must_redraw=0;
63 stat = get_stat();
64 tv.tv_sec = stat/byterate;
65 tv.tv_usec = (stat - tv.tv_sec*byterate)*1000000/byterate;
66 } else {
67 tv.tv_sec = 0;
68 tv.tv_usec = 200000;
71 if (FD_ISSET(fd, &sel_in)) {
72 already_requested = 0;
73 if (parse_vnc_in(fd) == -1)
74 break;
75 must_redraw = 1;
76 tv.tv_sec = 0;
77 tv.tv_usec = 0;
79 if (FD_ISSET(0, &sel_in)) {
80 if (parse_kbd_in(0, fd) == -1)
81 break;
84 tcsetattr(0, TCSANOW, &ti1);
85 #define W(a,b) write((a),(b),strlen(b))
86 W(1, "\n\x1bH\x1bJ");
87 return 0;