diff options
author | Norbert Preining <norbert@preining.info> | 2021-05-12 03:01:15 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-05-12 03:01:15 +0000 |
commit | bcdf6c829c6761de02484473ebe43fa3760adcaa (patch) | |
tree | de384ae80a1a9e34f900739a9478f92a0660a9ef /support/TeX4ht/source/checklog.lua | |
parent | 4a8a25f4c6acac624cf323115db94d934b19d6b1 (diff) |
CTAN sync 202105120301
Diffstat (limited to 'support/TeX4ht/source/checklog.lua')
-rw-r--r-- | support/TeX4ht/source/checklog.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/support/TeX4ht/source/checklog.lua b/support/TeX4ht/source/checklog.lua new file mode 100644 index 0000000000..0e048175db --- /dev/null +++ b/support/TeX4ht/source/checklog.lua @@ -0,0 +1,50 @@ +-- $Id$ +-- Public domain. Originally written by Michal Hoftich, 2020. +-- this script parses log files for errors +-- pass the .log file as a first argument +-- +-- Usage: +-- texlua checklog.lua <filename>.log + +kpse.set_program_name "luatex" +-- the following library is part of make4ht +local error_logparser = require("make4ht-errorlogparser") + +local function parse_log(input_file, content) + -- log parsing can be expensive on time, don't do it if we don't have + -- any error message in the log file + if content:match("\n!") then + local errors = error_logparser.parse(content) + if #errors > 0 then + print(input_file .. ": errors found:") + for _, err in ipairs(errors) do + print((err.filename or "?") .. ":" + .. (err.line or "?") .. ":" .. err.error) + end + os.exit(1) + end + end +end + +local content +-- the log file can be passed as filename argument, or piped from shell + +if #arg > 0 then + for _, input_file in ipairs(arg) do + local ext = input_file:match("%.([^%.]+)$") + if not ext then + input_file = input_file .. ".log" + elseif ext ~="log" then + input_file = input_file:gsub("[^%.]+$", "log") + end + local f = io.open(input_file, "r") + content = f:read("*all") + f:close() + parse_log(input_file, content) + end +else + -- read from STDIN + content = io.read("*all") + parse_log(content) +end + |