summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2008-12-07 12:12:30 +0000
committerNorbert Preining <preining@logic.at>2008-12-07 12:12:30 +0000
commit224c451888e2fd5157e005edf903dcd6878f734c (patch)
treef14cbbc0e97cd75726bdc3f9785f12646dfb3e72 /Master/tlpkg/etc
parent86fb9b993d39c2763986fd49b5c2cdcfd07e6dc4 (diff)
more test code for perl paper setting, now complete but the
case that context config file does not have a working line and the line we add is added *after* the \endinput git-svn-id: svn://tug.org/texlive/trunk@11545 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/etc')
-rw-r--r--Master/tlpkg/etc/test-code-for-papersize-in-perl.pl136
1 files changed, 122 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 49be2dbbd3e..1c9b6e4ba54 100644
--- a/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl
+++ b/Master/tlpkg/etc/test-code-for-papersize-in-perl.pl
@@ -1,16 +1,11 @@
#
# 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?
+# if no paperconfig line is found in do_simple it adds to the end of the
+# file the new line, but this does not work on context because it
+# has an \endinput at the end ... needs to be fixed
#
-# 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!!!
+# output is done to stdout, not the right config file
#
$^W = 1;
use strict;
@@ -107,6 +102,8 @@ if ($what eq "dvips") {
do_dvipdfmx(@ARGV);
} elsif ($what eq "context") {
do_context(@ARGV);
+} elsif ($what eq "pdftex") {
+ do_pdftex(@ARGV);
} elsif ($what eq "xdvi") {
do_xdvi(@ARGV);
} else {
@@ -115,7 +112,113 @@ if ($what eq "dvips") {
}
exit 0;
+#
+# pdftex pdftexconfig.tex format
+# /--- pdftexconfig.tex ---
+# |...
+# |\pdfpagewidth=NNN true <unit>
+# |\pdfpageheight=NNN true <unit>
+# |...
+# \------------------------
+#
+# Reading is done via --progname=pdftex --format='tex' pdftexconfig.tex
+# Writing is done to TEXMFSYSCONFIG/tex/generic/config/pdftexconfig.tex
+#
+sub do_pdftex {
+ my $newpaper = shift;
+ my $cf = `kpsewhich --progname=pdftex --format=tex pdftexconfig.tex`;
+ chomp($cf);
+ print STDERR "file used for pdftex: $cf\n";
+ open(FOO, "<$cf") or die("cannot open file: $!");
+ my @lines = <FOO>;
+ close(FOO);
+
+ my ($cpw, $cph);
+ my ($cpwidx, $cphidx);
+ my $endinputidx;
+ # read the lines and the last pdfpageswidth/height wins
+ for my $idx (0..$#lines) {
+ my $l = $lines[$idx];
+ if ($l =~ m/^\s*\\pdfpagewidth\s*=?\s*(.+)\s*$/) {
+ $cpw = $1;
+ $cpwidx = $idx;
+ next;
+ }
+ if ($l =~ m/^\s*\\pdfpageheight\s*=?\s*(.+)\s*$/) {
+ $cph = $1;
+ $cphidx = $idx;
+ next;
+ }
+ if ($l =~ m/^\s*\\endinput\s*/) {
+ $endinputidx = $idx;
+ next;
+ }
+ }
+ # trying to find the right papersize
+ #
+ my $currentpaper;
+ if (defined($cpw) && defined($cph)) {
+ for my $pname (keys %pdftex_papersize) {
+ my ($w, $h) = @{$pdftex_papersize{$pname}};
+ if (($w eq $cpw) && ($h eq $cph)) {
+ $currentpaper = $pname;
+ last;
+ }
+ }
+ } else {
+ $currentpaper = "(undefined)";
+ }
+ $currentpaper || ($currentpaper = "$cpw x $cph");
+ if (defined($newpaper)) {
+ if ($newpaper eq "--list") {
+ print "$currentpaper\n";
+ for my $p (keys %pdftex_papersize) {
+ print "$p\n" unless ($p eq $currentpaper);
+ }
+ } else {
+ my $found = 0;
+ for my $p (keys %pdftex_papersize) {
+ if ($p eq $newpaper) {
+ $found = 1;
+ last;
+ }
+ }
+ if ($found) {
+ my $newwline =
+ '\pdfpagewidth=' . ${$pdftex_papersize{$newpaper}}[0] . "\n";
+ my $newhline =
+ '\pdfpageheight=' . ${$pdftex_papersize{$newpaper}}[1] . "\n";
+ if (defined($cpwidx)) {
+ $lines[$cpwidx] = $newwline;
+ } else {
+ if (defined($endinputidx)) {
+ $lines[$endinputidx] = $newwline . $lines[$endinputidx];
+ } else {
+ $lines[$#lines] = $newwline;
+ }
+ }
+ if (defined($cphidx)) {
+ $lines[$cphidx] = $newhline;
+ } else {
+ if (defined($endinputidx)) {
+ $lines[$endinputidx] = $newhline . $lines[$endinputidx];
+ } else {
+ $lines[$#lines] = $newwline;
+ }
+ }
+ for (@lines) { print; }
+ } else {
+ warn "Not a valid paper size for pdftex: $newpaper\n";
+ }
+ }
+ } else {
+ # just print the current value
+ print "current pdftex paper size: $currentpaper\n";
+ }
+}
+
+###############################################
#
# dvips config.ps format:
# /--- config.ps ---
@@ -260,7 +363,7 @@ sub do_context {
return($ll);
}
}, "tex/context/user/cont-sys.rme", \@bla,
- '\setuppapersize[a4][a4]', $newpaper);
+ 'a4', '\setuppapersize[a4][a4]', $newpaper);
}
@@ -286,7 +389,7 @@ sub do_xdvi {
$ll =~ s/^\*paper:\s+(\w+)\s*$/\*paper: $np\n/;
return($ll);
}, "xdvi/XDvi", \@bla,
- '*paper: a4', $newpaper);
+ '(not defined)', '*paper: a4', $newpaper);
}
@@ -312,7 +415,7 @@ sub do_dvipdfm_and_x {
my ($ll,$np) = @_;
$ll =~ s/^p\s+(\w+)\s*$/p $np\n/;
return($ll);
- }, $outp, $paplist, 'p a4', $newpaper);
+ }, $outp, $paplist, '(not defined)', 'p a4', $newpaper);
}
sub do_dvipdfm {
@@ -347,9 +450,13 @@ sub do_dvipdfmx {
# $firstre are shipped over to $bl
# $outp .. location of the output file
# $paplist .. ref to an array with the list of admissible paper sizes
+# $defaultpaper .. default papersize (arbitrary string) if the $firstre is
+# not found in the config file
+# $defaultline .. the line to be added at the bottom of the file if
+# no line has been found
# $newpaper .. --list, new paper, or undef
sub do_simple {
- my ($inp, $prog, $firstre, $secondre, $bl, $outp, $paplist, $defaultline, $newpaper) = @_;
+ my ($inp, $prog, $firstre, $secondre, $bl, $outp, $paplist, $defaultpaper, $defaultline, $newpaper) = @_;
print STDERR "file used for $prog: $inp\n";
@@ -360,7 +467,7 @@ sub do_simple {
my $currentpaper;
my @paperlines = grep (m/$firstre/,@lines);
if (!@paperlines) {
- $currentpaper = "(undefined)";
+ $currentpaper = $defaultpaper;
} else {
if ($#paperlines > 0) {
warn "Strange, more than one paper definiton, using the first one!\n";
@@ -400,6 +507,7 @@ sub do_simple {
if (!$foundcfg) {
push @newlines, &$bl($defaultline, $newpaper);
}
+ # should save to $outf
for (@newlines) { print; }
} else {
warn "Not a valid paper size for $prog: $newpaper\n";