summaryrefslogtreecommitdiff
path: root/Master/tlpkg/archive/lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-12-31 23:19:25 +0000
committerKarl Berry <karl@freefriends.org>2019-12-31 23:19:25 +0000
commit7d8c399780981359be7896a5fb053a0bd873a3e6 (patch)
tree3680abb7f9038f8d19f0da0af63aab9dedcb770c /Master/tlpkg/archive/lua
parent449ceb762b8adeccbef9731acdf8001b20fa4f74 (diff)
archive old lua tlpdb attempt
git-svn-id: svn://tug.org/texlive/trunk@53284 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/archive/lua')
-rw-r--r--Master/tlpkg/archive/lua/texlive/getopt.tlu99
-rw-r--r--Master/tlpkg/archive/lua/texlive/tlpdb.tlu259
-rw-r--r--Master/tlpkg/archive/lua/texlive/utils.tlu78
3 files changed, 436 insertions, 0 deletions
diff --git a/Master/tlpkg/archive/lua/texlive/getopt.tlu b/Master/tlpkg/archive/lua/texlive/getopt.tlu
new file mode 100644
index 00000000000..7e52ddd357f
--- /dev/null
+++ b/Master/tlpkg/archive/lua/texlive/getopt.tlu
@@ -0,0 +1,99 @@
+#! /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/tlpkg/archive/lua/texlive/tlpdb.tlu b/Master/tlpkg/archive/lua/texlive/tlpdb.tlu
new file mode 100644
index 00000000000..4977431bd56
--- /dev/null
+++ b/Master/tlpkg/archive/lua/texlive/tlpdb.tlu
@@ -0,0 +1,259 @@
+#! /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/tlpkg/archive/lua/texlive/utils.tlu b/Master/tlpkg/archive/lua/texlive/utils.tlu
new file mode 100644
index 00000000000..a31475b351c
--- /dev/null
+++ b/Master/tlpkg/archive/lua/texlive/utils.tlu
@@ -0,0 +1,78 @@
+-- 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: #