summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2008-01-18 14:21:12 +0000
committerNorbert Preining <preining@logic.at>2008-01-18 14:21:12 +0000
commite967f9b787bb1118365533ab17c9c1a899b462cb (patch)
tree970aae70033a93839f9d7fa07ed7afeceb769724
parent72acf621ce5ef297de5122b1c4512c38a0664a92 (diff)
starting the rewrite of some scripts with texlua. mktexupd first draft
git-svn-id: svn://tug.org/texlive/trunk@6300 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-xMaster/tlpkg/texlua/mktexupd.texlua128
1 files changed, 128 insertions, 0 deletions
diff --git a/Master/tlpkg/texlua/mktexupd.texlua b/Master/tlpkg/texlua/mktexupd.texlua
new file mode 100755
index 00000000000..eeff4be98a5
--- /dev/null
+++ b/Master/tlpkg/texlua/mktexupd.texlua
@@ -0,0 +1,128 @@
+#!/usr/bin/env texlua
+--[[ Written in lua by Norbert Preining (2008) based on the shell script by
+Thomas Esser.
+Public domain.]]
+--[[ Changelog
+ 0.1
+ - first initial version
+]]
+
+progname = 'mktexupd (texlua version)';
+version = '0.1';
+usage = 'Usage: ' .. progname .. ' [-h|--help] DIR FILE\
+\
+ Update the ls-R file with an entry for FILE in DIR.\
+\
+ -h|--help\t\t Show this help\
+ -V|--version\t\t Print the version of the program\
+';
+
+
+function die (str)
+ io.stderr:write(str)
+ os.exit(1)
+end
+
+while table.maxn(arg) > 0 and string.match(arg[1],'^%-') do
+ curr_arg = table.remove(arg,1)
+ if string.match (curr_arg,'-h') or string.match (curr_arg,'--help') then
+ print (usage);
+ os.exit(0);
+ elseif string.match (curr_arg,'-V') or string.match (curr_arg,'--version') then
+ print (progname .. ' version: ' .. version );
+ os.exit(0);
+ end
+end
+
+if not arg[2] then
+ print (usage);
+ return
+end
+
+--[[ initialize kpathsea ]]
+kpse.set_program_name("mktexupd")
+
+dir = arg[1]
+file = arg[2]
+fullfile = dir .. '/' .. file
+
+if (not lfs.isdir(dir)) then
+ die (progname .. ': ' .. dir .. ' not a directory.\n')
+end
+if (not lfs.isfile(fullfile)) then
+ die (progname .. ': ' .. fullfile .. ' not a file.\n')
+end
+
+--[[
+-- we have to get the list of all directories where ls-R files are present
+-- using TEXMFDBS. In the shell code `kpsewhich -show-path=ls-R was used
+-- we do it with kpse.expand_braces("$TEXMFDBS") and then split at : and
+-- remove the !!
+--]]
+
+texmfdbs = kpse.expand_braces("$TEXMFDBS")
+for d in string.gmatch(texmfdbs,"[^:]+") do
+ if string.match(d,"^!!") then
+ d = string.sub(d,3)
+ end
+ pel = string.match(dir,d.."/(.*)$")
+ if pel then
+ target = d
+ pathcomponent = pel
+ end
+end
+if (not target) then
+ --[[ no path found, just give up ]]
+ os.exit(0)
+end
+
+db_file = target..'/ls-R'
+db_file_lc = target..'/ls-r'
+
+if (not(lfs.isfile(db_file))) then
+ if lfs.isfile(db_file_lc) then
+ db_file = db_file_lc
+ end
+end
+
+if (not(lfs.isfile(db_file))) then
+ print ('Calling mktexlsr for '..target)
+ os.execute("mktexlsr "..target)
+ os.exit()
+end
+
+ls_R_magic = '% ls-R -- filename database for kpathsea; do not change this line.'
+--[[ Old ls-R files should continue to work. ]]
+old_ls_R_magic='% ls-R -- maintained by MakeTeXls-R; do not change this line.'
+
+
+--[[ read first line of ls-R file ]]
+lsrfh = io.open(db_file)
+if (not(lsrfh)) then
+ die('that should not happen ...\n')
+end
+firstline = lsrfh:read()
+io.close(lsrfh)
+
+if (firstline ~= ls_R_magic) then
+ if (firstline ~= old_ls_R_magic) then
+ die(progname..': '..db_file..' lacks magic string '..ls_R_magic..'\n')
+ end
+end
+
+--[[ ok we are that far, try to open the file for writing ]]
+lsrfh,erro = io.open(db_file,"a+")
+if (not(lsrfh)) then
+ die(progname..': cannot open '..db_file..' for writing: '..erro..'\n')
+end
+
+--[[
+-- May as well always put in a new directory entry; presumably cron will
+-- come along soon enough and clean things up.
+--]]
+lsrfh:write('./'..pathcomponent..':\n')
+lsrfh:write(file..'\n')
+io.close(lsrfh)
+
+os.exit(0)
+