| 1 |
package main; |
| 2 |
|
| 3 |
# Copyright (c) 2009 Openismus GmbH <http://www.openismus.com/> |
| 4 |
# |
| 5 |
# This file is part of mm-common. |
| 6 |
# |
| 7 |
# mm-common is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published |
| 9 |
# by the Free Software Foundation, either version 2 of the License, |
| 10 |
# or (at your option) any later version. |
| 11 |
# |
| 12 |
# mm-common is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with mm-common. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
use strict; |
| 21 |
use warnings; |
| 22 |
use bytes; |
| 23 |
use File::Glob qw(:glob); |
| 24 |
use File::Spec; |
| 25 |
use Getopt::Long qw(:config no_getopt_compat no_ignore_case require_order bundling); |
| 26 |
|
| 27 |
sub path_basename ($) |
| 28 |
{ |
| 29 |
my ($path) = @_; |
| 30 |
my $basename = File::Spec->splitpath($path); |
| 31 |
|
| 32 |
return $basename; |
| 33 |
} |
| 34 |
|
| 35 |
sub exit_help () |
| 36 |
{ |
| 37 |
my $script_name = path_basename($0) || 'doc-postprocess.pl'; |
| 38 |
|
| 39 |
print <<"EOF"; |
| 40 |
Usage: perl $script_name [OPTION]... [PATTERN]... |
| 41 |
|
| 42 |
Post-process the Doxygen-generated HTML files matching PATTERN. |
| 43 |
|
| 44 |
Options: |
| 45 |
-?, --help display this help and exit |
| 46 |
EOF |
| 47 |
exit; |
| 48 |
} |
| 49 |
|
| 50 |
sub error (@) |
| 51 |
{ |
| 52 |
my $script_name = path_basename($0); |
| 53 |
$script_name =~ s/\.[^.]*$//s if (defined $script_name); |
| 54 |
|
| 55 |
print STDERR ($script_name || 'doc-postprocess', ': ', @_, "\n"); |
| 56 |
exit 1; |
| 57 |
} |
| 58 |
|
| 59 |
GetOptions('help|?' => \&exit_help) |
| 60 |
or exit 2; |
| 61 |
|
| 62 |
foreach my $filename (map(bsd_glob($_, GLOB_NOSORT), @ARGV)) |
| 63 |
{ |
| 64 |
my @buf; |
| 65 |
my $file; |
| 66 |
|
| 67 |
open($file, '<', $filename) and (@buf = <$file>) and close($file) |
| 68 |
or error('Failed to read ', path_basename($filename), ': ', $!); |
| 69 |
|
| 70 |
foreach (@buf) |
| 71 |
{ |
| 72 |
if (/<a class="el"/) |
| 73 |
{ |
| 74 |
# return value |
| 75 |
s/ & */& /; |
| 76 |
s/ \* */* /; |
| 77 |
|
| 78 |
# parameters |
| 79 |
s/ &/&/g; |
| 80 |
s/&\b/& /g; |
| 81 |
s/ \*/*/g; |
| 82 |
s/\*\b/* /g; |
| 83 |
|
| 84 |
# templates |
| 85 |
s/\btemplate</template </; |
| 86 |
} |
| 87 |
elsif (/<td class="md(?:name)?"/) |
| 88 |
{ |
| 89 |
# left parenthesis |
| 90 |
s/\( */(/; |
| 91 |
|
| 92 |
# return value |
| 93 |
s/ & /& /g; |
| 94 |
s/ \* /* /g; |
| 95 |
|
| 96 |
# parameters |
| 97 |
s/ & */& /g; |
| 98 |
s/ \* */* /g; |
| 99 |
|
| 100 |
# templates |
| 101 |
s/\btemplate</template </; |
| 102 |
} |
| 103 |
else |
| 104 |
{ |
| 105 |
# template decls |
| 106 |
s/^(<h\d>|)template</$1template </; |
| 107 |
} |
| 108 |
|
| 109 |
# For some reason, recent versions of Doxygen output the full path to |
| 110 |
# referenced tag files. This is bad since it breaks doc-install.pl, |
| 111 |
# and also because it leaks local path names into source tarballs. |
| 112 |
# Thus, strip the directory prefix here. |
| 113 |
s| doxygen="[^":]*/([^":]+\.tag):| doxygen="$1:|g; |
| 114 |
|
| 115 |
s/©/©/g; |
| 116 |
s/—/—/g; |
| 117 |
s/–/–/g; |
| 118 |
s/ * */ /g; |
| 119 |
} |
| 120 |
|
| 121 |
# write the whole buffer back |
| 122 |
open($file, '>', $filename) and print $file (@buf) and close($file) |
| 123 |
or error('Failed to write ', path_basename($filename), ': ', $!); |
| 124 |
} |
| 125 |
|
| 126 |
exit; |