tput.c revision d23589482994f9ec7e17f81415324eea6e26d015
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2012 Gary Mills
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* tput - print terminal attribute
*
* return-codes - command line arguments:
* 0: ok if boolean capname -> TRUE
* 1: for boolean capname -> FALSE
*
* return-codes - standard input arguments:
* 0: ok; tput for all lines was successful
*
* return-codes - both cases:
* 2 usage error
* 3 bad terminal type given or no terminfo database
* 4 unknown capname
* -1 capname is a numeric variable that is not specified in the
* terminfo database(E.g. tpu -T450 lines).
*
* tput printfs a value if an INT capname was given; e.g. cols.
* putp's a string if a STRING capname was given; e.g. clear. and
* for BOOLEAN capnames, e.g. hard-copy, just returns the boolean value.
*/
#include <curses.h>
#include <term.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <locale.h>
/* externs from libcurses */
extern int tigetnum();
static int allnumeric(char *string);
static void setdelay();
static void settabs();
static void initterm();
static void reset_term();
static char *progname; /* argv[0] */
static int CurrentBaudRate; /* current baud rate */
static int reset = 0; /* called as reset_term */
static int fildes = 1;
int
{
int i, std_argc;
int setuperr;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
switch (i) {
case 'T':
fildes = -1;
(void) putenv("LINES=");
(void) putenv("COLUMNS=");
break;
case 'S':
break;
case '?': /* FALLTHROUGH */
usage: /* FALLTHROUGH */
default:
"usage:\t%s [-T [term]] capname "
"[parm argument...]\n"), progname);
progname);
exit(2);
}
}
gettext("%s: No value for $TERM and no -T specified\n"),
progname);
exit(2);
}
switch (setuperr) {
case -2:
gettext("%s: unreadable terminal descriptor \"%s\"\n"),
exit(3);
break;
case -1:
exit(3);
break;
case 0:
gettext("%s: unknown terminal \"%s\"\n"),
exit(3);
}
/* command line arguments */
if (!std_input) {
goto usage;
initterm();
reset_term();
else
return (0);
} else { /* standard input argumets */
char buff[128];
char **v;
/* allocate storage for the 'faked' argv[] array */
v = (char **)malloc(10 * sizeof (char *));
for (i = 0; i < 10; i++)
v[i] = (char *)malloc(32 * sizeof (char));
/* read standard input line; skip over empty lines */
if ((std_argc =
"%31s %31s %31s %31s %31s %31s %31s %31s "
"%31s %31s",
v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7],
v[8], v[9])) < 1) {
continue;
}
cap = v[0];
optind = 1;
initterm();
reset_term();
} else {
}
}
return (0);
}
}
static long parm[9] = {
0, 0, 0, 0, 0, 0, 0, 0, 0
};
static int
{
int parmset = 0;
char *thisstr;
int i;
return (1 - i);
(void) printf("%d\n", i);
return (0);
}
if (!thisstr) {
return (1);
}
else
if (parmset)
else
return (0);
}
exit(4);
/* NOTREACHED */
}
/*
* The decision as to whether an argument is a number or not is to simply
* look at whether there are any non-digits in the string.
*/
static int
allnumeric(char *string)
{
if (*string) {
while (*string) {
return (0);
}
}
return (1);
} else {
return (0);
}
}
/*
* SYSTEM DEPENDENT TERMINAL DELAY TABLES
*
* These tables maintain the correspondence between the delays
* defined in terminfo and the delay algorithms in the tty driver
* on the particular systems. For each type of delay, the bits used
* for that delay must be specified, in XXbits, and a table
* must be defined giving correspondences between delays and
* algorithms. Algorithms which are not fixed delays, such
* as dependent on current column or line number, must be
* kludged in some way at this time.
*
* Some of this was taken from tset(1).
*/
struct delay
{
int d_delay;
int d_bits;
};
/* The appropriate speeds for various termio settings. */
static int speeds[] = {
0, /* B0, */
50, /* B50, */
75, /* B75, */
110, /* B110, */
134, /* B134, */
150, /* B150, */
200, /* B200, */
300, /* B300, */
600, /* B600, */
1200, /* B1200, */
1800, /* B1800, */
2400, /* B2400, */
4800, /* B4800, */
9600, /* B9600, */
19200, /* EXTA, */
38400, /* EXTB, */
57600, /* B57600, */
76800, /* B76800, */
115200, /* B115200, */
153600, /* B153600, */
230400, /* B230400, */
307200, /* B307200, */
460800, /* B460800, */
921600, /* B921600, */
0,
};
/* Unix 3.0 on up */
/* Carriage Return delays */
{
0, CR0,
80, CR1,
100, CR2,
150, CR3,
-1
};
/* New Line delays */
{
0, NL0,
100, NL1,
-1
};
/* Back Space delays */
{
0, BS0,
50, BS1,
-1
};
/* TaB delays */
{
0, TAB0,
100, TAB2,
/* TAB3 is XTABS and not a delay */
-1
};
/* Form Feed delays */
{
0, FF0,
2000, FF1,
-1
};
#else /* BSD */
/* Carriage Return delays */
{
0, CR0,
9, CR3,
80, CR1,
160, CR2,
-1
};
/* New Line delays */
{
0, NL0,
100, NL2,
-1
};
/* Tab delays */
{
0, TAB0,
-1
};
/* Form Feed delays */
{
0, FF0,
2000, FF1,
-1
};
#endif /* BSD */
/*
* Initterm, a.k.a. reset_term, does terminal specific initialization. In
* particular, the init_strings from terminfo are output and tabs are
* set, if they aren't hardwired in. Much of this stuff was done by
* the tset(1) program.
*/
/*
* Figure out how many milliseconds of padding the capability cap
* needs and return that number. Padding is stored in the string as "$<n>",
* where n is the number of milliseconds of padding. More than one
* padding string is allowed within the string, although this is unlikely.
*/
static int
{
int padding = 0;
/* No padding needed at speeds below padding_baud_rate */
return (0);
while (*cap) {
cap++;
cap++;
cap++;
cap++;
while (*cap == '>')
cap++;
} else {
cap++;
}
}
return (padding);
}
/*
* Set the appropriate delay bits in the termio structure for
* the given delay.
*/
static void
register int delay;
struct delay delaytable[];
int bits;
#ifdef SYSV
#else /* SYSV */
unsigned short *flags;
#endif /* SYSV */
{
register struct delay *p;
/* Clear out the bits, replace with new ones */
/* Scan the delay table for first entry with adequate delay */
for (lastdelay = p = delaytable;
p++) {
lastdelay = p;
}
/* use last entry if none will do */
}
/*
* Set the hardware tabs on the terminal, using clear_all_tabs,
* set_tab, and column_address capabilities. Cursor_address and cursor_right
* may also be used, if necessary.
* This is done before the init_file and init_3string, so they can patch in
* case we blow this.
*/
static void
settabs()
{
register int c;
/* Do not set tabs if they power up properly. */
if (init_tabs == 8)
return;
if (set_tab) {
/* Force the cursor to be at the left margin. */
if (carriage_return)
else
(void) putchar('\r');
/* Clear any current tab settings. */
if (clear_all_tabs)
/* Set the tabs. */
/* Get to that column. */
/* Set the tab. */
}
/* Get back to the left column. */
if (carriage_return)
else
(void) putchar('\r');
}
}
/*
* Copy "file" onto standard output.
*/
static void
char *file; /* File to copy. */
{
register int fd; /* File descriptor. */
register ssize_t i; /* Number characters read. */
if (fd < 0) {
perror("Cannot open initialization file");
} else {
}
}
/*
* Initialize the terminal.
* Send the initialization strings to the terminal.
*/
static void
initterm()
{
register int filedes; /* File descriptor for ioctl's. */
int i;
int istermios = -1;
#else /* BSD */
#endif
/* Get the terminal settings. */
/* First try standard output, then standard error, */
#ifdef SYSV
#endif /* SYSV */
filedes = -1;
} else
#ifdef SYSV
for (i = 0; i < NCC; i++)
} else
#endif /* SYSV */
if (xon_xoff) {
#ifdef SYSV
#else /* SYSV */
#endif /* SYSV */
} else {
#ifdef SYSV
#else /* SYSV */
#endif /* SYSV */
}
/* If tabs can be sent to the tty, turn off their expansion. */
#ifdef SYSV
#else /* SYSV */
#endif /* SYSV */
} else {
#ifdef SYSV
#else /* SYSV */
#endif /* SYSV */
}
/* Do the changes to the terminal settings */
#ifdef SYSV
if (istermios < 0) {
int i;
for (i = 0; i < NCC; i++)
} else
#else /* SYSV */
#endif /* SYSV */
/* Send first initialization strings. */
if (init_prog)
if (reset && reset_1string) {
} else if (init_1string) {
}
if (reset && reset_2string) {
} else if (init_2string) {
}
/* Set up the tabs stops. */
settabs();
/* Send out initializing file. */
if (reset && reset_file) {
} else if (init_file) {
}
/* Send final initialization strings. */
if (reset && reset_3string) {
} else if (init_3string) {
}
if (carriage_return) {
} else {
(void) putchar('\r');
}
/* Send color initialization strings */
if (orig_colors)
if (orig_pair)
/* Let the terminal settle down. */
(void) sleep(1);
}
static void
{
reset++;
initterm();
}