-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo2html
executable file
·735 lines (693 loc) · 25.2 KB
/
info2html
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
#!/usr/bin/perl
#---------------------------------------------------------
# info2html
#---------------------------------------------------------
#
# PURPOSE
# This perl script converts info nodes to HTML format.
#
# DESCRIPTION
# The node is specified on the command line using the
# syntax:
# (<infofile>)<tag>
#
# If <infofile> and/or <tag> are missing, (dir)Top is assumed.
#
# AUTHORS
# 2015.12.25 +A.M.Danischewski <adam_ lastname@not gamil.com>
# 2006.08.16 Jon Howell <jonh@cs.dartmouth.edu>
# 1995.08.04 Tim Witham <twitham@eng.fm.intel.com>
#
# ORIGINAL AUTHOR
# 11.10.93 Karl Guggisberg <guggis@iam.unibe.ch>
#
# HISTORY
# 11.10.93 V 1.0
# 14.10.93 V 1.0a some comments added
# 15.10.93 V 1.0b file for configuration settings
# 16.10.93 V 1.0c multiple info path possible
# some bugs in escaping references removed
# 28.6.94 V 1.0d some minor changes
# 8.4.95 V 1.1 bug fixes by Tim Witham
# <twitham@eng.fm.intel.com>
# 1998.05.05 V 1.2 bug fixes, added expires headers, added infocat,
# taken over web site maintenance.
# Jon Howell <jonh@cs.dartmouth.edu>
# 2006-08-16 V 2.0 Output HTML is tidier now. CSS added.
# Lots of new config vars added, so old config files
# may not work happily unless you tweak them a bit.
# Minor bugfixes to the (de)escaping logic.
# Minor typoes in comments fixed.
# 2015.12.25 V 2.1 Hacked into quasi PHP-CGI, removed CGI headers and
# and warnings. Changed configuration to auto-locate
# from the home directory of this script.
# +A.M.Danischewski <adam_ lastname@not gamil.com>
# 2015.12.27 V 2.1 Removed '.' from the first capture group of
# ParsHeaderToken, because some info pages have
# multiple .'s in their node name (e.g. Nasm).
#-------------------------------------------------------
require 5; # even though most of the code is in Perl 4 style.
$VERSION = "2.1";
# Getting the full path of the info2html.conf
$0 =~ m!(.*/)[^/]+$!;
use File::Basename;
$CURRENT_PATH=dirname(__FILE__);
$INFO2HTMLCONF = $CURRENT_PATH."/info2html.conf";
require($INFO2HTMLCONF); #-- configuration settings
$INFO2HTMLCSS = do { local(@ARGV, $/) = $CURRENT_PATH."/info2html.css"; <> };
$CSS_STYLE="<style>\n$INFO2HTMLCSS\n</style>";
use URI::Escape;
#-- patterns
$NODEBORDER = '\037\014?'; #-- delimiter of an info node
$REDIRSEP = '\177'; #-- delimiter in tag tables
$WS = '[ \t]+'; #-- white space +
$WSS = '[ \t]*'; #-- white space *
$TE = '[\t\,\.]'; #-- end of a tag
$TAG = '[^\t\,\.]+'; #-- pattern for a tag
$FTAG = '[^\)]+'; #-- pattern for a file name in
#-- a cross reference
#---------------------------------------------------------
# DieFileNotFound
#---------------------------------------------------------
# Replies and error message if the file '$FileName' is
# not accessible.
#---------------------------------------------------------
# Don't reveal where we're looking... --jonh 5/20/97 (and reapplied 5/4/1998)
sub DieFileNotFound{
local($FileName) = @_;
#-- TEXT : error message if a file could not be opened
print <<"EOF";
<!doctype html>
<html><head><title>Info Files - Error Message</title>
$BOTS_STAY_AWAY
$CSS_STYLE
$HTML_HEAD_STUFF</head><body class='error noopen'>
<h1>File IO Error</h1>
<p>The Info file could not be opened for reading.</p>
</body></html>
EOF
die "\n";
}
#---------------------------------------------------------
# Escape
#---------------------------------------------------------
sub Escape{
local($Tag) = @_;
return uri_escape($Tag);
}
#----------------------------------------------------------
# DeEscape
#----------------------------------------------------------
sub DeEscape{
local($Tag) = @_;
return uri_unescape($Tag);
}
#----------------------------------------------------------
# ParsHeaderToken
#----------------------------------------------------------
# Parses the heaer line of an info node for a specific
# link directive (e.g. Up, Prev)
#----------------------------------------------------------
sub ParsHeaderToken{
local($HL,$Token) = @_;
local($InfoFile,$Tag,$Temp);
return ("","") if $HL !~ /$Token:/; #-- token not available
$HL =~ m!$Token:$WS(\(($FTAG)\))!;
$InfoFile = $2;
$Temp = $2 ne "" ? '\('.$2.'\)' : "";
## +A.M.Danischewski 20151227 -- Removed the period from the first
## capture group, some info pages have multiple periods in the node
## name (e.g. Nasm).
$HL =~ m!$Token:$WS$Temp$WSS([^\t\,\n]+)?([\t\,\.\n])!;
$Tag = $1 ne "" ? $1 : "Top";
return $InfoFile,$Tag;
}
#---------------------------------------------------------
# ParsHeaderLine
#--------------------------------------------------------
# Parses the header line on an info node for all link
# directives allowed in a header line.
# Sometimes the keyword 'Previous' is found in stead of
# 'Prev'. That's why the redirection line is checked
# against both of these keywords.
#-------------------------------------------------------
sub ParsHeaderLine{
local($HL) = @_;
local(@LinkInfo,@LinkList);
#-- Node
@LinkInfo = &ParsHeaderToken($HL,"Node");
push(@LinkList,@LinkInfo);
#-- Next
@LinkInfo = &ParsHeaderToken($HL,"Next");
push(@LinkList,@LinkInfo);
#-- Up
@LinkInfo = &ParsHeaderToken($HL,"Up");
push(@LinkList,@LinkInfo);
#-- Prev or Previous
@LinkInfo = &ParsHeaderToken($HL,"Prev");
&ParsHeaderToken($HL,"Previous") if $LinkInfo[0] eq "" && $LinkInfo[1] eq "";
push(@LinkList,@LinkInfo);
return @LinkList;
}
############################################################
# turn tabs into correct number of spaces
#
sub Tab2Space {
local($line) = @_;
$line =~ s/^\t/ /; # 8 leading spaces if initial tab
while ($line =~ s/^([^\t]+)(\t)/$1 . ' ' x (8 - length($1) % 8)/e) {
} # replace each tab with right num of spaces
return $line;
}
#--------------------------------------------------------
# MenuItem2HTML
#--------------------------------------------------------
# Transform an info menu item in HTML with references
#-------------------------------------------------------
sub MenuItem2HTML{
local($Line,$BaseInfoFile) = @_;
local($MenuLinkTag,$MenuLinkFile,$MenuLinkRef,$MenuLinkText);
$Line = &Tab2Space($Line); # make sure columns line up well
if ($Line =~ /\* ([^:]+)::/){ # -- is a simple entry ending with :: ?
$MenuLinkTag = $1;
$MenuLinkRef = $1;
$MenuLinkText = $';
$MenuLinkFile = &Escape($BaseInfoFile);
} elsif ($Line =~ /\* ([^:]+):(\s*\(($FTAG)\)\.?)?(.*)$/) {
$MenuLinkFile = $BaseInfoFile;
$MenuLinkRef = $1;
$MenuLinkText = $4;
if ($2) {
$MenuLinkFile = $3;
$MenuLinkTag = 'Top';
$MenuLinkText = ($2 ? ' ' x (length($2)+1) : '') . "$4\n";
} else {
$Line = "$4\n";
if ($Line =~ /( *($TAG)?$TE(.*))$/) {
$MenuLinkTag = $2;
$MenuLinkText = $Line;
}
}
} else { # can't determine link, just show it
return $Line;
}
$MenuLinkTag = &Escape($MenuLinkTag); # -- escape special chars
# Yes, we routinely double-escape. Does anyone remember why?
#-- produce a HTML line
return "$MENU_DOT<a class='menux' href=\"info:$MenuLinkFile/$MenuLinkTag\">$MenuLinkRef</a>$MenuLinkText";
}
#-------------------------------------------------------------
# ReadIndirectTable
#------------------------------------------------------------
# Scans an info file for the occurence of an 'Indirect:'
# table. Scans the entries and returns two lists with the
# filenames and the global offsets.
#---------------------------------------------------------
sub ReadIndirectTable{
local($FileName,*InfoFiles,*Offsets) = @_;
local($i,$Next);
# open(FH1,$FileName) || &DieFileNotFound($FileName);
if ( $FileName =~ /^(.+)\.gz$/ ) {
open(FH1,"gunzip < " . $FileName . " 2>/dev/null |") || &DieFileNotFound($FileName);
} elsif ( $FileName =~ /^(.+)\.bz2$/ ) {
open(FH1,"bzcat " . $FileName . " 2>/dev/null |") || &DieFileNotFound($FileName);
} else {
open(FH1,$FileName) || &DieFileNotFound($FileName);
}
#-- scan for start of Indirect: Table
while(<FH1>){
$Next = <FH1> if /$NODEBORDER/;
last if $Next =~ /^Indirect:/i;
}
$i = 0;
#-- scan the entries and setup the arrays
while(<FH1>){
last if /$NODEBORDER/;
if(/([^:]+):[ \t]+(\d+)/){
push(@InfoFiles,$1);
push(@Offsets,$2);
}
}
close(FH1);
}
#---------------------------------------------------------
# ReadTagTable
#--------------------------------------------------------
# Reads in a tag table from an info file.
# Returns an associative array with the tags found.
# Tags are transformed to lower case (info is not
# case sensitive for tags).
# The entries in the associative array are of the
# form
# <file>#<offset>
# <file> may be empty if an indirect table is
# present or if the node is located in the
# main file.
# 'Exists' indicates if a tag table has been found.
# 'IsIndirect' indicates if the tag table is based
# on a indirect table.
#--------------------------------------------------------
sub ReadTagTable{
local($FileName,*TagList,*Exists,*IsIndirect) = @_;
local($File,$Offset);
if ( $FileName =~ /^(.+)\.gz$/ ) {
open(FH,"gunzip < " . $FileName . " 2>/dev/null |") || &DieFileNotFound($FileName);
} elsif ( $FileName =~ /^(.+)\.bz2$/ ) {
open(FH,"bzcat " . $FileName . " 2>/dev/null |") || &DieFileNotFound($FileName);
} else {
open(FH,$FileName) || &DieFileNotFound($FileName);
}
$Exists = 0;
$IsIndirect = 0;
#-- scan for start of tag table
while(<FH>){
if(/$NODEBORDER/){
if (<FH> =~ /^Tag table:/i){
$Exists = 1;
last;
}
}
}
#-- scan the entries
while (<FH>){
$IsIndirect = 1 if /^\(Indirect\)/i;
last if /$NODEBORDER/;
/Node:[ \t]+([^$REDIRSEP]+)$REDIRSEP(\d+)/;
$Tag = $1;
$Tag =~ y/A-Z/a-z/; #-- to lowercase
$Offset = $2;
if(/File:[ \t]+([^\t,]+)/){
$File = $1;
}
else{
$File = "";
}
$TagList{$Tag} = $File."#".$Offset;
}
close(FH);
}
#----------------------------------------------------------
# ParsCrossRefs
#----------------------------------------------------------
# scans a line for the existence of cross references and
# transforms them to HTML using a little icon
#----------------------------------------------------------
sub ParsCrossRefs{
local($prev,$Line,$BaseInfoFile) = @_;
local($NewLine,$Token) = ();
$Line = " ".$Line;
if ($prev =~ /\*Note([^\t\,\.]*)$/i) {
if ($Line =~ /^$TAG$TE/) {
$Line = "$prev-NEWLINE-$Line";
}
}
@Tokens = split(/(\*Note)\s*/i,$Line); # -- split the line
while($Token = shift @Tokens){
$CrossRefTag = $CrossRefRef = $CrossRefFile = $CrossRefText = '';
if($Token !~ /^\*Note/i){ #-- this part is pure text
$NewLine .= $Token;
next; #-- ... take the next part
}
$CrossRef = shift(@Tokens);
if ($CrossRef !~ /:/){ #-- seems not to be a valid cross ref.
$NewLine .= $Token.$CrossRef;
next; # -- ... take the next one
}
if ($CrossRef =~ /^([^:]+)::/){ # -- a simple cross ref..
$CrossRefTag = $1;
$CrossRefText = $';
$CrossRefRef = $CrossRefTag;
$CrossRefTag =~ s/-NEWLINE-/ /g;
$CrossRefTag =~ s/^\s+//;
$CrossRefTag =~ s/\s+/ /g;
$CrossRefRef =~ s/-NEWLINE-/\n/g;
$CrossRefTag = &Escape($CrossRefTag); # -- escape specials
$BaseInfoFile = &Escape($BaseInfoFile);
$NewLine .= "<a class='xref' title='a cross reference' href=\"info:$BaseInfoFile/$CrossRefTag\"\n>$CR_URL$CrossRefRef</a>$CrossRefText";
next; # -- .. take the next one
}
if ($CrossRef !~ /$TE/) { # never mind if tag doesn't end on this line
$NewLine .= $Token.$CrossRef;
next;
}
#print "--- Com. CR : $CrossRef --- \n";
$CrossRef =~ /([^:]+):/; #-- A more complicated one ..
$CrossRefRef = $1;
$CrossRef = $';
$CrossRefText = $CrossRef;
if ($CrossRef =~ /^(\s|\n|-NEWLINE-)*\(($FTAG)\)/){ #-- .. with another file ?
$CrossRefFile = $2;
$CrossRef = $';
}
$CrossRef =~ /^(\s|\n|-NEWLINE-)*($TAG)?($TE)/; #-- ... and a tag ?
$CrossRefTag = $2;
if ($CrossRefTag eq "" && $CrossRefFile eq ""){
$NewLine .= "*Note : $CrossRefText$3";
next;
}
$CrossRefTag =~ s/-NEWLINE-/ /g;
$CrossRefTag =~ s/^\s+//;
$CrossRefTag =~ s/\s+/ /g;
$CrossRefRef =~ s/-NEWLINE-/\n/g;
$CrossRefText =~ s/-NEWLINE-/\n/g;
$CrossRefFile = $BaseInfoFile if $CrossRefFile eq "";
$CrossRefTag = "Top" if $CrossRefTag eq "";
$CrossRefRef = "($CrossRefFile)$CrossRefTag" if $CrossRefRef eq '';
$CrossRefTag = &Escape($CrossRefTag); #-- escape specials
$CrossRefFile = &Escape($CrossRefFile);
#-- append the HTML text
$NewLine .= "<a class='xref' title='a cross reference' href=\"info:$CrossRefFile/$CrossRefTag\"\n>$CR_URL$CrossRefRef</a>$CrossRefText";
}
if ($NewLine =~ /\*Note([^\t\,\.]*)$/i) {
return "DONTPRINTYET $NewLine";
} else {
$NewLine; #-- return the new line
}
}
#-------------------------------------------------------------
# PrintLinkInfo
#-------------------------------------------------------------
# prints the HTML text for a link information in the
# header of an info node. Uses some URLs of icons
# are specified in 'info2html.conf'.
#------------------------------------------------------------
sub PrintLinkInfo{
local($LinkType,$LinkFile,$LinkTag,$BaseInfoFile,$NoKeys) = @_;
local($LinkFileEsc, $LinkAtts);
return if $LinkFile eq "" && $LinkTag eq "";
$LinkAtts = '';
#-- Link Type 'Prev'
if ($LinkType =~ /Prev/){
$LinkTypeText = $PREV_URL;
$LinkAtts = $NoKeys ? " title='$LinkType' "
: " accesskey='p' title='alt-p: previous' ";
}
#-- Link Type 'Up'
elsif($LinkType =~ /Up/){
$LinkTypeText = $UP_URL;
$LinkAtts = $NoKeys ? " title='$LinkType' "
: " accesskey='u' title='alt-u: up' ";
}
#-- Link Type 'Next'
elsif($LinkType =~ /Next/){
$LinkTypeText = $NEXT_URL;
$LinkAtts = $NoKeys ? " title='$LinkType' "
: " accesskey='n' title='alt-n: next' ";
}
#-- If no auxiliary file specified, use the current info file
$LinkFilePre = $LinkFile eq "" ? "" : "$LinkFile: ";
$LinkFile = $LinkFile eq "" ? $BaseInfoFile : $LinkFile;
$LinkRef = $LinkTag;
$LinkTag = &Escape($LinkTag);
$LinkFileEsc = &Escape($LinkFile);
#-- print the HTML Text
print <<"EOF";
<a href="info:$LinkFileEsc/$LinkTag" $LinkAtts
>$LinkTypeText
$LinkFilePre$LinkRef</a>
EOF
}
#-------------------------------------------------------------
# PrintHeader
#-------------------------------------------------------------
# Prints the header for an info node in HTML format
#------------------------------------------------------------
sub PrintHeader{
local(*LinkList,$BaseInfoFile) = @_;
#-- TEXT for the header of an info node
local $heading =
$LinkList[1] eq 'Top'
? "<h1 class='basetitle'>$BaseInfoFile</h1>"
: "<h2><em class='base'>$BaseInfoFile:</em> <span class='section'>$LinkList[1]</span></h2>"
;
print <<"EOF";
<!doctype html>
<html><head><title>Info: ($BaseInfoFile) $LinkList[1]</title>
$CSS_STYLE
$HTML_HEAD_STUFF</head><body class='node'>
EOF
if ($BaseInfoFile ne 'dir') {
print "\n<div class='nav navtop'\n>";
&PrintLinkInfo("Prev",$LinkList[6],$LinkList[7],$BaseInfoFile);
&PrintLinkInfo("Up", $LinkList[4],$LinkList[5],$BaseInfoFile);
&PrintLinkInfo("Next",$LinkList[2],$LinkList[3],$BaseInfoFile);
print "</div>";
}
print "\n\n$heading";
print "\n<pre>";
return;
}
#---------------------------------------------------------
# PrintFooter
#---------------------------------------------------------
# prints the footer for an info node in HTML format
#---------------------------------------------------------
sub PrintFooter{
local(*LinkList,$BaseInfoFile) =@_;
#-- TEXT for the footer of an info node
print "</pre>\n\n";
if ($BaseInfoFile ne 'dir') {
print "<div class='nav navbottom'\n>";
&PrintLinkInfo("Prev",$LinkList[6],$LinkList[7],$BaseInfoFile,1);
&PrintLinkInfo("Up", $LinkList[4],$LinkList[5],$BaseInfoFile,1);
&PrintLinkInfo("Next",$LinkList[2],$LinkList[3],$BaseInfoFile,1);
print "</div>\n";
}
print "<!-- info2html v$VERSION -->\n";
print "</body></html>\n";
return;
}
#----------------------------------------------------------
# ReplyNotFoundMessage
#----------------------------------------------------------
sub ReplyNotFoundMessage{
local($FileName,$Tag) = @_;
print <<"EOF";
<!doctype html>
<html><head><title>Info Files - Error Message</title>
$BOTS_STAY_AWAY
$CSS_STYLE
$HTML_HEAD_STUFF</head><body class='error nonesuch'>
<h1>Error: Page not found</h1>
<p>The Info node <q>$Tag</q> in Info file <em>$FileName</em>
does not exist.</p>
</body></html>
EOF
}
#-----------------------------------------------------------
# InfoNode2HTML
#-----------------------------------------------------------
# scans an info file for the node with the name '$Tag'
# starting at the postion '$Offset'.
# If found, the node is translated to HTML and printed.
#------------------------------------------------------------
sub InfoNode2HTML{
local($FileName,$Offset,$Tag,$BaseInfoFile) = @_;
local($Found);
if ( $FileName =~ /^(.+)\.gz$/ ) {
open(FH2,"gunzip < " . $FileName . " 2>/dev/null |") || &DieFileNotFound($FileName);
} elsif ( $FileName =~ /^(.+)\.bz2$/ ) {
open(FH2,"bzcat " . $FileName . " 2>/dev/null |") || &DieFileNotFound($FileName);
} else {
open(FH2,$FileName) || &DieFileNotFound($FileName);
}
seek(FH2,$Offset,0);
$Tag =~ y/A-Z/a-z/; # -- to lowercase
#-- scan for the node start
$Found = 0;
while(<FH2>){
if (/$NODEBORDER/){
$Line = <FH2>;
@LinkList = &ParsHeaderLine($Line);
$CompareTag = $Tag;
$CompareTag =~ s/([^0-9A-Za-z])/\\$1/g; #-- escape special chars
$Temp = $LinkList[1];
$Temp =~ y/A-Z/a-z/; #-- to lower case
if($Temp =~ /^\s*$CompareTag\s*$/){ #-- node start found ?
$Found = 1;
last;
}
}
}
if($Found == 0){ # -- break if not found
&ReplyNotFoundMessage($FileName,$Tag);
return;
}
&PrintHeader(*LinkList,$BaseInfoFile);
$InMenu = 0;
while(<FH2>){
last if /$NODEBORDER/;
#-- replace metacharacters
s/&/&/g;
s/>/>/g;
s/</</g;
if (/^\* Menu/ && $InMenu ==0) { #-- start of menu section ?
$InMenu = 1;
print "</pre>\n<h3>Menu</h3>\n<pre class='menu'>";
}
elsif (/^\* / && $InMenu == 1) { #-- a menu entry ?
$Line = &MenuItem2HTML($_,$BaseInfoFile);
print $Line;
}
else { #-- a normal line, just replace cross refs
$Line = &ParsCrossRefs($prev,$_,$BaseInfoFile);
if ($Line =~ /^DONTPRINTYET (.*)$/) {
$prev = $1;
} else {
$prev = $Line;
$Line =~ s!- (Variable|Function|Macro|Command|Special Form|User Option):.*$!<em>$&</em>!;
print $Line;
}
}
}
close(FH2);
&PrintFooter(*LinkList,$BaseInfoFile);
}
#-------------------------------------------------------------
# max
#------------------------------------------------------------
sub max{
local($a,$b) = @_;
return $a >= $b ? $a : $b;
}
#-----------------------------------------------------------
# GetFileAndOffset
#------------------------------------------------------------
# This procedure locates a specific node in a info file
# The location is based on the tag and indirect table in
# basic info file if such tables are available.
# Because the offsets specified in the tag and in the
# indirect tables are more or less inaccurate, the computed
# offset is set back 100 bytes. From this position
# the specified node will be looked for sequentially.
#------------------------------------------------------------
sub GetFileAndOffset{
local($BaseInfoFile,$NodeName) = @_;
local($Exists,$IsIndirect,$File,$Offset,$FileOffset);
$NodeName =~ y/A-Z/a-z/;
&ReadIndirectTable($BaseInfoFile,*FileNames,*Offsets);
&ReadTagTable($BaseInfoFile,*TagList,*Exists,*IsIndirect);
if ($Exists == 0){ #-- no tag table available
return "",0;
}
if (! defined $TagList{$NodeName}){ #-- tag is not in the tag table
return "",0;
}
($File,$Offset) = split(/#/,$TagList{$NodeName});
return $File, &max($Offset-100,0) if $File ne ""; #-- there is an
#-- explicite not in the tag table
if ($IsIndirect == 1){
for $i (0..$#Offsets){
if ($Offsets[$i] <= $Offset) { # cleaner if structure --jonh 1997.05.27
$FileOffset = $Offsets[$i];
$File = $FileNames[$i];
}
}
return $File, &max($Offset - $FileOffset - 100,0); #-- be safe (-100!)
}
else {
return "", &max($Offset - 100,0);
}
}
# FindFile: find the given file on the infopath, return full name or "".
# Let filenames optionally have .info suffix. Try named version first.
sub FindFile {
local($File) = @_;
local($Alt, $Name);
if ($File =~ /^(.+)\.info/) {
$Alt = $1;
} else {
$Alt = $File . '.info';
}
for $Name ($File, $File . '.gz', $File . '.bz2', $Alt, $Alt . '.gz', $Alt . '.bz2') {
for (@INFODIR) {
return "$_/$Name" if (-e "$_/$Name");
}
}
return "";
}
#-------------------------------------------------------
#
#------------------- MAIN -----------------------------
$PROGRAM = "info2html"; ## +A.M.Danischewski 20151225
$CommandLine = DeEscape($ARGV[0]); ## +A.M.Danischewski 20151225
if ($CommandLine =~ m#([^/]+)/(.+)#) { # <file>/<node>
$BaseInfoFile = &DeEscape($1);
$BaseInfoFile =~ s#\.\./##g; # jonh 5/20/97 -- sanitize up-references
$NodeName = &DeEscape($2);
} elsif( $CommandLine =~ /^([-_0-9a-zA-Z]+)$/) { # tolerate bare queries
$BaseInfoFile = &DeEscape($1);
$NodeName = 'Top';
} else {
$BaseInfoFile = 'dir';
$NodeName = 'Top';
}
$BaseInfoFile = "dir" if $BaseInfoFile =~ /^dir$/i;
$FileNameFull = &FindFile($BaseInfoFile);
($File,$Offset) = &GetFileAndOffset($FileNameFull,$NodeName);
$File = $BaseInfoFile if $File eq "";
$FileNameFull = &FindFile($File);
&InfoNode2HTML($FileNameFull,$Offset,$NodeName,$BaseInfoFile);
exit;
###############################################################################
# #
# Longer, more boring history #
# #
###############################################################################
# ----------------------------
# revision 1.12
# date: 1995/04/05 16:58:51; author: twitham; state: Exp; lines: +1 -0
# Emphasize variable, function, macro, etc. definitions.
# ----------------------------
# revision 1.11
# date: 1995/04/05 16:37:51; author: twitham; state: Exp; lines: +5 -5
# Fixed bug: (file) references must be next to the *Note blah:
# ----------------------------
# revision 1.10
# date: 1995/04/05 15:24:25; author: twitham; state: Exp; lines: +3 -3
# Fixed bug: node name was matching as substring of longer node names.
# ----------------------------
# revision 1.9
# date: 1995/04/04 23:27:14; author: twitham; state: Exp; lines: +1 -0
# Fixed bug of cross ref variables being used again within a page.
# ----------------------------
# revision 1.8
# date: 1995/04/04 23:05:52; author: twitham; state: Exp; lines: +2 -2
# Added some spaces for clarity.
# ----------------------------
# revision 1.7
# date: 1995/04/04 23:01:02; author: twitham; state: Exp; lines: +8 -9
# Cleaned up the HTML.
# ----------------------------
# revision 1.6
# date: 1995/04/04 22:25:34; author: twitham; state: Exp; lines: +51 -26
# Got multi-line cross references working.
# ----------------------------
# revision 1.5
# date: 1995/01/19 01:43:02; author: twitham; state: Exp; lines: +27 -32
# Changed to use (dir)Top as default,
# and to make links relative to current page.
# ----------------------------
# revision 1.4
# date: 1995/01/17 01:23:10; author: twitham; state: Exp; lines: +24 -20
# Cleaned up .info filename suffix option.
# ----------------------------
# revision 1.3
# date: 1995/01/14 01:52:33; author: twitham; state: Exp; lines: +61 -42
# Lined up columns in menus, got indexes working, many other improvements.
# ----------------------------
# revision 1.2
# date: 1995/01/13 16:33:33; author: twitham; state: Exp; lines: +2 -10
# almost working at this site.
# ----------------------------
# revision 1.1
# date: 1995/01/13 16:33:04; author: twitham; state: Exp;
# Initial revision
#
# V 1.0d
#
# Minor changes from 1.0b are
#
# update to cgi specification
# escaping/deescaping removed
# error messages in english