-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
texi2html
executable file
·2021 lines (1916 loc) · 52 KB
/
texi2html
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
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
'di ';
'ig 00 ';
#+##############################################################################
# #
# File: texi2html #
# #
# Description: Program to transform most Texinfo documents to HTML #
# #
#-##############################################################################
# @(#)texi2html 1.51 09/10/96 Written (mainly) by Lionel Cons, Lionel.Cons@cern.ch
# The man page for this program is included at the end of this file and can be
# viewed using the command 'nroff -man texi2html'.
# Please read the copyright at the end of the man page.
#+++############################################################################
# #
# Constants #
# #
#---############################################################################
$DEBUG_TOC = 1;
$DEBUG_INDEX = 2;
$DEBUG_BIB = 4;
$DEBUG_GLOSS = 8;
$DEBUG_DEF = 16;
$DEBUG_HTML = 32;
$DEBUG_USER = 64;
$BIBRE = '\[[\w\/]+\]'; # RE for a bibliography reference
$FILERE = '[\/\w.+-]+'; # RE for a file name
$VARRE = '[^\s\{\}]+'; # RE for a variable name
$NODERE = '[^@{}:\'`",]+'; # RE for a node name
$NODESRE = '[^@{}:\'`"]+'; # RE for a list of node names
$XREFRE = '[^@{}]+'; # RE for a xref (should use NODERE)
$ERROR = "***"; # prefix for errors and warnings
$THISPROG = "texi2html 1.51"; # program name and version
$HOMEPAGE = "http://wwwcn.cern.ch/dci/texi2html/"; # program home page
$TODAY = &pretty_date; # like "20 September 1993"
$SPLITTAG = "<!-- SPLIT HERE -->\n"; # tag to know where to split
$PROTECTTAG = "_ThisIsProtected_"; # tag to recognize protected sections
$html2_doctype = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Strict Level 2//EN">';
#
# language dependent constants
#
#$LDC_SEE = 'see';
#$LDC_SECTION = 'section';
#$LDC_IN = 'in';
#$LDC_TOC = 'Table of Contents';
#$LDC_GOTO = 'Go to the';
#$LDC_FOOT = 'Footnotes';
# TODO: @def* shortcuts
#
# pre-defined indices
#
%predefined_index = (
'cp', 'c',
'fn', 'f',
'vr', 'v',
'ky', 'k',
'pg', 'p',
'tp', 't',
);
#
# valid indices
#
%valid_index = (
'c', 1,
'f', 1,
'v', 1,
'k', 1,
'p', 1,
't', 1,
);
#
# texinfo section names to level
#
%sec2level = (
'top', 0,
'chapter', 1,
'unnumbered', 1,
'majorheading', 1,
'chapheading', 1,
'appendix', 1,
'section', 2,
'unnumberedsec', 2,
'heading', 2,
'appendixsec', 2,
'appendixsection', 2,
'subsection', 3,
'unnumberedsubsec', 3,
'subheading', 3,
'appendixsubsec', 3,
'subsubsection', 4,
'unnumberedsubsubsec', 4,
'subsubheading', 4,
'appendixsubsubsec', 4,
);
#
# accent map, TeX command to ISO name
#
%accent_map = (
'"', 'uml',
'~', 'tilde',
'^', 'circ',
'`', 'grave',
'\'', 'acute',
);
#
# texinfo "simple things" (@foo) to HTML ones
#
%simple_map = (
# cf. makeinfo.c
"*", "<BR>", # HTML+
" ", " ",
"\n", "\n",
"|", "",
# spacing commands
":", "",
"!", "!",
"?", "?",
".", ".",
);
#
# texinfo "things" (@foo{}) to HTML ones
#
%things_map = (
'TeX', 'TeX',
'br', '<P>', # paragraph break
'bullet', '*',
'copyright', '(C)',
'dots', '...',
'equiv', '==',
'error', 'error-->',
'expansion', '==>',
'minus', '-',
'point', '-!-',
'print', '-|',
'result', '=>',
'today', $TODAY,
);
#
# texinfo styles (@foo{bar}) to HTML ones
#
%style_map = (
'asis', '',
'b', 'B',
'cite', 'CITE',
'code', 'CODE',
'ctrl', '&do_ctrl', # special case
'dfn', 'STRONG', # DFN tag is illegal in the standard
'dmn', '', # useless
'emph', 'EM',
'file', '"TT', # will put quotes, cf. &apply_style
'i', 'I',
'kbd', 'KBD',
'key', 'KBD',
'r', '', # unsupported
'samp', '"SAMP', # will put quotes, cf. &apply_style
'sc', '&do_sc', # special case
'strong', 'STRONG',
't', 'TT',
'titlefont', '', # useless
'var', 'VAR',
'w', '', # unsupported
);
#
# texinfo format (@foo/@end foo) to HTML ones
#
%format_map = (
'display', 'PRE',
'example', 'PRE',
'format', 'PRE',
'lisp', 'PRE',
'quotation', 'BLOCKQUOTE',
'smallexample', 'PRE',
'smalllisp', 'PRE',
# lists
'itemize', 'UL',
'enumerate', 'OL',
# poorly supported
'flushleft', 'PRE',
'flushright', 'PRE',
);
#
# texinfo definition shortcuts to real ones
#
%def_map = (
# basic commands
'deffn', 0,
'defvr', 0,
'deftypefn', 0,
'deftypevr', 0,
'defcv', 0,
'defop', 0,
'deftp', 0,
# basic x commands
'deffnx', 0,
'defvrx', 0,
'deftypefnx', 0,
'deftypevrx', 0,
'defcvx', 0,
'defopx', 0,
'deftpx', 0,
# shortcuts
'defun', 'deffn Function',
'defmac', 'deffn Macro',
'defspec', 'deffn {Special Form}',
'defvar', 'defvr Variable',
'defopt', 'defvr {User Option}',
'deftypefun', 'deftypefn Function',
'deftypevar', 'deftypevr Variable',
'defivar', 'defcv {Instance Variable}',
'defmethod', 'defop Method',
# x shortcuts
'defunx', 'deffnx Function',
'defmacx', 'deffnx Macro',
'defspecx', 'deffnx {Special Form}',
'defvarx', 'defvrx Variable',
'defoptx', 'defvrx {User Option}',
'deftypefunx', 'deftypefnx Function',
'deftypevarx', 'deftypevrx Variable',
'defivarx', 'defcvx {Instance Variable}',
'defmethodx', 'defopx Method',
);
#
# things to skip
#
%to_skip = (
# comments
'c', 1,
'comment', 1,
# useless
'contents', 1,
'shortcontents', 1,
'summarycontents', 1,
'footnotestyle', 1,
'end ifclear', 1,
'end ifset', 1,
'titlepage', 1,
'end titlepage', 1,
# unsupported commands (formatting)
'afourpaper', 1,
'cropmarks', 1,
'finalout', 1,
'headings', 1,
'need', 1,
'page', 1,
'setchapternewpage', 1,
'everyheading', 1,
'everyfooting', 1,
'evenheading', 1,
'evenfooting', 1,
'oddheading', 1,
'oddfooting', 1,
'smallbook', 1,
'vskip', 1,
'filbreak', 1,
# unsupported formats
'cartouche', 1,
'end cartouche', 1,
'group', 1,
'end group', 1,
);
#+++############################################################################
# #
# Argument parsing, initialisation #
# #
#---############################################################################
$use_bibliography = 1;
$use_acc = 0;
$debug = 0;
$doctype = '';
$check = 0;
$expandinfo = 0;
$use_glossary = 0;
$invisible_mark = '';
$use_iso = 0;
@include_dirs = ();
$show_menu = 0;
$number_sections = 0;
$split_node = 0;
$split_chapter = 0;
$monolithic = 0;
$verbose = 0;
$usage = <<EOT;
This is $THISPROG
To convert a Texinfo file to HMTL: $0 [options] file
where options can be:
-expandinfo : use \@ifinfo sections, not \@iftex
-glossary : handle a glossary
-invisible name: use 'name' as an invisible anchor
-I dir : search also for files in 'dir'
-menu : handle menus
-monolithic : output only one file including ToC
-number : number sections
-split_chapter : split on main sections
-split_node : split on nodes
-usage : print usage instructions
-verbose : verbose output
To check converted files: $0 -check [-verbose] files
EOT
while ($#ARGV >= 0 && $ARGV[0] =~ /^-/) {
$_ = shift(@ARGV);
if (/^-acc$/) { $use_acc = 1; next; }
if (/^-d(ebug)?(\d+)?$/) { $debug = $2 || shift(@ARGV); next; }
if (/^-doctype$/) { $doctype = shift(@ARGV); next; }
if (/^-c(heck)?$/) { $check = 1; next; }
if (/^-e(xpandinfo)?$/) { $expandinfo = 1; next; }
if (/^-g(lossary)?$/) { $use_glossary = 1; next; }
if (/^-i(nvisible)?$/) { $invisible_mark = shift(@ARGV); next; }
if (/^-iso$/) { $use_iso = 1; next; }
if (/^-I(.+)?$/) { push(@include_dirs, $1 || shift(@ARGV)); next; }
if (/^-m(enu)?$/) { $show_menu = 1; next; }
if (/^-mono(lithic)?$/) { $monolithic = 1; next; }
if (/^-n(umber)?$/) { $number_sections = 1; next; }
if (/^-s(plit)?_?(n(ode)?|c(hapter)?)?$/) {
if ($2 =~ /^n/) {
$split_node = 1;
} else {
$split_chapter = 1;
}
next;
}
if (/^-v(erbose)?$/) { $verbose = 1; next; }
die $usage;
}
if ($check) {
die $usage unless @ARGV > 0;
✓
exit;
}
if (($split_node || $split_chapter) && $monolithic) {
warn "Can't use -monolithic with -split, -monolithic ignored.\n";
$monolithic = 0;
}
if ($expandinfo) {
$to_skip{'ifinfo'}++;
$to_skip{'end ifinfo'}++;
} else {
$to_skip{'iftex'}++;
$to_skip{'end iftex'}++;
}
$invisible_mark = '<IMG SRC="invisible.xbm">' if $invisible_mark eq 'xbm';
die $usage unless @ARGV == 1;
$docu = shift(@ARGV);
if ($docu =~ /.*\//) {
chop($docu_dir = $&);
$docu_name = $';
} else {
$docu_dir = '.';
$docu_name = $docu;
}
unshift(@include_dirs, $docu_dir);
$docu_name =~ s/\.te?x(i|info)?$//; # basename of the document
$docu_doc = "$docu_name.html"; # document's contents
if ($monolithic) {
$docu_toc = $docu_foot = $docu_doc;
} else {
$docu_toc = "${docu_name}_toc.html"; # document's table of contents
$docu_foot = "${docu_name}_foot.html"; # document's footnotes
}
#
# variables
#
%value = (); # hold texinfo variables
$value{'html'} = 1; # predefine html (the output format)
$value{'texi2html'} = '1.51'; # predefine texi2html (the translator)
# _foo: internal to track @foo
foreach ('_author', '_title', '_subtitle',
'_settitle', '_setfilename') {
$value{$_} = ''; # prevent -w warnings
}
%node2sec = (); # node to section name
%node2href = (); # node to HREF
%bib2href = (); # bibliography reference to HREF
%gloss2href = (); # glossary term to HREF
@sections = (); # list of sections
%tag2pro = (); # protected sections
#
# initial indexes
#
$bib_num = 0;
$foot_num = 0;
$gloss_num = 0;
$idx_num = 0;
$sec_num = 0;
$doc_num = 0;
$html_num = 0;
#
# can I use ISO8879 characters? (HTML+)
#
if ($use_iso) {
$things_map{'bullet'} = "•";
$things_map{'copyright'} = "©";
$things_map{'dots'} = "…";
$things_map{'equiv'} = "≡";
$things_map{'expansion'} = "→";
$things_map{'point'} = "∗";
$things_map{'result'} = "⇒";
}
#
# read texi2html extensions (if any)
#
$extensions = 'texi2html.ext'; # extensions in working directory
if (-f $extensions) {
print "# reading extensions from $extensions\n" if $verbose;
require($extensions);
}
($progdir = $0) =~ s/[^\/]+$//;
if ($progdir && ($progdir ne './')) {
$extensions = "${progdir}texi2html.ext"; # extensions in texi2html directory
if (-f $extensions) {
print "# reading extensions from $extensions\n" if $verbose;
require($extensions);
}
}
print "# reading from $docu\n" if $verbose;
#+++############################################################################
# #
# Pass 1: read source, handle command, variable, simple substitution #
# #
#---############################################################################
@lines = (); # whole document
@toc_lines = (); # table of contents
$toplevel = 0; # top level seen in hierarchy
$curlevel = 0; # current level in TOC
$node = ''; # current node name
$in_table = 0; # am I inside a table
$table_type = ''; # type of table ('', 'f', 'v')
@tables = (); # nested table support
$in_bibliography = 0; # am I inside a bibliography
$in_glossary = 0; # am I inside a glossary
$in_top = 0; # am I inside the top node
$in_pre = 0; # am I inside a preformatted section
$in_list = 0; # am I inside a list
$in_html = 0; # am I inside an HTML section
$first_line = 1; # is it the first line
$dont_html = 0; # don't protect HTML on this line
$split_num = 0; # split index
$deferred_ref = ''; # deferred reference for indexes
@html_stack = (); # HTML elements stack
$html_element = ''; # current HTML element
&html_reset;
# build code for simple substitutions
# the maps used (%simple_map and %things_map) MUST be aware of this
# watch out for regexps, / and escaped characters!
$subst_code = '';
foreach (keys(%simple_map)) {
($re = $_) =~ s/(\W)/\\$1/g; # protect regexp chars
$subst_code .= "s/\\\@$re/$simple_map{$_}/g;\n";
}
foreach (keys(%things_map)) {
$subst_code .= "s/\\\@$_\\{\\}/$things_map{$_}/g;\n";
}
if ($use_acc) {
# accentuated characters
foreach (keys(%accent_map)) {
if ($_ eq "`") {
$subst_code .= "s/$;3";
} elsif ($_ eq "'") {
$subst_code .= "s/$;4";
} else {
$subst_code .= "s/\\\@\\$_";
}
$subst_code .= "([aeiou])/&\${1}$accent_map{$_};/gi;\n";
}
}
eval("sub simple_substitutions { $subst_code }");
&init_input;
while ($_ = &next_line) {
#
# remove \input on the first lines only
#
if ($first_line) {
next if /^\\input/;
$first_line = 0;
}
#
# parse texinfo tags
#
$tag = '';
$end_tag = '';
if (/^\@end\s+(\w+)\b/) {
$end_tag = $1;
} elsif (/^\@(\w+)\b/) {
$tag = $1;
}
#
# handle @ifhtml / @end ifhtml
#
if ($in_html) {
if ($end_tag eq 'ifhtml') {
$in_html = 0;
} else {
$tag2pro{$in_html} .= $_;
}
next;
} elsif ($tag eq 'ifhtml') {
$in_html = $PROTECTTAG . ++$html_num;
push(@lines, $in_html);
next;
}
#
# try to skip the line
#
if ($end_tag) {
next if $to_skip{"end $end_tag"};
} elsif ($tag) {
next if $to_skip{$tag};
last if $tag eq 'bye';
}
if ($in_top) {
# parsing the top node
if ($tag eq 'node' || $tag eq 'include' || $sec2level{$tag}) {
# no more in top
$in_top = 0;
} else {
# skip it
next;
}
}
#
# try to remove inlined comments
# syntax from tex-mode.el comment-start-skip
#
s/((^|[^\@])(\@\@)*)\@c(omment)? .*/$1/;
# non-@ substitutions cf. texinfmt.el
s/``/\"/g;
s/''/\"/g;
s/([\w ])---([\w ])/$1--$2/g;
#
# analyze the tag
#
if ($tag) {
# skip lines
&skip_until($tag), next if $tag eq 'ignore';
if ($expandinfo) {
&skip_until($tag), next if $tag eq 'iftex';
} else {
&skip_until($tag), next if $tag eq 'ifinfo';
}
&skip_until($tag), next if $tag eq 'tex';
# handle special tables
if ($tag eq 'table') {
$table_type = '';
} elsif ($tag eq 'ftable') {
$tag = 'table';
$table_type = 'f';
} elsif ($tag eq 'vtable') {
$tag = 'table';
$table_type = 'v';
}
# special cases
if ($tag eq 'top' || ($tag eq 'node' && /^\@node\s+top\s*,/i)) {
$in_top = 1;
@lines = (); # ignore all lines before top (title page garbage)
next;
} elsif ($tag eq 'node') {
$in_top = 0;
warn "$ERROR Bad node line: $_" unless $_ =~ /^\@node\s$NODESRE$/o;
$_ = &protect_html($_); # if node contains '&' for instance
s/^\@node\s+//;
($node) = split(/,/);
&normalise_node($node);
if ($split_node) {
&next_doc;
push(@lines, $SPLITTAG) if $split_num++;
push(@sections, $node);
}
next;
} elsif ($tag eq 'include') {
if (/^\@include\s+($FILERE)\s*$/o) {
$file = $1;
unless (-e $file) {
foreach $dir (@include_dirs) {
$file = "$dir/$1";
last if -e $file;
}
}
if (-e $file) {
&open($file);
print "# including $file\n" if $verbose;
} else {
warn "$ERROR Can't find $file, skipping";
}
} else {
warn "$ERROR Bad include line: $_";
}
next;
} elsif ($tag eq 'ifclear') {
if (/^\@ifclear\s+($VARRE)\s*$/o) {
next unless defined($value{$1});
&skip_until($tag);
} else {
warn "$ERROR Bad ifclear line: $_";
}
next;
} elsif ($tag eq 'ifset') {
if (/^\@ifset\s+($VARRE)\s*$/o) {
next if defined($value{$1});
&skip_until($tag);
} else {
warn "$ERROR Bad ifset line: $_";
}
next;
} elsif ($tag eq 'menu') {
unless ($show_menu) {
&skip_until($tag);
next;
}
&html_push_if($tag);
push(@lines, &html_debug("\n", __LINE__));
} elsif ($format_map{$tag}) {
$in_pre = 1 if $format_map{$tag} eq 'PRE';
&html_push_if($format_map{$tag});
push(@lines, &html_debug("\n", __LINE__));
$in_list++ if $format_map{$tag} eq 'UL' || $format_map{$tag} eq 'OL' ;
push(@lines, &debug("<$format_map{$tag}>\n", __LINE__));
next;
} elsif ($tag eq 'table') {
if (/^\@[fv]?table\s+\@(\w+)\s*$/) {
$in_table = $1;
unshift(@tables, join($;, $table_type, $in_table));
push(@lines, &debug("<DL COMPACT>\n", __LINE__));
&html_push_if('DL');
push(@lines, &html_debug("\n", __LINE__));
} else {
warn "$ERROR Bad table line: $_";
}
next;
} elsif ($tag eq 'synindex' || $tag eq 'syncodeindex') {
if (/^\@$tag\s+(\w)\w\s+(\w)\w\s*$/) {
eval("*${1}index = *${2}index");
} else {
warn "$ERROR Bad syn*index line: $_";
}
next;
} elsif ($tag eq 'sp') {
push(@lines, &debug("<P>\n", __LINE__));
next;
} elsif ($tag eq 'setref') {
&protect_html; # if setref contains '&' for instance
if (/^\@$tag\s*{($NODERE)}\s*$/) {
$setref = $1;
$setref =~ s/\s+/ /g; # normalize
$setref =~ s/ $//;
$node2sec{$setref} = $name;
$node2href{$setref} = "$docu_doc#$docid";
} else {
warn "$ERROR Bad setref line: $_";
}
next;
} elsif ($tag eq 'defindex' || $tag eq 'defcodeindex') {
if (/^\@$tag\s+(\w\w)\s*$/) {
$valid_index{$1} = 1;
} else {
warn "$ERROR Bad defindex line: $_";
}
next;
} elsif (defined($def_map{$tag})) {
if ($def_map{$tag}) {
s/^\@$tag\s+//;
$tag = $def_map{$tag};
$_ = "\@$tag $_";
$tag =~ s/\s.*//;
}
} elsif (defined($user_sub{$tag})) {
s/^\@$tag\s+//;
$sub = $user_sub{$tag};
print "# user $tag = $sub, arg: $_" if $debug & $DEBUG_USER;
if (defined(&$sub)) {
chop($_);
&$sub($_);
} else {
warn "$ERROR Bad user sub for $tag: $sub\n";
}
next;
}
if (defined($def_map{$tag})) {
s/^\@$tag\s+//;
if ($tag =~ /x$/) {
# extra definition line
$tag = $`;
$is_extra = 1;
} else {
$is_extra = 0;
}
while (/\{([^\{\}]*)\}/) {
# this is a {} construct
($before, $contents, $after) = ($`, $1, $');
# protect spaces
$contents =~ s/\s+/$;9/g;
# restore $_ protecting {}
$_ = "$before$;7$contents$;8$after";
}
@args = split(/\s+/, &protect_html($_));
foreach (@args) {
s/$;9/ /g; # unprotect spaces
s/$;7/\{/g; # ... {
s/$;8/\}/g; # ... }
}
$type = shift(@args);
$type =~ s/^\{(.*)\}$/$1/;
print "# def ($tag): {$type} ", join(', ', @args), "\n"
if $debug & $DEBUG_DEF;
$type .= ':'; # it's nicer like this
$name = shift(@args);
$name =~ s/^\{(.*)\}$/$1/;
if ($is_extra) {
$_ = &debug("<DT>", __LINE__);
} else {
$_ = &debug("<DL>\n<DT>", __LINE__);
}
if ($tag eq 'deffn' || $tag eq 'defvr' || $tag eq 'deftp') {
$_ .= "<U>$type</U> <B>$name</B>";
$_ .= " <I>@args</I>" if @args;
} elsif ($tag eq 'deftypefn' || $tag eq 'deftypevr'
|| $tag eq 'defcv' || $tag eq 'defop') {
$ftype = $name;
$name = shift(@args);
$name =~ s/^\{(.*)\}$/$1/;
$_ .= "<U>$type</U> $ftype <B>$name</B>";
$_ .= " <I>@args</I>" if @args;
} else {
warn "$ERROR Unknown definition type: $tag\n";
$_ .= "<U>$type</U> <B>$name</B>";
$_ .= " <I>@args</I>" if @args;
}
$_ .= &debug("\n<DD>", __LINE__);
$name = &unprotect_html($name);
if ($tag eq 'deffn' || $tag eq 'deftypefn') {
unshift(@input_spool, "\@findex $name\n");
} elsif ($tag eq 'defop') {
unshift(@input_spool, "\@findex $name on $ftype\n");
} elsif ($tag eq 'defvr' || $tag eq 'deftypevr' || $tag eq 'defcv') {
unshift(@input_spool, "\@vindex $name\n");
} else {
unshift(@input_spool, "\@tindex $name\n");
}
$dont_html = 1;
}
} elsif ($end_tag) {
if ($format_map{$end_tag}) {
$in_pre = 0 if $format_map{$end_tag} eq 'PRE';
$in_list-- if $format_map{$end_tag} eq 'UL' || $format_map{$end_tag} eq 'OL' ;
&html_pop_if('LI', 'P');
&html_pop_if();
push(@lines, &debug("</$format_map{$end_tag}>\n", __LINE__));
push(@lines, &html_debug("\n", __LINE__));
} elsif ($end_tag eq 'table' ||
$end_tag eq 'ftable' ||
$end_tag eq 'vtable') {
shift(@tables);
if (@tables) {
($table_type, $in_table) = split($;, $tables[0]);
} else {
$in_table = 0;
}
push(@lines, "</DL>\n");
&html_pop_if('DD');
&html_pop_if();
} elsif (defined($def_map{$end_tag})) {
push(@lines, &debug("</DL>\n", __LINE__));
} elsif ($end_tag eq 'menu') {
&html_pop_if();
push(@lines, $_); # must keep it for pass 2
}
next;
}
#
# misc things
#
# protect texi and HTML things
&protect_texi;
$_ = &protect_html($_) unless $dont_html;
$dont_html = 0;
# substitution (unsupported things)
s/^\@center\s+//g;
s/^\@exdent\s+//g;
s/\@noindent\s+//g;
s/\@refill\s+//g;
# other substitutions
&simple_substitutions;
s/\@value{($VARRE)}/$value{$1}/eg;
s/\@footnote\{/\@footnote$docu_doc\{/g; # mark footnotes, cf. pass 4
#
# analyze the tag again
#
if ($tag) {
if (defined($sec2level{$tag}) && $sec2level{$tag} > 0) {
if (/^\@$tag\s+(.+)$/) {
$name = $1;
$name =~ s/\s+$//;
$level = $sec2level{$tag};
$name = &update_sec_num($tag, $level) . " $name"
if $number_sections && $tag !~ /^unnumbered/;
if ($tag =~ /heading$/) {
push(@lines, &html_debug("\n", __LINE__));
if ($html_element ne 'body') {
# We are in a nice pickle here. We are trying to get a H? heading
# even though we are not in the body level. So, we convert it to a
# nice, bold, line by itself.
$_ = &debug("\n\n<P><STRONG>$name</STRONG></P>\n\n", __LINE__);
} else {
$_ = &debug("<H$level>$name</H$level>\n", __LINE__);
&html_push_if('body');
}
print "# heading, section $name, level $level\n"
if $debug & $DEBUG_TOC;
} else {
if ($split_chapter) {
unless ($toplevel) {
# first time we see a "section"
unless ($level == 1) {
warn "$ERROR The first section found is not of level 1: $_";
warn "$ERROR I'll split on sections of level $level...\n";
}
$toplevel = $level;
}
if ($level == $toplevel) {
&next_doc;
push(@lines, $SPLITTAG) if $split_num++;
push(@sections, $name);
}
}
$sec_num++;
$docid = "SEC$sec_num";
$tocid = "TOC$sec_num";
# check biblio and glossary
$in_bibliography = ($name =~ /^([A-Z]|\d+)?(\.\d+)*\s*bibliography$/i);
$in_glossary = ($name =~ /^([A-Z]|\d+)?(\.\d+)*\s*glossary$/i);
# check node
if ($node) {
if ($node2sec{$node}) {
warn "$ERROR Duplicate node found: $node\n";
} else {
$node2sec{$node} = $name;
$node2href{$node} = "$docu_doc#$docid";
print "# node $node, section $name, level $level\n"
if $debug & $DEBUG_TOC;
}
$node = '';
} else {
print "# no node, section $name, level $level\n"
if $debug & $DEBUG_TOC;
}
# update TOC
while ($level > $curlevel) {
$curlevel++;
push(@toc_lines, "<UL>\n");
}
while ($level < $curlevel) {
$curlevel--;
push(@toc_lines, "</UL>\n");
}
$_ = "<LI>" . &anchor($tocid, "$docu_doc#$docid", $name, 1);
push(@toc_lines, &substitute_style($_));
# update DOC
push(@lines, &html_debug("\n", __LINE__));
&html_reset;
$_ = "<H$level>".&anchor($docid, "$docu_toc#$tocid", $name)."</H$level>\n";
$_ = &debug($_, __LINE__);
push(@lines, &html_debug("\n", __LINE__));
}
# update DOC
foreach $line (split(/\n+/, $_)) {
push(@lines, "$line\n");
}
next;
} else {
warn "$ERROR Bad section line: $_";
}
} else {
# track variables
$value{$1} = $2, next if /^\@set\s+($VARRE)\s+(.*)$/o;
delete $value{$1}, next if /^\@clear\s+($VARRE)\s*$/o;
# store things
$value{'_setfilename'} = $1, next if /^\@setfilename\s+(.*)$/;
$value{'_settitle'} = $1, next if /^\@settitle\s+(.*)$/;
$value{'_author'} .= "$1\n", next if /^\@author\s+(.*)$/;
$value{'_subtitle'} .= "$1\n", next if /^\@subtitle\s+(.*)$/;
$value{'_title'} .= "$1\n", next if /^\@title\s+(.*)$/;
# index
if (/^\@(..?)index\s+/) {
unless ($valid_index{$1}) {
warn "$ERROR Undefined index command: $_";
next;
}
$id = 'IDX' . ++$idx_num;
$index = $1 . 'index';
$what = &substitute_style($');
$what =~ s/\s+$//;
print "# found $index for '$what' id $id\n"
if $debug & $DEBUG_INDEX;
eval(<<EOC);
if (defined(\$$index\{\$what\})) {
\$$index\{\$what\} .= "$;$docu_doc#$id";
} else {
\$$index\{\$what\} = "$docu_doc#$id";
}
EOC
#
# dirty hack to see if I can put an invisible anchor...
#
if ($html_element eq 'P' ||
$html_element eq 'LI' ||
$html_element eq 'DT' ||
$html_element eq 'DD' ||
$html_element eq 'ADDRESS' ||
$html_element eq 'B' ||
$html_element eq 'BLOCKQUOTE' ||
$html_element eq 'PRE' ||
$html_element eq 'SAMP') {
push(@lines, &anchor($id, '', $invisible_mark, !$in_pre));
} elsif ($html_element eq 'body') {
push(@lines, &debug("<P>\n", __LINE__));
push(@lines, &anchor($id, '', $invisible_mark, !$in_pre));
&html_push('P');
} elsif ($html_element eq 'DL' ||
$html_element eq 'UL' ||
$html_element eq 'OL' ) {
$deferred_ref .= &anchor($id, '', $invisible_mark, !$in_pre) . " ";
}
next;
}
# list item
if (/^\@itemx?\s+/) {
$what = $';
$what =~ s/\s+$//;
if ($in_bibliography && $use_bibliography) {
if ($what =~ /^$BIBRE$/o) {
$id = 'BIB' . ++$bib_num;
$bib2href{$what} = "$docu_doc#$id";
print "# found bibliography for '$what' id $id\n"
if $debug & $DEBUG_BIB;
$what = &anchor($id, '', $what);
}
} elsif ($in_glossary && $use_glossary) {
$id = 'GLOSS' . ++$gloss_num;
$entry = $what;
$entry =~ tr/A-Z/a-z/ unless $entry =~ /^[A-Z\s]+$/;
$gloss2href{$entry} = "$docu_doc#$id";
print "# found glossary for '$entry' id $id\n"
if $debug & $DEBUG_GLOSS;
$what = &anchor($id, '', $what);
}
&html_pop_if('P');
if ($html_element eq 'DL' || $html_element eq 'DD') {
if ($things_map{$in_table} && !$what) {
# special case to allow @table @bullet for instance
push(@lines, &debug("<DT>$things_map{$in_table}\n", __LINE__));
} else {
push(@lines, &debug("<DT>\@$in_table\{$what\}\n", __LINE__));
}
push(@lines, "<DD>");
&html_push('DD') unless $html_element eq 'DD';
if ($table_type) { # add also an index
unshift(@input_spool, "\@${table_type}index $what\n");
}
} else {
push(@lines, &debug("<LI>$what\n", __LINE__));
&html_push('LI') unless $html_element eq 'LI';
}
push(@lines, &html_debug("\n", __LINE__));
if ($deferred_ref) {
push(@lines, &debug("$deferred_ref\n", __LINE__));
$deferred_ref = '';
}
next;
}
}