diff options
author | Daniel Elstner <danielk@openismus.com> | 2009-08-19 14:48:19 +0200 |
---|---|---|
committer | Daniel Elstner <danielk@openismus.com> | 2009-08-19 14:48:19 +0200 |
commit | b2e30f81f0ff1f854fef3952d01e505f32c4b362 (patch) | |
tree | 81684a0a918812172205563da63b82fcbee580d7 | |
parent | 39a478647c5b9988590285be76fd3d235f5b2744 (diff) | |
download | mm-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.
-rw-r--r-- | util/doc-postprocess.pl | 69 |
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/ & /& /; - s/ \* /* /; + s/ & */& /; + s/ \* */* /; # parameters s/ &/&/g; @@ -48,15 +86,15 @@ foreach my $filename (map(glob, @ARGV)) elsif (/<td class="md(?:name)?"/) { # left parenthesis - s/\( /(/; + s/\( */(/; # return value s/ & /& /g; s/ \* /* /g; # parameters - s/ & /& /g; - s/ \* /* /g; + s/ & */& /g; + s/ \* */* /g; # templates s/\btemplate</template </; @@ -66,16 +104,17 @@ foreach my $filename (map(glob, @ARGV)) # template decls s/^(<h\d>|)template</$1template </; } - s/ / /g; - push(@outbuf, $_); + s/©/©/g; + s/—/—/g; + s/–/–/g; + s/ * */ /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; |