Commit | Line | Data |
---|---|---|
a2119650 | 1 | #!/usr/bin/perl -w |
8127b38f | 2 | # $Cambridge: exim/doc/doc-docbook/OS-Fixups,v 1.2 2009/11/09 16:12:37 nm4 Exp $ |
a2119650 NM |
3 | use strict; |
4 | ||
5 | # Script to hack around using absolute paths in xsl:import with fixups. | |
6 | # Let every OS define its own manipulations. | |
7 | # Uses the Perl $^O values to identify the current OS. | |
8 | # | |
9 | # Define filter_$^O to do substitutions, will be called for every line of | |
10 | # every .xsl file. | |
11 | ||
12 | sub filter_freebsd | |
13 | { | |
14 | s{"/usr/share/sgml/docbook/xsl-stylesheets-1.70.1/} | |
15 | {"/usr/local/share/xsl/docbook/}; | |
16 | s{"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"} | |
17 | {"/usr/local/share/xml/docbook/4.2/docbookx.dtd"}; | |
18 | } | |
19 | ||
8127b38f NM |
20 | sub filter_darwin |
21 | { | |
22 | # NB - this uses the Mac Ports installations | |
23 | s{"/usr/share/sgml/docbook/xsl-stylesheets-1.70.1/} | |
24 | {"/opt/local/share/xsl/docbook-xsl/}; | |
25 | s{"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"} | |
26 | {"/opt/local/share/xml/docbook/4.2/docbookx.dtd"}; | |
27 | } | |
28 | ||
29 | ||
a2119650 NM |
30 | # Define OS filters above. |
31 | ||
32 | my $os_filter; | |
33 | $os_filter = $main::{"filter_$^O"} if exists $main::{"filter_$^O"}; | |
34 | ||
35 | unless (defined $os_filter) | |
36 | { | |
37 | print "No changes defined for your OS ($^O).\n"; | |
38 | exit 0; | |
39 | } | |
40 | ||
41 | for my $fn (<*.xsl>, <*.xml>) | |
42 | { | |
43 | my $orig = "$fn.orig"; | |
44 | rename($fn, $orig) or die "Failed to rename($fn, $orig): $!\n"; | |
45 | # Most portable is two-argument form, and none of our filenames are | |
46 | # untrusted or contain whitespace. | |
47 | open(OLD, "< $orig") or die "Failed to read-open($orig): $!\n"; | |
48 | open(NEW, "> $fn") or die "Failed to write-open($fn): $!\n"; | |
49 | while (<OLD>) | |
50 | { | |
51 | $os_filter->(); | |
52 | print NEW $_ or die "Write to \"$fn\" failed: $!\n"; | |
53 | } | |
54 | close(NEW) or die "Failed to close($fn) after writing: $!\n"; | |
55 | close(OLD); | |
56 | } |