Skip to content

Commit

Permalink
Merge pull request #1835 from alerque/correct-master-filename
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Aug 22, 2023
2 parents 153fed0 + 29667a7 commit f473d20
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ function class:finish ()
end
SILE.typesetter:runHooks("pageend") -- normally run by the typesetter
self:endPage()
if SILE.typesetter then
assert(SILE.typesetter:isQueueEmpty(), "queues not empty")
end
if SILE.typesetter then
assert(SILE.typesetter:isQueueEmpty(), "queues not empty")
end
SILE.outputter:finish()
self:runHooks("finish")
end
Expand Down
2 changes: 1 addition & 1 deletion core/makedeps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local makeDeps = {
write = function (self)
self:add_modules()
if type(self.filename) ~= "string" then
self.filename = SILE.masterFilename .. ".d"
self.filename = pl.path.splitext(SILE.input.filenames[1]) .. ".d"
end
local depfile, err = io.open(self.filename, "w")
if not depfile then return SU.error(err) end
Expand Down
14 changes: 6 additions & 8 deletions core/sile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function SILE.processString (doc, format, filename, options)
-- a specific inputter to use, use it at the exclusion of all content type
-- detection
local inputter
if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename and SILE.inputter then
if filename and pl.path.normcase(pl.path.normpath(filename)) == pl.path.normcase(SILE.input.filenames[1]) and SILE.inputter then
inputter = SILE.inputter
else
format = format or detectFormat(doc, filename)
Expand All @@ -301,7 +301,7 @@ function SILE.processString (doc, format, filename, options)
inputter = SILE.inputters[format](options)
-- If we did content detection *and* this is the master file, save the
-- inputter for posterity and postambles
if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename then
if filename and pl.path.normcase(filename) == pl.path.normcase(SILE.input.filenames[1]) then
SILE.inputter = inputter
end
end
Expand All @@ -315,17 +315,15 @@ function SILE.processFile (filename, format, options)
local doc
if filename == "-" then
filename = "STDIN"
SILE.masterFilename = "STDIN"
doc = io.stdin:read("*a")
else
-- Turn slashes around in the event we get passed a path from a Windows shell
filename = filename:gsub("\\", "/")
if not SILE.masterFilename then
-- Strip extension
SILE.masterFilename = string.match(filename, "(.+)%..-$") or filename
SILE.masterFilename = pl.path.splitext(pl.path.normpath(filename))
end
if SILE.masterFilename and not SILE.masterDir then
SILE.masterDir = SILE.masterFilename:match("(.-)[^%/]+$")
if SILE.input.filenames[1] and not SILE.masterDir then
SILE.masterDir = pl.path.dirname(SILE.input.filenames[1])
end
if SILE.masterDir and SILE.masterDir:len() >= 1 then
_G.extendSilePath(SILE.masterDir)
Expand Down Expand Up @@ -463,7 +461,7 @@ function SILE.finish ()
end
if SU.debugging("profile") then
ProFi:stop()
ProFi:writeReport(SILE.masterFilename..'.profile.txt')
ProFi:writeReport(pl.path.splitext(SILE.input.filenames[1]) .. '.profile.txt')
end
if SU.debugging("versions") then
SILE.shaper:debugVersions()
Expand Down
2 changes: 1 addition & 1 deletion documentation/c10-classdesign.sil
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ Here is a function to be called by the \code{finish} output routine:
function package.writeToc (_)
-- (Simplified from the actual implementation.)
local tocdata = pl.pretty.write(SILE.scratch.tableofcontents)
local tocfile, err = io.open(SILE.masterFilename .. '.toc', "w")
local tocfile, err = io.open(pl.path.splitext(SILE.input.filenames[1]) .. '.toc', "w")
if not tocfile then return SU.error(err) end
tocfile:write("return " .. tocdata)
tocfile:close()
Expand Down
4 changes: 2 additions & 2 deletions outputters/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function outputter:getOutputFilename ()
local fname
if SILE.outputFilename then
fname = SILE.outputFilename
elseif SILE.masterFilename then
fname = SILE.masterFilename
elseif SILE.input.filenames[1] then
fname = pl.path.splitext(SILE.input.filenames[1])
if self.extension then
fname = fname .. "." .. self.extension
end
Expand Down
2 changes: 1 addition & 1 deletion packages/cropmarks/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
function package:registerCommands ()

self:registerCommand("crop:header", function (_, _)
local info = SILE.masterFilename .. " - " .. self.class:date("%x %X") .. " - " .. outcounter
local info = SILE.input.filenames[1] .. " - " .. self.class:date("%x %X") .. " - " .. outcounter
SILE.typesetter:typeset(info)
end)

Expand Down
4 changes: 2 additions & 2 deletions packages/tableofcontents/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end

function package.writeToc (_)
local tocdata = pl.pretty.write(SILE.scratch.tableofcontents)
local tocfile, err = io.open(SILE.masterFilename .. '.toc', "w")
local tocfile, err = io.open(pl.path.splitext(SILE.input.filenames[1]) .. '.toc', "w")
if not tocfile then return SU.error(err) end
tocfile:write("return " .. tocdata)
tocfile:close()
Expand All @@ -34,7 +34,7 @@ function package.readToc (_)
-- already loaded
return SILE.scratch._tableofcontents
end
local tocfile, _ = io.open(SILE.masterFilename .. '.toc')
local tocfile, _ = io.open(pl.path.splitext(SILE.input.filenames[1]) .. '.toc')
if not tocfile then
return false -- No TOC yet
end
Expand Down

0 comments on commit f473d20

Please sign in to comment.