From bcdf6c829c6761de02484473ebe43fa3760adcaa Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 12 May 2021 03:01:15 +0000 Subject: CTAN sync 202105120301 --- support/TeX4ht/source/checklog.lua | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 support/TeX4ht/source/checklog.lua (limited to 'support/TeX4ht/source/checklog.lua') 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 .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 + -- cgit v1.2.3