summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2008-02-09 10:04:07 +0000
committerNorbert Preining <preining@logic.at>2008-02-09 10:04:07 +0000
commit9be678d6ee982e37d6b60b6eb76e2f15840d9174 (patch)
tree127e20b8e639265227c4300695167e4ab03fec20 /Master/tlpkg/etc
parente6a0c70017b9ef0a801520f6c9f49247fc78b47a (diff)
move mktexupd.texlua to etc
git-svn-id: svn://tug.org/texlive/trunk@6579 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/etc')
-rwxr-xr-xMaster/tlpkg/etc/mktexupd.texlua124
1 files changed, 124 insertions, 0 deletions
diff --git a/Master/tlpkg/etc/mktexupd.texlua b/Master/tlpkg/etc/mktexupd.texlua
new file mode 100755
index 00000000000..13bb58771ad
--- /dev/null
+++ b/Master/tlpkg/etc/mktexupd.texlua
@@ -0,0 +1,124 @@
+#!/usr/bin/env texlua
+-- Written in lua by Norbert Preining (2008) based on the shell script by
+-- Thomas Esser.
+-- Copyright 2008 Norbert Preining
+-- License: GPL
+
+
+-- 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
+ d = d:gsub("^!!","")
+ 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
+
+-- Old ls-R files should continue to work.
+ls_R_magic = '% ls-R -- filename database for kpathsea; do not change this line.'
+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)
+