cleanup, get padding and archive creation right
[unix-history] / usr / src / usr.bin / tput / tput.c
CommitLineData
9fb610a8
KB
1/*-
2 * Copyright (c) 1980, 1988 The Regents of the University of California.
3b1bb731
KB
3 * All rights reserved.
4 *
9fb610a8 5 * %sccs.include.redist.c%
fcd2465c
DF
6 */
7
8#ifndef lint
9char copyright[] =
9fb610a8 10"@(#) Copyright (c) 1980, 1988 The Regents of the University of California.\n\
fcd2465c 11 All rights reserved.\n";
3b1bb731 12#endif /* not lint */
fcd2465c
DF
13
14#ifndef lint
9fb610a8 15static char sccsid[] = "@(#)tput.c 5.7 (Berkeley) %G%";
3b1bb731 16#endif /* not lint */
45e33619 17
eee80001
KB
18#include <sys/termios.h>
19#include <stdio.h>
20#include <unistd.h>
21
22main(argc, argv)
23 int argc;
24 char **argv;
45e33619 25{
eee80001
KB
26 extern char *optarg;
27 extern int optind;
d5d6bc1b
KB
28 int ch, exitval, n, outc();
29 char *cptr, *p, *term, buf[1024], tbuf[1024];
eee80001
KB
30 char *getenv(), *tgetstr(), *realname();
31
32 term = NULL;
33 while ((ch = getopt(argc, argv, "T:")) != EOF)
34 switch(ch) {
35 case 'T':
36 term = optarg;
37 break;
38 case '?':
39 default:
40 usage();
3b1bb731 41 }
eee80001
KB
42 argc -= optind;
43 argv += optind;
44
45 if (!term && !(term = getenv("TERM"))) {
46 (void)fprintf(stderr, "tput: no terminal type specified.\n");
d5d6bc1b 47 exit(2);
eee80001
KB
48 }
49 if (tgetent(tbuf, term) != 1) {
50 (void)fprintf(stderr, "tput: tgetent failure.\n");
d5d6bc1b 51 exit(2);
eee80001
KB
52 }
53 setospeed();
809ff644 54 for (cptr = buf, exitval = 0; p = *argv; ++argv) {
d5d6bc1b
KB
55 switch(*p) {
56 case 'c':
57 if (!strcmp(p, "clear"))
58 p = "cl";
59 break;
60 case 'i':
61 if (!strcmp(p, "init"))
62 p = "is";
63 break;
64 case 'l':
65 if (!strcmp(p, "longname"))
66 prlongname(tbuf);
67 continue;
68 case 'r':
69 if (!strcmp(p, "reset"))
70 p = "rs";
71 break;
72 }
73 if (tgetstr(p, &cptr))
74 (void)tputs(buf, 1, outc);
75 else if ((n = tgetnum(p)) != -1)
76 (void)printf("%d\n", n);
eee80001 77 else
d5d6bc1b
KB
78 exitval = !tgetflag(p);
79 }
eee80001
KB
80 exit(exitval);
81}
82
d5d6bc1b
KB
83prlongname(buf)
84 char *buf;
eee80001 85{
d5d6bc1b
KB
86 register char *p;
87 int savech;
88 char *savep;
eee80001 89
d5d6bc1b
KB
90 for (p = buf; *p && *p != ':'; ++p);
91 savech = *(savep = p);
92 for (*p = '\0'; p >= buf && *p != '|'; --p);
93 (void)printf("%s\n", p + 1);
94 *savep = savech;
eee80001
KB
95}
96
97setospeed()
98{
99 extern int errno, ospeed;
100 struct termios t;
101 char *strerror();
102
2b3e5373
KB
103 if (tcgetattr(STDOUT_FILENO, &t) != -1)
104 ospeed = 0;
105 else
106 ospeed = cfgetospeed(&t);
eee80001
KB
107}
108
d5d6bc1b
KB
109outc(c)
110 int c;
111{
112 putchar(c);
113}
114
eee80001
KB
115usage()
116{
117 (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n");
3b1bb731 118 exit(1);
45e33619 119}