source: trunk/minix/commands/simple/tget.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.7 KB
Line 
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>
9
10void fputchar(int c)
11{
12 putchar(c);
13}
14
15void usage(void)
16{
17 fprintf(stderr,
18"Usage: tget [-flag id] [-num id] [-str id] [-goto col line] [[-echo] string]\n"
19 );
20 exit(-1);
21}
22
23void main(int argc, char **argv)
24{
25 char termbuf[1024];
26 char string[256], *pstr;
27 char *term;
28 int i;
29 int excode= 0;
30
31 if ((term= getenv("TERM")) == nil) {
32 fprintf(stderr, "tget: $TERM is not set\n");
33 exit(-1);
34 }
35
36 if (tgetent(termbuf, term) != 1) {
37 fprintf(stderr, "tget: no termcap entry for '%s'\n", term);
38 exit(-1);
39 }
40
41 for (i= 1; i < argc; i++) {
42 char *option= argv[i];
43 char *id;
44
45 if (option[0] != '-') {
46 fputs(option, stdout);
47 continue;
48 }
49
50 if (++i == argc) usage();
51 id= argv[i];
52
53 if (strcmp(option, "-flag") == 0) {
54 excode= tgetflag(id) ? 0 : 1;
55 } else
56 if (strcmp(option, "-num") == 0) {
57 int num;
58
59 if ((num= tgetnum(id)) == -1) {
60 excode= 1;
61 } else {
62 excode= 0;
63 printf("%d", num);
64 }
65 } else
66 if (strcmp(option, "-str") == 0) {
67 char *str;
68
69 if ((str= tgetstr(id, (pstr= string, &pstr))) == nil) {
70 excode= 1;
71 } else {
72 excode= 0;
73 tputs(str, 0, fputchar);
74 }
75 } else
76 if (strcmp(option, "-goto") == 0) {
77 char *cm;
78 int col, line;
79
80 col= atoi(id);
81 if (++i == argc) usage();
82 line= atoi(argv[i]);
83
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);
89 }
90 } else
91 if (strcmp(option, "-echo") == 0) {
92 fputs(id, stdout);
93 } else {
94 usage();
95 }
96 }
97 exit(excode);
98}
Note: See TracBrowser for help on using the repository browser.