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