summaryrefslogtreecommitdiff
path: root/Master/tlpkg/dev/mktexupd.texlua
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2009-09-15 09:40:04 +0000
committerNorbert Preining <preining@logic.at>2009-09-15 09:40:04 +0000
commit60d44731afa4954a7324f3bbe3e111598874afd2 (patch)
treeb44918fd5babb878b576cdf2a688af6542fcf7e8 /Master/tlpkg/dev/mktexupd.texlua
parent568f2a84fedd5654cc87f3408d72bd32b4363df3 (diff)
move howto-translations to doc, and rename etc to dev in tlpkg
git-svn-id: svn://tug.org/texlive/trunk@15293 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/dev/mktexupd.texlua')
-rwxr-xr-xMaster/tlpkg/dev/mktexupd.texlua124
1 files changed, 124 insertions, 0 deletions
diff --git a/Master/tlpkg/dev/mktexupd.texlua b/Master/tlpkg/dev/mktexupd.texlua
new file mode 100755
index 00000000000..13bb58771ad
--- /dev/null
+++ b/Master/tlpkg/dev/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)
+