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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
#!/usr/bin/perl -w
use strict;
my $source = "Table.Codes";
my $html = 1;
my $test = 0;
# Syntax -----------------------------------------------------------------------
#
# Dotted.Name Text
# Dotted.Name
# Text
# Lines
#
# The dotted names have to be unique. Conceptually, they form a tree.
#
# Data Model ------------------------------------------------------------------
# This is currently pretty wierd.
#
# Empirically, we have
#
# NAME.head <Title Line>
# NAME.attr { lots ... }
# NAME.dflt Value ...
# NAME.code <Typ>|<Ide>|<Parm>
# NAME.text
# <text with some special tricks>
# NAME.table.TAB
# <"|"-separated head line>
# <"|"-separated data rows>
#
# Section.html
# <html-text>
#
# TABs
# - .XPS, used for instructions with subcodes
# Subcode|Emulation|Scope|Operation|Parameter|Meaning
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Analyze Source --------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
my $all = {};
my $state = 0;
my $name = '';
my $value = '';
sub parse
{
sub chkstate
{ my ($expect,$lineno,$line) = @_;
if ($state != $expect)
{
print STDERR "$source($lineno): line unexpected in state $state. : $line\n";
}
}
sub reduce
{
$all->{$name} = $value;
$state = 0;
$value = '';
}
open(CODES, $source) || die "cannot open file '" . $source . "'.";
while (<CODES>)
{
chop; # strip record separator
my @Fld = split(' ', $_);
if ($#Fld == -1)
{
reduce() if $state != 0;
}
elsif (substr($_, 0, 1) eq '#')
{
; #ignore
}
elsif (substr($_, 0, 1) eq ' ')
{ &chkstate(1,$.,$_);
$value .= ($value eq "" ? "" : "\n") . $_; #FIXME: unchop
}
else
{
reduce() if $state != 0;
$name = $Fld[0];
if ($#Fld == 0)
{
$state = 1;
}
else
{
$value = join ' ', @Fld[1..$#Fld];
reduce();
}
}
}
reduce() if ($state == 1);
chkstate(0,$.,$_);
return $all;
}
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Html Layout -----------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
sub head
{
if ($html)
{
print "<table>\n";
print "<tr><td width=10%%><td><td><td><td><td><td width=40%%>\n";
}
}
sub tail
{
if ($html)
{
print "</table>\n";
}
}
my $color1 = " bgcolor=\"#D0D0D0\""; # table head // section head
my $color2 = " bgcolor=\"#5BA5B2\""; # table body (even)
my $color3 = " bgcolor=\"#5188B2\""; # table body (odd)
my $color4 = ""; # code, default
my $color5 = ""; # text
sub txt2Html
{
my ($Doku) = @_;
$_ = $Doku;
s/</</g;
s/>/>/g;
s/\\ref:([A-Z0-9]+)/<a href=#$1>$1<\/a>/g;
s/\n \.\n/\n <p>\n/g;
return $_;
}
sub tqlayout
{ my ($Name, $Head, $Code, $Doku, $Dflt, $Attr) = @_;
if ($html)
{
print "<tr><td><p></td></tr>\n";
print "<tr><td $color1><a name=$Name>$Name</a>\n";
if ($Attr eq '')
{
print " <td $color1 colspan=6><b>$Head</b>\n";
}
else
{
print " <td colspan=5 $color1><b>$Head</b>\n";
print " <td $color1>$Attr\n";
}
if ($Code ne '')
{
my @Part = split('\|',$Code);
my $Type = $Part[0];
my $Indi = $#Part > 0 ? $Part[1] : "";
my $Parm = $#Part > 1 ? $Part[2] : "";
$Code = $Parm if $Type eq 'PRN';
$Code = $Indi if $Type eq 'CTL';
$Code = "ESC $Indi" if $Type eq 'ESC';
$Code = "0x7f" if $Type eq 'DEL';
$Code = "ESC # $Indi" if $Type eq 'HSH';
$Code = "ESC $Parm" if $Type eq 'SCS';
$Code = "ESC Y $Parm" if $Type eq 'VT5';
$Code = "ESC [ $Parm $Indi" if $Type eq 'CSI';
$Code = "ESC [ ? $Parm $Indi" if $Type eq 'PRI';
print "<tr><td><p></td>\n";
print "<tr><td>\n";
print " <td colspan=5 $color4>", codeToHtml($Code), "\n";
print " <td $color4>Default: $Dflt\n" if ($Dflt ne '');
}
print "<tr><td><p></td>\n";
print "<tr><td></td>\n";
# $_ = $Doku;
# s/</</g;
# s/>/>/g;
# s/\\ref:([A-Z0-9]+)/<a href=#$1>$1<\/a>/g;
# s/\n \.\n/\n <p>\n/g;
print " <td $color5 colspan=6>";
print txt2Html($Doku);
print "\n";
}
if ($test)
{
print "NAME: $Name\n";
print "TEXT: $Head\n";
print "CODE: $Code\n";
print "ATTR: $Attr\n";
print "DFLT: $Dflt\n";
# print "DOCU: $Doku\n";
}
}
sub codeToHtml
{ my ($code) = @_;
my $res = '<code>';
foreach (split(' ', $code))
{
/^\{(.*)\}$/ && do { $res .= " <em>$1</em>"; next; };
/^<$/ && do { $res .= ' <b><</b>'; next; };
/^>$/ && do { $res .= ' <b>></b>'; next; };
$res .= " <b>$_</b>";
}
return $res . '</code>';
}
# -----------------------------------------------------------------------------
sub secthead
{ my ($Title) = @_;
print "<h2>\n";
print "<table width=100%>\n";
print "<tr><td align=center bgcolor=#d0d0d0></td></tr>\n";
print "<tr><td align=center bgcolor=#d0d0d0>$Title</td></tr>\n";
print "<tr><td align=center bgcolor=#d0d0d0></td></tr>\n";
print "</table>\n";
print "</h2>\n";
}
sub tqlayout2
{ my ($Name, $Head, $Code) = @_;
my @Part = split('\|',$Code);
my $Type = $#Part > -1 ? $Part[0] : "";
my $Indi = $#Part > 0 ? $Part[1] : "";
my $Parm = $#Part > 1 ? $Part[2] : "";
if ($Type eq 'CTL')
{
$_ = $Indi;
s/0x00/@/; s/0x01/A/; s/0x02/B/; s/0x03/C/;
s/0x04/D/; s/0x05/E/; s/0x06/F/; s/0x07/G/;
s/0x08/H/; s/0x09/I/; s/0x0a/J/; s/0x0b/K/;
s/0x0c/L/; s/0x0d/M/; s/0x0e/N/; s/0x0f/O/;
s/0x10/P/; s/0x11/Q/; s/0x12/R/; s/0x13/S/;
s/0x14/T/; s/0x15/U/; s/0x16/V/; s/0x17/W/;
s/0x18/X/; s/0x19/Y/; s/0x1a/Z/; s/0x1b/[/;
s/0x1c/\\/; s/0x1d/]/; s/0x1e/^/; s/0x1f/_/;
$Indi = $_;
}
print "<tr>\n";
print "<td $color1><a href=#$Name>$Name</a>\n";
print "<td $color1>$Type\n";
print "<td $color1>$Indi\n";
print "<td $color1>$Parm\n";
print "<td $color1>$Head\n";
}
sub tqlayoutTable
{
my ($Head, $t, $Include) = @_;
my $p;
print "<tr><td colspan=5><h3>$Head</h3>\n";
foreach $p (sort keys %$t)
{
my @Fld = split('\.', $p);
if ($#Fld == 1 && $Fld[1] eq 'head')
{
my $name = $Fld[0];
my $head = $t->{$p};
my $attr = exists $t->{"$name.sect"}?$t->{"$name.sect"}:"";
if ($attr =~ /$Include/)
{
tqlayout2( $name, $head, exists $t->{"$name.code"}?$t->{"$name.code"}:"");
}
}
}
}
sub sortTest
{
my ($t) = @_;
my $p;
my $s = {};
my $n = {};
my $curr = "";
foreach $p (keys %$t)
{
my @Fld = split('\.', $p);
if ($#Fld == 1 && $Fld[1] eq 'head')
{
my $name = $Fld[0];
if (exists $t->{"$name.code"})
{
$s->{$t->{"$name.code"}} = $name;
}
}
}
print "<table>\n";
foreach $p (sort keys %$s)
{
my $name = $s->{$p};
my @Fld = split('\|', $p);
if ($Fld[0] ne $curr)
{
print "<tr><td colspan=5><h3>$Fld[0] codes</h3>\n";
}
$curr = $Fld[0];
tqlayout2($name,$t->{"$name.head"},$p);
}
print "</table>\n";
}
sub htmlsect
{
my ($h) = @_;
$_ = $all->{"$h.html"};
s/\n \.\n/\n <p>\n/g;
print "$_\n";
}
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# MAIN ------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
my $t = parse();
my $p;
my $table = 0;
# -------------------------------
htmlsect("Introduction");
# -------------------------------
secthead("Control Sequences");
htmlsect("Sequences");
# -------------------------------
secthead("Host to Terminal (Instructions by Code)");
sortTest($t);
# -------------------------------
secthead("Host to Terminal (Instructions by Group)");
htmlsect("Operations");
print "<table>\n";
tqlayoutTable("Commands (Character Display Operation)",$t,"Command\.Display");
tqlayoutTable("Commands (Rendition related status)",$t,"Command\.RenderMode");
tqlayoutTable("Commands (Cursor)",$t,"Command\.Cursor");
tqlayoutTable("Commands (Cursor related status)",$t,"Command\.CursMode");
tqlayoutTable("Commands (Edit)",$t,"Command\.Erase|Command\.Insert|Command.\Delete");
tqlayoutTable("Commands (Miscellaneous)",$t,"Command[^.]|Command\$");
tqlayoutTable("Commands (General mode setting)",$t,"Command\.SetMode");
tqlayoutTable("Commands (Miscellaneous status)",$t,"Command\.Mode");
tqlayoutTable("Commands (VT52)",$t,"Command\.VT52");
tqlayoutTable("Commands (Not implemented)",$t,"Command\.NoImp");
tqlayoutTable("Commands (Ignored)",$t,"Command\.Ignored");
tqlayoutTable("Commands (Requests)",$t,"Command\.Request");
print "</table>\n";
# -------------------------------
secthead("Terminal to Host");
print "<table>\n";
tqlayoutTable("Replies",$t,"Reply");
tqlayoutTable("Events",$t,"Event");
# -------------------------------
print "</table>\n";
secthead("Modes");
print "<table>\n";
tqlayoutTable("Modes",$t,"Mode");
#print "<h3>Other Codes</h3>\n";
print "</table>\n";
# -------------------------------
secthead("Appendix A - Notion Details");
htmlsect("ConceptDB");
# -------------------------------
head();
foreach $p (sort keys %$t)
{
my @Fld = split('\.', $p);
if ($#Fld == 1 && $Fld[1] eq 'head')
{
# print "</table>\n" if ($table);
my $name = $Fld[0];
my $head = $t->{$p};
tqlayout( $name, $head,
exists $t->{"$name.code"}?$t->{"$name.code"}:"",
exists $t->{"$name.text"}?$t->{"$name.text"}:"",
exists $t->{"$name.dflt"}?$t->{"$name.dflt"}:"",
exists $t->{"$name.emus"}?$t->{"$name.emus"}:"" );
$table = 0;
}
if ($html && $#Fld == 2 && $Fld[1] eq 'table')
{
my $lines = $t->{$p};
my $line;
my $field;
my @fldspan = ();
my $ln = 0;
print "<tr><td><p></td></tr>\n";
# print "<tr><td $color1>$Fld[2]</td><td $color1>Meaning</td></tr>\n";
foreach $line (split('\n', $lines))
{
my $fn = 0;
@fldspan = split('\|',$line) if ($ln == 0);
print "<tr>\n";
print "<td></td>\n";
foreach $field (split('\|',$line))
{
if ($ln == 0)
{
my @Parts = split(":",$field);
$field = $Parts[0];
$fldspan[$fn] = ($#Parts > 0) ? $Parts[1] : 1;
}
print "<td";
printf(" colspan=%s",$fldspan[$fn]);
print " $color1" if ($ln == 0);
print " $color2" if ($ln > 0 && $ln % 2 == 0);
print " $color3" if ($ln > 0 && $ln % 2 == 1);
print ">";
print txt2Html($field);
print "</td>";
$fn += 1;
}
print "</tr>\n";
$ln += 1;
}
$table = 1;
}
}
tail();
|