Hi, I'm using kpse.find_file() in order to determine the location of some config files. In some cases I have to set kpse.set_program_name. Here is the code: _______________________________________________________ #!/usr/bin/env texlua --*- Lua -*- 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, "\.texlua$", "")) kpse.set_program_name(filename, basename) print(kpse.find_file('pdftexconfig.tex', 'tex', true)) print(kpse.find_file('config.ps', 'dvips config', true)) kpse.set_program_name('xdvi') print(kpse.find_file('XDvi', 'other text files', true)) kpse.set_program_name('dvipdfm') print(kpse.find_file('config', 'other text files', true)) print(kpse.find_file('dvipdfmx.cfg', 'other text files', true)) kpse.set_program_name(filename, basename) os.exit(0) ______________________________________________________ The result is: ______________________________________________________ /home/reinhard/.texlive-alpha/texmf-config/tex/generic/config/pdftexconfig.tex /home/reinhard/.texlive-alpha/texmf-config/dvips/config/config.ps /home/reinhard/.texlive-alpha/texmf-config/xdvi/XDvi nil nil ______________________________________________________ Note that the last two entries are 'nil'. When I comment out the line print(kpse.find_file('XDvi', 'other text files', true)) then I get: ______________________________________________________ /home/reinhard/.texlive-alpha/texmf-config/tex/generic/config/pdftexconfig.tex /home/reinhard/.texlive-alpha/texmf-config/dvips/config/config.ps /home/reinhard/.texlive-alpha/texmf-config/dvipdfm/config/config /home/reinhard/.texlive-alpha/texmf-config/dvipdfm/config/dvipdfmx.cfg ______________________________________________________ Is there anything wrong with the XDvi entry? It produces correct output but why are the other entries 'nil'? Regards, Reinhard -- ---------------------------------------------------------------------------- Reinhard Kotucha Phone: +49-511-4592165 Marschnerstr. 25 D-30167 Hannover mailto:reinhard.kotucha@web.de ---------------------------------------------------------------------------- Microsoft isn't the answer. Microsoft is the question, and the answer is NO. ----------------------------------------------------------------------------
Reinhard Kotucha wrote:
Is there anything wrong with the XDvi entry? It produces correct output but why are the other entries 'nil'?
Not with that entry itself, but kpathsea only initializes its file search paths once per file type. You asked it to set up "other text files" for xdvi, but it will not re- initialize for the later dvipdfm (it *will* initialize new types for dvipdfm now, but that is too late to help). I can try to fix this, but I don't know yet how hard that will be (kpathsea was never written for use as a general- purpose library) Best wishes, Taco
Taco Hoekwater wrote:
Reinhard Kotucha wrote:
Is there anything wrong with the XDvi entry? It produces correct output but why are the other entries 'nil'?
Not with that entry itself, but kpathsea only initializes its file search paths once per file type. You asked it to set up "other text files" for xdvi, but it will not re- initialize for the later dvipdfm (it *will* initialize new types for dvipdfm now, but that is too late to help).
I can try to fix this, but I don't know yet how hard that will be (kpathsea was never written for use as a general- purpose library)
it probably involves rehashing and such; since multiple prognames per application are rather special and probably only take place in setup scripts, i think that just reinitializing kpse is the most simple approach; normally kpse is initialized at the first usage, so maybe it's just a matter of resetting a flag that tells the library that it needs to reinitialize (probably a reload of lsr files, but that's no big deal in setup scripts) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen wrote:
normally kpse is initialized at the first usage, so maybe it's just a matter of resetting a flag that tells the library that it needs to reinitialize (probably a reload of lsr files, but that's no big deal in setup scripts)
I found kpse_reset_program_name(). Reinhard, can you verify that the trunk behaves OK now, please ? Best wishes, Taco
Taco Hoekwater writes:
Hans Hagen wrote:
normally kpse is initialized at the first usage, so maybe it's just a matter of resetting a flag that tells the library that it needs to reinitialize (probably a reload of lsr files, but that's no big deal in setup scripts)
I found kpse_reset_program_name(). Reinhard, can you verify that the trunk behaves OK now, please ?
Works perfectly now. Many thanks! BTW, when I run the script with strace -eopen, I see that all the ls-R files are loaded only once. Everything is efficient and very fast. Regards, Reinhard -- ---------------------------------------------------------------------------- Reinhard Kotucha Phone: +49-511-4592165 Marschnerstr. 25 D-30167 Hannover mailto:reinhard.kotucha@web.de ---------------------------------------------------------------------------- Microsoft isn't the answer. Microsoft is the question, and the answer is NO. ----------------------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Reinhard Kotucha
-
Taco Hoekwater