Research V7 development
[unix-history] / usr / src / cmd / tabs.c
CommitLineData
a570deab
KT
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
18struct 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
29struct 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};
44int margset = 1;
45
46syslook(w)
47char *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
57main(argc,argv)
58int argc; char **argv;
59{
60 struct sgttyb tb;
61 int type;
62
63 type=0;
64 if (argc>=2 && strcmp(argv[1],"-n")==0) {
65 margset--; argc--; argv++;
66 }
67 if (argc>=2) {
68 type=syslook(argv[1]);
69 }
70
71 switch(type) {
72
73 case DASI300: dasi300(); break;
74
75 case DASI300S: dasi300(); break;
76
77 case DASI450: dasi450(); break;
78
79 case TN300: tn300(); break;
80
81 case TTY37: tty37(); break;
82
83 case HP: hp2645(); break;
84
85 default:
86 gtty (0, &tb);
87 if ( (tb.sg_flags & (LCASE|CRMOD)) == CRMOD) {
88 /* test for CR map on, upper case off, i.e. terminet but not 33 */
89 if ((tb.sg_ispeed) == B300) /* test for 300 baud */
90 misc();
91 }
92 else if ((tb.sg_flags & (CRMOD|LCASE)) == 0 && (tb.sg_ispeed ) == B150) {
93 /* apparent model 37 */
94 tty37();
95 }
96 }
97}
98
99clear(n)
100{
101 escape(CLR);
102 delay(n);
103 putchar(CR); nl();
104}
105
106delay(n)
107{
108 while (n--) putchar(DEL);
109}
110
111tabs(n)
112{
113 int i,j;
114
115 if(margset) n--;
116
117 for( i=0; i<n; ++i ){
118 for( j=0; j<8; ++j ) {
119 putchar(SP);
120 }
121 escape(SET);
122 }
123}
124
125margin(n)
126{
127 int i;
128
129 if(margset) {
130 for( i=0; i<n; ++i) putchar(SP);
131 }
132}
133
134escape(c)
135{
136 putchar(ESC); putchar(c);
137}
138
139bs(n)
140{
141 while (n--) putchar(BS);
142}
143
144nl()
145{
146 putchar(NL);
147}
148
149
150
151/* ======== terminal types ======== */
152
153dasi450()
154{
155 struct sgttyb t;
156 gtty(0,&t);
157 t.sg_flags &= ~ALLDELAY;
158 stty(0,&t);
159 clear(8); bs(16); margin(8); escape(MGN); nl(); tabs(16);
160 escape(RHM); nl();
161}
162
163tty37()
164{
165 putchar(SI); clear(40); bs(8); tabs(9); nl();
166}
167
168dasi300()
169{
170 clear(8); tabs(15); nl();
171}
172
173tn300()
174{
175 struct sgttyb t;
176 gtty(0,&t);
177 t.sg_flags &= ~ALLDELAY;
178 t.sg_flags |= CR1|BS1;
179 stty(0,&t);
180 clear(8); margin(8); escape(SET); tabs(14); nl();
181}
182
183hp2645()
184{
185 escape('3'); /*clr*/
186 putchar(CR);
187 tabs(10);
188 nl();
189}
190
191misc()
192{
193 tabs(14); nl();
194}