|
|
1.1 root 1: /* entry points:
2: tgate() called to initialize things; if TERM not set inquires
3: tpos(row,col) moves cursor
4: clr2end () clears to end of screen
5: ifclear() returns true if terminal CAN clear to end of screen
6: clrline() clears to end of line
7: ifclrline() returns true if terminal CAN clear to end of line
8: stterm(s) sets terminal name to s; not usually needed
9: gtterm() returns name of terinal
10: compile with -ltermlib
11: uses /etc/termcap file
12: */
13: /* ce is the parameter for "clear to end of line" */
14: # include "stdio.h"
15: # include "ctype.h"
16: char *tgetent(), *tgoto(), *tputs(), *tgetstr(), *getenv();
17: static char tname[25]="", tcapbuf[1024], *Movcur, strarea[1204], *p_area=strarea;
18: static char *Home=NULL, *Clr2nd=NULL, *Clear=NULL, *ClrLine=NULL;
19: static int tset=0;
20: tgate()
21: {
22: static gate=0; char *envp;
23: if (gate==0)
24: {
25: gate=1;
26: if (!isatty(1)) return; /* don't ask pointless questions */
27: if (tset==0)
28: {
29: envp = getenv("TERM");
30: if (tname[0]==0 && envp != NULL)
31: strncpy (tname, envp, 25);
32: if (! *tname) {
33: fputs ("Terminal type? ", stdout);
34: fflush(stdout);
35: gets(tname);
36: }
37: }
38: if (*tname==0) return;
39: switch ( tgetent(tcapbuf, tname))
40: {
41: case -1: fprintf(stderr, "No termcap file\n");
42: exit(1);
43: case 0: /* unknown terminal */
44: return;
45: default: break;
46: }
47: if (strcmp(tname, "adm3a")==0)
48: {
49: extern char *UP;
50: UP = "xxx";
51: }
52: Movcur = tgetstr("cm", &p_area);
53: Home = tgetstr("ho", &p_area);
54: Clr2nd = tgetstr("cd", &p_area);
55: Clear = tgetstr("cl", &p_area);
56: ClrLine = tgetstr("ce", &p_area);
57: }
58: }
59: tpos (line, col)
60: {
61: tgate();
62: if (Movcur!=NULL)
63: {
64: char tmpstr[100];
65: strncpy(tmpstr, tgoto(Movcur, col, line), 100);
66: if (strcmp(tmpstr, "OOPS")==0) return;
67: termwr(tmpstr);
68: }
69: else
70: if (Home!=NULL)
71: {
72: termwr(Home);
73: while (line-- > 0)
74: termwr("\n");
75: while (col-- > 0)
76: termwr(" ");
77: }
78: return;
79: }
80: startsc()
81: {
82: tgate();
83: if (Home != NULL)
84: termwr(Home);
85: else
86: if (Movcur != NULL)
87: tpos(0,0);
88: if (Clr2nd != NULL)
89: termwr(Clr2nd);
90: else if (Clear !=NULL)
91: termwr(Clear);
92: }
93: clr2end ()
94: {
95: tgate();
96: if (Clr2nd !=NULL)
97: termwr(Clr2nd);
98: }
99: clrline()
100: {
101: tgate();
102: if (ClrLine !=NULL)
103: termwr(ClrLine);
104: }
105: ifclear()
106: {
107: return (Clr2nd!=NULL);
108: }
109: ifclrline()
110: {
111: return(ClrLine!=NULL);
112: }
113: stterm(t)
114: char *t;
115: {
116: strcpy(tname, t);
117: tset=1;
118: }
119: char *
120: gtterm()
121: {
122: return(tname);
123: }
124: termwr(s)
125: char *s;
126: {
127: int delay; char *sr;
128: for(sr=s; isdigit(*sr); sr++)
129: ;
130: fputs(sr, stdout);
131: if (sr<=s) return;
132: for (delay=atoi(s)/10; delay>0; delay--)
133: putc(000, stdout);
134: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.