2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1996, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * untic.c CURSES Library
2N/A *
2N/A * Copyright 1990, 1992 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A * Portions of this code Copyright 1982 by Pavel Curtis.
2N/A *
2N/A */
2N/A
2N/A#ifdef M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] = "$Header: /rd/src/tic/rcs/untic.c 1.18 1995/06/22 20:04:01 ant Exp $";
2N/A#endif
2N/A#endif
2N/A
2N/A#include <mks.h>
2N/A#include <ctype.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <stdarg.h>
2N/A#include <term.h>
2N/A#include <unistd.h>
2N/A#include <m_ord.h>
2N/A
2N/A#ifdef _XOPEN_CURSES
2N/A/*
2N/A * MKS XCurses to be conforming has to avoid name space pollution
2N/A * by using reserved prefixes. Map the pre-XCurses names to the
2N/A * new ones.
2N/A */
2N/A#define BOOLCOUNT __COUNT_BOOL
2N/A#define NUMCOUNT __COUNT_NUM
2N/A#define STRCOUNT __COUNT_STR
2N/A#define boolnames __m_boolnames
2N/A#define boolcodes __m_boolcodes
2N/A#define boolfnames __m_boolfnames
2N/A#define numnames __m_numnames
2N/A#define numcodes __m_numcodes
2N/A#define numfnames __m_numfnames
2N/A#define strnames __m_strnames
2N/A#define strcodes __m_strcodes
2N/A#define strfnames __m_strfnames
2N/A#define __t_term_header terminfo_header_t
2N/A#define TERMINFO_MAGIC __TERMINFO_MAGIC
2N/A#define Booleans _bool
2N/A#define Numbers _num
2N/A#define Strings _str
2N/A#define term_names _names
2N/A#endif
2N/A
2N/Aextern char *_cmdname;
2N/A
2N/A/* Exit Status */
2N/A#define SUCCESS 0
2N/A#define NOT_DEFINED 1
2N/A#define USAGE 2
2N/A#define BAD_TERMINAL 3
2N/A#define NOT_VALID 4
2N/A#define ERROR 5
2N/A
2N/ASTATIC char *escape ANSI((int));
2N/ASTATIC void error ANSI((char *, ...)); /* GENTEXT: error */
2N/ASTATIC void untic ANSI((TERMINAL *));
2N/A
2N/Achar **Bool;
2N/Achar **Num;
2N/Achar **Str;
2N/A
2N/Achar usage[] = m_textstr(3137, "usage: %s [-CILV] [term_name ...]\n", "U _");
2N/Achar version[] = m_textstr(
2N/A 3138, "%s - Display compiled terminfo database entry. Oct 92\n", "I _"
2N/A);
2N/A
2N/A
2N/Aint
2N/Amain(argc, argv)
2N/Aint argc;
2N/Achar **argv;
2N/A{
2N/A int err;
2N/A char *ap, **av = argv;
2N/A setlocale(LC_ALL, "");
2N/A _cmdname = *argv;
2N/A Bool = boolnames;
2N/A Num = numnames;
2N/A Str = strnames;
2N/A for (--argc, ++argv; 0 < argc && **argv == '-'; --argc, ++argv) {
2N/A ap = &argv[0][1];
2N/A if (*ap == '-' && ap[1] == '\0') {
2N/A --argc;
2N/A ++argv;
2N/A break;
2N/A }
2N/A while (*ap != '\0') {
2N/A switch (*ap++) {
2N/A case 'C':
2N/A Bool = boolcodes;
2N/A Num = numcodes;
2N/A Str = strcodes;
2N/A break;
2N/A case 'I':
2N/A Bool = boolnames;
2N/A Num = numnames;
2N/A Str = strnames;
2N/A break;
2N/A case 'L':
2N/A Bool = boolfnames;
2N/A Num = numfnames;
2N/A Str = strfnames;
2N/A break;
2N/A case 'V':
2N/A (void) fprintf(
2N/A stderr, m_strmsg(version), _cmdname
2N/A );
2N/A break;
2N/A default:
2N/A (void) fprintf(
2N/A stderr, m_strmsg(usage), _cmdname
2N/A );
2N/A return (USAGE);
2N/A }
2N/A break;
2N/A }
2N/A }
2N/A if (argc <= 0) {
2N/A if ((ap = getenv("TERM")) == NULL) {
2N/A (void) fprintf(stderr, m_strmsg(usage), _cmdname);
2N/A return (USAGE);
2N/A }
2N/A /* Assume that, even if there were no parameters, space
2N/A * for argv[0] (the command name) and argv[1] (NULL) would
2N/A * have been put aside. We can use this space to fake a
2N/A * a single default parameter.
2N/A */
2N/A argc = 1;
2N/A argv[0] = ap;
2N/A argv[1] = NULL;
2N/A
2N/A }
2N/A use_env(0);
2N/A for (; 0 < argc; --argc, ++argv) {
2N/A (void) setupterm(*argv, STDOUT_FILENO, &err);
2N/A switch (err) {
2N/A case 1:
2N/A untic(cur_term);
2N/A (void) del_curterm(cur_term);
2N/A break;
2N/A case 0:
2N/A error(
2N/A m_textmsg(202, "Unknown terminal \"%s\".\n", "E term"),
2N/A *argv
2N/A );
2N/A return (BAD_TERMINAL);
2N/A case -1:
2N/A error(m_textmsg(203, "No terminfo database.\n", "E"));
2N/A return (BAD_TERMINAL);
2N/A }
2N/A }
2N/A return (SUCCESS);
2N/A}
2N/A
2N/A/*f
2N/A * Dump the contents of a compiled terminfo file into a
2N/A * human readable format.
2N/A */
2N/ASTATIC void
2N/Auntic(tp)
2N/ATERMINAL *tp;
2N/A{
2N/A int i;
2N/A char *p;
2N/A (void) printf("%s,\n", tp->term_names);
2N/A for (i = 0; i < BOOLCOUNT; ++i) {
2N/A if (tp->Booleans[i])
2N/A (void) printf("\t%s,\n", Bool[i]);
2N/A }
2N/A for (i = 0; i < NUMCOUNT; ++i) {
2N/A if (tp->Numbers[i] != -1)
2N/A (void) printf("\t%s#%d,\n", Num[i],tp->Numbers[i]);
2N/A }
2N/A for (i = 0; i < STRCOUNT; ++i) {
2N/A if (tp->Strings[i] != NULL) {
2N/A (void) printf("\t%s=", Str[i]);
2N/A for (p = tp->Strings[i]; *p != '\0'; ++p)
2N/A (void) fputs(escape(*p), stdout);
2N/A (void) fputs(",\n", stdout);
2N/A }
2N/A }
2N/A (void) putchar('\n');
2N/A}
2N/A
2N/A/*f
2N/A * Display error message.
2N/A */
2N/ASTATIC void
2N/Aerror VARARG1(char*, fmt)
2N/A{
2N/A va_list ap;
2N/A (void) fprintf(stderr, "%s: ", _cmdname);
2N/A va_start(ap, fmt);
2N/A (void) vfprintf(stderr, fmt, ap);
2N/A va_end(ap);
2N/A}
2N/A
2N/A/*f
2N/A * This routine is a codeset independent method of specifying a translation
2N/A * from an internal binary value, to an unambiguous printable format.
2N/A * This mapping is defined by Table 2-13 in section 2-12 of POSIX.2.
2N/A *
2N/A * This table has been extended to account for tic/infocmp specification
2N/A * of additional characters: <escape>, <space>, <colon>, <caret>, <comma>
2N/A */
2N/Achar *
2N/Aescape(c)
2N/Aint c;
2N/A{
2N/A int i;
2N/A static char buf[5];
2N/A static int cntl_code[] = {
2N/A '\0', '\\', M_ALERT, '\b', '\f', '\n', '\r', '\t',
2N/A M_VTAB, M_ESCAPE, ' ', ':', '^', ',',
2N/A -1
2N/A };
2N/A static char *cntl_str[] = {
2N/A "\\0", "\\\\", "\\a", "\\b", "\\f", "\\n", "\\r", "\\t",
2N/A "\\v", "\\E", "\\s", "\\:", "\\^", "\\,"
2N/A };
2N/A for (i = 0; cntl_code[i] != -1; ++i)
2N/A if (c == cntl_code[i])
2N/A return (cntl_str[i]);
2N/A if (!isprint(c))
2N/A (void) sprintf(buf, "\\%03.3o", (unsigned char) c);
2N/A else
2N/A buf[0] = c, buf[1] = '\0';
2N/A return (buf);
2N/A}