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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <ctype.h>
include "stdgraph.h"
define SZ_PROGRAM 256
define MAXARGSTR 15
# SHOWCAP - Show the ascii control string sent to a device to implement a
# control function. Useful for testing graphcap entries.
procedure t_showcap()
char cap[2]
int g_reg[NREGISTERS]
char g_mem[SZ_MEMORY]
char argstr[MAXARGSTR]
int arg1, arg2, arg3, op, len_prog, status, nchars
pointer tty, sp, prog, ip, cmd
pointer ttygdes(), ttycaps()
int stg_encode(), ctoi(), getline(), strncmp()
int ttygets(), ctowrd(), strlen()
bool ttygetb(), streq()
define getargs_ 91
begin
call smark (sp)
call salloc (cmd, SZ_LINE, TY_CHAR)
call salloc (prog, SZ_PROGRAM, TY_CHAR)
# Print instructions.
call printf ("cmd : `set' device\n")
call printf (" | `*' (to dump full graphcap entry\n")
call printf (" | cc [arg1 [arg2 [arg3]]]\n")
call printf (" ;\n")
call printf ("\n")
call printf ("cc : a two chararacter capcode (e.g., 'cm')\n")
call printf (" | an encoder program (non alpha first char)\n")
call printf (" ;\n")
call printf ("\n")
# Interpret and translate control commands until EOF or "bye"
# is typed.
tty = NULL
repeat {
# Prompt for input.
call printf ("* ")
call flush (STDOUT)
if (getline (STDIN, Memc[cmd]) == EOF) {
call printf ("\n")
break
}
for (ip=cmd; IS_WHITE (Memc[ip]); ip=ip+1)
;
if (Memc[ip] == '\n') {
next
} else if (strncmp (Memc[ip], "set", 3) == 0) {
ip = ip + 3
len_prog = ctowrd (Memc, ip, Memc[prog], SZ_PROGRAM)
if (tty != NULL)
call ttycdes (tty)
tty = ttygdes (Memc[prog])
call sgc_dump (STDOUT, Memc[ttycaps(tty)],
strlen (Memc[ttycaps(tty)]))
next
} else if (Memc[ip] == '*') {
call sgc_dump (STDOUT, Memc[ttycaps(tty)],
strlen (Memc[ttycaps(tty)]))
next
} else if (!IS_ALPHA (Memc[ip])) {
len_prog = ctowrd (Memc, ip, Memc[prog], SZ_PROGRAM)
cap[1] = EOS
goto getargs_
} else if (strncmp (Memc[ip], "bye", 3) == 0)
break
# Parse command with optional arguments, e.g., "RC 1".
# Extract 2 character capability name (required).
op = 1
while (IS_ALNUM(Memc[ip])) {
cap[op] = Memc[ip]
ip = ip + 1
op = min (2, op + 1)
}
cap[3] = EOS
getargs_
# Argument type depends on whether encoding or decoding.
if (streq ("SC", cap)) {
nchars = ctowrd (Memc, ip, argstr, MAXARGSTR)
if (nchars == 0) {
call printf ("SC must have 1 contiguous string argument\n")
next
}
} else {
# Extract up to three arguments (optional).
if (ctoi (Memc, ip, arg1) <= 0)
arg1 = 0
if (ctoi (Memc, ip, arg2) <= 0)
arg2 = 0
if (ctoi (Memc, ip, arg3) <= 0)
arg3 = 0
}
# Fetch the program from the graphcap file. Zero is returned if
# the device does not have the named capability, in which case
# the function is inapplicable and should be ignored.
if (cap[1] != EOS)
if (tty == NULL) {
call printf ("use `set' to specify device name\n")
next
} else
len_prog = ttygets (tty, cap, Memc[prog], SZ_PROGRAM)
if (len_prog > 0) {
if (Memc[prog] == '#')
call sgc_dump (STDOUT, Memc[prog+1], len_prog - 1)
else {
# Dump the program on the standard output.
if (cap[1] != EOS) {
call printf ("program: ")
call sgc_dump (STDOUT, Memc[prog], len_prog)
}
# Set memory or registers depending on whether encoding or
# decoding.
if (streq ("SC", cap))
call strcpy (argstr, g_mem, nchars)
else {
g_reg[1] = arg1
g_reg[2] = arg2
g_reg[3] = arg3
}
g_reg[E_IOP] = 1
g_reg[E_TOP] = SZ_MEMORY
# If scan_cursor, decode the input string and write the
# registers to the output file. Else, encode the output
# string and write the encoded string to the output file.
status = stg_encode (Memc[prog], g_mem, g_reg)
if (status == OK) {
nchars = g_reg[E_IOP] - 1
if (streq ("SC", cap)) {
call printf ("X(R1)=%d, Y(R2)=%d, key=%c\n")
call pargi (g_reg[1])
call pargi (g_reg[2])
call pargi (g_reg[3])
} else {
call printf ("encoding: ")
call sgc_dump (STDOUT, g_mem, nchars)
}
} else
call printf ("error encoding control string\n")
call printf (" status = %d\n")
call pargi (status)
}
} else if (len_prog == 0)
if (ttygetb (tty, cap))
call printf ("boolean capability is true\n")
else {
call printf ("device capability `%s' not found\n")
call pargstr (cap)
}
}
if (tty != NULL)
call ttycdes (tty)
call sfree (sp)
end
# SGC_DUMP -- Dump a sequence of ascii characters in printable form.
procedure sgc_dump (fd, data, nchars)
int fd # output file
char data[ARB] # chars to be dumped
int nchars
int ip
int col
begin
col = 1
for (ip=1; ip <= nchars; ip=ip+1) {
call putcc (fd, data[ip])
if (data[ip] == ':' && col > 60) {
call putci (fd, '\\')
call putci (fd, '\n')
col = 1
} else
col = col + 1
}
call putci (fd, '\n')
end
|