summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2014-03-02 15:40:48 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2018-12-02 21:09:42 +0100
commit639d43ea3673791dc223fe9d0e67e6f4b8d312b4 (patch)
tree4cdd7ccaa1b7dc0ae731d6b60a717f0319fb941d /src
parentb2ab0ab20e2455ef112cf340e09e2f33cf641993 (diff)
downloadcontext-rst-639d43ea3673791dc223fe9d0e67e6f4b8d312b4.tar.gz
use luatex.registertempfile() for creating temporary file names
Diffstat (limited to 'src')
-rw-r--r--src/rst_parser.lua43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/rst_parser.lua b/src/rst_parser.lua
index 3928161..10994d9 100644
--- a/src/rst_parser.lua
+++ b/src/rst_parser.lua
@@ -54,6 +54,7 @@ local utf = unicode.utf8
local ioopen = io.open
local iowrite = io.write
+local select = select
local stringfind = string.find
local stringformat = string.format
local stringgsub = string.gsub
@@ -61,8 +62,8 @@ local stringlen = string.len
local stringmatch = string.match
local stringstrip = string.strip
local stringsub = string.sub
+local tableconcat = table.concat
local utflen = utf.len
-local select = select
local context = context
@@ -1537,12 +1538,29 @@ do
p_strip_comments = Cs((comment + 1)^0)
end
+
+local tempfile_count = { } --- map category -> count
+
+local get_tmpfile = function (category)
+ local cnt = tempfile_count[category]
+ if not cnt then
+ cnt = 0
+ end
+ cnt = cnt + 1
+ tempfile_count[category] = cnt
+ return luatex.registertempfile (
+ stringformat ("%s_rst-%s-%d",
+ tex.jobname,
+ category,
+ cnt)
+ )
+end
+
function thirddata.rst.do_rst_file(fname)
local raw_data = load_file(fname)
local processed = lpegmatch (rst_parser, raw_data)
local setups = get_setups(false)
- local tmp_file = tex.jobname .. "–rst_temporary.tex.tmp"
-
+ local tmp_file = get_tmpfile "temporary"
if processed then
processed = lpegmatch (p_strip_comments, setups..processed.."\n\\stoptext\n")
save_file(tmp_file, processed)
@@ -1556,9 +1574,7 @@ function thirddata.rst.do_rst_inclusion (iname, fname)
local raw_data = load_file(fname)
local processed = lpegmatch (rst_parser, raw_data)
local setups = get_setups(true)
-
- local incnr = #rst_incsetups + 1
- local tmp_file = tex.jobname .. stringformat("–rst_inclusion-%d.tex.tmp", incnr)
+ local tmp_file = get_tmpfile "setup"
if processed then
processed = lpegmatch (p_strip_comments, processed)
@@ -1569,9 +1585,9 @@ function thirddata.rst.do_rst_inclusion (iname, fname)
end
function thirddata.rst.do_rst_setups ()
- local out = table.concat(rst_incsetups)
+ local out = tableconcat(rst_incsetups)
--context(out) --- why doesn’t this work?
- local tmp_file = tex.jobname .. "–rst_setups.tex.tmp"
+ local tmp_file = get_tmpfile "setup"
save_file(tmp_file, out)
context.input(tmp_file)
end
@@ -1587,15 +1603,14 @@ end
function thirddata.rst.do_rst_snippet(txt)
local processed = lpegmatch (rst_parser, txt)
local setups = get_setups(true)
- local tmp_file = tex.jobname .. "–rst_temporary.tex.tmp"
-
+ local tmp_file = get_tmpfile "snippet"
if processed then
- warn("·cs·",txt)
+ warn("·cs·", txt)
processed = lpegmatch (p_strip_comments, setups..processed)
- save_file(tmp_file,processed)
- context.input("./"..tmp_file)
+ save_file(tmp_file, processed)
+ context.input("./" .. tmp_file)
else
- warn("·cs·",txt)
+ warn("·cs·", txt)
context.par()
context("{\\bf context-rst could not process snippet.\\par}")
context.type(txt)