1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <ctype.h>
include <ttyset.h>
include "tty.h"
# Debug TTY package.
task find=t_find, cap=t_cap, init=t_init
define SZ_CAPSTR 30
define FAKE_PADCHAR 177B
# FIND -- Find an entry in the termcap database, and print out the caplist
# string.
procedure t_find()
char ttyname[SZ_FNAME]
pointer tty, ttygdes()
begin
call clgstr ("ttyname", ttyname, SZ_FNAME)
tty = ttygdes (ttyname)
call printf ("Termcap entry for '%s', %d capabilities\n")
call pargstr (ttyname)
call pargi (T_NCAPS(tty))
call printf (" pc=%oB, bsok=%b, htok=%b, %d by %d, %d baud\n")
call pargi (T_PADCHAR(tty))
call pargi (T_BSOK(tty))
call pargi (T_HTOK(tty))
call pargi (T_NCOLS(tty))
call pargi (T_NLINES(tty))
call pargi (T_BAUD(tty))
call putline (STDOUT, T_CAPLIST(tty))
call putci (STDOUT, '\n')
call ttycdes (tty)
end
# CAP -- Open descriptor, then sit in a get/put capability loop. Capabilities
# are put to the stdout in a readable form.
procedure t_cap()
char ttyname[SZ_FNAME], capstr[SZ_CAPSTR]
char ctrlstr[SZ_CTRLSTR], tempstr[SZ_CTRLSTR], obuf[SZ_LINE]
int fd, args[MAX_COORDS], nargs, nchars
int stropen(), ttygets(), ttysubi(), clglstr(), strlen(), nscan()
pointer tty, ttygdes()
begin
call clgstr ("ttyname", ttyname, SZ_FNAME)
tty = ttygdes (ttyname)
call ttyseti (tty, TTY_PADCHAR, FAKE_PADCHAR)
call printf ("Termcap entry for '%s', %d capabilities\n")
call pargstr (ttyname)
call pargi (T_NCAPS(tty))
call printf (" pc=%oB, bsok=%b, htok=%b, %d by %d, %d baud\n")
call pargi (T_PADCHAR(tty))
call pargi (T_BSOK(tty))
call pargi (T_HTOK(tty))
call pargi (T_NCOLS(tty))
call pargi (T_NLINES(tty))
call pargi (T_BAUD(tty))
while (clglstr ("cap", capstr, SZ_CAPSTR) != EOF)
if (ttygets (tty, capstr, ctrlstr, SZ_CTRLSTR) == 0) {
call printf ("capability '%s' not found\n")
call pargstr (capstr)
} else {
fd = stropen (obuf, SZ_LINE, NEW_FILE)
# Expand args? (as in "cap: cm 11 4")
if (strlen (capstr) > 2) {
call sscan (capstr[3])
for (nargs=0; nscan() == nargs; nargs=nargs+1)
call gargi (args[nargs+1])
nargs = nargs - 1
call strcpy (ctrlstr, tempstr, SZ_CTRLSTR)
nchars = ttysubi (tempstr, ctrlstr,SZ_CTRLSTR, args,nargs)
} else
nargs = 0
call ttyputs (fd, tty, ctrlstr, 1)
if (nargs > 0 && args[1] != 0 || args[2] != 0) {
call fprintf (fd, " residual x=%d, y=%d")
call pargi (args[1])
call pargi (args[2])
}
call close (fd)
call dump_chars (STDOUT, obuf)
}
call putci (STDOUT, '\n')
call ttycdes (tty)
end
# INIT -- Output initialization string in human readable form on the standard
# output.
define SZ_OBUF 1024
procedure t_init()
char ttyname[SZ_FNAME]
char obuf[SZ_OBUF]
int fd
int stropen()
pointer tty, ttygdes()
begin
call clgstr ("ttyname", ttyname, SZ_FNAME)
tty = ttygdes (ttyname)
call ttyseti (tty, TTY_PADCHAR, FAKE_PADCHAR)
# Print header identifying basic terminal capabilities.
call printf ("Termcap entry for '%s', %d capabilities\n")
call pargstr (ttyname)
call pargi (T_NCAPS(tty))
call printf (" pc=%oB, bsok=%b, htok=%b, %d by %d, %d baud\n")
call pargi (T_PADCHAR(tty))
call pargi (T_BSOK(tty))
call pargi (T_HTOK(tty))
call pargi (T_NCOLS(tty))
call pargi (T_NLINES(tty))
call pargi (T_BAUD(tty))
# Dump initialization string into buffer, print buffer in readable
# form on STDOUT.
fd = stropen (obuf, SZ_OBUF, NEW_FILE)
call ttyinit (fd, tty)
call close (fd)
call dump_chars (STDOUT, obuf)
call putci (STDOUT, '\n')
call ttycdes (tty)
end
# DUMP_CHARS -- Print out a sequence of normal and control chars in a nice
# readable form.
procedure dump_chars (fd, str)
int fd
char str[ARB]
char ch
int ip, iptop
int stridx()
errchk putci, putline
begin
for (ip=1; str[ip] != EOS; ) {
if (ip > 1)
call putci (fd, '\n')
call putline (fd, " ")
for (iptop=ip+50; ip < iptop && str[ip] != EOS; ip=ip+1) {
ch = str[ip]
if (IS_CNTRL(ch)) {
if (stridx (ch, "\b\f\t\r\n") > 0)
call putcc (fd, ch)
else {
call putci (fd, '^')
call putci (fd, ch + 'A' - 1)
}
} else if (ch == FAKE_PADCHAR) {
call putci (fd, '.')
} else
call putc (fd, ch)
}
}
if (ip < iptop)
call putci (fd, '\n')
end
|