|
|
1.1 ! root 1: /*- ! 2: * Copyright (c) 1980, 1988 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: char copyright[] = ! 22: "@(#) Copyright (c) 1980, 1988 The Regents of the University of California.\n\ ! 23: All rights reserved.\n"; ! 24: #endif /* not lint */ ! 25: ! 26: #ifndef lint ! 27: static char sccsid[] = "@(#)tput.c 5.7 (Berkeley) 6/7/90"; ! 28: #endif /* not lint */ ! 29: ! 30: #include <sys/termios.h> ! 31: #include <stdio.h> ! 32: #include <unistd.h> ! 33: ! 34: main(argc, argv) ! 35: int argc; ! 36: char **argv; ! 37: { ! 38: extern char *optarg; ! 39: extern int optind; ! 40: int ch, exitval, n, outc(); ! 41: char *cptr, *p, *term, buf[1024], tbuf[1024]; ! 42: char *getenv(), *tgetstr(), *realname(); ! 43: ! 44: term = NULL; ! 45: while ((ch = getopt(argc, argv, "T:")) != EOF) ! 46: switch(ch) { ! 47: case 'T': ! 48: term = optarg; ! 49: break; ! 50: case '?': ! 51: default: ! 52: usage(); ! 53: } ! 54: argc -= optind; ! 55: argv += optind; ! 56: ! 57: if (!term && !(term = getenv("TERM"))) { ! 58: (void)fprintf(stderr, "tput: no terminal type specified.\n"); ! 59: exit(2); ! 60: } ! 61: if (tgetent(tbuf, term) != 1) { ! 62: (void)fprintf(stderr, "tput: tgetent failure.\n"); ! 63: exit(2); ! 64: } ! 65: setospeed(); ! 66: for (cptr = buf, exitval = 0; p = *argv; ++argv) { ! 67: switch(*p) { ! 68: case 'c': ! 69: if (!strcmp(p, "clear")) ! 70: p = "cl"; ! 71: break; ! 72: case 'i': ! 73: if (!strcmp(p, "init")) ! 74: p = "is"; ! 75: break; ! 76: case 'l': ! 77: if (!strcmp(p, "longname")) ! 78: prlongname(tbuf); ! 79: continue; ! 80: case 'r': ! 81: if (!strcmp(p, "reset")) ! 82: p = "rs"; ! 83: break; ! 84: } ! 85: if (tgetstr(p, &cptr)) ! 86: (void)tputs(buf, 1, outc); ! 87: else if ((n = tgetnum(p)) != -1) ! 88: (void)printf("%d\n", n); ! 89: else ! 90: exitval = !tgetflag(p); ! 91: } ! 92: exit(exitval); ! 93: } ! 94: ! 95: prlongname(buf) ! 96: char *buf; ! 97: { ! 98: register char *p; ! 99: int savech; ! 100: char *savep; ! 101: ! 102: for (p = buf; *p && *p != ':'; ++p); ! 103: savech = *(savep = p); ! 104: for (*p = '\0'; p >= buf && *p != '|'; --p); ! 105: (void)printf("%s\n", p + 1); ! 106: *savep = savech; ! 107: } ! 108: ! 109: setospeed() ! 110: { ! 111: extern int errno, ospeed; ! 112: struct termios t; ! 113: char *strerror(); ! 114: ! 115: if (tcgetattr(STDOUT_FILENO, &t) != -1) ! 116: ospeed = 0; ! 117: else ! 118: ospeed = cfgetospeed(&t); ! 119: } ! 120: ! 121: outc(c) ! 122: int c; ! 123: { ! 124: putchar(c); ! 125: } ! 126: ! 127: usage() ! 128: { ! 129: (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n"); ! 130: exit(1); ! 131: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.