Codepage messages related translated & other stuff...
[midnight-commander.git] / src / rxvt.c
blob8a122105f4ea38988e05f98ab1e4608e7dc1e649
1 /* rxvt.c - gives output lines on rxvt with a special rxvt patch
2 Copyright (C) 1997 Paul Sheer
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <config.h>
20 #include <stdio.h> /* read, printf */
21 #include <sys/types.h>
22 #include <string.h>
23 #ifdef HAVE_UNISTD_H
24 # include <unistd.h>
25 #endif
27 #ifndef SCO_FLAVOR
28 # include <sys/time.h> /* struct timeval */
29 #endif /* SCO_FLAVOR */
31 #if HAVE_SYS_SELECT_H
32 # include <sys/select.h>
33 #endif
35 #include "tty.h" /* move, addch */
36 #include "global.h"
37 #include "cons.saver.h"
39 int rxvt_extensions = 0;
41 int look_for_rxvt_extensions (void)
43 static int been_called = 0;
44 char *e;
45 if (!been_called) {
46 rxvt_extensions = 0;
47 e = getenv ("RXVT_EXT");
48 if (e)
49 if (!strcmp (e, "1.0"))
50 rxvt_extensions = 1;
51 been_called = 1;
53 if (rxvt_extensions)
54 console_flag = 4;
55 return rxvt_extensions;
58 /* my own wierd protocol base 16 - paul */
59 static int rxvt_getc (void)
61 int r;
62 unsigned char c;
63 while (read (0, &c, 1) != 1);
64 if (c == '\n')
65 return -1;
66 r = (c - 'A') * 16;
67 while (read (0, &c, 1) != 1);
68 r += (c - 'A');
69 return r;
72 extern int keybar_visible;
74 static int anything_ready ()
76 fd_set fds;
77 struct timeval tv;
79 FD_ZERO (&fds);
80 FD_SET (0, &fds);
81 tv.tv_sec = 0;
82 tv.tv_usec = 0;
83 return select (1, &fds, 0, 0, &tv);
86 void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
88 unsigned char *k;
89 int bytes, i, j, cols = 0;
90 y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */
91 y2 += (keybar_visible != 0);
92 while (anything_ready ())
93 getch ();
95 /* my own wierd protocol base 26 - paul */
96 printf ("\033CL%c%c%c%c\n",
97 (y1 / 26) + 'A', (y1 % 26) + 'A',
98 (y2 / 26) + 'A', (y2 % 26) + 'A');
100 bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
101 j = 0;
102 k = g_malloc (bytes);
103 for (;;) {
104 int c;
105 c = rxvt_getc ();
106 if (c < 0)
107 break;
108 if (j < bytes)
109 k[j++] = c;
110 for (cols = 1;;cols++) {
111 c = rxvt_getc ();
112 if (c < 0)
113 break;
114 if (j < bytes)
115 k[j++] = c;
118 for (i = 0; i < j; i++) {
119 if ((i % cols) == 0)
120 move (starty + (i / cols), 0);
121 addch (is_printable (k[i]) ? k[i] : ' ');
123 g_free (k);