unstack - fix ipcvecs
[minix.git] / commands / tget / tget.c
blobe09009b20e3a04e2d4eea49b5cc01aeb18d7481d
1 /* tget 1.0 - get termcap values Author: Kees J. Bot
2 * 6 Mar 1994
3 */
4 #define nil 0
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <termcap.h>
10 void fputchar(int c)
12 putchar(c);
15 void usage(void)
17 fprintf(stderr,
18 "Usage: tget [-flag id] [-num id] [-str id] [-goto col line] [[-echo] string]\n"
20 exit(-1);
23 int main(int argc, char **argv)
25 char termbuf[1024];
26 char string[256], *pstr;
27 char *term;
28 int i;
29 int excode= 0;
31 if ((term= getenv("TERM")) == nil) {
32 fprintf(stderr, "tget: $TERM is not set\n");
33 exit(-1);
36 if (tgetent(termbuf, term) != 1) {
37 fprintf(stderr, "tget: no termcap entry for '%s'\n", term);
38 exit(-1);
41 for (i= 1; i < argc; i++) {
42 char *option= argv[i];
43 char *id;
45 if (option[0] != '-') {
46 fputs(option, stdout);
47 continue;
50 if (++i == argc) usage();
51 id= argv[i];
53 if (strcmp(option, "-flag") == 0) {
54 excode= tgetflag(id) ? 0 : 1;
55 } else
56 if (strcmp(option, "-num") == 0) {
57 int num;
59 if ((num= tgetnum(id)) == -1) {
60 excode= 1;
61 } else {
62 excode= 0;
63 printf("%d", num);
65 } else
66 if (strcmp(option, "-str") == 0) {
67 char *str;
69 if ((str= tgetstr(id, (pstr= string, &pstr))) == nil) {
70 excode= 1;
71 } else {
72 excode= 0;
73 tputs(str, 0, fputchar);
75 } else
76 if (strcmp(option, "-goto") == 0) {
77 char *cm;
78 int col, line;
80 col= atoi(id);
81 if (++i == argc) usage();
82 line= atoi(argv[i]);
84 if ((cm= tgetstr("cm", (pstr= string, &pstr))) == nil) {
85 excode= 1;
86 } else {
87 excode= 0;
88 tputs(tgoto(cm, col, line), 0, fputchar);
90 } else
91 if (strcmp(option, "-echo") == 0) {
92 fputs(id, stdout);
93 } else {
94 usage();
97 exit(excode);