From 8e0222695a489184e3cc92e2206db971a5ac48d7 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 28 Jan 2022 22:36:18 +0000 Subject: texlogfilter (28jan22) git-svn-id: svn://tug.org/texlive/trunk@61780 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/texk/texlive/linked_scripts/Makefile.am | 1 + .../source/texk/texlive/linked_scripts/Makefile.in | 1 + .../source/texk/texlive/linked_scripts/scripts.lst | 1 + .../linked_scripts/texlogfilter/texlogfilter | 349 +++++++++++++++++++++ 4 files changed, 352 insertions(+) create mode 100755 Build/source/texk/texlive/linked_scripts/texlogfilter/texlogfilter (limited to 'Build') diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.am b/Build/source/texk/texlive/linked_scripts/Makefile.am index 65f3903d7f9..d4f1293a96f 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.am +++ b/Build/source/texk/texlive/linked_scripts/Makefile.am @@ -236,6 +236,7 @@ texmf_other_scripts = \ texlive-extra/e2pall.pl \ texliveonfly/texliveonfly.py \ texloganalyser/texloganalyser \ + texlogfilter/texlogfilter \ texlogsieve/texlogsieve \ texplate/texplate.sh \ thumbpdf/thumbpdf.pl \ diff --git a/Build/source/texk/texlive/linked_scripts/Makefile.in b/Build/source/texk/texlive/linked_scripts/Makefile.in index 41c945af09a..360cad53423 100644 --- a/Build/source/texk/texlive/linked_scripts/Makefile.in +++ b/Build/source/texk/texlive/linked_scripts/Makefile.in @@ -450,6 +450,7 @@ texmf_other_scripts = \ texlive-extra/e2pall.pl \ texliveonfly/texliveonfly.py \ texloganalyser/texloganalyser \ + texlogfilter/texlogfilter \ texlogsieve/texlogsieve \ texplate/texplate.sh \ thumbpdf/thumbpdf.pl \ diff --git a/Build/source/texk/texlive/linked_scripts/scripts.lst b/Build/source/texk/texlive/linked_scripts/scripts.lst index abe4b5036d6..920f7bb9caa 100644 --- a/Build/source/texk/texlive/linked_scripts/scripts.lst +++ b/Build/source/texk/texlive/linked_scripts/scripts.lst @@ -175,6 +175,7 @@ texlive/updmap.pl texlive-extra/e2pall.pl texliveonfly/texliveonfly.py texloganalyser/texloganalyser +texlogfilter/texlogfilter texlogsieve/texlogsieve texplate/texplate.sh thumbpdf/thumbpdf.pl diff --git a/Build/source/texk/texlive/linked_scripts/texlogfilter/texlogfilter b/Build/source/texk/texlive/linked_scripts/texlogfilter/texlogfilter new file mode 100755 index 00000000000..ee962a3e9b7 --- /dev/null +++ b/Build/source/texk/texlive/linked_scripts/texlogfilter/texlogfilter @@ -0,0 +1,349 @@ +#!/usr/bin/env perl +################################################################################ +# texlogfilter - filter latex engines output or log file +# Julien Labbé, 2021 +# +# This work may be distributed and/or modified under the conditions of the LaTeX +# Project Public License, either version 1.3 of this license or (at your option) +# any later version. The latest version of this license is in +# http://www.latex-project.org/lppl.txt and version 1.3 +# or later is part of all distributions of LaTeX version 2005/12/01 or later. +################################################################################ + +use strict; +use warnings; +use Getopt::Long; +use Term::ANSIColor; + +my $name = "texlogfilter"; +my $version = "1.0"; + +# options +my @userfilters; +my $showhelp = 0; +my $showversion = 0; +my $showrefmsg = 1; +my $showboxmsg = 1; +my $showskips = 0; +my $skipmarker = "..."; +my $extpattern = "tex|sty|cls|bib"; +my $fulllog = 0; +my $printfilename = -1; # -1: value not modified by options +my $errcolor = "red"; +my $wrncolor = "yellow"; +my $infcolor = "blue"; +my $skpcolor = "bright_black"; +my $usrcolor = "reset"; + +GetOptions ("box!" => \$showboxmsg, # show box warnings + "ref!" => \$showrefmsg, # show reference and citation warnings + "skips!" => \$showskips, # show that lines have been skipped + "skip-marker=s" => \$skipmarker, # how to indicate skipped lines + "files-ext=s" => \$extpattern, # file extension regex pattern + "add-filter=s" => \@userfilters, # user filters list + "errors-color=s" => \$errcolor, # color for errors + "warnings-color=s" => \$wrncolor, # color for warnings + "infos-color=s" => \$infcolor, # color for informations + "skips-color=s" => \$skpcolor, # color for skipped lines marker + "user-color=s" => \$usrcolor, # color for content filtered by pattern added with --add-filter + "filename!" => \$printfilename, # print current file name + "full-log!" => \$fulllog, # show full log (don't filter - only colorize latex engine output) + "help" => \$showhelp, + "version" => \$showversion); + +if ($printfilename == -1 && $fulllog) { $printfilename = 0; } # don't show filename for full log, if not explicitly required + +# counters +my $nerr = 0; +my $nwrn = 0; + +# iteration state +my $nextlines = 0; +my $currentpackage = ""; +my $currentfile = ""; +my $lastfile = ""; +my $samecontext = -1; # expected values: 0 (continuing previous line) / 1 (lines skipped) / -1 (initial value) + +# functions + +sub print_help { + # print usage + print <) { + + # assume currentfile is given in the last open parenthesis + # (works badly for packages) + if (/\(([^)]+$extpattern)$/) {$currentfile = $1;} + + # try to show usefull lines following some warnings or errors (starting with + # whitespaces or package name) + if ($currentpackage ne ""){ + if (/(s+|\($currentpackage\))/){print $_;} + else {$currentpackage = ""; } + } + + # print above lines, if required + if ($nextlines > 0) { $nextlines--; print $_; } + + # find errors + elsif (/^(!\s+|.*?:\d+:\s+)?(Class|Package) (\w+ )?Error/i) { if ($3){$currentpackage=$3} handle_error(0, "nofilename"); } + elsif (/^(!\s+)?LaTeX (?:Error)/i) { handle_error(); } + elsif (/^(!|.*?:\d+:) Undefined control sequence\./i) { chomp; handle_error(4); } + elsif (/^(!|.*?:\d+:) Use of (.*) doesn't match its definition\./i) { handle_error(3); } + elsif (/^(!|.*?:\d+:) Missing/i) { handle_error(3); } + elsif (/^(!|.*?:\d+:)/i) { handle_error(); } + elsif (/^No pages of output/i) { handle_error(); } + + # find warning + elsif (/^(!\s+)?(Class|Package) (\w+ )?Warning/i) { if ($3){$currentpackage=$3} handle_warning(0, "nofilename"); } + elsif (/^(!\s+)?(LaTeX|\* LaTeX) Warning: (Citation|Reference)/i) { if ($showrefmsg) {handle_warning();} } + elsif (/^(!\s+)?(LaTeX|\* LaTeX) Warning/i) { handle_warning(); } + elsif (/Runaway argument\?/i) { handle_warning(1); } + elsif (/(overfull|underfull|badbox)/i) { if ($showboxmsg){handle_warning(1);} } + + # find infos + elsif (/^(LaTeX)/i) { handle_info(); } + elsif (/^Document Class/i) { handle_info(); } + elsif (/^\\input/) { handle_info(); } + elsif (/^Output written/i) { print "\n"; handle_info(0, "bold"); } + + else { + # user added filters + my $line=$_; + my $usrmatch=0; + for my $filter (@userfilters){ + if ($line =~ m/$filter/ && ! $usrmatch) { + $usrmatch = 1; + print_skips(); + print color($usrcolor), $line; + } + } + # if not, skip line + if (! $usrmatch){ + $samecontext=0; + if ($fulllog ){ print color("reset"), $line, ; } + } + } +} + +# end message +print "\n"; +if ($nerr > 0) {print color("bold"), color($errcolor), "Found ", $nerr, " error(s)\n", color("reset") ;} +if ($nwrn > 0) {print color("bold"), color($wrncolor), "Found ", $nwrn, " warning(s)\n", color("reset") ;} + +__END__ + +=pod + +=encoding utf8 + +=head1 texlogfilter + +=head2 NAME + +texlogfilter - filter latex engines output or log file + +=head2 SYNOPSIS + + texlogfilter [options] file.log + +=head2 DESCRIPTION + +Filter latex engines output or log file. For latex, pdflatex, lualatex or +xelatex output or log file. + +Without input file, standard input is used. Use on latex engine output with: + + latex file.tex < /dev/null | texlogfilter + +=head2 OPTIONS + + --help : print this help and exit + --version : print version and exit + + --box : show box warnings + --no-box : mask box warnings + + --ref : show reference/citation warnings + --no-ref : mask reference/citation warnings + + --filename : print current file name + --no-filename : do not print current file name + --files-ext=string : regex pattern used to match files extension (default: tex|sty|cls|bib) + + --skips : indicate skipped lines + --no-skips : mask skipped lines + --skip-marker=string : marker used to indicate skipped lines (defaut: ...) + + --add-filter=string : add user filter pattern (as perl regular expression) + + --full-log : show full log (don't filter - only colorize latex engine output) + + --errors-color=string + --warnings-color=string + --infos-color=string + --skips-color=string + --user-color=string : colors used for errors, warnings, informations and skipped lines + +=head2 ALTERNATIVES + +=over + +=item * B : L + +=item * B : L + +=back + +=head2 AUTHOR + +Written by Julien Labbé. + +Inspired from a script given by Martin Scharrer on Stack Exchange network (see +L). + +=head2 LICENCE + +This work may be distributed and/or modified under the conditions of the LaTeX +Project Public License, either version 1.3 of this license or (at your option) +any later version. The latest version of this license is in +L and version 1.3 or later is part of all +distributions of LaTeX version 2005/12/01 or later. + +=head2 VERSION + +1.0 + +=head2 HISTORY + +=over + +=item * 2021, november : version 1.0 (initial version). + +=back + +=cut + +=head2 DOCUMENTATION + +The documentation is integrated, writtent in Plain Old Documentation (POD) +format. Exported versions are available, in the following files: + +=over + +=item * F: created with perldoc. + +=item * F: created with pod2html. + +=back + +=cut -- cgit v1.2.3