summaryrefslogtreecommitdiff
path: root/info/symbols/comprehensive/source/makefakeworldflags
blob: 4043f637536bf4168a08ebd2618269701c3de5dc (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
66
67
68
#! /usr/bin/env perl

##########################################
# Patch the worldflags package to reduce #
# conflicts with other packages          #
#                                        #
# By Scott Pakin <scott.clsl@pakin.org>  #
##########################################

use warnings;
use strict;

# ------------------ #
# fakeworldflags.sty #
# ------------------ #

# Prepare to modify the worldflags.sty file into fakeworldflags.sty.
my $styname = `kpsewhich worldflags.sty`;
chomp $styname;
die "${0}: Failed to find worldflags.sty\n" if !$styname;
open(STY_IN, "<", $styname) || die "${0}: open failed ($!)\n";
open(STY_OUT, ">", "fakeworldflags.sty") || die "${0}: open failed ($!)\n";

# Output some header boilerplate.
print STY_OUT "\%" x 43, "\n";
print STY_OUT "\% This is a generated file.  DO NOT EDIT. \%\n";
print STY_OUT "\%" x 43, "\n";
print STY_OUT "\n";

# Apply a prefix to each of \b, \h, and \ifgrid.
foreach my $ln (<STY_IN>) {
    $ln =~ s/\\([bh])\b/\\wflags\@$1/g;
    $ln =~ s/\\ifgrid\b/\\ifwflags\@grid/g;
    $ln =~ s/\\grid(true|false)\b/\\wflags\@grid$1/g;
    print STY_OUT $ln;
}

# Finish the fakeworldflags.sty file.
close STY_OUT or die "${0}: close failed ($!)\n";
close STY_IN or die "${0}: close failed ($!)\n";

# ---------------- #
# worldflag_GY.tex #
# ---------------- #

# Prepare to modify the worldflag_GY.tex file into the current directory.
unlink "worldflag_GY.tex";  # Delete any existing version of the file.
my $texname = `kpsewhich worldflag_GY.tex`;
chomp $texname;
die "${0}: Failed to find worldflag_GY.tex\n" if !$texname;
open(TEX_IN, "<", $texname) || die "${0}: open failed ($!)\n";
open(TEX_OUT, ">", "worldflag_GY.tex") || die "${0}: open failed ($!)\n";

# Output some header boilerplate.
print TEX_OUT "\%" x 43, "\n";
print TEX_OUT "\% This is a generated file.  DO NOT EDIT. \%\n";
print TEX_OUT "\%" x 43, "\n";
print TEX_OUT "\n";

# Apply a prefix to \d.
foreach my $ln (<TEX_IN>) {
    $ln =~ s/\\d\b/\\wflagsD/g;
    print TEX_OUT $ln;
}

# Finish the worldflag_GY.tex file.
close TEX_OUT or die "${0}: close failed ($!)\n";
close TEX_IN or die "${0}: close failed ($!)\n";