Mercurial > hg > batmud > ggrtf
changeset 1682:de46e2e23c66
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 01 Apr 2024 23:03:33 +0300 |
parents | 63e789382fc6 |
children | 61eb734a16f3 |
files | docs/tfdoc.pl |
diffstat | 1 files changed, 31 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/tfdoc.pl Mon Apr 01 22:45:06 2024 +0300 +++ b/docs/tfdoc.pl Mon Apr 01 23:03:33 2024 +0300 @@ -2,16 +2,17 @@ ### ### TFDoc for extending GgrTF DocBook manual with embedded TF docs. ### Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org> -### (C) Copyright 2009-2016 Tecnic Software productions (TNSP) +### (C) Copyright 2009-2024 Tecnic Software productions (TNSP) ### use strict; use warnings; +use utf8; ## Convert special characters to HTML/XML entities sub xmlentities($) { - my $value = $_[0]; + my ($value) = @_; $value =~ s/&/&/g; $value =~ s/</</g; $value =~ s/>/>/g; @@ -21,7 +22,7 @@ sub xmlentities2($) { - my $value = $_[0]; + my ($value) = @_; $value =~ s/&/&/g; my $str = ""; @@ -45,18 +46,19 @@ ### Scan one TinyFugue script file for documentation entries sub scan_file($) { - my $filename = $_[0]; - print STDERR "Scanning '$filename'\n"; + my ($filename) = @_; + + print STDERR "Scanning '".$filename."'\n"; my $data = {}; my $cmd = ""; my $sect = ""; 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>) + open(my $fh, "<:encoding(iso-8859-1)", $filename) or die("Could not open '".$filename."' for reading.\n"); + while (defined(my $line = <$fh>)) { - chomp; - if (/\/prdef(c|g|b)bind\s+-s\"(.+?)\"\s+-c\"(.+?)\"\s*(.*)$/) + chomp($line); + if ($line =~ /\/prdef(c|g|b)bind\s+-s\"(.+?)\"\s+-c\"(.+?)\"\s*(.*)$/) { my $opts = $4; my $type = $bindtypes{$1}; @@ -67,17 +69,17 @@ $tmp->{"notarget"} = ($opts =~ /-n/) ? 1 : 0; push(@{$data->{"binds"}{$type}}, $tmp); } - elsif (/;\s*\@keybind\s+(.*?)\s*=\s*(.*?)$/) + elsif ($line =~ /;\s*\@keybind\s+(.*?)\s*=\s*(.*?)$/) { $data->{"keybinds"}{$1} = $2; } - elsif (/;\s*\@command\s+(\S+)\s*?(.*)$/) + elsif ($line =~ /;\s*\@command\s+(\S+)\s*?(.*)$/) { $cmd = $1; $sect = "commands"; $data->{$sect}{$cmd}{"opts"} = $2; } - elsif (/;\s*\@desc\s+(.*)$/) + elsif ($line =~ /;\s*\@desc\s+(.*)$/) { if ($sect ne "" && $cmd ne "") { @@ -86,7 +88,7 @@ } } - close(FILE); + close($fh); return $data; } @@ -99,14 +101,14 @@ print "<table>\n". - " <title>$title</title>\n". - " <tgroup cols=\"$cols\" align=\"left\">\n". + " <title>".$title."</title>\n". + " <tgroup cols=\"".$cols."\" align=\"left\">\n". " <thead>\n". " <row>\n"; foreach my $col (@_) { - print " <entry>$col</entry>\n"; + print " <entry>".$col."</entry>\n"; } print @@ -128,7 +130,7 @@ { my ($mode, $title, $currfile, $files, $linen) = @_; - die("Directive '\@$mode $title' found, but no \@file directive set before it on line $linen.\n") + die("Directive '\@".$mode." ". $title."' found, but no \@file directive set before it on line ".$linen.".\n") unless defined($currfile); if ($mode eq "keybinds") @@ -156,7 +158,7 @@ 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"); + table_start((defined($title) ? xmlentities($title)." " : "")."'".$type."' type command bindings", "4", "Command", "Quiet", "NoTarget", "Description"); foreach my $entry (sort @{$data->{$type}}) { print @@ -189,7 +191,7 @@ } else { - die("Invalid/unsupported directive '\@$mode $title' on line $linen.\n"); + die("Invalid/unsupported directive '\@".$mode." ".$title."' on line ".$linen.".\n"); } } @@ -199,7 +201,7 @@ ### my $basepath = shift or die("Usage: <tfdir basepath> < input.sgml > output.sgml\n"); -print STDERR "Using TF-basepath '$basepath'\n"; +print STDERR "Using TF-basepath '".$basepath."'\n"; binmode(STDOUT, ":utf8"); binmode(STDIN, ":utf8"); @@ -208,12 +210,14 @@ my ($currfile, $currtitle); my $files = {}; -while (<STDIN>) { +while (defined (my $line = <STDIN>)) +{ $linen++; + # Get module filenames from section titles - if (/<title>(.*?)\((\S+?\.tf)\)<\/title>/) + if ($line =~ /<title>(.*?)\((\S+?\.tf)\)<\/title>/) { - print $_; + print $line; $currtitle = $1; $currfile = $2; if (!defined($files->{$currfile})) @@ -221,7 +225,7 @@ $files->{$currfile} = scan_file($basepath.$currfile); } } - elsif (/<!--\s*\@file\s+\"(.+?)\"\s+\"(.+?)\"\s*-->/) + elsif ($line =~ /<!--\s*\@file\s+\"(.+?)\"\s+\"(.+?)\"\s*-->/) { $currfile = $1; $currtitle = $2; @@ -230,16 +234,16 @@ $files->{$currfile} = scan_file($basepath.$currfile); } } - elsif (/<!--\s*\@([a-z]+)\s+\"(.+?)\"\s*-->/) + elsif ($line =~ /<!--\s*\@([a-z]+)\s+\"(.+?)\"\s*-->/) { handle_directive($1, $2, $currfile, $files, $linen); } - elsif (/<!--\s*\@([a-z]+)\s*-->/) + elsif ($line =~ /<!--\s*\@([a-z]+)\s*-->/) { handle_directive($1, $currtitle, $currfile, $files, $linen); } else { - print $_; + print $line; } }