diff options
author | Guillaume Rousse <guillomovitch@mandriva.org> | 2009-03-29 22:23:05 +0000 |
---|---|---|
committer | Guillaume Rousse <guillomovitch@mandriva.org> | 2009-03-29 22:23:05 +0000 |
commit | a70ba566e18196a2a981b37d8993e6871464d1ff (patch) | |
tree | 3684ed34ea0423ebbb76efbf907b18c790d75746 | |
parent | 0389e3f728699e16bb2d7b2de664a17e6bd6db22 (diff) | |
download | spec-helper-a70ba566e18196a2a981b37d8993e6871464d1ff.tar spec-helper-a70ba566e18196a2a981b37d8993e6871464d1ff.tar.gz spec-helper-a70ba566e18196a2a981b37d8993e6871464d1ff.tar.bz2 spec-helper-a70ba566e18196a2a981b37d8993e6871464d1ff.tar.xz spec-helper-a70ba566e18196a2a981b37d8993e6871464d1ff.zip |
initial import
-rwxr-xr-x | normalize_man_pages | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/normalize_man_pages b/normalize_man_pages new file mode 100755 index 0000000..2a93927 --- /dev/null +++ b/normalize_man_pages @@ -0,0 +1,60 @@ +#!/usr/bin/perl +# $Id: fix_eol 242516 2008-05-14 08:54:21Z guillomovitch $ +# ensure all man pages contains a comment line + +use strict; +use warnings; +use File::Find; +use File::Temp; + +my $buildroot = $ENV{RPM_BUILD_ROOT}; +die "No build root defined" unless $buildroot; +die "Invalid build root" unless -d $buildroot; +# normalize build root +$buildroot =~ s|/$||; + +my $mandir=`rpm --eval %{_mandir}`; +chomp $mandir; + +my $exclude_string = join('|', + map { '(:?' . quotemeta($_) . ')' } + $ENV{EXCLUDE_FROM_MAN_PAGE_NORMALIZATION} ? + split(' ', $ENV{EXCLUDE_FROM_MAN_PAGE_NORMALIZATION}) : () +); +my $exclude_pattern = qr/$exclude_string/; + +find(\&normalize, $buildroot . $mandir); + +sub normalize { + # skip everything but files + return unless -f $_; + # skip symlinks + return if -l $_; + # skip excluded files + return if $exclude_string && $File::Find::name =~ $exclude_pattern; + + # check if first line begin with a comment + open(my $in, '<', $_) or die "Unable to open file $_: $!"; + my $line = <$in>; + if (defined $line && $line !~ /^\.\\"/) { + # process all file + my $out = File::Temp->new(DIR => '.', UNLINK => 0); + print $out <<'EOF'; +.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\" make the file command recognize this file as a roff text +.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +EOF + print $out $line; + while (defined ($line = <$in>)) { + print $out $line; + } + my $tmp = $out->filename; + $out = undef; + + # rename file, taking care to keep original permissions + my $perms = (stat $_)[2] & 07777; + rename($tmp, $_) or die "Unable to rename $tmp to $_: $!"; + chmod($perms, $_); + } + close($in); +} |