summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2008-12-01 12:25:56 +0000
committerNorbert Preining <preining@logic.at>2008-12-01 12:25:56 +0000
commit482e1562295f261296814542810909346b6ef512 (patch)
tree8acb9fe80694320ce957a4dbf5a936597d33839c /Master/tlpkg/etc
parent2ae8d127dc2ba020dacfd3c5b14045123111d7c2 (diff)
updates
git-svn-id: svn://tug.org/texlive/trunk@11496 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/etc')
-rw-r--r--Master/tlpkg/etc/test-code-for-papersize-in-perl.pl167
1 files changed, 153 insertions, 14 deletions
diff --git a/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl b/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl
index f91cdd4630e..49be2dbbd3e 100644
--- a/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl
+++ b/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl
@@ -1,4 +1,17 @@
+#
+# TODO TODO TODO
+# what happens, especially with do_simple, if NO paper config line is
+# found, so nothing has been set up. That happens with context already
+# It seems that the dvipdfm/config, dvipdfmx.cfg, XDvi we are shipping
+# already all have a line. But what happens if someone has a line
+# hanging around?
+#
+# For dvipdfm(x) and xdvi I have fixed that by adding a line at the
+# bottom.
+#
+# For context this doesn't work because there is an \endinput there!!!
+#
$^W = 1;
use strict;
@@ -90,6 +103,10 @@ if ($what eq "dvips") {
do_dvips(@ARGV);
} elsif ($what eq "dvipdfm") {
do_dvipdfm(@ARGV);
+} elsif ($what eq "dvipdfmx") {
+ do_dvipdfmx(@ARGV);
+} elsif ($what eq "context") {
+ do_context(@ARGV);
} elsif ($what eq "xdvi") {
do_xdvi(@ARGV);
} else {
@@ -98,6 +115,7 @@ if ($what eq "dvips") {
}
exit 0;
+
#
# dvips config.ps format:
# /--- config.ps ---
@@ -208,6 +226,45 @@ sub do_dvips {
}
#
+# context format:
+# /--- cont-sys.{tex,rme}
+# |...
+# |\setuppapersize[letter][letter]
+# |...
+# \------------
+#
+# Reading is done first via kpsewhich -prog=tex -format=tex cont-sys.tex
+# if that fails via -prog=tex -format='other text files' cont-sys.rme
+#
+# Writing is done to TEXMFSYSCONFIG/tex/context/user/cont-sys.tex
+#
+sub do_context {
+ my $newpaper = shift;
+ # TODO TODO
+ # we should check whether context is installed at all!!!!
+ my $inp = `kpsewhich --progname=tex --format=tex cont-sys.tex`;
+ chomp($inp);
+ if (!$inp) {
+ # we didn't get anything, so retry with .rme
+ $inp = `kpsewhich --progname=tex --format='other text files' cont-sys.rme`;
+ chomp($inp);
+ }
+ my @bla = keys %pdftex_papersize;
+ do_simple($inp, "context", '^\s*\\setuppapersize\s*',
+ '^\s*\\setuppapersize\s*\[([^][]*)\]',
+ sub {
+ my ($ll,$np) = @_;
+ if ($ll =~ m/^\s*\\setuppapersize\s*/) {
+ return("\\setuppapersize[$np][$np]\n");
+ } else {
+ return($ll);
+ }
+ }, "tex/context/user/cont-sys.rme", \@bla,
+ '\setuppapersize[a4][a4]', $newpaper);
+}
+
+
+#
# xdvi format:
# /--- XDvi ---
# |...
@@ -222,14 +279,86 @@ sub do_xdvi {
my $newpaper = shift;
my $xdvi = `kpsewhich --progname=xdvi --format='other text files' XDvi`;
chomp($xdvi);
- print "file used: $xdvi\n";
+ my @bla = keys %xdvi_papersize;
+ do_simple($xdvi, "xdvi", '^\*paper: ', '^\*paper:\s+(\w+)\s*$',
+ sub {
+ my ($ll,$np) = @_;
+ $ll =~ s/^\*paper:\s+(\w+)\s*$/\*paper: $np\n/;
+ return($ll);
+ }, "xdvi/XDvi", \@bla,
+ '*paper: a4', $newpaper);
+}
+
- open(FOO, "<$xdvi") or die("cannot open file: $!");
+#
+# dvipdfm(x) format:
+# /--- dvipdfm/config, dvipdfmx/dvipdfmx.cfg ---
+# |...
+# |p <NAME>
+# |...
+# \------------
+#
+# Reading is done
+# for dvipdfm via --progname=dvipdfm --format='other text files' config
+# for dvipdfmx via --progname=dvipdfmx --format='other text files' dvipdfmx.cfg
+# Writing is done to TEXMFSYSCONFIG/dvipdfm/config/config
+# and /dvipdfmx/dvipdfmx.cfg
+#
+#
+sub do_dvipdfm_and_x {
+ my ($inp, $prog, $outp, $paplist, $newpaper) = @_;
+ do_simple($inp, $prog, '^p\s+', '^p\s+(\w+)\s*$',
+ sub {
+ my ($ll,$np) = @_;
+ $ll =~ s/^p\s+(\w+)\s*$/p $np\n/;
+ return($ll);
+ }, $outp, $paplist, 'p a4', $newpaper);
+}
+
+sub do_dvipdfm {
+ my $newpaper = shift;
+ my $inp = `kpsewhich --progname=dvipdfm --format='other text files' config`;
+ chomp($inp);
+ my @bla = keys %dvipdfm_papersize;
+ do_dvipdfm_and_x($inp, "dvipdfm", "dvipdfm/config/config", \@bla, $newpaper);
+}
+sub do_dvipdfmx {
+ my $newpaper = shift;
+ my $inp = `kpsewhich --progname=dvipdfmx --format='other text files' dvipdfmx.cfg`;
+ chomp($inp);
+ my @bla = keys %dvipdfm_papersize;
+ do_dvipdfm_and_x($inp, "dvipdfmx", "dvipdfmx/dvipdfmx.cfg", \@bla, $newpaper);
+}
+
+
+
+#
+# do_simple does the work for single line config files
+# (xdvi, dvipdfm, dvipdfmx)
+# arguments:
+# $inp, $prog, $firstre, $secondre, $bl, $outp, $paplist, $newpaper
+# with
+# $inp .. input file location
+# $prog .. program name
+# $firstre .. re that searches for paper lines
+# $secondre .. re that extracts the paper from a paper line
+# $bl .. block/sub taking two args, one paper line and the new paper, and
+# returns the line with the paper configured, only lines mathing
+# $firstre are shipped over to $bl
+# $outp .. location of the output file
+# $paplist .. ref to an array with the list of admissible paper sizes
+# $newpaper .. --list, new paper, or undef
+sub do_simple {
+ my ($inp, $prog, $firstre, $secondre, $bl, $outp, $paplist, $defaultline, $newpaper) = @_;
+
+ print STDERR "file used for $prog: $inp\n";
+
+ open(FOO, "<$inp") or die("cannot open file: $!");
my @lines = <FOO>;
close(FOO);
my $currentpaper;
- my @paperlines = grep (m/^\*paper: /,@lines);
+ my @paperlines = grep (m/$firstre/,@lines);
if (!@paperlines) {
$currentpaper = "(undefined)";
} else {
@@ -238,41 +367,51 @@ sub do_xdvi {
}
$currentpaper = $paperlines[0];
chomp($currentpaper);
- $currentpaper =~ s/^\*paper:\s+(\w+)\s*$/$1/;
+ $currentpaper =~ s/$secondre/$1/;
}
# change value
if (defined($newpaper)) {
if ($newpaper eq "--list") {
print "$currentpaper\n";
- for my $p (keys %xdvi_papersize) {
+ for my $p (@$paplist) {
print "$p\n" unless ($p eq $currentpaper);
}
} else {
my $found = 0;
- for my $p (keys %xdvi_papersize) {
+ for my $p (@$paplist) {
if ($p eq $newpaper) {
$found = 1;
last;
}
}
if ($found) {
- map { +s/^\*paper:\s+(\w+)\s*$/\*paper: $newpaper\n/; } @lines;
- # output should go to $texmfsysconfig/xdvi/XDvi TODO TODO
- for (@lines) { print; }
+ my @newlines;
+ my $foundcfg = 0;
+ for my $l (@lines) {
+ if ($l =~ m/$firstre/) {
+ push @newlines, &$bl($l, $newpaper);
+ $foundcfg = 1;
+ } else {
+ push @newlines, $l;
+ }
+ }
+ # what to do if no default line found???
+ if (!$foundcfg) {
+ push @newlines, &$bl($defaultline, $newpaper);
+ }
+ for (@newlines) { print; }
} else {
- warn "Not a valid paper size for xdvi: $newpaper\n";
+ warn "Not a valid paper size for $prog: $newpaper\n";
}
}
} else {
- # just print the current value
- print "current xdvi paper size: $currentpaper\n";
+ # just return the current value
+ print "Current paper setting for $prog: $currentpaper\n";
}
}
-
-
### Local Variables:
### perl-indent-level: 2
### tab-width: 2