annotate docs/tfdoc.pl @ 1682:de46e2e23c66

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Apr 2024 23:03:33 +0300
parents acd73fb8402f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/perl -w
1642
acd73fb8402f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1622
diff changeset
2 ###
acd73fb8402f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1622
diff changeset
3 ### TFDoc for extending GgrTF DocBook manual with embedded TF docs.
acd73fb8402f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1622
diff changeset
4 ### Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
5 ### (C) Copyright 2009-2024 Tecnic Software productions (TNSP)
1642
acd73fb8402f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1622
diff changeset
6 ###
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 use strict;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 use warnings;
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
9 use utf8;
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
1642
acd73fb8402f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1622
diff changeset
11
1054
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
12 ## Convert special characters to HTML/XML entities
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
13 sub xmlentities($)
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
14 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
15 my ($value) = @_;
1622
cc4b935b9482 Fix entity handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1621
diff changeset
16 $value =~ s/&/&amp;/g;
cc4b935b9482 Fix entity handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1621
diff changeset
17 $value =~ s/</&lt;/g;
cc4b935b9482 Fix entity handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1621
diff changeset
18 $value =~ s/>/&gt;/g;
1054
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
19 return $value;
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
20 }
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
21
1642
acd73fb8402f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1622
diff changeset
22
1424
6a0876dfc9d4 Handle TFDoc @desc lines differently when it comes to entity expansion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1070
diff changeset
23 sub xmlentities2($)
6a0876dfc9d4 Handle TFDoc @desc lines differently when it comes to entity expansion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1070
diff changeset
24 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
25 my ($value) = @_;
1622
cc4b935b9482 Fix entity handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1621
diff changeset
26 $value =~ s/&/&amp;/g;
1560
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
27
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
28 my $str = "";
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
29 my $state = 0;
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
30 foreach my $qch (split(//, $value))
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
31 {
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
32 if ($qch eq "\$")
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
33 {
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
34 $state = !$state;
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
35 $str .= ($state ? "<emphasis>" : "</emphasis>");
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
36 }
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
37 else
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
38 {
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
39 $str .= $qch;
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
40 }
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
41 }
96c55e665a55 Improve TFdoc syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 1424
diff changeset
42 return $str;
1424
6a0876dfc9d4 Handle TFDoc @desc lines differently when it comes to entity expansion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1070
diff changeset
43 }
6a0876dfc9d4 Handle TFDoc @desc lines differently when it comes to entity expansion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1070
diff changeset
44
1054
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
45
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 ### Scan one TinyFugue script file for documentation entries
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 sub scan_file($)
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
49 my ($filename) = @_;
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
50
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
51 print STDERR "Scanning '".$filename."'\n";
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 my $data = {};
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 my $cmd = "";
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 my $sect = "";
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 my %bindtypes = ("c" => "cast", "g" => "general", "s" => "skill");
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
57 open(my $fh, "<:encoding(iso-8859-1)", $filename) or die("Could not open '".$filename."' for reading.\n");
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
58 while (defined(my $line = <$fh>))
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
59 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
60 chomp($line);
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
61 if ($line =~ /\/prdef(c|g|b)bind\s+-s\"(.+?)\"\s+-c\"(.+?)\"\s*(.*)$/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
62 {
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 my $opts = $4;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 my $type = $bindtypes{$1};
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 my $tmp = {};
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 $tmp->{"name"} = $2;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 $tmp->{"desc"} = $3;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 $tmp->{"quiet"} = ($opts =~ /-q/) ? 1 : 0;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 $tmp->{"notarget"} = ($opts =~ /-n/) ? 1 : 0;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 push(@{$data->{"binds"}{$type}}, $tmp);
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
71 }
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
72 elsif ($line =~ /;\s*\@keybind\s+(.*?)\s*=\s*(.*?)$/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
73 {
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 $data->{"keybinds"}{$1} = $2;
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
75 }
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
76 elsif ($line =~ /;\s*\@command\s+(\S+)\s*?(.*)$/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
77 {
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 $cmd = $1;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 $sect = "commands";
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 $data->{$sect}{$cmd}{"opts"} = $2;
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
81 }
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
82 elsif ($line =~ /;\s*\@desc\s+(.*)$/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
83 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
84 if ($sect ne "" && $cmd ne "")
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
85 {
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 $data->{$sect}{$cmd}{"desc"} .= $1." ";
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
91 close($fh);
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 return $data;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
95
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 ### Print out a DocBook SGML/XML table header
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 sub table_start
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 my $title = shift;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 my $cols = shift;
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
102 print
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
103 "<table>\n".
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
104 " <title>".$title."</title>\n".
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
105 " <tgroup cols=\"".$cols."\" align=\"left\">\n".
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
106 " <thead>\n".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
107 " <row>\n";
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
109 foreach my $col (@_)
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
110 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
111 print " <entry>".$col."</entry>\n";
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
114 print
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
115 " </row>\n".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
116 " </thead>\n".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
117 " <tbody>\n";
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 sub table_end
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 {
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 print
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
123 " </tbody>\n".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
124 " </tgroup>\n".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
125 "</table>\n";
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
1061
Matti Hamalainen <ccr@tnsp.org>
parents: 1056
diff changeset
129 sub handle_directive($$$$$)
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
130 {
1061
Matti Hamalainen <ccr@tnsp.org>
parents: 1056
diff changeset
131 my ($mode, $title, $currfile, $files, $linen) = @_;
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
133 die("Directive '\@".$mode." ". $title."' found, but no \@file directive set before it on line ".$linen.".\n")
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
134 unless defined($currfile);
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
136 if ($mode eq "keybinds")
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
137 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
138 # Keyboard bindings
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
139 if (defined($files->{$currfile}{"keybinds"}))
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
140 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
141 my $data = $files->{$currfile}{"keybinds"};
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
142 table_start((defined($title) ? xmlentities($title)." k" : "K")."eybindings", "2", "Key(s)", "Function");
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
143 foreach my $tmp (sort keys %{$data})
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
144 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
145 print
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
146 " <row><entry>".xmlentities($tmp)."</entry>".
1054
04d9510b9591 Convert special characters to XML entities when processing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
147 "<entry>".xmlentities($data->{$tmp})."</entry></row>\n";
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
148 }
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
149 table_end();
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
150 }
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
151 }
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
152 elsif ($mode eq "binds")
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
153 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
154 # Command bindings
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
155 if (defined($files->{$currfile}{"binds"}))
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
156 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
157 my $data = $files->{$currfile}{"binds"};
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
158 foreach my $type (sort keys %{$data})
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
159 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
160 my $entry = $data->{$type};
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
161 table_start((defined($title) ? xmlentities($title)." " : "")."'".$type."' type command bindings", "4", "Command", "Quiet", "NoTarget", "Description");
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
162 foreach my $entry (sort @{$data->{$type}})
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
163 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
164 print
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
165 " <row><entry>".xmlentities($entry->{"name"})."</entry>".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
166 "<entry>".($entry->{"quiet"} ? "X" : "")."</entry>".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
167 "<entry>".($entry->{"notarget"} ? "X" : "")."</entry>".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
168 "<entry>".xmlentities($entry->{"desc"})."</entry></row>\n";
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 table_end();
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
172 }
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
173 }
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
174 elsif ($mode eq "commands")
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
175 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
176 # Macro commands
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
177 if (defined($files->{$currfile}{"commands"}))
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
178 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
179 my $data = $files->{$currfile}{"commands"};
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
180
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
181 table_start((defined($title) ? xmlentities($title)." m" : "M")."acro commands", "2", "Command", "Description");
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
182 foreach my $tmp (sort keys %{$data})
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
183 {
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
184 print
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
185 " <row><entry><emphasis>".xmlentities($tmp)."</emphasis> ".xmlentities($data->{$tmp}{"opts"})."</entry>".
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
186 "<entry>".xmlentities2($data->{$tmp}{"desc"}).
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
187 "</entry></row>\n";
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 }
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
189 table_end();
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 }
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
191 }
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
192 else
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
193 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
194 die("Invalid/unsupported directive '\@".$mode." ".$title."' on line ".$linen.".\n");
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
195 }
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
196 }
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
197
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
198
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
199 ###
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
200 ### Main program
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
201 ###
1061
Matti Hamalainen <ccr@tnsp.org>
parents: 1056
diff changeset
202 my $basepath = shift or die("Usage: <tfdir basepath> < input.sgml > output.sgml\n");
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
203
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
204 print STDERR "Using TF-basepath '".$basepath."'\n";
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
205
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
206 binmode(STDOUT, ":utf8");
1061
Matti Hamalainen <ccr@tnsp.org>
parents: 1056
diff changeset
207 binmode(STDIN, ":utf8");
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
208
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
209 my $linen = 0;
1051
8fd19954854b Bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
210 my ($currfile, $currtitle);
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
211 my $files = {};
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
212
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
213 while (defined (my $line = <STDIN>))
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
214 {
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
215 $linen++;
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
216
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
217 # Get module filenames from section titles
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
218 if ($line =~ /<title>(.*?)\((\S+?\.tf)\)<\/title>/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
219 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
220 print $line;
1051
8fd19954854b Bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
221 $currtitle = $1;
8fd19954854b Bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
222 $currfile = $2;
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
223 if (!defined($files->{$currfile}))
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
224 {
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
225 $files->{$currfile} = scan_file($basepath.$currfile);
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
226 }
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
227 }
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
228 elsif ($line =~ /<!--\s*\@file\s+\"(.+?)\"\s+\"(.+?)\"\s*-->/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
229 {
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
230 $currfile = $1;
1051
8fd19954854b Bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
231 $currtitle = $2;
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
232 if (!defined($files->{$currfile}))
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
233 {
1047
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
234 $files->{$currfile} = scan_file($basepath.$currfile);
4451f1a1467a Modularize the code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1044
diff changeset
235 }
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
236 }
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
237 elsif ($line =~ /<!--\s*\@([a-z]+)\s+\"(.+?)\"\s*-->/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
238 {
1061
Matti Hamalainen <ccr@tnsp.org>
parents: 1056
diff changeset
239 handle_directive($1, $2, $currfile, $files, $linen);
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
240 }
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
241 elsif ($line =~ /<!--\s*\@([a-z]+)\s*-->/)
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
242 {
1061
Matti Hamalainen <ccr@tnsp.org>
parents: 1056
diff changeset
243 handle_directive($1, $currtitle, $currfile, $files, $linen);
1621
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
244 }
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
245 else
6bfd2865941a Reformat / reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 1568
diff changeset
246 {
1682
de46e2e23c66 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1642
diff changeset
247 print $line;
1044
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
d8b504e5b356 Imported initial implementation of TFDoc, an extremely simplistic embedded documentation extractor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 }