From 7bbe8b9e43d79660594f369b25a1640799e9612d Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 11 Nov 2006 01:11:28 +0100 Subject: [PATCH] reorganize some code Signed-off-by: Pierre Habouzit --- madtty/Makefile.in | 5 ++- madtty/Makefile.old | 54 --------------------------- madtty/{rote.c => madtty.c} | 46 +++++++++++++++++++++++ madtty/rote_keymap.c | 73 ------------------------------------- 4 files changed, 49 insertions(+), 129 deletions(-) delete mode 100644 madtty/Makefile.old rename madtty/{rote.c => madtty.c} (83%) delete mode 100644 madtty/rote_keymap.c diff --git a/madtty/Makefile.in b/madtty/Makefile.in index f126861..8eee84c 100644 --- a/madtty/Makefile.in +++ b/madtty/Makefile.in @@ -5,9 +5,10 @@ DISTCLEANFILES = madtty.pc include_HEADERS = madtty.h - lib_LIBRARIES = libmadtty -libmadtty_SOURCES = inject.c inject_csi.c inject_csi.h madtty.h rote.c rote_keymap.c roteprivate.h + +libmadtty_SOURCES = madtty.h inject_csi.h roteprivate.h \ + madtty.c inject_csi.c inject.c libmadtty_CPPFLAGS = -Wno-error libmadtty_VERSION = @PACKAGE_VERSION@ diff --git a/madtty/Makefile.old b/madtty/Makefile.old deleted file mode 100644 index d2760cd..0000000 --- a/madtty/Makefile.old +++ /dev/null @@ -1,54 +0,0 @@ -DEPTH=.. -include $(DEPTH)/admin/header.mk - -__LIB__ = madtty - -madtty_SOURCES = inject.c inject_csi.c inject_csi.h madtty.h rote.c rote_keymap.c roteprivate.h - -MADTTY_VERSION=@PACKAGE_VERSION@ -MADTTY_SONAME=libmadtty.so.0 - -CC=@CC@ -CFLAGS=@CFLAGS@ -Wall -W -fPIC -LIBS=@LIBS@ -LDFLAGS=@LDFLAGS@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ -bindir=@bindir@ - -#all: libmadtty.so.$(MADTTY_VERSION) - -install: all - mkdir -p $(DESTDIR)$(includedir)/madtty - rm -f $(DESTDIR)$(includedir)/madtty/*.h - cp madtty.h $(DESTDIR)$(includedir)/madtty - mkdir -p $(DESTDIR)$(libdir) - cp libmadtty.so.$(MADTTY_VERSION) $(DESTDIR)$(libdir) - cd $(DESTDIR)$(libdir) && ln -sf libmadtty.so.$(MADTTY_VERSION) libmadtty.so - cd $(DESTDIR)$(libdir) && ln -sf libmadtty.so.$(MADTTY_VERSION) $(MADTTY_SONAME) - mkdir -p $(DESTDIR)$(libdir)/pkgconfig - cp madtty.pc $(DESTDIR)$(libdir)/pkgconfig - @echo "-----------------------------------------------------------" - @echo "MADTTY - the Mad tty Emulation Library v$(MADTTY_VERSION)" - @echo - @echo "Include files installed at: $(DESTDIR)$(includedir)" - @echo "Library files installed at: $(DESTDIR)$(libdir)" - @echo "-----------------------------------------------------------" - -libmadtty.so.$(MADTTY_VERSION): $(OBJECTS) - $(CC) $(CFLAGS) -shared -o $@ -Wl,-soname=$(MADTTY_SONAME) $(OBJECTS) $(LDFLAGS) $(LIBS) - -.depends: $(SOURCES) $(HEADERS) - $(CC) $(CFLAGS) -MM $(SOURCES) >.depends - --include .depends - -clean:: - libmadtty.so.* - -distclean:: - rm -rf autom4te.cache configure config.status config.log Makefile madtty.pc - -include $(DEPTH)/admin/footer.mk diff --git a/madtty/rote.c b/madtty/madtty.c similarity index 83% rename from madtty/rote.c rename to madtty/madtty.c index 83dd331..0d1eba6 100644 --- a/madtty/rote.c +++ b/madtty/madtty.c @@ -259,3 +259,49 @@ int rote_vt_get_pty_fd(RoteTerm *rt) { return rt->pd->pty; } +static const char *keytable[KEY_MAX+1]; +static int initialized = 0; + +static void keytable_init(); + +void rote_vt_keypress(RoteTerm *rt, int keycode) { + char c = (char) keycode; + + if (!initialized) keytable_init(); + + if (keycode >= 0 && keycode < KEY_MAX && keytable[keycode]) + rote_vt_write(rt, keytable[keycode], strlen(keytable[keycode])); + else + rote_vt_write(rt, &c, 1); /* not special, just write it */ +} + +static void keytable_init() { + initialized = 1; + memset(keytable, 0, KEY_MAX+1 * sizeof(const char*)); + + keytable['\n'] = "\r"; + keytable[KEY_UP] = "\e[A"; + keytable[KEY_DOWN] = "\e[B"; + keytable[KEY_RIGHT] = "\e[C"; + keytable[KEY_LEFT] = "\e[D"; + keytable[KEY_BACKSPACE] = "\b"; + keytable[KEY_HOME] = "\e[1~"; + keytable[KEY_IC] = "\e[2~"; + keytable[KEY_DC] = "\e[3~"; + keytable[KEY_END] = "\e[4~"; + keytable[KEY_PPAGE] = "\e[5~"; + keytable[KEY_NPAGE] = "\e[6~"; + keytable[KEY_SUSPEND] = "\x1A"; /* Ctrl+Z gets mapped to this */ + keytable[KEY_F(1)] = "\e[[A"; + keytable[KEY_F(2)] = "\e[[B"; + keytable[KEY_F(3)] = "\e[[C"; + keytable[KEY_F(4)] = "\e[[D"; + keytable[KEY_F(5)] = "\e[[E"; + keytable[KEY_F(6)] = "\e[17~"; + keytable[KEY_F(7)] = "\e[18~"; + keytable[KEY_F(8)] = "\e[19~"; + keytable[KEY_F(9)] = "\e[20~"; + keytable[KEY_F(10)] = "\e[21~"; +} + + diff --git a/madtty/rote_keymap.c b/madtty/rote_keymap.c deleted file mode 100644 index 253a110..0000000 --- a/madtty/rote_keymap.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - LICENSE INFORMATION: - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License (LGPL) as published by the Free Software Foundation. - - Please refer to the COPYING file for more information. - - 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 Lesser General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Copyright © 2004 Bruno T. C. de Oliveira - Copyright © 2006 Pierre Habouzit - */ - -#include -#include -#include - -#include "madtty.h" - -static const char *keytable[KEY_MAX+1]; -static int initialized = 0; - -static void keytable_init(); - -void rote_vt_keypress(RoteTerm *rt, int keycode) { - char c = (char) keycode; - - if (!initialized) keytable_init(); - - if (keycode >= 0 && keycode < KEY_MAX && keytable[keycode]) - rote_vt_write(rt, keytable[keycode], strlen(keytable[keycode])); - else - rote_vt_write(rt, &c, 1); /* not special, just write it */ -} - -static void keytable_init() { - initialized = 1; - memset(keytable, 0, KEY_MAX+1 * sizeof(const char*)); - - keytable['\n'] = "\r"; - keytable[KEY_UP] = "\e[A"; - keytable[KEY_DOWN] = "\e[B"; - keytable[KEY_RIGHT] = "\e[C"; - keytable[KEY_LEFT] = "\e[D"; - keytable[KEY_BACKSPACE] = "\b"; - keytable[KEY_HOME] = "\e[1~"; - keytable[KEY_IC] = "\e[2~"; - keytable[KEY_DC] = "\e[3~"; - keytable[KEY_END] = "\e[4~"; - keytable[KEY_PPAGE] = "\e[5~"; - keytable[KEY_NPAGE] = "\e[6~"; - keytable[KEY_SUSPEND] = "\x1A"; /* Ctrl+Z gets mapped to this */ - keytable[KEY_F(1)] = "\e[[A"; - keytable[KEY_F(2)] = "\e[[B"; - keytable[KEY_F(3)] = "\e[[C"; - keytable[KEY_F(4)] = "\e[[D"; - keytable[KEY_F(5)] = "\e[[E"; - keytable[KEY_F(6)] = "\e[17~"; - keytable[KEY_F(7)] = "\e[18~"; - keytable[KEY_F(8)] = "\e[19~"; - keytable[KEY_F(9)] = "\e[20~"; - keytable[KEY_F(10)] = "\e[21~"; -} - - -- 2.20.1