1 /* $NetBSD: tput.c,v 1.22 2011/10/04 12:23:14 roy Exp $ */
4 * Copyright (c) 1980, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1980, 1988, 1993\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "@(#)tput.c 8.3 (Berkeley) 4/28/95";
42 __RCSID("$NetBSD: tput.c,v 1.22 2011/10/04 12:23:14 roy Exp $");
56 static void usage(void) __dead
;
57 static char **process(const char *, const char *, char **);
60 main(int argc
, char **argv
)
68 while ((ch
= getopt(argc
, argv
, "T:")) != -1)
80 if (!term
&& !(term
= getenv("TERM")))
81 errx(2, "No terminal type specified and no TERM "
82 "variable set in the environment.");
83 setupterm(term
, 0, NULL
);
84 for (exitval
= 0; (p
= *argv
) != NULL
; ++argv
) {
87 if (!strcmp(p
, "clear"))
91 if (!strcmp(p
, "init")) {
99 if (!strcmp(p
, "longname")) {
100 (void)printf("%s\n", longname());
105 if (!strcmp(p
, "reset")) {
114 if (((s
= tigetstr(p
)) != NULL
&& s
!= (char *)-1) ||
115 (pl
<= 2 && (s
= tgetstr(p
, NULL
)) != NULL
))
116 argv
= process(p
, s
, argv
);
117 else if ((((n
= tigetnum(p
)) != -1 && n
!= -2 ) ||
118 (pl
<= 2 && (n
= tgetnum(p
)) != -1)))
119 (void)printf("%d\n", n
);
121 exitval
= tigetflag(p
);
124 exitval
= !tgetflag(p
);
134 return argv
? exitval
: 2;
138 process(const char *cap
, const char *str
, char **argv
)
140 static const char errfew
[] =
141 "Not enough arguments (%d) for capability `%s'";
142 static const char erresc
[] =
143 "Unknown %% escape `%c' for capability `%s'";
146 int arg_need
, p1
, p2
, p3
, p4
, p5
, p6
, p7
, p8
, p9
;
148 /* Count how many values we need for this capability. */
151 while ((c
= *p
++) != '\0') {
160 if (c
< '1' || c
> '9')
161 errx(2, erresc
, c
, cap
);
169 if (*++argv == NULL || *argv[0] == '\0') \
170 errx(2, errfew, 1, cap); \
219 /* And print them. */
220 (void)tputs(tparm(str
, p1
, p2
, p3
, p4
, p5
, p6
, p7
, p8
, p9
), 0, outc
);
233 (void)fprintf(stderr
,
234 "Usage: %s [-T term] attribute [attribute-args] ...\n",