add opendir alias
[minix.git] / commands / tget / tget.c
blobfc1158de3065919fd9f83424ac19e6016ed947b5
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 usage(void)
12 fprintf(stderr,
13 "Usage: tget [-flag id] [-num id] [-str id] [-goto col line] [[-echo] string]\n"
15 exit(-1);
18 int main(int argc, char **argv)
20 char termbuf[1024];
21 char string[256], *pstr;
22 char *term;
23 int i;
24 int excode= 0;
26 if ((term= getenv("TERM")) == nil) {
27 fprintf(stderr, "tget: $TERM is not set\n");
28 exit(-1);
31 if (tgetent(termbuf, term) != 1) {
32 fprintf(stderr, "tget: no termcap entry for '%s'\n", term);
33 exit(-1);
36 for (i= 1; i < argc; i++) {
37 char *option= argv[i];
38 char *id;
40 if (option[0] != '-') {
41 fputs(option, stdout);
42 continue;
45 if (++i == argc) usage();
46 id= argv[i];
48 if (strcmp(option, "-flag") == 0) {
49 excode= tgetflag(id) ? 0 : 1;
50 } else
51 if (strcmp(option, "-num") == 0) {
52 int num;
54 if ((num= tgetnum(id)) == -1) {
55 excode= 1;
56 } else {
57 excode= 0;
58 printf("%d", num);
60 } else
61 if (strcmp(option, "-str") == 0) {
62 char *str;
64 if ((str= tgetstr(id, (pstr= string, &pstr))) == nil) {
65 excode= 1;
66 } else {
67 excode= 0;
68 tputs(str, 0, putchar);
70 } else
71 if (strcmp(option, "-goto") == 0) {
72 char *cm;
73 int col, line;
75 col= atoi(id);
76 if (++i == argc) usage();
77 line= atoi(argv[i]);
79 if ((cm= tgetstr("cm", (pstr= string, &pstr))) == nil) {
80 excode= 1;
81 } else {
82 excode= 0;
83 tputs(tgoto(cm, col, line), 0, putchar);
85 } else
86 if (strcmp(option, "-echo") == 0) {
87 fputs(id, stdout);
88 } else {
89 usage();
92 exit(excode);