From 828d1ed09e2a2f21c974bb1969d816d1bbb6b3f1 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 4 Jun 2009 16:47:01 +0400 Subject: [PATCH] RXVT: merged src/tty/rxvt.c into src/tty/win.c. src/tty/win.c: formatted in accordance with maint/template.c. --- src/tty/Makefile.am | 1 - src/tty/rxvt.c | 128 ------------------------------------------ src/tty/win.c | 132 ++++++++++++++++++++++++++++++++++++++++---- src/tty/win.h | 4 +- 4 files changed, 123 insertions(+), 142 deletions(-) delete mode 100644 src/tty/rxvt.c diff --git a/src/tty/Makefile.am b/src/tty/Makefile.am index 70abd05b8..f3ee061ad 100644 --- a/src/tty/Makefile.am +++ b/src/tty/Makefile.am @@ -16,7 +16,6 @@ TTY_SRC = \ color.c color.h \ key.c key.h keyxdef.c \ mouse.c mouse.h \ - rxvt.c \ tty.c tty.h \ win.c win.h \ x11conn.c x11conn.h diff --git a/src/tty/rxvt.c b/src/tty/rxvt.c deleted file mode 100644 index aa44abd6a..000000000 --- a/src/tty/rxvt.c +++ /dev/null @@ -1,128 +0,0 @@ -/* rxvt.c - gives output lines on rxvt with a special rxvt patch - Copyright (C) 1997 Paul Sheer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** \file rxvt.c - * \brief Source: gives output lines on rxvt with a special rxvt patch - */ - -#include - -#include -#include -#include -#include -#include - -#include "../../src/global.h" - -#include "../../src/tty/tty.h" /* tty_gotoyx, tty_print_char */ - -#include "../../src/cons.saver.h" /* console_flag */ - -static gboolean rxvt_extensions = FALSE; - -gboolean -look_for_rxvt_extensions (void) -{ - static gboolean been_called = FALSE; - - if (!been_called) { - const char *e = getenv ("RXVT_EXT"); - rxvt_extensions = ((e != NULL) && (strcmp (e, "1.0") == 0)); - been_called = TRUE; - } - - if (rxvt_extensions) - console_flag = 4; - - return rxvt_extensions; -} - -/* my own wierd protocol base 16 - paul */ -static int -rxvt_getc (void) -{ - int r; - unsigned char c; - while (read (0, &c, 1) != 1) - ; - if (c == '\n') - return -1; - r = (c - 'A') * 16; - while (read (0, &c, 1) != 1) - ; - r += (c - 'A'); - return r; -} - -extern int keybar_visible; - -static int -anything_ready (void) -{ - fd_set fds; - struct timeval tv; - - FD_ZERO (&fds); - FD_SET (0, &fds); - tv.tv_sec = 0; - tv.tv_usec = 0; - return select (1, &fds, 0, 0, &tv); -} - -void -show_rxvt_contents (int starty, unsigned char y1, unsigned char y2) -{ - unsigned char *k; - int bytes, i, j, cols = 0; - - y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */ - y2 += (keybar_visible != 0); - while (anything_ready ()) - getch (); - -/* my own wierd protocol base 26 - paul */ - printf ("\033CL%c%c%c%c\n", - (y1 / 26) + 'A', (y1 % 26) + 'A', - (y2 / 26) + 'A', (y2 % 26) + 'A'); - - bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */ - j = 0; - k = g_malloc (bytes); - for (;;) { - int c; - c = rxvt_getc (); - if (c < 0) - break; - if (j < bytes) - k[j++] = c; - for (cols = 1;;cols++) { - c = rxvt_getc (); - if (c < 0) - break; - if (j < bytes) - k[j++] = c; - } - } - for (i = 0; i < j; i++) { - if ((i % cols) == 0) - tty_gotoyx (starty + (i / cols), 0); - tty_print_char (is_printable (k[i]) ? k[i] : ' '); - } - g_free (k); -} diff --git a/src/tty/win.c b/src/tty/win.c index 7d5a412ec..69c54a734 100644 --- a/src/tty/win.c +++ b/src/tty/win.c @@ -1,4 +1,4 @@ -/* Curses utilities +/* Terminal management xterm and rxvt support Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. @@ -17,36 +17,146 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** \file win.c - * \brief Source: curses utilities + * \brief Source: Terminal management xterm and rxvt support */ #include #include #include +#include +#include +#include +#include "../../src/tty/tty.h" /* tty_gotoyx, tty_print_char */ #include "../../src/tty/win.h" +#include "../../src/cons.saver.h" /* console_flag */ + +/*** global variables **************************************************/ + /* This flag is set by xterm detection routine in function main() */ /* It is used by function view_other_cmd() */ int xterm_flag = 0; -/* The following routines only work on xterm terminals */ +extern int keybar_visible; + +/*** file scope macro definitions **************************************/ + +/*** file scope type declarations **************************************/ + +/*** file scope variables **********************************************/ + +static gboolean rxvt_extensions = FALSE; + +/*** file scope functions **********************************************/ + +/* my own wierd protocol base 16 - paul */ +static int +rxvt_getc (void) +{ + int r; + unsigned char c; + + while (read (0, &c, 1) != 1) + ; + if (c == '\n') + return -1; + r = (c - 'A') * 16; + while (read (0, &c, 1) != 1) + ; + r += (c - 'A'); + return r; +} + +static int +anything_ready (void) +{ + fd_set fds; + struct timeval tv; + + FD_ZERO (&fds); + FD_SET (0, &fds); + tv.tv_sec = 0; + tv.tv_usec = 0; + return select (1, &fds, 0, 0, &tv); +} + +/*** public functions **************************************************/ void do_enter_ca_mode (void) { - if (!xterm_flag) - return; - fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h"); - fflush (stdout); + if (!xterm_flag) { + fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h"); + fflush (stdout); + } } void do_exit_ca_mode (void) { - if (!xterm_flag) - return; - fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m"); - fflush (stdout); + if (!xterm_flag) { + fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m"); + fflush (stdout); + } +} + +void +show_rxvt_contents (int starty, unsigned char y1, unsigned char y2) +{ + unsigned char *k; + int bytes, i, j, cols = 0; + + y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */ + y2 += (keybar_visible != 0); + while (anything_ready ()) + getch (); + +/* my own wierd protocol base 26 - paul */ + printf ("\033CL%c%c%c%c\n", + (y1 / 26) + 'A', (y1 % 26) + 'A', + (y2 / 26) + 'A', (y2 % 26) + 'A'); + + bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */ + j = 0; + k = g_malloc (bytes); + for (;;) { + int c; + c = rxvt_getc (); + if (c < 0) + break; + if (j < bytes) + k[j++] = c; + for (cols = 1; ; cols++) { + c = rxvt_getc (); + if (c < 0) + break; + if (j < bytes) + k[j++] = c; + } + } + for (i = 0; i < j; i++) { + if ((i % cols) == 0) + tty_gotoyx (starty + (i / cols), 0); + tty_print_char (is_printable (k[i]) ? k[i] : ' '); + } + g_free (k); +} + +gboolean +look_for_rxvt_extensions (void) +{ + static gboolean been_called = FALSE; + + if (!been_called) { + const char *e = getenv ("RXVT_EXT"); + rxvt_extensions = ((e != NULL) && (strcmp (e, "1.0") == 0)); + been_called = TRUE; + } + + if (rxvt_extensions) + console_flag = 4; + + return rxvt_extensions; } diff --git a/src/tty/win.h b/src/tty/win.h index dccb32450..7f1a62b33 100644 --- a/src/tty/win.h +++ b/src/tty/win.h @@ -1,6 +1,6 @@ /** \file win.h - * \brief Header: curses utilities + * \brief Header: X terminal management: xterm and rxvt */ #ifndef MC_WIN_H @@ -8,8 +8,8 @@ #include "../../src/global.h" /* */ -/* Terminal management */ extern int xterm_flag; + void do_enter_ca_mode (void); void do_exit_ca_mode (void);