| 1 |
-- $Id$ |
| 2 |
-- Public domain. Originally written by Michal Hoftich, 2020. |
| 3 |
-- this script parses log files for errors |
| 4 |
-- pass the .log file as a first argument |
| 5 |
-- |
| 6 |
-- Usage: |
| 7 |
-- texlua checklog.lua <filename>.log |
| 8 |
|
| 9 |
kpse.set_program_name "luatex" |
| 10 |
-- the following library is part of make4ht |
| 11 |
local error_logparser = require("make4ht-errorlogparser") |
| 12 |
|
| 13 |
local function parse_log(input_file, content) |
| 14 |
-- log parsing can be expensive on time, don't do it if we don't have |
| 15 |
-- any error message in the log file |
| 16 |
if content:match("\n!") then |
| 17 |
local errors = error_logparser.parse(content) |
| 18 |
if #errors > 0 then |
| 19 |
print(input_file .. ": errors found:") |
| 20 |
for _, err in ipairs(errors) do |
| 21 |
print((err.filename or "?") .. ":" |
| 22 |
.. (err.line or "?") .. ":" .. err.error) |
| 23 |
end |
| 24 |
os.exit(1) |
| 25 |
end |
| 26 |
end |
| 27 |
end |
| 28 |
|
| 29 |
local content |
| 30 |
-- the log file can be passed as filename argument, or piped from shell |
| 31 |
|
| 32 |
if #arg > 0 then |
| 33 |
for _, input_file in ipairs(arg) do |
| 34 |
local ext = input_file:match("%.([^%.]+)$") |
| 35 |
if not ext then |
| 36 |
input_file = input_file .. ".log" |
| 37 |
elseif ext ~="log" then |
| 38 |
input_file = input_file:gsub("[^%.]+$", "log") |
| 39 |
end |
| 40 |
local f = io.open(input_file, "r") |
| 41 |
content = f:read("*all") |
| 42 |
f:close() |
| 43 |
parse_log(input_file, content) |
| 44 |
end |
| 45 |
else |
| 46 |
-- read from STDIN |
| 47 |
content = io.read("*all") |
| 48 |
parse_log(content) |
| 49 |
end |
| 50 |
|