summaryrefslogtreecommitdiff
path: root/doc/doc-docbook/OS-Fixups
blob: baae4fb93616082d77679a4f1dbdcb6cd42a994d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl -w
#  $Cambridge: exim/doc/doc-docbook/OS-Fixups,v 1.3 2010/05/28 15:38:18 nm4 Exp $
use strict;

# Script to hack around using absolute paths in xsl:import with fixups.
# Let every OS define its own manipulations.
# Uses the Perl $^O values to identify the current OS.
#
# Define filter_$^O to do substitutions, will be called for every line of
# every .xsl file.

sub filter_freebsd
{
s{"/usr/share/sgml/docbook/xsl-stylesheets-1.70.1/}
 {"/usr/local/share/xsl/docbook/};
s{"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"}
 {"/usr/local/share/xml/docbook/4.2/docbookx.dtd"};
}

sub filter_linux
{
# SUSE 10 with extra pkgs
s{"/usr/share/sgml/docbook/xsl-stylesheets-1.70.1/}
 {"/usr/share/xml/docbook/stylesheet/nwalsh/1.71.1/};
s{"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"}
 {"/usr/share/xml/docbook/schema/dtd/4.2/docbookx.dtd"};
}

sub filter_darwin
{
# NB - this uses the Mac Ports installations
s{"/usr/share/sgml/docbook/xsl-stylesheets-1.70.1/}
 {"/opt/local/share/xsl/docbook-xsl/};
s{"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"}
 {"/opt/local/share/xml/docbook/4.2/docbookx.dtd"};
}


# Define OS filters above.

my $os_filter;
$os_filter = $main::{"filter_$^O"} if exists $main::{"filter_$^O"};

unless (defined $os_filter)
  {
  print "No changes defined for your OS ($^O).\n";
  exit 0;
  }

for my $fn (<*.xsl>, <*.xml>)
  {
  my $orig = "$fn.orig";
  rename($fn, $orig) or die "Failed to rename($fn, $orig): $!\n";
  # Most portable is two-argument form, and none of our filenames are
  # untrusted or contain whitespace.
  open(OLD, "< $orig") or die "Failed to read-open($orig): $!\n";
  open(NEW, "> $fn") or die "Failed to write-open($fn): $!\n";
  while (<OLD>)
    {
    $os_filter->();
    print NEW $_ or die "Write to \"$fn\" failed: $!\n";
    }
  close(NEW) or die "Failed to close($fn) after writing: $!\n";
  close(OLD);
  }