Mercurial > hg > batmud > ggrtf
changeset 1621:6bfd2865941a
Reformat / reindent.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 04 Nov 2016 14:06:40 +0200 |
parents | 655fc46ff672 |
children | cc4b935b9482 |
files | docs/tfdoc.pl |
diffstat | 1 files changed, 104 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/tfdoc.pl Sat Oct 29 13:57:19 2016 +0300 +++ b/docs/tfdoc.pl Fri Nov 04 14:06:40 2016 +0200 @@ -2,7 +2,7 @@ # # TFDoc for extending GgrTF DocBook manual with embedded TF docs. # Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org> -# (C) Copyright 2009-2013 Tecnic Software productions (TNSP) +# (C) Copyright 2009-2016 Tecnic Software productions (TNSP) # use strict; use warnings; @@ -59,9 +59,11 @@ my %bindtypes = ("c" => "cast", "g" => "general", "s" => "skill"); open(FILE, "<:encoding(iso-8859-1)", $filename) or die("Could not open '$filename' for reading.\n"); - while (<FILE>) { + while (<FILE>) + { chomp; - if (/\/prdef(c|g|b)bind\s+-s\"(.+?)\"\s+-c\"(.+?)\"\s*(.*)$/) { + if (/\/prdef(c|g|b)bind\s+-s\"(.+?)\"\s+-c\"(.+?)\"\s*(.*)$/) + { my $opts = $4; my $type = $bindtypes{$1}; my $tmp = {}; @@ -70,14 +72,21 @@ $tmp->{"quiet"} = ($opts =~ /-q/) ? 1 : 0; $tmp->{"notarget"} = ($opts =~ /-n/) ? 1 : 0; push(@{$data->{"binds"}{$type}}, $tmp); - } elsif (/;\s*\@keybind\s+(.*?)\s*=\s*(.*?)$/) { + } + elsif (/;\s*\@keybind\s+(.*?)\s*=\s*(.*?)$/) + { $data->{"keybinds"}{$1} = $2; - } elsif (/;\s*\@command\s+(\S+)\s*?(.*)$/) { + } + elsif (/;\s*\@command\s+(\S+)\s*?(.*)$/) + { $cmd = $1; $sect = "commands"; $data->{$sect}{$cmd}{"opts"} = $2; - } elsif (/;\s*\@desc\s+(.*)$/) { - if ($sect ne "" && $cmd ne "") { + } + elsif (/;\s*\@desc\s+(.*)$/) + { + if ($sect ne "" && $cmd ne "") + { $data->{$sect}{$cmd}{"desc"} .= $1." "; } } @@ -87,33 +96,37 @@ return $data; } + ### Print out a DocBook SGML/XML table header sub table_start { my $title = shift; my $cols = shift; - print "<table>\n". - " <title>$title</title>\n". - " <tgroup cols=\"$cols\" align=\"left\">\n". - " <thead>\n". - " <row>\n"; + print + "<table>\n". + " <title>$title</title>\n". + " <tgroup cols=\"$cols\" align=\"left\">\n". + " <thead>\n". + " <row>\n"; - foreach my $col (@_) { + foreach my $col (@_) + { print " <entry>$col</entry>\n"; } - print " </row>\n". - " </thead>\n". - " <tbody>\n"; + print + " </row>\n". + " </thead>\n". + " <tbody>\n"; } sub table_end { print - " </tbody>\n". - " </tgroup>\n". - "</table>\n"; + " </tbody>\n". + " </tgroup>\n". + "</table>\n"; } @@ -124,50 +137,66 @@ die("Directive '\@$mode $title' found, but no \@file directive set before it on line $linen.\n") unless defined($currfile); - if ($mode eq "keybinds") { - # Keyboard bindings - if (defined($files->{$currfile}{"keybinds"})) { - my $data = $files->{$currfile}{"keybinds"}; - table_start((defined($title) ? xmlentities($title)." k" : "K")."eybindings", "2", "Key(s)", "Function"); - foreach my $tmp (sort keys %{$data}) { - print " <row><entry>".xmlentities($tmp)."</entry>". + if ($mode eq "keybinds") + { + # Keyboard bindings + if (defined($files->{$currfile}{"keybinds"})) + { + my $data = $files->{$currfile}{"keybinds"}; + table_start((defined($title) ? xmlentities($title)." k" : "K")."eybindings", "2", "Key(s)", "Function"); + foreach my $tmp (sort keys %{$data}) + { + print + " <row><entry>".xmlentities($tmp)."</entry>". "<entry>".xmlentities($data->{$tmp})."</entry></row>\n"; + } + table_end(); + } + } + elsif ($mode eq "binds") + { + # Command bindings + if (defined($files->{$currfile}{"binds"})) + { + my $data = $files->{$currfile}{"binds"}; + foreach my $type (sort keys %{$data}) + { + my $entry = $data->{$type}; + table_start((defined($title) ? xmlentities($title)." " : "")."'$type' type command bindings", "4", "Command", "Quiet", "NoTarget", "Description"); + foreach my $entry (sort @{$data->{$type}}) + { + print + " <row><entry>".xmlentities($entry->{"name"})."</entry>". + "<entry>".($entry->{"quiet"} ? "X" : "")."</entry>". + "<entry>".($entry->{"notarget"} ? "X" : "")."</entry>". + "<entry>".xmlentities($entry->{"desc"})."</entry></row>\n"; } table_end(); } - } elsif ($mode eq "binds") { - # Command bindings - if (defined($files->{$currfile}{"binds"})) { - my $data = $files->{$currfile}{"binds"}; - foreach my $type (sort keys %{$data}) { - my $entry = $data->{$type}; - table_start((defined($title) ? xmlentities($title)." " : "")."'$type' type command bindings", "4", "Command", "Quiet", "NoTarget", "Description"); - foreach my $entry (sort @{$data->{$type}}) { - print " <row><entry>".xmlentities($entry->{"name"})."</entry>". - "<entry>".($entry->{"quiet"} ? "X" : "")."</entry>". - "<entry>".($entry->{"notarget"} ? "X" : "")."</entry>". - "<entry>".xmlentities($entry->{"desc"})."</entry></row>\n"; - } - table_end(); - } + } + } + elsif ($mode eq "commands") + { + # Macro commands + if (defined($files->{$currfile}{"commands"})) + { + my $data = $files->{$currfile}{"commands"}; + + table_start((defined($title) ? xmlentities($title)." m" : "M")."acro commands", "2", "Command", "Description"); + foreach my $tmp (sort keys %{$data}) + { + print + " <row><entry><emphasis>".xmlentities($tmp)."</emphasis> ".xmlentities($data->{$tmp}{"opts"})."</entry>". + "<entry>".xmlentities2($data->{$tmp}{"desc"}). + "</entry></row>\n"; } - } elsif ($mode eq "commands") { - # Macro commands - if (defined($files->{$currfile}{"commands"})) { - my $data = $files->{$currfile}{"commands"}; - - table_start((defined($title) ? xmlentities($title)." m" : "M")."acro commands", "2", "Command", "Description"); - foreach my $tmp (sort keys %{$data}) { - print " <row><entry><emphasis>".xmlentities($tmp)."</emphasis> ". - xmlentities($data->{$tmp}{"opts"}). - "</entry><entry>".xmlentities2($data->{$tmp}{"desc"}). - "</entry></row>\n"; - } - table_end(); - } - } else { - die("Invalid/unsupported directive '\@$mode $title' on line $linen.\n"); + table_end(); } + } + else + { + die("Invalid/unsupported directive '\@$mode $title' on line $linen.\n"); + } } @@ -188,24 +217,35 @@ while (<STDIN>) { $linen++; # Get module filenames from section titles - if (/<title>(.*?)\((\S+?\.tf)\)<\/title>/) { + if (/<title>(.*?)\((\S+?\.tf)\)<\/title>/) + { print $_; $currtitle = $1; $currfile = $2; - if (!defined($files->{$currfile})) { + if (!defined($files->{$currfile})) + { $files->{$currfile} = scan_file($basepath.$currfile); } - } elsif (/<!--\s*\@file\s+\"(.+?)\"\s+\"(.+?)\"\s*-->/) { + } + elsif (/<!--\s*\@file\s+\"(.+?)\"\s+\"(.+?)\"\s*-->/) + { $currfile = $1; $currtitle = $2; - if (!defined($files->{$currfile})) { + if (!defined($files->{$currfile})) + { $files->{$currfile} = scan_file($basepath.$currfile); } - } elsif (/<!--\s*\@([a-z]+)\s+\"(.+?)\"\s*-->/) { + } + elsif (/<!--\s*\@([a-z]+)\s+\"(.+?)\"\s*-->/) + { handle_directive($1, $2, $currfile, $files, $linen); - } elsif (/<!--\s*\@([a-z]+)\s*-->/) { + } + elsif (/<!--\s*\@([a-z]+)\s*-->/) + { handle_directive($1, $currtitle, $currfile, $files, $linen); - } else { + } + else + { print $_; } }