|
|
1.1 root 1: #include <stdio.h>
2: #include <sgtty.h>
3:
4: #define SP ' '
5: #define TB '\t'
6: #define NL '\n'
7:
8: # define ESC 033
9: # define RHM 060
10: # define SI 017
11: # define DEL 0177
12: # define SET '1'
13: # define CLR '2'
14: # define MGN '9'
15: # define CR '\r'
16: # define BS '\b'
17:
18: struct sysnod {
19: char *sysnam;
20: int sysval;
21: };
22:
23: #define DASI300 1
24: #define DASI300S 2
25: #define DASI450 3
26: #define TN300 4
27: #define TTY37 5
28: #define HP 6
29: struct sysnod tty[] = {
30: {"dasi300", DASI300},
31: {"300", DASI300},
32: {"dasi300s", DASI300S},
33: {"300s", DASI300S},
34: {"dasi450", DASI450},
35: {"450", DASI450},
36: {"37", TTY37},
37: {"tty37", TTY37},
38: {"tn300", TN300},
39: {"terminet", TN300},
40: {"tn", TN300},
41: {"hp", HP},
42: {0, 0},
43: };
44: int margset = 1;
45:
46: syslook(w)
47: char *w;
48: {
49: register struct sysnod *sp;
50:
51: for (sp = tty; sp->sysnam!=NULL; sp++)
52: if (strcmp(sp->sysnam, w)==0)
53: return(sp->sysval);
54: return(0);
55: }
56:
57: main(argc,argv)
58: int argc; char **argv;
59: {
60: struct sgttyb tb;
61: int type;
62: char *getenv();
63:
64: type=0;
65: if (argc>=2 && strcmp(argv[1],"-n")==0) {
66: margset--; argc--; argv++;
67: }
68: if (argc>=2) {
69: type=syslook(argv[1]);
70: } else {
71: type=syslook(getenv("TERM"));
72: }
73:
74: switch(type) {
75:
76: case DASI300: dasi300(); break;
77:
78: case DASI300S: dasi300(); break;
79:
80: case DASI450: dasi450(); break;
81:
82: case TN300: tn300(); break;
83:
84: case TTY37: tty37(); break;
85:
86: case HP: hp2645(); break;
87:
88: default:
89: gtty (0, &tb);
90: if ( (tb.sg_flags & (LCASE|CRMOD)) == CRMOD) {
91: /* test for CR map on, upper case off, i.e. terminet but not 33 */
92: if ((tb.sg_ispeed) == B300) /* test for 300 baud */
93: misc();
94: }
95: else if ((tb.sg_flags & (CRMOD|LCASE)) == 0 && (tb.sg_ispeed ) == B150) {
96: /* apparent model 37 */
97: tty37();
98: }
99: }
100: }
101:
102: clear(n)
103: {
104: escape(CLR);
105: delay(n);
106: putchar(CR); nl();
107: }
108:
109: delay(n)
110: {
111: while (n--) putchar(DEL);
112: }
113:
114: tabs(n)
115: {
116: int i,j;
117:
118: if(margset) n--;
119:
120: for( i=0; i<n; ++i ){
121: for( j=0; j<8; ++j ) {
122: putchar(SP);
123: }
124: escape(SET);
125: }
126: }
127:
128: margin(n)
129: {
130: int i;
131:
132: if(margset) {
133: for( i=0; i<n; ++i) putchar(SP);
134: }
135: }
136:
137: escape(c)
138: {
139: putchar(ESC); putchar(c);
140: }
141:
142: bs(n)
143: {
144: while (n--) putchar(BS);
145: }
146:
147: nl()
148: {
149: putchar(NL);
150: }
151:
152:
153:
154: /* ======== terminal types ======== */
155:
156: dasi450()
157: {
158: struct sgttyb t;
159: gtty(0,&t);
160: t.sg_flags &= ~ALLDELAY;
161: stty(0,&t);
162: clear(8); bs(16); margin(8); escape(MGN); nl(); tabs(16);
163: escape(RHM); nl();
164: }
165:
166: tty37()
167: {
168: putchar(SI); clear(40); bs(8); tabs(9); nl();
169: }
170:
171: dasi300()
172: {
173: clear(8); tabs(15); nl();
174: }
175:
176: tn300()
177: {
178: struct sgttyb t;
179: gtty(0,&t);
180: t.sg_flags &= ~ALLDELAY;
181: t.sg_flags |= CR1|BS1;
182: stty(0,&t);
183: clear(8); margin(8); escape(SET); tabs(14); nl();
184: }
185:
186: hp2645()
187: {
188: escape('3'); /*clr*/
189: putchar(CR);
190: tabs(10);
191: nl();
192: }
193:
194: misc()
195: {
196: tabs(14); nl();
197: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.