diff options
author | Norbert Preining <preining@logic.at> | 2009-09-15 18:56:50 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2009-09-15 18:56:50 +0000 |
commit | 995770ec5a02a4379ee49acbad1ce091601f7203 (patch) | |
tree | 1d78cb5bf9ab257c8c5d66ceb3127337fbd4b0b3 /Master/tlpkg/dev | |
parent | 29b6bc51ba93d568c16f16e04fbc509653d85241 (diff) |
rework tlpkg/doc and tlpkg/dev layout
git-svn-id: svn://tug.org/texlive/trunk@15301 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/dev')
-rw-r--r-- | Master/tlpkg/dev/README | 45 | ||||
-rw-r--r-- | Master/tlpkg/dev/dev.multi-source-support.README | 127 | ||||
-rw-r--r-- | Master/tlpkg/dev/dev.usermode-tlmgr.README | 207 | ||||
-rw-r--r-- | Master/tlpkg/dev/test-code-for-papersize-in-perl.pl | 528 |
4 files changed, 379 insertions, 528 deletions
diff --git a/Master/tlpkg/dev/README b/Master/tlpkg/dev/README new file mode 100644 index 00000000000..61ea2a60b97 --- /dev/null +++ b/Master/tlpkg/dev/README @@ -0,0 +1,45 @@ +dev.multi-source-support.patch +dev.multi-source-support.README + see dev.multi-source-support.README + +dev.tempfile-for-tlpdb.patch + trial to make symlink attacks harder by using tmpfiles instead + of the always same filename when downloading the tlpdb.xz + +dev.usermode-tlmgr.patch +dev.usermode-tlmgr.README + see dev.usermode-tlmgr.README + +makeself-runscript.sh + a run.sh for a makeself (tlmgr-update-latest.sh) that even + allows installation of texlive by installing the bare bone + minimal (texlive.infra) and then bootstrapping into some + minimal env + + Needs work, both on the script and tlmgr itself + +mktextex.pl + Simple mktextex program that can be used to query the tlpdb + on missing files and install them automatically. + Probably not useable in real life, only for testing. + +mktexupd.texlua + rewrite of mktexupd in texlua + +tlmgr1.pl-with-recreate-tlpdb + version of tlmgr.pl as shipped with TL2008 DVD, but with the + recreate-tlpdb action added, so that people can go back to + some working state after the tlpdb has been hosed. + +tlnet-disabled-packages.txt + this file collects packages that should NOT be updated in + tlnet, read by tl-update-containers. + + This is probably the wrong place for this file, but where else? + +tlrepo-from-minimals.pl + Semi-working (WIP) script that automatically creates a + TL repository from the context minimals. + Needs work (the minimals are developping too fast) + + diff --git a/Master/tlpkg/dev/dev.multi-source-support.README b/Master/tlpkg/dev/dev.multi-source-support.README new file mode 100644 index 00000000000..e0b3af6f3aa --- /dev/null +++ b/Master/tlpkg/dev/dev.multi-source-support.README @@ -0,0 +1,127 @@ +Multi source support in TeX Live +-------------------------------- +(Work in progress) + +(completely independent from generalized revisions) +[karl: good.] + +1) extension of the location part in 00texlive-installation.config +------------------------------------------------------------------ + +Every line can contain an aditional tag ([a-z0-9,]+) after the actual location, +examples: + depend location:http://mirror.ctan.org/systems/texlive/tlnet/2008 ctan + depend location:http://server.local.uni/texlive/packages department + +done +[karl: how do these lines get added? tool, manual editing of tlpdb?] +[norbert: tlmgr location url1 url2=tag1 url3 url4=tag2 ... + # sets url1, url2 with tag tag1, url3, and url4 with tag2 + # as the list of available locations + # backward compatibility with former usage + tlmgr location add ... + # adds locations to the list of available locs + tlmgr location remove ... + # removes locations ... +] +[k2: well, there is no "location" action now, so compatibility isn't an issue. +having this new action seems like a good idea. tlmgr option location foo +will just become a synonm for tlmgr location add foo. yes?] + +2) invocation of tlmgr/installation +----------------------------------- + +Normally tlmgr will install the candidate with the highest revision number. +[karl: ok, given pinning below. otherwise i don't like it.] +[norbert: Why, can you explain why you don't like that the highest revision + number wins?] +[k2: because it is random, except in the one case where you want to use + it. that is, i understand that you want to copy a tl package, make + some local fixes, and install it locally, keeping track of the rev + number. that's fine for you. but there's no way most people are + going to bother with that. if mojca sets up a context repo, say, + those revision numbers are (should be) completely independent of tl's + revision numbers. therefore, all the context packages should be + pinned to the context repo, so the context repo always wins. without + pinning, it would be an unmaintainable situation.] + +That will be achieved by + tlmgr install package + +If you want to install a package from a specific mirror you can do + tlmgr install package/TAG + (tlmgr install package/SOURCE) +where TAG is the tag given above, and SOURCE is the full source address. +So continuing the above example we could call + tlmgr install package/department +or + tlmgr install package/http://server.local.uni/texlive/packages +(maybe we don't allow the later form ...?) +[karl: well, if it's done, then I see no reason not to support it.] + +done + +3) pinning +---------- + +tlmgr will evaluate an additional config file + ROOT/tlpkg/pinning +or the one given via cmdline + tlmgr -pins /path/to/pinning/file +[karl: maybe it should be found in texmf-local/tlpkg? look there + before ROOT/tlpkg but allow both? maybe other places too. have to think + about it. Also, the filename should be something clearer, perhaps + tlpkgpins.txt.] +[norbert: agreed, that texmf-local might be a better place. should be + thought out] + +That file contains lines + package:tag:pin +where package is a package name or * (or regexp? or glob context* eg?) +[glob is better than regexp in this case I think] +and tag is [a-z0-9,]+ as for tags above, or *, +and pin is an integer between 0 and 1000. + +Now the evaluation *which* package will be installed will be done as follows: + +1) create the list of candidates, i.e., all tlpobj from different sources + where the name matches the one to be installed +[karl: if a package is pinned to a single source (99% case, seems to + me), the other sources (e.g., default ctan) won't even be considered, right?] + +[norbert: well, it depends. There will be a default pin value of say 500, + and you can give pin values lower than 500 to prefer packages from other + sources, or higher pin values to prefer these sources] + +[k2: I understand there is all this flexibility, but that's not my +point. I envision the single most common use of this (by far) to say +"get package foo from my special location bar", where foo is a local +font, or tlmgr from tlcritical. In these cases, the user will set a +single location. And then it would be a waste of time for tlmgr to even +consider looking at the default location (tlnet) for foo. It should not +even be a candidate.] + + +2) compute the pins of all the candidates + +3) if there are different pins cancel those candidates with a non-maximal pin + (i.e., let pin_max = max { pin(candidate) : candidate in candidates }, + and new candidates are those with pin(candidate) = pin_max) + +4) within all the remaining candidates choose the one with the highest + revision number + + +======================================== + +Consequences of the above: +- no source: part necessary in the revisions +- packages can be pinned to a specific source, and will not be updated + even if another source ships a higher version number +- no changes to the general server infrastructure are needed +- default installations continue as before +- normal installations with multiple sources but without pinning will + simply *do*the*right*thing*, namely install the highest revision number. +[karl: it's unclear to me that that is the right thing, in general, but + I can see how it is the right thing in some cases, e.g., yours, so fine.] +[norbert: see above ... I don't see the wrong point ;-) ] diff --git a/Master/tlpkg/dev/dev.usermode-tlmgr.README b/Master/tlpkg/dev/dev.usermode-tlmgr.README new file mode 100644 index 00000000000..e79fce55af1 --- /dev/null +++ b/Master/tlpkg/dev/dev.usermode-tlmgr.README @@ -0,0 +1,207 @@ +Using the TeX Live Manager in Usermode +====================================== +(to be discussed and implemented) +(partial implementation working for install and remove is in + tlpkg/dev/dev.usermode-tlmgr.patch) + + +0. Contents +----------- + +0. Contents +1. Rational and definition +2. General layout +3. Description of actions +4. Open questions +5. Changes to the infrastructure + +--------------------------------------------------------------- + +0.1 Implementation notes +------------------------ + +- User has to first call + tlmgr init-usertree [ --usertree .... ] +- available_architectures is set to the empty list, this allows + updating packages depending on .ARCH packages, but I am not sure + if that is a good idea + fixed now, only relocated packages can be installed in usermode +- update, install, remove, paper done +- postinstall action call -sys variant if !$opts{"usermode"} +- most other actions exit 1 with warning if in usermode +- backup and restore should be checked + +--------------------------------------------------------------- + +1. Rationale and definition +--------------------------- + +The idea behind developing a user mode for the TeX Live Manager is +providing a tool to manage different texmf trees for users without +write permissions to the system TeX Live installation on a multi user +system. + +If a user without write permissions to the main installation +tree is calling tlmgr, or it is called with --user (name to be decided) +command line argument, then tlmgr will work in "usermode" and will behave +as specified here. + +Already supported actions (where no write permissions are needed): + help, version, search, show, list, check, print-arch + +Actions that behave differently in usermode: + install, update, remove, option, paper, generate, backup, restore + uninstall, symlinks + +Actions that are not supported in usermode: + arch + +Actions I am not sure by now + gui + +------------------------------------------------------------ + +2. General layout +----------------- + +In usermode tlmgr manages a different texmf tree. By default it is TEXMFHOME +but can be changed with --user-tree ... (name to be decided) (which implies +automatically --user). The so managed texmf tree TREE contains a new toplevel +directory + TREE/tlpkg +which in turns contains the tlpdb, and the sub directory tlpkg/tlpobj. + +The file + TREE/tlpkg/texlive.tlpdb +contains only the packages that have been installed into the user tree TREE +plus additional options in the virtual package 00texlive.installation +(like with the main installation's texlive.tlpdb). + +Management in user mode is only possible for "relocatable" packages, that are +packages that share the common prefix + $TeXLive::TLConfig::RelocPrefix +which is set to + texmf-dist +That means that only a package where all files are from the texmf-dist tree +can be managed in usermode. + +These packages' containers are created relocatable, that is, the files in +the tar file do not have the "texmf-dist" part included, thus can be +unpacked directly into TEXMFHOME. In the tlpdb this fact is advertised +in a TLPOBJ with the new field + relocated 1 +As an example: + name 12many + category Package + revision ... + relocated 1 + shortdesc ... + ... + docfiles size=98 + RELOC/doc/latex/12many/12many.pdf + RELOC/doc/latex/12many/README + ... + srcfiles size=6 + RELOC/source/latex/12many/12many.dtx + RELOC/source/latex/12many/12many.ins + runfiles size=1 + RELOC/tex/latex/12many/12many.sty + ... + +The normal installation procedure of TeX Live (i.e., currently +TLUtils::install_package) will take care that when unpacking these +relocated containers the missing "texmf-dist" is added. + +----------------------------------------------- + +3. Description of actions +------------------------- + +install: + in usermode the tlmgr action install will check that the package + and all depending packages are either all relocated, or those that + are not relocated are already installed in the system installation. + If this is true it will unpack all containers to be installed into + the user tree (TEXMFHOME or the value of --user-tree) and add the + respective packages to the user texlive.tlpdb (creating it if there + has non be created till now). + + Open question: Should we support installation of dependencies at all + or should install only work on single package in user mode. If only + on single package, what to do with collections and other dependencies? + Maybe the user has to install all packages by hand? + +backup, restore, remove, update: + in usermode the tlmgr action update will check that all packages + to be updated are installed in the user tree, otherwise it behaves + exactely like the system tlmgr. + +option: + only acts upon the user's texlive.tlpdb + +paper: + changes configuration files in user tree + +generate: + creates configuration files in user tree + +uninstall: + will remove all packages from the user's texlive.tlpdb, and then + remove the tlpkg directory in the user tree + +symlinks: + takes the settings from the user's texlive.tlpdb, other then that + it behaves the same way + +gui: + the GUI should be adapted to do (at least): + - if in usermode show all packages with specification whether it is + from user tree or system tree + - show packags that have versions in the user tree and the system tree + - other actions work as described above + +arch: + is simply not supported because it needs access to the binary directories + which are not in the texmf-dist prefix, so no operation is allowed + +----------------------------------------------------------------------- + +4. Open questions +----------------- + +a. Post install actions: + what should be done with post install actions: + - fileassoc -> ignore + - shortcuts -> make them only for the user? + - TLPackageConfigurations (should it go anyway) ? + - post install code scripts: we could pass the "user" argument + so scripts can react on that + +b. Behaviour if system tree has been updated and provides newer packages: + - warn the user + - automatically remove packages in the user tree that are older NO!!! + +c. Currently user mode is only when installing from CD/NET, but not + from svn/DVD. Should this be fixed? + +-------------------------------------------------------------------------- + +5. Changes to the infrastructure (those already known) +-------------------------------- + +- texlive.tlpdb: + entries can now files without any leading texmf tree, but then the + package has to contain the "relocated 1" key/value pair +- TLPOBJ.pm: accept new key "relocated" +- tl-update-container: + . add cmd line option for $opt_relative + . adjust the tlpobj if the container was build relocatable so that + texmf-dist prefix is removed from the files +- TLUtils.pm + install_package(s): check for relocatable and adjust $target by + adding $RelocPrefix +- tlmgr.pl + too many to actually list them + +--------------------------------------------------------------------------- +np, last changed 2009-05-02 diff --git a/Master/tlpkg/dev/test-code-for-papersize-in-perl.pl b/Master/tlpkg/dev/test-code-for-papersize-in-perl.pl deleted file mode 100644 index 1c9b6e4ba54..00000000000 --- a/Master/tlpkg/dev/test-code-for-papersize-in-perl.pl +++ /dev/null @@ -1,528 +0,0 @@ - -# -# TODO TODO TODO -# 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 -# -# output is done to stdout, not the right config file -# -$^W = 1; -use strict; - - -my %pdftex_papersize = ( - "letter" => [ '8.5 true in', '11 true in' ], - "a4" => [ '210 true mm', '297 true mm' ], -); - -my %xdvi_papersize; -$xdvi_papersize{'us'}='8.5x11'; -$xdvi_papersize{'letter'}='8.5x11'; -$xdvi_papersize{'usr'}='11x8.5'; -$xdvi_papersize{'legal'}='8.5x14'; -$xdvi_papersize{'ledger'}='17.0x11.0'; -$xdvi_papersize{'tabloid'}= '11.0x17.0'; -$xdvi_papersize{'foolscap'}='13.5x17.0'; -$xdvi_papersize{'a1'}='59.4x84.0cm'; -$xdvi_papersize{'a2'}='42.0x59.4cm'; -$xdvi_papersize{'a3'}='29.7x42.0cm'; -$xdvi_papersize{'a4'}='21.0x29.7cm'; -$xdvi_papersize{'a5'}='14.85x21.0cm'; -$xdvi_papersize{'a6'}='10.5x14.85cm'; -$xdvi_papersize{'a7'}='7.42x10.5cm'; -$xdvi_papersize{'a1r'}='84.0x59.4cm'; -$xdvi_papersize{'a2r'}='59.4x42.0cm'; -$xdvi_papersize{'a3r'}='42.0x29.7cm'; -$xdvi_papersize{'a4r'}='29.7x21.0cm'; -$xdvi_papersize{'a5r'}='21.0x14.85cm'; -$xdvi_papersize{'a6r'}='14.85x10.5cm'; -$xdvi_papersize{'a7r'}='10.5x7.42cm'; -$xdvi_papersize{'b1'}='70.6x100.0cm'; -$xdvi_papersize{'b2'}='50.0x70.6cm'; -$xdvi_papersize{'b3'}='35.3x50.0cm'; -$xdvi_papersize{'b4'}='25.0x35.3cm'; -$xdvi_papersize{'b5'}='17.6x25.0cm'; -$xdvi_papersize{'b6'}='13.5x17.6cm'; -$xdvi_papersize{'b7'}='8.8x13.5cm'; -$xdvi_papersize{'b1r'}='100.0x70.6cm'; -$xdvi_papersize{'b2r'}='70.6x50.0cm'; -$xdvi_papersize{'b3r'}='50.0x35.3cm'; -$xdvi_papersize{'b4r'}='35.3x25.0cm'; -$xdvi_papersize{'b5r'}='25.0x17.6cm'; -$xdvi_papersize{'b6r'}='17.6x13.5cm'; -$xdvi_papersize{'b7r'}='13.5x8.8cm'; -$xdvi_papersize{'c1'}='64.8x91.6cm'; -$xdvi_papersize{'c2'}='45.8x64.8cm'; -$xdvi_papersize{'c3'}='32.4x45.8cm'; -$xdvi_papersize{'c4'}='22.9x32.4cm'; -$xdvi_papersize{'c5'}='16.2x22.9cm'; -$xdvi_papersize{'c6'}='11.46x16.2cm'; -$xdvi_papersize{'c7'}='8.1x11.46cm'; -$xdvi_papersize{'c1r'}='91.6x64.8cm'; -$xdvi_papersize{'c2r'}='64.8x45.8cm'; -$xdvi_papersize{'c3r'}='45.8x32.4cm'; -$xdvi_papersize{'c4r'}='32.4x22.9cm'; -$xdvi_papersize{'c5r'}='22.9x16.2cm'; -$xdvi_papersize{'c6r'}='16.2x11.46cm'; -$xdvi_papersize{'c7r'}='11.46x8.1cm'; - -my %dvipdfm_papersize = ( 'letter' => 1, 'legal' => 1, 'ledger' => 1, - 'tabloid' => 1, 'a4' => 1, 'a3' => 1 ); - -my $texmfsysvar = `kpsewhich -var-value=TEXMFSYSVAR`; -chomp($texmfsysvar); -my $texmfsysconfig = `kpsewhich -var-value=TEXMFSYSCONFIG`; -chomp($texmfsysconfig); - -# we are doing -sys variants -$ENV{"TEXMFVAR"} = $texmfsysvar; -$ENV{"TEXMFCONFIG"} = $texmfsysconfig; - -my $what = shift; - -if (!$what) { - print "need an argument\n"; - exit 1; -} - -# all subs do_* work the same way -# do_foobar --list -# list all available sizes with the selected first -# do_foobar -# informational string which paper has been selected -# doo_foobar <paper> -# selects the given <paper> - -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 "pdftex") { - do_pdftex(@ARGV); -} elsif ($what eq "xdvi") { - do_xdvi(@ARGV); -} else { - print "Unknown what $what!\n"; - exit 1; -} -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 --- -# |... -# |stuff not related to paper sizes -# |... -# | <empty line> -# |% some comments -# |% more comments -# |@ <NAME> <WIDTH> <HEIGHT> -# |@+ ...definition line -# |@+ ...definition line -# |... more definition lines -# |@+ %%EndPaperSize -# | -# |@ <NAME> <WIDTH> <HEIGHT> -# |... -# \------------ -# -# the first paper definition is the default -# selecting paper is done like with texconfig which used ed to move the -# selected part between @ $selected_paper .... @ /-1 (the line before the -# next @ line) to the line before the first @ line. -# (what a tricky ed invocation te created there, impressive!!!) -# -# Reading is done via --progname=dvips --format='dvips config' config.ps -# Writing is done to TEXMFSYSCONFIG/dvips/config/config.ps -# -sub do_dvips { - my $newpaper = shift; - my $configps = `kpsewhich --progname=dvips --format='dvips config' config.ps`; - chomp($configps); - print "file used: $configps\n"; - - open(FOO, "<$configps") or die("cannot open file: $!"); - my @lines = <FOO>; - close(FOO); - - my @papersizes; - my $firstpaperidx; - my %startidx; - my %endidx; - my $in_block = ""; - my $idx = 0; - for my $idx (0 .. $#lines) { - if ($lines[$idx] =~ m/^@ (\w+)/) { - $startidx{$1} = $idx; - $firstpaperidx || ($firstpaperidx = $idx-1); - $in_block = $1; - push @papersizes, $1; - next; - } - # empty lines or comments stop a block - if ($in_block) { - if ($lines[$idx] =~ m/^\s*(%.*)?\s*$/) { - $endidx{$in_block} = $idx-1; - $in_block = ""; - } - next; - } - } - - #for my $p (@papersizes) { - # print "papersize $p from idx $startidx{$p} to $endidx{$p}\n"; - #} - - if (defined($newpaper)) { - if ($newpaper eq "--list") { - for my $p (@papersizes) { - print "$p\n"; # first is already the selected one - } - } else { - my $found = 0; - for my $p (@papersizes) { - if ($p eq $newpaper) { - $found = 1; - last; - } - } - if ($found) { - my @newlines; - for my $idx (0..$#lines) { - if ($idx < $firstpaperidx) { - push @newlines, $lines[$idx]; - next; - } - if ($idx == $firstpaperidx) { - # insert the selected paper definition - push @newlines, @lines[$startidx{$newpaper}..$endidx{$newpaper}]; - push @newlines, $lines[$idx]; - next; - } - if ($idx >= $startidx{$newpaper} && $idx <= $endidx{$newpaper}) { - next; - } - push @newlines, $lines[$idx]; - } - # output should go to $texmfsysconfig/dvips/config/config.ps TODO TODO - for (@newlines) { print; } - } else { - warn "Not a valid paper size for dvips: $newpaper\n"; - } - } - } else { - # just print the current value - print "current dvips paper size: $papersizes[0]\n"; - } -} - -# -# 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, - 'a4', '\setuppapersize[a4][a4]', $newpaper); -} - - -# -# xdvi format: -# /--- XDvi --- -# |... -# |*paper: <NAME> -# |... -# \------------ -# -# Reading is done via --progname=xdvi --format='other text files' XDvi -# Writing is done to TEXMFSYSCONFIG/xdvi/XDvi -# -sub do_xdvi { - my $newpaper = shift; - my $xdvi = `kpsewhich --progname=xdvi --format='other text files' XDvi`; - chomp($xdvi); - 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, - '(not defined)', '*paper: a4', $newpaper); -} - - -# -# 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, '(not defined)', '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 -# $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, $defaultpaper, $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/$firstre/,@lines); - if (!@paperlines) { - $currentpaper = $defaultpaper; - } else { - if ($#paperlines > 0) { - warn "Strange, more than one paper definiton, using the first one!\n"; - } - $currentpaper = $paperlines[0]; - chomp($currentpaper); - $currentpaper =~ s/$secondre/$1/; - } - - # change value - if (defined($newpaper)) { - if ($newpaper eq "--list") { - print "$currentpaper\n"; - for my $p (@$paplist) { - print "$p\n" unless ($p eq $currentpaper); - } - } else { - my $found = 0; - for my $p (@$paplist) { - if ($p eq $newpaper) { - $found = 1; - last; - } - } - if ($found) { - 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); - } - # should save to $outf - for (@newlines) { print; } - } else { - warn "Not a valid paper size for $prog: $newpaper\n"; - } - } - } else { - # just return the current value - print "Current paper setting for $prog: $currentpaper\n"; - } -} - - -### Local Variables: -### perl-indent-level: 2 -### tab-width: 2 -### indent-tabs-mode: nil -### End: -# vim:set tabstop=2 expandtab: # |