BSD 3 development
[unix-history] / usr / src / cmd / tabs.c
CommitLineData
e9af7caa
BJ
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 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
102clear(n)
103{
104 escape(CLR);
105 delay(n);
106 putchar(CR); nl();
107}
108
109delay(n)
110{
111 while (n--) putchar(DEL);
112}
113
114tabs(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
128margin(n)
129{
130 int i;
131
132 if(margset) {
133 for( i=0; i<n; ++i) putchar(SP);
134 }
135}
136
137escape(c)
138{
139 putchar(ESC); putchar(c);
140}
141
142bs(n)
143{
144 while (n--) putchar(BS);
145}
146
147nl()
148{
149 putchar(NL);
150}
151
152
153
154/* ======== terminal types ======== */
155
156dasi450()
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
166tty37()
167{
168 putchar(SI); clear(40); bs(8); tabs(9); nl();
169}
170
171dasi300()
172{
173 clear(8); tabs(15); nl();
174}
175
176tn300()
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
186hp2645()
187{
188 escape('3'); /*clr*/
189 putchar(CR);
190 tabs(10);
191 nl();
192}
193
194misc()
195{
196 tabs(14); nl();
197}