diff options
author | Karl Berry <karl@freefriends.org> | 2019-12-31 23:19:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2019-12-31 23:19:25 +0000 |
commit | 7d8c399780981359be7896a5fb053a0bd873a3e6 (patch) | |
tree | 3680abb7f9038f8d19f0da0af63aab9dedcb770c /Master/texmf-dist/scripts | |
parent | 449ceb762b8adeccbef9731acdf8001b20fa4f74 (diff) |
archive old lua tlpdb attempt
git-svn-id: svn://tug.org/texlive/trunk@53284 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rw-r--r-- | Master/texmf-dist/scripts/texlive/lua/texlive/getopt.tlu | 99 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/texlive/lua/texlive/tlpdb.tlu | 259 | ||||
-rw-r--r-- | Master/texmf-dist/scripts/texlive/lua/texlive/utils.tlu | 78 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/texlive/test-tlpdb.tlu | 45 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/texlive/texconf.tlu | 728 |
5 files changed, 0 insertions, 1209 deletions
diff --git a/Master/texmf-dist/scripts/texlive/lua/texlive/getopt.tlu b/Master/texmf-dist/scripts/texlive/lua/texlive/getopt.tlu deleted file mode 100644 index 7e52ddd357f..00000000000 --- a/Master/texmf-dist/scripts/texlive/lua/texlive/getopt.tlu +++ /dev/null @@ -1,99 +0,0 @@ -#! /usr/bin/env texlua ---*-Lua-*- --- getopt.tlu --- --- (tex)lua library function for argument processing --- $Id$ --- --- Copyright 2008 Norbert Preining --- --- This code will presumably be changed in the near future. Don't use --- it for your own scripts! --- --- This file is licensed under the GNU General Public License version 2 --- or any later version. --- --- The file provides a basic getopt function --- it takes as argument a table with the argument names as keys and the --- number of argument options as values --- --- It returns a tables with the found arguments as keys and --- . true as value for an option not taking any values --- . a single value for an option taking one value --- . an array of values for an option taking more than one value --- --- Example: --- options = getopt( { help = 0, foo = 1, bar = 2 } ) --- and calling the script with --- script a --help b --bar c d e --foo f g h --- will leave a b e g h in the arguments and will return --- options["help"] = true --- options["foo"] = "f" --- options["bar"] = { "c", "d" } --- --- Options can start with a single or a double dash, but values may NOT be --- separated with a =, but need to be seprate arguments! --- --- Example code for printing out the options: --- print ("OPTIONS:") --- for o,v in pairs(options) do --- if (type(v) == "boolean") then --- print ("option "..o) --- elseif (type(v) == "table") then --- for a,b in ipairs(v) do --- print ("option "..o.."["..a.."] = "..b) --- end --- else --- print ("option "..o.." = "..v) --- end --- end - -function getopt(spec) - local newarg = {} - local retargs = {} - do - local i, limit = 1, #arg - while (i <= limit) do - local found = false - for k,v in pairs(spec) do - if (arg[i] == "--"..k or arg[i] == "-"..k) then - found = true - if (v == 0) then - -- boolean argument - retargs[k] = true - elseif (v == 1) then - -- one single argument - retargs[k] = arg[i+1] - i = i + 1 - else - local bla = {} - for n=1, v do - bla[n] = arg[i+n] - end - retargs[k] = bla - -- we have to shift the next i!!! - i = i + v - end - -- we have found the arg, so stop processing further spec arguments - break - end - end - if not(found) then - -- non of the spec args did hit, so we push the arg to the newargs - newarg[#newarg+1] = arg[i] - end - i = i + 1 - end - end - -- replace the global arg with the cleaned newarg - arg = newarg - -- return the found arguments - return retargs -end - --- Local Variables: --- lua-indent-level: 2 --- tab-width: 2 --- indent-tabs-mode: nil --- End: --- vim:set tabstop=2 expandtab: # diff --git a/Master/texmf-dist/scripts/texlive/lua/texlive/tlpdb.tlu b/Master/texmf-dist/scripts/texlive/lua/texlive/tlpdb.tlu deleted file mode 100644 index 4977431bd56..00000000000 --- a/Master/texmf-dist/scripts/texlive/lua/texlive/tlpdb.tlu +++ /dev/null @@ -1,259 +0,0 @@ -#! /usr/bin/env texlua --- texlive/tlpdb.tlu --- $Id$ --- --- Copyright (C) 2008 Norbert Preining --- This file is licensed under the GNU General Public License version 2 --- or any later version. --- --- TODO: tag evaluation of docfiles lines ... --- --- providing the tlpdb as a lua table --- --- format --- tlpobj = tlpdb[packagename] --- tlpobj.name string --- tlpobj.revision string --- tlpobj.category string --- tlpobj.shortdesc string --- tlpobj.longdesc string --- tlpobj.catalogue string --- tlpobj.cataloguedata table indexed by various catalogue values --- tlpobj.containersize string --- tlpobj.srccontainersize string --- tlpobj.doccontainersize string --- tlpobj.containerchecksum string --- tlpobj.srccontainerchecksum string --- tlpobj.doccontainerchecksum string --- tlpobj.binfiles table indexed by archs giving table indexed by numbers --- tlpobj.binsize table indexed by archs giving strings --- tlpobj.docfiles = table indexed by numbers --- tlpobj.docfiledata[docfile][tag] = value --- tlpobj.docsize string --- tlpobj.srcfiles = table indexed by numbers --- tlpobj.srcsize string --- tlpobj.runfiles = table indexed by numbers --- tlpobj.runsize string --- tlpobj.depend = table indexed by numbers --- tlpobj.execute = table of strings indexed by numbers --- tlpobj.postaction = table of strings indexed by numbers --- tlpobj.relocated = boolean --- ---*-Lua-*- - -function read_tlpdb(root) - local fn = root..'/tlpkg/texlive.tlpdb' - if (lfs.isfile(fn)) then -- tlpdb exists - local lineno = 0 -- current line number - local errline = '' -- current line - local function die(msg) - io.stderr:write(msg..' in '..fn..' at line '..tostring(lineno) - ..'\n>>'..errline..'<<\n') - -- for now, exit, but this is bad behaviour if we want to be used - -- as a library. FIXME. - os.exit(1) - end - local started = false - local lastcmd = "" - local arch - local size - local tlpobj = {} - local name - local tlpdb = {} - for line in io.lines(fn) do - lineno = lineno + 1 - errline = line - if string.match(line, '^%s*$') then - if started then - -- we have encountered an empty line while creating a tlpobj, so - -- stop that tlpobj, add it to the tlpdb, and restart - --tlpdb[name] = tlpobj - tlpdb[name] = tlpobj - tlpobj = {} - --print ("adding "..name.." to tlpdb") - started = false - end - else - if string.match(line, '^ ') then - if lastcmd == 'runfiles' or - lastcmd == 'binfiles' or - lastcmd == 'docfiles' or - lastcmd == 'srcfiles' or - lastcmd == 'execute' or - lastcmd == 'depend' then - line = string.gsub(line, '^ ', lastcmd.."continued ") - else - die('Continuation of '..lastcmd..' not allowed') - end - end - local first - local rest - first, rest = string.match(line,'^(%S+)%s*(.*)%s*$') - --print ("DEBUG: line = "..line) - --print ("DEBUG: first = "..first) - lastcmd = first - if first == "name" then - tlpobj.name = rest - name = rest - started = true - elseif first == "revision" then - tlpobj.revision = rest - elseif first == "category" then - tlpobj.category = rest - elseif first == "shortdesc" then - tlpobj.shortdesc = rest - elseif first == "catalogue" then - tlpobj.catalogue = rest - elseif string.match(first,'^catalogue%-') then - --local data = string.match(first,'^catalogue-(.*)$') - local cdata = string.gsub(first,'^catalogue%-', '') - --print("DEBUG: cdata = "..cdata..", first = "..first) - if not(tlpobj.cataloguedata) then - tlpobj.cataloguedata = {} - end - tlpobj.cataloguedata[cdata] = rest - elseif first == "containersize" then - tlpobj.containersize = rest - elseif first == "srccontainersize" then - tlpobj.srccontainersize = rest - elseif first == "doccontainersize" then - tlpobj.doccontainersize = rest - elseif first == "containerchecksum" then - tlpobj.containerchecksum = rest - elseif first == "srccontainerchecksum" then - tlpobj.srccontainerchecksum = rest - elseif first == "doccontainerchecksum" then - tlpobj.doccontainerchecksum = rest - elseif first == "runfiles" then - local rsize = string.match(rest,'size=([0-9]*)') - if (rsize) then - tlpobj.runsize = rsize - else - if #rest > 0 then - die('Unknown tag') - end - end - elseif first == "docfiles" then - local dsize = string.match(rest,'size=([0-9]*)') - if (dsize) then - tlpobj.docsize = dsize - else - if #rest > 0 then - die('Unknown tag') - end - end - elseif first == "srcfiles" then - local ssize = string.match(rest,'size=([0-9]*)') - if (ssize) then - tlpobj.srcsize = ssize - else - if #rest > 0 then - die('Unknown tag') - end - end - elseif first == "binfiles" then - arch = "" - local barch - local bsize - for aaa in string.gmatch(rest,'%S+') do - if string.match(aaa,'^arch=(%S*)$') then - barch = string.match(aaa,'^arch=(%S*)$') - elseif string.match(aaa,'^size=(%S*)$') then - bsize = string.match(aaa,'^size=(%S*)$') - else - die('Unknown tag') - end - end - if barch and bsize then - if not(tlpobj.binsize) then - tlpobj.binsize = {} - end - tlpobj.binsize[barch] = bsize - arch = barch - else - die('Incomplete binfile tags ') - end - elseif first == "runfilescontinued" then - if not(tlpobj.runfiles) then - tlpobj.runfiles = {} - end - table.insert(tlpobj.runfiles,rest) - lastcmd = "runfiles" - elseif first == "docfilescontinued" then - local dfile,tags = string.match(rest,'^(%S+)%s*(.*)%s*$') - if not(tlpobj.docfiles) then - tlpobj.docfiles = {} - end - table.insert(tlpobj.docfiles,dfile) - for aaa,bbb in string.gmatch(tags,'(%S+)=(%b"")') do - if not(tlpobj.docfiledata) then - tlpobj.docfiledata = {} - end - if aaa == "details" or aaa == "language" then - if not(tlpobj.docfiledata[dfile]) then - tlpobj.docfiledata[dfile] = {} - end - tlpobj.docfiledata[dfile][aaa] = bbb - else - die('Unknown docfile tag') - end - end - lastcmd = "docfiles" - elseif first == "srcfilescontinued" then - if not(tlpobj.srcfiles) then - tlpobj.srcfiles = {} - end - table.insert(tlpobj.srcfiles,rest) - lastcmd = "srcfiles" - elseif first == "binfilescontinued" then - if not(tlpobj.binfiles) then - tlpobj.binfiles = {} - end - if not(tlpobj.binfiles[arch]) then - tlpobj.binfiles[arch] = {} - end - table.insert(tlpobj.binfiles[arch],rest) - lastcmd = "binfiles" - elseif first == "depend" then - if not(tlpobj.depend) then - tlpobj.depend = {} - end - table.insert(tlpobj.depend,rest) - elseif first == "longdesc" then - if tlpobj.longdesc then - tlpobj.longdesc = tlpobj.longdesc.." "..rest - else - tlpobj.longdesc = rest - end - elseif first == "execute" then - if not(tlpobj.execute) then - tlpobj.execute = {} - end - table.insert(tlpobj.execute,rest) - elseif first == 'postaction' then - tlpobj.postaction = tlpobj.postaction or {} - table.insert(tlpobj.postaction, rest) - elseif first == 'relocated' then - -- don't even try to validate the value - tlpobj.relocated = (rest == '1') - else - die('Unknown directive') - end - if not(first) then - die('Missing directive') - end - end - end - return tlpdb - else - print (fn..' not found.') - end -end - - --- Local Variables: --- lua-indent-level: 2 --- tab-width: 2 --- indent-tabs-mode: nil --- End: --- vim:set tabstop=2 shiftwidth=2 expandtab: # diff --git a/Master/texmf-dist/scripts/texlive/lua/texlive/utils.tlu b/Master/texmf-dist/scripts/texlive/lua/texlive/utils.tlu deleted file mode 100644 index a31475b351c..00000000000 --- a/Master/texmf-dist/scripts/texlive/lua/texlive/utils.tlu +++ /dev/null @@ -1,78 +0,0 @@ --- texlive/utils.tlu --- $Id$ --- --- Copyright (C) 2008 Reinhard Kotucha, Norbert Preining --- You may freely use, modify and/or distribute this file. --- --- general utilities for TeX Live lua scripts - -function setupperl() - -- For Windows we use the shipped perl interpreter, otherwise we expect - -- a perl to be installed - local perlbin - if os.type == 'windows' then - perlbin=TEXDIR..'/tlpkg/tlperl/bin/perl.exe' - os.setenv('PERL5LIB', TEXDIR..'/tlpkg/tlperl/lib') - else - perlbin = 'perl' - end - return perlbin -end - -function findscript(scriptname) - local script = kpse.find_file(scriptname, 'texmfscripts') - if script then - return script - else - io.stderr:write(filename..': Cannot find script '..scriptname) - return false - end -end - --- fix arguments for windows -function fixwin(args_unix) - if os.type == 'windows' then - local args_win={} -- new table - args_win[0]=args_unix[1] - for i=1, #args_unix do - args_win[i]='"'..args_unix[i]..'"' - end - return args_win - else - return args_unix - end -end - -function rmtree (path) - if lfs.isdir(path) then - for file in lfs.dir(path) do - if file ~= '.' and file ~= '..' then - local f = path..'/'..file - if lfs.isdir(f) then - rmtree(f) - lfs.rmdir(f) - else - os.remove(f) - end - end - end - lfs.rmdir(path) - end -end - - -function list (t) - local i = 0 - return function () - i = i + 1 - return t[i] - end -end - - --- Local Variables: --- lua-indent-level: 2 --- tab-width: 2 --- indent-tabs-mode: nil --- End: --- vim:set tabstop=2 expandtab: # diff --git a/Master/texmf-dist/scripts/texlive/test-tlpdb.tlu b/Master/texmf-dist/scripts/texlive/test-tlpdb.tlu deleted file mode 100755 index 2004e958fb1..00000000000 --- a/Master/texmf-dist/scripts/texlive/test-tlpdb.tlu +++ /dev/null @@ -1,45 +0,0 @@ -#! /usr/bin/env texlua ---*- Lua -*- - --- Copyright (C) 2008 Norbert Preining. --- You may freely use, modify and/or distribute this file. - --- test the functionality of tlpdb.tlu - -kpse.set_program_name(arg[-1]) -texmfmain = kpse.var_value('TEXMFMAIN') -package.path = texmfmain.."/scripts/texlive/lua/?.tlu" -require("texlive.tlpdb") -master=kpse.var_value('SELFAUTOPARENT') -io.stderr:write('reading tlpdb ... ') -tlpdb = read_tlpdb(master) -io.stderr:write('done\n') - ---os.exit(0) - -for a,b in pairs(tlpdb) do - print ("package = "..a) - for c,d in pairs(b) do - if (type(d) == "table") then - print (" "..c..":") - for cdata,cvalue in pairs(d) do - if (type(cvalue) == "table") then - print (" "..cdata..":") - for aaa,bbb in pairs(cvalue) do - print (" "..aaa.." = "..bbb) - end - else - print (" "..cdata.." = "..cvalue) - end - end - else - print (" "..c.." = "..tostring(d)) - end - end -end --- Local Variables: --- lua-indent-level: 2 --- tab-width: 2 --- indent-tabs-mode: nil --- End: --- vim:set tabstop=2 shiftwidth=2 expandtab: # diff --git a/Master/texmf-dist/scripts/texlive/texconf.tlu b/Master/texmf-dist/scripts/texlive/texconf.tlu deleted file mode 100755 index e41500cc447..00000000000 --- a/Master/texmf-dist/scripts/texlive/texconf.tlu +++ /dev/null @@ -1,728 +0,0 @@ -#! /usr/bin/env texlua ---*- Lua -*- --- $Id$ - --- Copyright (C) 2008 Reinhard Kotucha, Norbert Preining. --- You may freely use, modify and/or distribute this file. - --- texconf is a subset of Thomas Esser's texconfig shell script. - -if string.find(arg[0], '/') then -- UNIX path - filename=select(1, string.gsub(arg[0], '.*/', '')) -elseif string.find(arg[0], '\\') then -- Windows path - filename=select(1, string.gsub(arg[0], '.*\\', '')) -else -- no path - filename=arg[0] -end - -basename=select(1, string.gsub(filename, '\.tlu$', '')) - -usageprogname = basename - -domktexlsr = false -doformat = false -sys=false -noformatopt = false - -if string.find(basename, '-sys$') then - basename=select(1, string.gsub(basename, '-sys$', '')) - sys=true -end - --- this script does NOT appear in the patch, so we cannot use its basename --- for kpse.set_program_name --- thus we use simply mktexlsr, which always is in the path and which --- does not have any special settings in texmf.cnf --- kpse.set_program_name(filename, basename) -kpse.set_program_name( "mktexlsr" ) - --- set the search path for lua libraries -texmfmain = kpse.var_value('TEXMFMAIN') -texmfdist = kpse.var_value('TEXMFDIST') -package.path = texmfmain.."/scripts/texlive/lua/?.tlu" -require("texlive.getopt") -require("texlive.utils") - --- do argument processing -options = getopt ( { sys = 0, prog = 1, noformat = 0 } ) -if (options["sys"]) then - sys = true -end -if (options["prog"]) then - usageprogname = options["prog"] -end -if (options["noformat"]) then - noformatopt = true -end - -if (sys) then - texmfconfig=kpse.var_value('TEXMFSYSCONFIG') - os.setenv('TEXMFCONFIG', texmfconfig) - texmfsysvar=kpse.var_value('TEXMFSYSVAR') - os.setenv('TEXMFVAR', texmfsysvar) -else - texmfconfig=kpse.var_value('TEXMFCONFIG') - if string.match(texmfconfig, '^~') then - -- workaround for old texlua, new kpathsea which expands '~' not - -- integrated yet. - if os.type == 'windows' then - home = os.getenv('USERPROFILE') - else - home = os.getenv('HOME') - end - texmfconfig = string.gsub(texmfconfig, '^~', home) - end -end - - -pdftex_papersize={} -pdftex_papersize['letter']={'8.5 true in', '11 true in'} -pdftex_papersize['a4']={'210 true mm', '297 true mm'} - -xdvi_papersize={} -xdvi_papersize['us']='8.5x11' -xdvi_papersize['usr']='11x8.5' -xdvi_papersize['legal']='8.5x14' -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' - -dvipdfm_papersize={'letter', 'legal', 'ledger', 'tabloid', 'a4', 'a3'} - -function mkdirhier(path) - local dirs={} - local dir=path - while string.match(dir, '/') do - dirs[#dirs+1]=dir - dir=select(1, string.gsub(dir, '/[^/]*$', '')) - end - -- reverse the list - local dirlist={} - for i=1, #dirs do - dirlist[#dirlist+1]=dirs[#dirs-i+1] - end - for i=1, #dirlist do - if not lfs.isdir(dirlist[i]) then - lfs.mkdir(dirlist[i]) - end - end -end - -function set_dvips_papersize(papersize) - -- If the argument is 'list' then a list of available paper sizes is - -- returned to stdout. It can be used by dialog(1) or */Tk - -- interfaces in order to build up the menu. The topmost entry is - -- the one which is actually used by dvips. - local i, key, val - local partab={} - local par=1 - local line - local lin=1 - partab[par]={} - -- Read the file. partab{} contains all paragraphs. - kpse.set_program_name('dvips') - local filename=kpse.find_file('config.ps', 'dvips config') - -- print ('< '..filename) - local infile=assert(io.open(filename, 'r')) - while true do - line=infile:read('*line') - if line == nil then break end - if string.find(line, '^\s*$') then - par=par+1 - partab[par]={} - lin=1 - else - partab[par][lin]=line - lin=lin+1 - end - end - -- par_papersize{} is a list which associates papersizes with - -- paragraphs. Paregraphs containing no papersize information are - -- denoted by 'NO_SIZE_PAR'. - local par_papersize={} - for i=1, #partab do - par_papersize[i]='NO_SIZE_PAR' - for k=1, #partab[i] do - if string.find(partab[i][k], '^@%s') then - par_papersize[i]=string.match(partab[i][k], '^@%s+(%w+)%s') - end - end - end - infile:close() - - local index=-1 --the papagraph wich contains the desired size. - if papersize=='--list' then - -- print a list of available sizes to stdout. - -- the topmost item is the one currently used by dvips. - for key, val in ipairs(par_papersize) do - if val ~= 'NO_SIZE_PAR' and val ~= 'unknown' then - io.stdout:write(val..'\n') - end - end - elseif papersize=='help' then - io.stdout:write('Usage: '..usageprogname..' dvips paper PAPER\n\n'.. - 'Valid PAPER settings:\n ') - local buffer='' - for key, val in ipairs(par_papersize) do - if val ~= 'NO_SIZE_PAR' and val ~= 'unknown' then - if #buffer + #val < 77 then - buffer=buffer..' '..val - else - io.stdout:write(buffer..'\n') - buffer=' '..val - end - end - end - io.stdout:write(buffer..'\n') - else --change paper size - for key, val in ipairs(par_papersize) do - if string.find(val, '^'..papersize..'$') then - index=key - end - end - if index == -1 then - io.stderr:write('Error: Paper Size "'..papersize.. - '" undefined. Aborting...\n') - os.exit(1) - end - -- print stuff which doesn't contain paper size information. - local outfile={} - for key, val in ipairs(par_papersize) do - if val == 'NO_SIZE_PAR' then - for i=1, #partab[key] do - outfile[#outfile+1]=partab[key][i]..'\n' - end - outfile[#outfile+1]='\n' - end - end - -- print selected par - for i=1, #partab[index] do - outfile[#outfile+1]=partab[index][i]..'\n' - end - outfile[#outfile+1]='\n' - -- print other pars to outfile table - for key, val in ipairs(par_papersize) do - if val ~= 'NO_SIZE_PAR' then - if key~=index then - for i=1, #partab[key] do - outfile[#outfile+1]=partab[key][i]..'\n' - end - outfile[#outfile+1]='\n' - end - end - end - -- write file - mkdirhier(texmfconfig..'/dvips/config') - local config=assert(io.open(texmfconfig..'/dvips/config/config.ps', 'w')) - for i=1, #outfile do - if not (string.match(outfile[i],'^%s*$') - and string.match(outfile[i-1],'^%s*$')) then - config:write(outfile[i]) - end - end - config:close() - print ('> '..texmfconfig..'/dvips/config/config.ps') - domktexlsr = true - end -end -- set_dvips_papersize - - -function set_xdvi_papersize(papersize) - local current_setting - -- Read the file. - local filename - if os.type == 'windows' then - return - end - - kpse.set_program_name('xdvi') - filename=kpse.find_file('XDvi', 'other text files') - - -- print ('< '..filename) - local infile=assert(io.open(filename, 'r')) - local lines={} - while true do - line=infile:read('*line') - if line == nil then break end - lines[#lines+1]=line - end - infile:close() - - if papersize=='--list' then - current_setting='a4' - for n, line in ipairs(lines) do - if string.find(line, '^\*paper:') then - current_setting=string.match(line, '^\*paper:%s+(%S+)') - for ptype, psize in pairs(xdvi_papersize) do - if current_setting==psize then - current_setting=ptype - end - end - end - end - print (current_setting) - for key, val in pairs(xdvi_papersize) do - if key ~= current_setting then - print(key) - end - end - elseif papersize=='help' then - io.stdout:write('Usage: '..usageprogname..' xdvi paper PAPER\n\n'.. - 'Valid PAPER settings:\n ') - local buffer='' - for ptype, psize in pairs(xdvi_papersize) do - if #buffer + #ptype < 77 then - buffer=buffer..' '..ptype - else - io.stdout:write(buffer..'\n') - buffer=' '..ptype - end - end - io.stdout:write(buffer..'\n') - else --change paper size - mkdirhier(texmfconfig..'/xdvi') - local config=assert(io.open(texmfconfig..'/xdvi/XDvi', 'w')) - for n=1, #lines do - if string.find(lines[n], '^!*\*paper:') then - config:write('*paper: '..papersize..'\n') - else - config:write(lines[n]..'\n') - end - end - config:close() - print ('> '..texmfconfig..'/xdvi/XDvi') - domktexlsr = true - end -end - - -function set_pdftex_papersize(papersize) - local current_setting - --Read the file. - kpse.set_program_name('pdftex') - local filename=kpse.find_file('pdftexconfig.tex', 'tex') - - -- print ('< '..filename) - local infile=assert(io.open(filename, 'r')) - local lines={} - while true do - line=infile:read('*line') - if line == nil then break end - if string.find(line, '^\\pdfpagewidth') then - pagewidth=string.match(line, '^\\pdfpagewidth%s*=?%s*(.+)%s*$') - end - if string.find(line, '^\\pdfpageheight') then - pageheight=string.match(line, '^\\pdfpageheight%s*=?%s*(.+)%s*$') - end - lines[#lines+1]=line - end - infile:close() - - current_setting='a4' - for ptype, sizes in pairs(pdftex_papersize) do - if pagewidth == pdftex_papersize[ptype][1] then - ptype_x=ptype - end - if pageheight == pdftex_papersize[ptype][2] then - ptype_y=ptype - end - end - if ptype_x == ptype_y then - current_setting=ptype_x - end - - if papersize=='--list' then - print(current_setting) - for ptype, sizes in pairs(pdftex_papersize) do - if ptype ~= current_setting then - print(ptype) - end - end - elseif papersize=='help' then - io.stdout:write('Usage: '..usageprogname..' pdftex paper PAPER\n\n'.. - 'Valid PAPER settings:\n ') - local buffer='' - for ptype, sizes in pairs(pdftex_papersize) do - if #buffer + #ptype < 77 then - buffer=buffer..' '..ptype - else - io.stdout:write(buffer..'\n') - buffer=' '..ptype - end - end - io.stdout:write(buffer..'\n') - else --change paper size - mkdirhier(texmfconfig..'/tex/generic/config') - local outfile=texmfconfig..'/tex/generic/config/pdftexconfig.tex' - local config=assert(io.open(outfile, 'w')) - for n=1, #lines do - line=lines[n] - if string.find(line, '^\\pdfpagewidth') then - config:write('\\pdfpagewidth='..pdftex_papersize[papersize][1]..'\n') - elseif string.find(line, '^\\pdfpageheight') then - config:write('\\pdfpageheight='..pdftex_papersize[papersize][2]..'\n') - else - config:write(line..'\n') - end - end - config:close() - print ('> '..outfile) - domktexlsr = true - doformat = true - end -end - - -function set_dvipdfm_papersize(papersize, program) - local current_setting - -- Read the file. - local filename - if program == 'dvipdfm' then - kpse.set_program_name('dvipdfm') - filename=kpse.find_file('config', 'other text files') - elseif program == 'dvipdfmx' then - kpse.set_program_name('dvipdfmx') - filename=kpse.find_file('dvipdfmx.cfg', 'other text files') - end - if not(filename) then - print ("Cannot find config file for "..program..", exiting!") - os.exit(1) - end - -- print ('< '..filename) - local infile=assert(io.open(filename, 'r')) - local lines={} - local current_setting='a4' - while true do - line=infile:read('*line') - if line == nil then break end - if string.find(line, '^p ') then - current_setting=string.match(line, '^p%s+(%S+)') - end - lines[#lines+1]=line - end - infile:close() - - if papersize=='--list' then - print(current_setting) - for i, ptype in ipairs(dvipdfm_papersize) do - if ptype ~= current_setting then - print (ptype) - end - end - elseif papersize=='help' then - io.stdout:write('Usage: '..usageprogname..' '..program..' paper PAPER\n\n'.. - 'Valid PAPER settings:\n ') - local buffer='' - for i, ptype in pairs(dvipdfm_papersize) do - if #buffer + #ptype < 77 then - buffer=buffer..' '..ptype - else - io.stdout:write(buffer..'\n') - buffer=' '..ptype - end - end - io.stdout:write(buffer..'\n') - else --change paper size - local outfile - mkdirhier(texmfconfig..'/dvipdfm/config') - if program == 'dvipdfm' then - outfile=texmfconfig..'/dvipdfm/config/config' - mkdirhier(texmfconfig..'/dvipdfm/config') - else - outfile=texmfconfig..'/dvipdfmx/dvipdfmx.cfg' - mkdirhier(texmfconfig..'/dvipdfmx') - end - print ('> '..outfile) - local config=assert(io.open(outfile, 'w')) - for n=1, #lines do - line=lines[n] - if string.find(line, '^p ') then - config:write('p '..papersize..'\n') - else - config:write(line..'\n') - end - end - config:close() - domktexlsr = true - end -end - - -function set_context_papersize(papersize) - local current_setting - - -- we cannot guarantee that context is installed, so we check for the - -- file we would need for creating the configuration, and if that is - -- missing we just return (with a warning). - if not(lfs.isfile(texmfdist..'/tex/context/user/cont-sys.rme')) then - io.stderr:write('context not installed, skipping paper setting for it\n') - return - end - - -- Read the file. - local filename - - kpse.set_program_name('tex') - filename=kpse.find_file('cont-sys.tex', 'tex') - if not(filename) then - filename=kpse.find_file('cont-sys.rme', 'other text files') - end - if not(filename) then - print ("Cannot find config file for context, exiting!") - os.exit(1) - end - -- print ('< '..filename) - - local infile=assert(io.open(filename, 'r')) - local lines={} - local current_setting='A4' - local papersize_regexp='^%s*\\setuppapersize%s*%[([^%[]*)%]' - while true do - line=infile:read('*line') - if line == nil then break end - if string.find(line, '^%s*\\setuppapersize') then - current_setting=string.match(line, papersize_regexp) - end - lines[#lines+1]=line - end - infile:close() - - -- print ('current setting: '..current_setting) - - if papersize=='--list' then - print(current_setting) - if (string.match (current_setting, '[aA]4')) then - print ('letter') - else - print ('A4') - end - elseif papersize=='help' then - io.stdout:write('Usage: '..usageprogname..' context paper PAPER\n\n'.. - 'Valid PAPER settings:\n\nA4 letter\n') - else --change paper size - -- make sure we have uppercase A4 for paper size - if (string.match (papersize, 'a4')) then - papersize = 'A4' - end - local outfile - mkdirhier(texmfconfig..'/tex/context/user') - outfile=texmfconfig..'/tex/context/user/cont-sys.tex' - print ('> '..outfile) - local config=assert(io.open(outfile, 'w')) - for n=1, #lines do - line=lines[n] - if string.find(line, '\setuppapersize') then - config:write('\\setuppapersize['..papersize..']['..papersize..']\n') - else - config:write(line..'\n') - end - end - config:close() - domktexlsr = true - end -end - - -function set_papersize(papersize) - if papersize == '--list' then - set_pdftex_papersize('--list') - elseif papersize == 'help' then - io.stdout:write('Usage: '..usageprogname..' paper PAPER\n\n'.. - 'Valid PAPER settings:\n a4 letter\n') - end - if papersize ~= 'a4' and papersize ~= 'letter' then - io.stdout:write('Invalid paper size "'..papersize..'".'.. - ' Valid sizes: a4 letter\n') - os.exit(1) - else - set_dvips_papersize(papersize) - set_pdftex_papersize(papersize) - set_xdvi_papersize(papersize) - set_context_papersize(papersize) - set_dvipdfm_papersize(papersize, 'dvipdfm') - set_dvipdfm_papersize(papersize, 'dvipdfmx') - end -end - - -function usage_main() - local usage={ - 'help', - 'xdvi paper PAPER (xdvi paper size)', - 'dvips paper PAPER (dvips paper size)', - 'pdftex paper PAPER (pdftex paper size)', - 'dvipdfm paper PAPER (dvipdfm paper size)', - 'dvipdfmx paper PAPER (dvipdfmx paper size)', - 'paper [a4|letter] (paper size for all programs)', - 'init [FORMAT] ... (rebuild FORMATs, or all formats plus run updmap)', - 'rehash (rebuild ls-R files with mktexlsr)' - } - io.stdout:write('Usage:\n') - for i, msg in ipairs(usage) do - io.stdout:write(' '..usageprogname..' '..msg..'\n') - end - os.exit(0) -end - - -function usage_paper(progname) - io.stdout:write('Usage: '..usageprogname..' '..progname..' paper PAPER\n') - io.stdout:write(' '..usageprogname..' '..progname..' help\n') - os.exit(0) -end - - -function set_prog_papersize(prog,size) - if (prog == 'dvips') then - set_dvips_papersize(size) - elseif (prog == 'xdvi') then - set_xdvi_papersize(size) - elseif (prog == 'pdftex') then - set_pdftex_papersize(size) - elseif (prog == 'dvipdfm') then - set_dvipdfm_papersize(size, "dvipdfm") - elseif (prog == 'dvipdfmx') then - set_dvipdfm_papersize(size, "dvipdfmx") - end -end - - -if arg[1] == 'help' then - usage_main() -elseif arg[1] == 'paper' then - if arg[2] == 'help' or arg[2] == nil then - usage_main() - else - set_papersize(arg[2]) - end -elseif arg[1] == 'rehash' then - command = { "mktexlsr" } - command = fixwin(command) - os.exec(command) - -- does not return -elseif arg[1] == 'init' then - if arg[2] == nil then - -- we have set TEXMFCONFIG and TEXMFVAR to the SYS variants above, - -- so we can run the normal fmtutil/updmap program - os.execute('fmtutil --all') - os.execute('updmap') - else - for i=2, #arg do - os.execute('fmtutil --byfmt "'..arg[i]..'"') - end - end -elseif arg[1] == 'paper' then - set_papersize(arg[2]) -elseif arg[1] == 'dvips' then - if arg[2] == 'help' or arg[3]==nil then - usage_paper('dvips') - elseif arg[2]=='paper' then - set_dvips_papersize(arg[3]) - end -elseif arg[1] == 'xdvi' then - if arg[2] == 'help' or arg[3]==nil then - usage_paper('xdvi') - elseif arg[2]=='paper' then - set_xdvi_papersize(arg[3]) - end -elseif arg[1] == 'pdftex' then - if arg[2] == 'help' or arg[3]==nil then - usage_paper(pdftex) - elseif arg[2]=='paper' then - set_pdftex_papersize(arg[3]) - end -elseif arg[1] == 'dvipdfm' then - if arg[2] == 'help' or arg[3]==nil then - usage_paper('dvipdfm') - elseif arg[2]=='paper' then - set_dvipdfm_papersize(arg[3], 'dvipdfm') - end -elseif arg[1] == 'dvipdfmx' then - if arg[2] == 'help' or arg[3]==nil then - usage_paper('dvipdfmx') - elseif arg[2]=='paper' then - set_dvipdfm_papersize(arg[3], 'dvipdfmx') - end -elseif arg[1] == 'context' then - if arg[2] == 'help' or arg[3]==nil then - usage_paper('context') - elseif arg[2]=='paper' then - set_context_papersize(arg[3]) - end -else - usage_main() -end - - -if sys and domktexlsr then - command = { "mktexlsr", texmfconfig } - command = fixwin(command) - os.spawn(command) -end - -if noformatopt then - doformat = false -end - -if doformat then - -- we have to update the formats - -- I don't know how to select only those formats for which pdftexconfig.tex - -- is necessary, so we call fmtutil-sys --refresh - -- that will recreate a lot, sorry - -- - -- on win32 texlua's os.spawn does not find fmtutil-sys.texlua as executable - -- even if I give it the full path. So we have to work around that - if sys then - command = 'fmtutil-sys --refresh' - else - command = 'fmtutil --refresh' - end - os.execute(command) -end - --- Local Variables: --- lua-indent-level: 2 --- tab-width: 2 --- indent-tabs-mode: nil --- End: --- vim:set tabstop=2 expandtab: # |