Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src libterminfo can now compile a single terminfo description wh...
details: https://anonhg.NetBSD.org/src/rev/177f2bbf70e9
branches: trunk
changeset: 752316:177f2bbf70e9
user: roy <roy%NetBSD.org@localhost>
date: Mon Feb 22 23:05:39 2010 +0000
description:
libterminfo can now compile a single terminfo description which allows
$TERMINFO to be a terminfo description as well as a file reference.
This enables the user to modify the terminfo description on read-only
media.
diffstat:
lib/libterminfo/Makefile | 4 +-
lib/libterminfo/compile.c | 652 ++++++++++++++++++++++++++++++++++++++++
lib/libterminfo/curterm.c | 10 +-
lib/libterminfo/term.c | 49 +-
lib/libterminfo/term_private.h | 36 ++-
lib/libterminfo/terminfo.5.in | 13 +-
tools/tic/Makefile | 4 +-
usr.bin/infocmp/infocmp.c | 9 +-
usr.bin/tic/tic.c | 665 ++++------------------------------------
9 files changed, 820 insertions(+), 622 deletions(-)
diffs (truncated from 1828 to 300 lines):
diff -r 3c44021e329c -r 177f2bbf70e9 lib/libterminfo/Makefile
--- a/lib/libterminfo/Makefile Mon Feb 22 22:28:57 2010 +0000
+++ b/lib/libterminfo/Makefile Mon Feb 22 23:05:39 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2010/02/19 13:53:17 njoly Exp $
+# $NetBSD: Makefile,v 1.11 2010/02/22 23:05:39 roy Exp $
USE_SHLIBDIR= yes
@@ -8,7 +8,7 @@
CPPFLAGS+= -I${.CURDIR}
SRCS= term.c ti.c setupterm.c curterm.c tparm.c tputs.c
-SRCS+= hash.c
+SRCS+= compile.c hash.c
INCS= term.h
INCSDIR= /usr/include
diff -r 3c44021e329c -r 177f2bbf70e9 lib/libterminfo/compile.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libterminfo/compile.c Mon Feb 22 23:05:39 2010 +0000
@@ -0,0 +1,652 @@
+/* $NetBSD: compile.c,v 1.1 2010/02/22 23:05:39 roy Exp $ */
+
+/*
+ * Copyright (c) 2009, 2010 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.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: compile.c,v 1.1 2010/02/22 23:05:39 roy Exp $");
+
+#include <assert.h>
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <term_private.h>
+#include <term.h>
+
+static void __attribute__((__format__(__printf__, 2, 3)))
+dowarn(int flags, const char *fmt, ...)
+{
+ va_list va;
+
+ errno = EINVAL;
+ if (flags & TIC_WARNING) {
+ va_start(va, fmt);
+ vwarnx(fmt, va);
+ va_end(va);
+ }
+}
+
+char *
+_ti_grow_tbuf(TBUF *tbuf, size_t len)
+{
+ char *buf;
+ size_t l;
+
+ _DIAGASSERT(tbuf != NULL);
+
+ l = tbuf->bufpos + len;
+ if (l > tbuf->buflen) {
+ if (tbuf->bufpos == 0)
+ buf = malloc(l);
+ else
+ buf = realloc(tbuf->buf, l);
+ if (buf == NULL)
+ return NULL;
+ tbuf->buf = buf;
+ tbuf->buflen = l;
+ }
+ return tbuf->buf;
+}
+
+char *
+_ti_find_cap(TBUF *tbuf, char type, short ind)
+{
+ size_t n;
+ short num;
+ char *cap;
+
+ _DIAGASSERT(tbuf != NULL);
+
+ cap = tbuf->buf;
+ for (n = tbuf->entries; n > 0; n--) {
+ num = le16dec(cap);
+ cap += sizeof(uint16_t);
+ if (num == ind)
+ return cap;
+ switch (type) {
+ case 'f':
+ cap++;
+ break;
+ case 'n':
+ cap += sizeof(uint16_t);
+ break;
+ case 's':
+ num = le16dec(cap);
+ cap += sizeof(uint16_t);
+ cap += num;
+ break;
+ }
+ }
+
+ errno = ESRCH;
+ return NULL;
+}
+
+char *
+_ti_find_extra(TBUF *tbuf, const char *code)
+{
+ size_t n;
+ short num;
+ char *cap;
+
+ _DIAGASSERT(tbuf != NULL);
+ _DIAGASSERT(code != NULL);
+
+ cap = tbuf->buf;
+ for (n = tbuf->entries; n > 0; n--) {
+ num = le16dec(cap);
+ cap += sizeof(uint16_t);
+ if (strcmp(cap, code) == 0)
+ return cap + num;
+ cap += num;
+ switch (*cap++) {
+ case 'f':
+ cap++;
+ break;
+ case 'n':
+ cap += sizeof(uint16_t);
+ break;
+ case 's':
+ num = le16dec(cap);
+ cap += sizeof(uint16_t);
+ cap += num;
+ break;
+ }
+ }
+
+ errno = ESRCH;
+ return NULL;
+}
+
+size_t
+_ti_store_extra(TIC *tic, int wrn, char *id, char type, char flag, short num,
+ char *str, size_t strl, int flags)
+{
+ size_t l;
+
+ _DIAGASSERT(tic != NULL);
+
+ if (strcmp(id, "use") != 0) {
+ if (_ti_find_extra(&tic->extras, id) != NULL)
+ return 0;
+ if (!(flags & TIC_EXTRA)) {
+ if (wrn != 0)
+ dowarn(flags, "%s: %s: unknown capability",
+ tic->name, id);
+ return 0;
+ }
+ }
+
+ l = strlen(id) + 1;
+ if (l > UINT16_T_MAX) {
+ dowarn(flags, "%s: %s: cap name is too long", tic->name, id);
+ return 0;
+ }
+
+ if (!_ti_grow_tbuf(&tic->extras,
+ l + strl + (sizeof(uint16_t) * 2) + 1))
+ return 0;
+ le16enc(tic->extras.buf + tic->extras.bufpos, l);
+ tic->extras.bufpos += sizeof(uint16_t);
+ memcpy(tic->extras.buf + tic->extras.bufpos, id, l);
+ tic->extras.bufpos += l;
+ tic->extras.buf[tic->extras.bufpos++] = type;
+ switch (type) {
+ case 'f':
+ tic->extras.buf[tic->extras.bufpos++] = flag;
+ break;
+ case 'n':
+ le16enc(tic->extras.buf + tic->extras.bufpos, num);
+ tic->extras.bufpos += sizeof(uint16_t);
+ break;
+ case 's':
+ le16enc(tic->extras.buf + tic->extras.bufpos, strl);
+ tic->extras.bufpos += sizeof(uint16_t);
+ memcpy(tic->extras.buf + tic->extras.bufpos, str, strl);
+ tic->extras.bufpos += strl;
+ break;
+ }
+ tic->extras.entries++;
+ return 1;
+}
+
+ssize_t
+_ti_flatten(uint8_t **buf, const TIC *tic)
+{
+ size_t buflen, len, alen, dlen;
+ uint8_t *cap;
+
+ _DIAGASSERT(buf != NULL);
+ _DIAGASSERT(tic != NULL);
+
+ len = strlen(tic->name) + 1;
+ if (tic->alias == NULL)
+ alen = 0;
+ else
+ alen = strlen(tic->alias) + 1;
+ if (tic->desc == NULL)
+ dlen = 0;
+ else
+ dlen = strlen(tic->desc) + 1;
+ buflen = sizeof(char) +
+ sizeof(uint16_t) + len +
+ sizeof(uint16_t) + alen +
+ sizeof(uint16_t) + dlen +
+ (sizeof(uint16_t) * 2) + tic->flags.bufpos +
+ (sizeof(uint16_t) * 2) + tic->nums.bufpos +
+ (sizeof(uint16_t) * 2) + tic->strs.bufpos +
+ (sizeof(uint16_t) * 2) + tic->extras.bufpos;
+ *buf = malloc(buflen);
+ if (*buf == NULL)
+ return -1;
+
+ cap = *buf;
+ *cap++ = 2; /* version */
+ le16enc(cap, len);
+ cap += sizeof(uint16_t);
+ memcpy(cap, tic->name, len);
+ cap += len;
+
+ le16enc(cap, alen);
+ cap += sizeof(uint16_t);
+ if (tic->alias != NULL) {
+ memcpy(cap, tic->alias, alen);
+ cap += alen;
+ }
+ le16enc(cap, dlen);
+ cap += sizeof(uint16_t);
+ if (tic->desc != NULL) {
+ memcpy(cap, tic->desc, dlen);
+ cap += dlen;
+ }
+
+ if (tic->flags.entries == 0) {
+ le16enc(cap, 0);
+ cap += sizeof(uint16_t);
+ } else {
+ le16enc(cap, (tic->flags.bufpos + sizeof(uint16_t)));
+ cap += sizeof(uint16_t);
+ le16enc(cap, tic->flags.entries);
+ cap += sizeof(uint16_t);
+ memcpy(cap, tic->flags.buf, tic->flags.bufpos);
+ cap += tic->flags.bufpos;
+ }
+
+ if (tic->nums.entries == 0) {
+ le16enc(cap, 0);
+ cap += sizeof(uint16_t);
+ } else {
+ le16enc(cap, (tic->nums.bufpos + sizeof(uint16_t)));
+ cap += sizeof(uint16_t);
+ le16enc(cap, tic->nums.entries);
+ cap += sizeof(uint16_t);
+ memcpy(cap, tic->nums.buf, tic->nums.bufpos);
+ cap += tic->nums.bufpos;
Home |
Main Index |
Thread Index |
Old Index