|
|
1.1 root 1: /*
2: * clear.c
3: * 3/18/91
4: * Usage: clear
5: * cc -o clear clear.c -lterm
6: * Clear the screen (stdout) using termcap.
7: */
8:
9: #include <stdio.h>
10:
11: #define TCBUFLEN 1024
12: #define TCAPSLEN 315
13: #define NLINES 22
14:
15: extern char *getenv();
16: extern int tgetent();
17: extern char *tgetstr();
18: extern char *tgoto();
19: extern int ttputc();
20:
21: void fatal();
22: int ttputc();
23:
24: char tcbuf[TCBUFLEN];
25: char tcapbuf[TCAPSLEN];
26:
27: main()
28: {
29: register char *clear, *move, *tv_stype, *p;
30:
31: p = tcapbuf;
32: if ((tv_stype=getenv("TERM")) == NULL)
33: fatal("enviroment variable TERM not defined");
34: else if (tgetent(tcbuf, tv_stype) != 1)
35: fatal("unknown terminal type \"%s\"", tv_stype);
36: else if ((clear=tgetstr("cd", &p)) == NULL
37: || (move =tgetstr("cm", &p)) == NULL)
38: fatal("incomplete termcap entry");
39: tputs(tgoto(move, 0, 0), 1, ttputc);
40: tputs(clear, 1, ttputc);
41: exit(0);
42: }
43:
44: /* VARARGS */
45: void
46: fatal(x) char *x;
47: {
48: register int i;
49:
50: fprintf(stderr, "clear: %r\n", &x);
51: for (i = 1; i <= NLINES; i++)
52: putchar('\n');
53: exit(1);
54: }
55:
56: int
57: ttputc(c) int c;
58: {
59: return fputc(c, stdout);
60: }
61:
62: /* end of clear.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.