Skip to content

Commit

Permalink
Merge pull request #1738 from alerque/multi-inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed May 18, 2023
2 parents 8d98a33 + 219b0ad commit d09efb8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
19 changes: 14 additions & 5 deletions core/cli.lua
Expand Up @@ -15,7 +15,7 @@ cli.parseArguments = function ()
changed to .pdf. Additional input or output formats can be handled by requiring a
module that adds support for them first.
]])
cliargs:splat("INPUT", "input document, by default in SIL or XML format")
cliargs:splat("INPUTS", "input document(s), by default in SIL or XML format", nil, 999)
cliargs:option("-b, --backend=VALUE", "choose an alternative output backend")
cliargs:option("-c, --class=VALUE", "override default document class")
cliargs:option("-d, --debug=VALUE", "show debug information for tagged aspects of SILE’s operation", {})
Expand All @@ -42,11 +42,20 @@ cli.parseArguments = function ()
local code = parse_err:match("^Usage:") and 0 or 1
os.exit(code)
end
if opts.INPUT then
if opts.INPUT == "STDIO" then
opts.INPUT = "-"
if opts.INPUTS then
local has_input_filename = false
pl.tablex.foreachi(opts.INPUTS, function (v, k)
if v == "STDIO" then
opts.INPUTS[k] = "-"
elseif not has_input_filename then
has_input_filename = true
end
end)
if not has_input_filename and not opts.output then
SU.error("Unable to derive an output filename (perhaps because input is a STDIO stream).\n"..
" Please use --output to set one explicitly.")
end
SILE.input.filename = opts.INPUT
SILE.input.filenames = opts.INPUTS
end
if opts.backend then
SILE.backend = opts.backend
Expand Down
7 changes: 4 additions & 3 deletions core/sile.lua
Expand Up @@ -62,7 +62,7 @@ SILE.rawHandlers = {}
-- needed for a user to use a SILE-as-a-library verion to produce documents
-- programatically.
SILE.input = {
filename = "",
filenames = {},
evaluates = {},
evaluateAfters = {},
includes = {},
Expand Down 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 filename:gsub("STDIN", "-") == SILE.input.filename and SILE.inputter then
if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename 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 filename:gsub("STDIN", "-") == SILE.input.filename then
if filename and pl.path.splitext(pl.path.normcase(filename)) == SILE.masterFilename then
SILE.inputter = inputter
end
end
Expand All @@ -315,6 +315,7 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion documentation/c01-whatis.sil
Expand Up @@ -19,7 +19,7 @@ There are several important differences.
The job of a word processor is to produce a document that looks exactly like what you type on the screen.
By contrast, the job of a typesetting system is to take raw content and produce a document that looks as good as possible.
The input for SILE is a text document that includes instructions about how the content should be laid out on a page.
In order to obtain the typeset result, the input file must be \em{processed} to render the desired output.
In order to obtain the typeset result, the input file(s) must be \em{processed} to render the desired output.

Word processors often describe themselves as WYSIWYG: What You See Is What You Get.
SILE is cheerfully \em{not} WYSIWYG.
Expand Down
2 changes: 1 addition & 1 deletion documentation/c02-gettingstarted.sil
Expand Up @@ -298,7 +298,7 @@ All the available CLI options are documented both in the help output (\code{sile
This manual will only mention a few in passing as they come up in other other topics.

\begin{autodoc:note}
SILE output filenames are generated by replacing the extension from the master input filename with the proper extension for the outputter.
SILE generates output filenames by replacing the extension from the first input filename with the default extension for the outputter.
For most outputters this will be \code{.pdf} but, for example, the text backend will append \code{.txt} instead.
If you want to write to a different filename altogether, use the \code{--output file.pdf} command line option.
You can use \code{--output -} to write the output directly to the system IO stream—useful if you wish to use SILE as part of a pipeline.
Expand Down
2 changes: 1 addition & 1 deletion documentation/c10-classdesign.sil
Expand Up @@ -15,7 +15,7 @@ Their use below is straightforward and is expected to be covered by examples, bu

\section{Designing a package}

Packages live somewhere in the \code{packages/} subdirectory of either where your input file is located, your current working directory, or your SILE path (typically \code{/usr/local/share/sile}).
Packages live somewhere in the \code{packages/} subdirectory of either where your first input file is located, your current working directory, or your SILE path (typically \code{/usr/local/share/sile}).

\subsection{Implementing a bare package}

Expand Down
2 changes: 1 addition & 1 deletion documentation/c12-tricks.sil
Expand Up @@ -444,7 +444,7 @@ stack traceback:

Sometimes it’s useful for you to try out Lua code within the SILE environment;
SILE contains a REPL (read-evaluate-print loop) for you to enter Lua code and print the results back to you.
If you call SILE with no input file name, it enters the REPL:
If you call SILE with no input file names, it enters the REPL:

\begin{autodoc:codeblock}
\sileversion
Expand Down
4 changes: 2 additions & 2 deletions sile.in
Expand Up @@ -29,7 +29,7 @@ end

SILE.init()

if SILE.input.filename and SILE.input.filename:len() > 0 then
if SILE.input.filenames and #SILE.input.filenames >= 1 then

-- Deprecated, notice given in core.cli when argument used
for _, path in ipairs(SILE.input.includes) do
Expand All @@ -49,7 +49,7 @@ if SILE.input.filename and SILE.input.filename:len() > 0 then
end

local main, err = xpcall(function()
return SILE.processFile(SILE.input.filename)
pl.tablex.imap(SILE.processFile, SILE.input.filenames)
end, SILE.errorHandler)

if not main then
Expand Down

0 comments on commit d09efb8

Please sign in to comment.