annotate docs/tfdoc.pl @ 1642:acd73fb8402f

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