summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDaniel Elstner <danielk@openismus.com>2009-08-19 14:48:19 +0200
committerDaniel Elstner <danielk@openismus.com>2009-08-19 14:48:19 +0200
commitb2e30f81f0ff1f854fef3952d01e505f32c4b362 (patch)
tree81684a0a918812172205563da63b82fcbee580d7 /util
parent39a478647c5b9988590285be76fd3d235f5b2744 (diff)
downloadmm-common-b2e30f81f0ff1f854fef3952d01e505f32c4b362.tar.gz
Turn doc-postprocess.pl into a good Unix citizen
* util/doc-postprocess.pl: Implement rudimentary error reporting and minimal command-line option handling, so that at least --help works. Also, refine some of the substitutions performed and add new ones to translate entity references to numerical code points.
Diffstat (limited to 'util')
-rw-r--r--util/doc-postprocess.pl69
1 files changed, 54 insertions, 15 deletions
diff --git a/util/doc-postprocess.pl b/util/doc-postprocess.pl
index 7da75d8..5af4ef0 100644
--- a/util/doc-postprocess.pl
+++ b/util/doc-postprocess.pl
@@ -1,6 +1,6 @@
package main;
-# Copyright (c) 2009 Daniel Elstner <daniel.kitta@gmail.com>
+# Copyright (c) 2009 Openismus GmbH <http://www.openismus.com/>
#
# This file is part of mm-common.
#
@@ -20,21 +20,59 @@ package main;
use strict;
use warnings;
use bytes;
+use File::Spec;
+use Getopt::Long qw(:config no_getopt_compat no_ignore_case require_order bundling);
+
+sub path_basename ($)
+{
+ my ($path) = @_;
+ my $basename = File::Spec->splitpath($path);
+
+ return $basename;
+}
+
+sub exit_help ()
+{
+ my $script_name = path_basename($0) || 'doc-postprocess.pl';
+
+ print <<"EOF";
+Usage: perl $script_name [OPTION]... [PATTERN]...
+
+Post-process the Doxygen-generated HTML files matching PATTERN.
+
+Options:
+ -?, --help display this help and exit
+EOF
+ exit;
+}
+
+sub error (@)
+{
+ my $script_name = path_basename($0);
+ $script_name =~ s/\.[^.]*$//s if (defined $script_name);
+
+ print STDERR ($script_name || 'doc-postprocess', ': ', @_, "\n");
+ exit 1;
+}
+
+GetOptions('help|?' => \&exit_help)
+ or exit 2;
foreach my $filename (map(glob, @ARGV))
{
- my @outbuf = ();
+ my @buf;
my $file;
- open($file, '<', $filename);
+ open($file, '<', $filename) and (@buf = <$file>) and close($file)
+ or error('Failed to read ', path_basename($filename), ': ', $!);
- while (<$file>)
+ foreach (@buf)
{
if (/<a class="el"/)
{
# return value
- s/ &amp;&nbsp;/&amp;&#160;/;
- s/ \*&nbsp;/*&#160;/;
+ s/ &amp;&nbsp; */&amp;&#160;/;
+ s/ \*&nbsp; */*&#160;/;
# parameters
s/ &amp;/&amp;/g;
@@ -48,15 +86,15 @@ foreach my $filename (map(glob, @ARGV))
elsif (/<td class="md(?:name)?"/)
{
# left parenthesis
- s/\(&nbsp;/(/;
+ s/\(&nbsp; */(/;
# return value
s/ &amp; /&amp; /g;
s/ \* /* /g;
# parameters
- s/ &amp;&nbsp;/&amp;&#160;/g;
- s/ \*&nbsp;/*&#160;/g;
+ s/ &amp;&nbsp; */&amp;&#160;/g;
+ s/ \*&nbsp; */*&#160;/g;
# templates
s/\btemplate&lt;/template &lt;/;
@@ -66,16 +104,17 @@ foreach my $filename (map(glob, @ARGV))
# template decls
s/^(<h\d>|)template&lt;/$1template &lt;/;
}
- s/&nbsp;/&#160;/g;
- push(@outbuf, $_);
+ s/&copy;/&#169;/g;
+ s/&mdash;/&#8212;/g;
+ s/&ndash;/&#8211;/g;
+ s/ *&nbsp; */&#160;/g;
+ s/(?<=\S)\s{2,}/ /g;
}
- close($file);
# write the whole buffer back
- open($file, '>', $filename);
- print $file ($_) foreach (@outbuf);
- close($file);
+ open($file, '>', $filename) and print $file (@buf) and close($file)
+ or error('Failed to write ', path_basename($filename), ': ', $!);
}
exit;