Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Import my terminfo implementation.



details:   https://anonhg.NetBSD.org/src/rev/03ec2b13aeaa
branches:  trunk
changeset: 751401:03ec2b13aeaa
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Feb 03 15:16:32 2010 +0000

description:
Import my terminfo implementation.
This uses the ncurses terminal definitions.

OK: core@, jdc@

diffstat:

 lib/libterminfo/Makefile       |    107 +
 lib/libterminfo/curterm.c      |     97 +
 lib/libterminfo/genhash        |    103 +
 lib/libterminfo/genman         |     64 +
 lib/libterminfo/genthash       |     62 +
 lib/libterminfo/setupterm.c    |    124 +
 lib/libterminfo/shlib_version  |      5 +
 lib/libterminfo/term.c         |    304 +
 lib/libterminfo/term.h         |   1518 ++
 lib/libterminfo/term_private.h |    116 +
 lib/libterminfo/termcap.3      |    139 +
 lib/libterminfo/termcap.c      |    183 +
 lib/libterminfo/termcap.h      |     57 +
 lib/libterminfo/termcap_map.c  |    515 +
 lib/libterminfo/terminfo.3     |    222 +
 lib/libterminfo/terminfo.5.in  |    224 +
 lib/libterminfo/ti.c           |    137 +
 lib/libterminfo/tparm.c        |    553 +
 lib/libterminfo/tputs.c        |    173 +
 share/terminfo/Makefile        |     13 +
 share/terminfo/terminfo        |  21717 +++++++++++++++++++++++++++++++++++++++
 usr.bin/infocmp/Makefile       |     10 +
 usr.bin/infocmp/infocmp.1      |    129 +
 usr.bin/infocmp/infocmp.c      |    785 +
 usr.bin/tic/Makefile           |     13 +
 usr.bin/tic/tic.1              |    108 +
 usr.bin/tic/tic.c              |    982 +
 27 files changed, 28460 insertions(+), 0 deletions(-)

diffs (truncated from 28568 to 300 lines):

diff -r 429863c3fba6 -r 03ec2b13aeaa lib/libterminfo/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libterminfo/Makefile  Wed Feb 03 15:16:32 2010 +0000
@@ -0,0 +1,107 @@
+#      $NetBSD: Makefile,v 1.1 2010/02/03 15:16:32 roy Exp $
+
+USE_SHLIBDIR=  yes
+
+LIB=           terminfo
+WARNS=         4
+
+SRCS=          term.c ti.c setupterm.c curterm.c tparm.c tputs.c
+SRCS+=         hash.c
+INCS=          term.h
+INCSDIR=       /usr/include
+
+LIBTIDIR?=     ${.CURDIR}
+CPPFLAGS+=     -I${LIBTIDIR}
+
+# Generate our string and hash tables
+hash.c: genhash term.h
+               @echo "Generating terminfo hash"
+               cd ${LIBTIDIR}; ./genhash >${.OBJDIR}/$@
+
+# Update our man page with terminfo long names, short names and termcaps
+terminfo.5: genman terminfo.5.in term.h termcap.c
+               @echo "Generating terminfo man pages"
+               cd ${LIBTIDIR}; ./genman >${.OBJDIR}/$@
+
+MAN=           terminfo.3 terminfo.5
+CLEANFILES+=   terminfo.5 hash.c
+MLINKS=                terminfo.3 setupterm.3 \
+               terminfo.3 set_curterm.3 terminfo.3 del_curterm.3 \
+               terminfo.3 tigetnum.3 terminfo.3 tigetflag.3 \
+               terminfo.3 tigetstr.3 terminfo.3 tparm.3 terminfo.3 tputs.3 \
+               terminfo.3 putp.3 \
+               terminfo.3 ti_setupterm.3 terminfo.3 ti_getflag.3 \
+               terminfo.3 ti_getnum.3 terminfo.3 ti_getstr.3 \
+               terminfo.3 t_parm.3 terminfo.3 t_vparm.3 \
+               terminfo.3 ti_puts.3 terminfo.3 ti_putp.3
+
+# Build in termcap emulation
+SRCS+=         termcap.c
+INCS+=         termcap.h
+CPPFLAGS+=     -I${.OBJDIR}
+MAN+=          termcap.3
+CLEANFILES+=   _termcap.c termcap_hash.c
+MLINKS+=       termcap.3 tgetent.3 termcap.3 tgetflag.3 termcap.3 tgetnum.3 \
+               termcap.3 tgetstr.3 termcap.3 tgoto.3
+
+# Generate our string and hash tables
+termcap_hash.c:        genthash termcap_map.c
+               @echo "Generating termcap hash"
+               cd ${LIBTIDIR}; ./genthash >${.OBJDIR}/$@
+
+# Depend on our hash table
+termcap.c:     termcap_hash.c
+
+.include <bsd.own.mk>
+.include <bsd.shlib.mk>
+
+.if ${MKLINKLIB} != "no"
+SYMLINKS+=     libterminfo.a ${LIBDIR}/libtermcap.a
+SYMLINKS+=     libterminfo.a ${LIBDIR}/libtermlib.a
+.endif
+
+.if ${MKPROFILE} != "no"
+SYMLINKS+=     libterminfo_p.a ${LIBDIR}/libtermcap_p.a
+SYMLINKS+=     libterminfo_p.a ${LIBDIR}/libtermlib_p.a
+.endif
+
+.if ${MKPIC} != "no"
+
+.if ${MKPICINSTALL} != "no"
+SYMLINKS+=     libterminfo_pic.a ${LIBDIR}/libtermcap_pic.a
+SYMLINKS+=     libterminfo_pic.a ${LIBDIR}/libtermlib_pic.a
+.endif
+
+.if exists(${.CURDIR}/shlib_version)
+SYMLINKS+=     libterminfo.so.${SHLIB_FULLVERSION} \
+               ${_LIBSODIR}/libtermcap.so.0.6
+SYMLINKS+=     libterminfo.so.${SHLIB_FULLVERSION} \
+               ${_LIBSODIR}/libtermlib.so.0.6
+.if ${_LIBSODIR} != ${LIBDIR}
+SYMLINKS+=     libterminfo.so.${SHLIB_FULLVERSION} \
+               ${LIBDIR}/libtermcap.so.0.6
+SYMLINKS+=     libterminfo.so.${SHLIB_FULLVERSION} \
+               ${LIBDIR}/libtermlib.so.0.6
+.endif
+
+.if (${OBJECT_FMT} == "ELF")
+SYMLINKS+=     libterminfo.so.${SHLIB_MAJOR} \
+               ${_LIBSODIR}/libtermcap.so.0
+SYMLINKS+=     libterminfo.so ${_LIBSODIR}/libtermcap.so
+SYMLINKS+=     libterminfo.so.${SHLIB_MAJOR} \
+               ${_LIBSODIR}/libtermlib.so.0
+SYMLINKS+=     libterminfo.so ${_LIBSODIR}/libtermlib.so
+.if ${_LIBSODIR} != ${LIBDIR}
+SYMLINKS+=     libterminfo.so.${SHLIB_MAJOR} \
+       ${LIBDIR}/libtermcap.so.0
+SYMLINKS+=     libterminfo.so ${LIBDIR}/libtermcap.so
+SYMLINKS+=     libterminfo.so.${SHLIB_MAJOR} \
+               ${LIBDIR}/libtermlib.so.0
+SYMLINKS+=     libterminfo.so ${LIBDIR}/libtermlib.so
+.endif
+.endif
+.endif # exists shlib_version
+
+.endif # ${MKPIC} != "no"
+
+.include <bsd.lib.mk>
diff -r 429863c3fba6 -r 03ec2b13aeaa lib/libterminfo/curterm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libterminfo/curterm.c Wed Feb 03 15:16:32 2010 +0000
@@ -0,0 +1,97 @@
+/* $NetBSD: curterm.c,v 1.1 2010/02/03 15:16:32 roy Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roy Marples.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: curterm.c,v 1.1 2010/02/03 15:16:32 roy Exp $");
+
+#include <assert.h>
+#include <stdlib.h>
+#include <term_private.h>
+#include <term.h>
+#include <termios.h>
+
+TERMINAL *cur_term;
+
+static const speed_t bauds[] = {
+       0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 2400, 4800, 9600,
+       19200, 38400, 57600, 115200, 230400, 460800, 921600
+};
+
+void
+_ti_setospeed(TERMINAL *term)
+{
+       struct termios termios;
+       speed_t os;
+       size_t i;
+
+       _DIAGASSERT(term != NULL);
+       
+       term->_ospeed = 0;
+       if (tcgetattr(term->fildes, &termios) == 0) {
+               os = cfgetospeed(&termios);
+               for (i = 0; i < __arraycount(bauds); i++)
+                       if (bauds[i] == os) {
+                               term->_ospeed = i;
+                               break;
+                       }
+       }
+}
+
+TERMINAL *
+set_curterm(TERMINAL *nterm)
+{
+       TERMINAL *oterm;
+
+       oterm = cur_term;
+       cur_term = nterm;
+
+       ospeed = 0;
+       if (cur_term == NULL)
+               PC = '\0';
+       else {
+               if (pad_char == NULL)
+                       PC = '\0';
+               else
+                       PC = *pad_char;
+               _ti_setospeed(nterm);
+               ospeed = nterm->_ospeed;
+       }
+
+       return oterm;
+}
+
+int
+del_curterm(TERMINAL *oterm)
+{
+       if (oterm != NULL) {
+               _ti_freeterm(oterm);
+               free(oterm);
+       }
+       return 0;
+}
diff -r 429863c3fba6 -r 03ec2b13aeaa lib/libterminfo/genhash
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libterminfo/genhash   Wed Feb 03 15:16:32 2010 +0000
@@ -0,0 +1,103 @@
+#!/bin/sh
+# $NetBSD: genhash,v 1.1 2010/02/03 15:16:32 roy Exp $
+
+# Copyright (c) 2009 The NetBSD Foundation, Inc.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Roy Marples.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+# Generate string and hash tables for our terminfo strings in term.h
+# We don't expose the hash or tables directly, but instead via functions.
+# This allows use to freely change how we hash or store our string tables
+# in the future.
+
+: ${TOOL_AWK:=awk}
+: ${TOOL_NBPERF:=nbperf}
+: ${TOOL_SED:=sed}
+
+TERMH=${1:-term.h}
+
+genent()
+{
+       local name=$1 NAME=$2 len=
+
+       # Calculate the maximum word length plus terminator
+       len=`$TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
+            -e 's/.*TICODE_\([^,]*\).*/\1X/' $TERMH | \
+           $TOOL_AWK 'BEGIN {L=0} {if (length($1)>L) L=length($1)} END {print L}'`
+
+       echo
+       echo "static const char _ti_${name}ids[][${len}] = {"
+       $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
+            -e 's/.*TICODE_\([^,]*\).*/        "\1",/' $TERMH
+       echo "};"
+       echo
+       $TOOL_SED -e "1,/enum TI${NAME}/d" -e '/};/,$d' \
+           -e 's/.*TICODE_\([^,]*\).*/\1/' $TERMH | \
+           $TOOL_NBPERF -sn _ti_${name}hash;
+
+       cat <<EOF
+
+const char *
+_ti_${name}id(ssize_t idx)
+{
+
+       if ((size_t)idx > __arraycount(_ti_${name}ids))
+               return NULL;
+       return _ti_${name}ids[idx];
+}
+
+ssize_t
+_ti_${name}index(const char *key)
+{
+       uint32_t idx;
+
+       idx = _ti_${name}hash((const unsigned char *)key, strlen(key));
+       if (idx > __arraycount(_ti_${name}ids) ||
+           strcmp(key, _ti_${name}ids[idx]) != 0)
+               return -1;
+       return idx;
+}
+EOF
+}
+



Home | Main Index | Thread Index | Old Index