diff options
author | Norbert Preining <norbert@preining.info> | 2019-11-03 03:01:01 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-11-03 03:01:01 +0000 |
commit | aa26106a9b77529d1eae806729d8076378ced64b (patch) | |
tree | c1a96609e17d84e6fc764caf3a52c65e7ed8c5eb /support/chklref/src | |
parent | 3479a92321ed7fe7e2133d3daec2d4f5fd53fbc6 (diff) |
CTAN sync 201911030301
Diffstat (limited to 'support/chklref/src')
-rw-r--r-- | support/chklref/src/Makefile.in | 33 | ||||
-rw-r--r-- | support/chklref/src/chklref.in | 126 | ||||
-rw-r--r-- | support/chklref/src/chklref.sty | 137 | ||||
-rw-r--r-- | support/chklref/src/chkparser | 275 |
4 files changed, 0 insertions, 571 deletions
diff --git a/support/chklref/src/Makefile.in b/support/chklref/src/Makefile.in deleted file mode 100644 index 9e916b8dd8..0000000000 --- a/support/chklref/src/Makefile.in +++ /dev/null @@ -1,33 +0,0 @@ -.PHONY: all clean distclean install uninstall - -include ../Make.incl - -SCRIPTS=chkparser -BINFILES=chklref -TEXFILES=chklref.sty - - -all: - -install: all - if ! test -d $(DESTDIR)$(bindir); then $(INSTALL) -d $(DESTDIR)$(bindir); fi - $(INSTALL) -m 755 $(BINFILES) $(DESTDIR)$(bindir) - if ! test -d $(DESTDIR)$(SCRIPTSDIR); then $(INSTALL) -d $(DESTDIR)$(SCRIPTSDIR); fi - $(INSTALL) -m 755 $(SCRIPTS) $(DESTDIR)$(SCRIPTSDIR) - if ! test -d $(DESTDIR)$(LATEXDIR); then $(INSTALL) -d $(DESTDIR)$(LATEXDIR); fi - $(INSTALL) -m 644 $(TEXFILES) $(DESTDIR)$(LATEXDIR) - - -define chk_rm -@for f in $(2); do echo "uninstalling $(1)/$$f"; $(RM) $(1)/$$f; done -endef - -uninstall: - $(call chk_rm, $(bindir), $(DESTDIR)$(BINFILES)) - $(call chk_rm, $(LATEXDIR), $(DESTDIR)$(TEXFILES)) - $(call chk_rm, $(SCRIPTSDIR), $(DESTDIR)$(SCRIPTS)) - - -distclean: - $(RM) chklref - diff --git a/support/chklref/src/chklref.in b/support/chklref/src/chklref.in deleted file mode 100644 index dee79c9ac7..0000000000 --- a/support/chklref/src/chklref.in +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env sh - -## -## wrapper for chklref program -## Automatically generated by configure from chklref.in -## - -######################################################################### -# Written and (C) by Jérôme Lelong <jerome.lelong@gmail.com> # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <http://www.gnu.org/licenses/>. # -######################################################################### - -prefix=@prefix@ -bindir=@bindir@ -SCRIPTSDIR=@SCRIPTSDIR@ - -PERL=@PERL_PATH@ -LATEX=@LATEX_PATH@ -PDFLATEX=@PDFLATEX_PATH@ -VERSION=@VERSION@ -LATEXDIR=@LATEXDIR@ -DOCDIR=@DOCDIR@ -SCRIPTSDIR=@SCRIPTSDIR@ - -print_usage() -{ - cat << EOF - -chklref - -This is a latex utility to check for unused labels and bibitems in -a LaTeX file. - -usage: chklref [OPTIONS] file[.tex] - -OPTIONS - - -p,--pdf : Use pdflatex instead of latex - -q,--quiet : Run LaTeX quietly - -d,--debug : Run in deubgging mode - -h,--help : Display this help - --version : Display the version number - -EOF -} - -out='/dev/stdout' -latex_cmd=$LATEX -debug=0 -while test -n "$1" -do - case "$1" in - -p|--pdf) - latex_cmd=$PDFLATEX - shift - ;; - -h|--help) - print_usage - exit 0 - ;; - -q|--quiet) - out='/dev/null' - shift - ;; - -d|--debug) - debug=1 - shift - ;; - --version) - echo "chklref version $VERSION" - exit 0 - ;; - -*) - echo "Unknown option: $1" - print_usage - exit 1 - ;; - *) - break - ;; - esac -done - -INFILE=$1 -if test -z "$INFILE"; then - echo "$0: You must specify an input file" - exit 1 -fi - -if test ! -f "${INFILE}"; then - INFILE=${INFILE}.tex -fi -if test ! -f "${INFILE}"; then - echo "$0: Neither ${INFILE} nor ${INFILE}.tex exists" - exit 1 -fi - -# POSIX extractions of dirname and basename -basetexfile=${INFILE##*/} -basetexfile=${basetexfile%.tex} -dirtexfile=${INFILE%/*} -if [ "${dirtexfile}" = "$1" ]; then dirtexfile="."; fi - -cd -- "${dirtexfile}" - -echo "Running $latex_cmd on $basetexfile.tex to collect labels, -references and environment declarations\n\n" > "$out" -$latex_cmd --interaction errorstopmode "${basetexfile}" > "$out" 2>&1 -rm -f -- "$basetexfile".tex.chk -$latex_cmd --interaction errorstopmode --jobname "$basetexfile" \ - '\RequirePackage{chklref}\input' "{$basetexfile.tex}" > "$out" 2>&1 -$PERL "$SCRIPTSDIR"/chkparser "$basetexfile".chk -[ $debug -ne 0 ] || rm -f -- "$basetexfile".chk - diff --git a/support/chklref/src/chklref.sty b/support/chklref/src/chklref.sty deleted file mode 100644 index ecaff108f4..0000000000 --- a/support/chklref/src/chklref.sty +++ /dev/null @@ -1,137 +0,0 @@ -%% -*-mode: tex-mode -*- - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Written and (C) by Jérôme Lelong <jerome.lelong@gmail.com> %% -%% %% -%% This program is free software; you can redistribute it and/or modify %% -%% it under the terms of the GNU General Public License as published by %% -%% the Free Software Foundation; either version 3 of the License, or %% -%% (at your option) any later version. %% -%% %% -%% This program is distributed in the hope that it will be useful, %% -%% but WITHOUT ANY WARRANTY; without even the implied warranty of %% -%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% -%% GNU General Public License for more details. %% -%% %% -%% You should have received a copy of the GNU General Public License %% -%% along with this program. If not, see <http://www.gnu.org/licenses/>. %% -%% %% -%% This file is part of the chklref package. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -\NeedsTeXFormat{LaTeX2e}% -\ProvidesPackage{chklref}% -\RequirePackage{afterpackage}% - -\gdef\CHK@stack{} - -\newwrite\CHK@write -\immediate\openout\CHK@write\jobname.chk% -\def\CHK@immediate@write{\immediate\write} -\def\CHK@print#1{% - \protect\CHK@immediate@write\CHK@write{#1}% -} - -% Make sure the auxiliary files are still suitable for usage without the -% chklref package. -\RequirePackage{auxhook}[2009/12/14] -\AddLineBeginAux{\string\let\string\CHK@immediate@write\string\@gobbletwo} -\let\@starttoc@orig\@starttoc -\def\@starttoc#1{% - \@starttoc@orig{#1}% - \addtocontents{#1}{\string\let\string\CHK@immediate@write\string\@gobbletwo} -} - -% Track the name of the file currently processed. -% This is successfuly done by currfile for -% \include{toto}, \input{toto} but NOT \input toto -% So we need an extra trick, but do it as late as possible. -\RequirePackage{currfile} -\def\CHK@currentfile{\expandafter\expandafter\currfilename} -\def\CHK@@input#1 {\input{#1}} -\AtBeginDocument{% - \def\input{\@ifnextchar\bgroup\@iinput\CHK@@input} -} - -\def\CHK@redefine#1#2{% - \expandafter\let\csname CHK@#1@orig\expandafter\endcsname\csname#1\endcsname% - \expandafter\def\csname#1\endcsname##1{% - \CHK@print{#2{##1} line \the\inputlineno\space file \CHK@currentfile}% - \expandafter\expandafter\csname CHK@#1@orig\endcsname{##1}} -} - -\def\CHK@redefine@#1#2{% - \expandafter\let\csname CHK@#1@orig\expandafter\endcsname\csname#1\endcsname% - \expandafter\def\csname#1\endcsname##1{% - \CHK@print{#2 ##1 line \the\inputlineno\space file \CHK@currentfile}% - \expandafter\expandafter\csname CHK@#1@orig\endcsname{##1}} -} - -\CHK@redefine{begin}{begin} -\CHK@redefine{end}{end} - -\AfterPackage{hyperref}{ - \AtBeginDocument{% - \let\CHK@label@orig=\label - \def\label#1{% - \CHK@print{label #1 line \the\inputlineno\space file \CHK@currentfile}% - \CHK@label@orig{#1}} - - \Hy@SetCatcodes - \def\HyPsd@ref#1{\HyPsd@@ref#1*\END}% - \def\HyPsd@@ref#1*#2\END{% - \ifx\\#2\\% - \HyPsd@@@ref{#1}% - \else - \expandafter\HyPsd@@@ref - \fi - }% - \def\HyPsd@@@ref#1{% - \expandafter\ifx\csname r@#1\endcsname\relax - ??% - \else - \expandafter\expandafter\expandafter\@car\csname r@#1\endcsname\@nil - \fi - \CHK@print{ref #1 line \the\inputlineno\space file \CHK@currentfile}% - } - \let\ref=\HyPsd@ref - \Hy@RestoreCatcodes - } -} - -\AtBeginDocument{% - \newif\ifCHK@hyperref - \newif\ifCHK@amsmath - \@ifpackageloaded{hyperref}{\CHK@hyperreftrue}{} - \@ifpackageloaded{amsmath}{\CHK@amsmathtrue}{} - - \ifCHK@amsmath% %With AMS-LaTeX tags - %%\CHK@redefine{label@in@display}{label@in@display} - \let\CHK@label@in@display@orig=\label@in@display - \def\label@in@display#1{% - \CHK@print{label #1 line \the\inputlineno\space file \CHK@currentfile} - \CHK@label@in@display@orig{#1}} - - \CHK@redefine@{eqref}{ref} - \CHK@redefine@{ref}{ref} - \CHK@redefine@{label}{label} - \CHK@redefine@{citation}{citation} - \CHK@redefine@{bibcite}{bibcite} - - \else - \ifCHK@hyperref\else - \CHK@redefine@{label}{label} - \CHK@redefine@{ref}{ref} - \CHK@redefine@{citation}{citation} - \CHK@redefine@{bibcite}{bibcite} - \fi - \fi -} - -\AtEndDocument{ - \message{\CHK@stack} -} -% To prevent error with packages already defining the \AfterPackage macro. -\let\AfterPackage=\relax -\endinput diff --git a/support/chklref/src/chkparser b/support/chklref/src/chkparser deleted file mode 100644 index 09ecd96bb7..0000000000 --- a/support/chklref/src/chkparser +++ /dev/null @@ -1,275 +0,0 @@ -#!/usr/bin/env perl -w - -######################################################################### -# Written and (C) by Jérôme Lelong <jerome.lelong@gmail.com> # -# # -# This program is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <http://www.gnu.org/licenses/>. # -######################################################################### - -use strict; -use warnings; -# recognised math environments -my @have_star_modes = qw( equation eqnarray align multline table gather); -my $have_star_mode = join('|', @have_star_modes); -$have_star_mode = "($have_star_mode)"; - -# Create a hash with three keys "str", "line", "file" and returns a -# reference to it -# -# Input: 3 args -# a string -# a line number -# a filename -sub new_ref -{ - my ($str, $line, $file) = @_; - my $ref = {}; - $ref->{str} = $str; - $ref->{line} = $line; - $ref->{file} = $file; - return $ref; -} - -# Create a hash with six keys "str", "begin", "end", "star", -# "label_line" and "label" and returns a reference to it. -# -# Input : 7 args -# a string (the env name) -# line of beginning -# line of end -# has the env a star? -# line on which the label appears -# value of the label -# file name -sub new_math_env -{ - my ($str, $begin, $end, $star, $label_line, $label, $file) = @_; - my $this = {}; - $this->{str} = $str; - $this->{begin} = $begin; - $this->{end} = $end; - $this->{star} = $star; - $this->{label_line} = $label_line; - $this->{label} = $label; - $this->{file} = $file; - return $this; -} - - -# Parse .chk file and looks for the environments defined by -# @have_star_modes. The first and last line of the environment are stored -# along with the name of the environment. One last variable is -# used to remember if the star version was used. -# -# Input: -# a chk file content -# entries -# refs -# labels -# the last 3 args are passed as references and are modified -sub chk_parse -{ - my ($txt, $entries, $refs, $labels, $citations, $bibcites) = @_; - my ($str, $begin, $end, $star, $labelled_env, $label, $file, $entry, $l); - - - while (defined($l = shift(@$txt))) - { - if ($l =~ m/^label (.+) line (\d+) file (.+)\n$/o) - { - push(@$labels, new_ref($1, $2, $3)); - } - elsif ($l =~ m/^ref (.+) line (\d+) file (.+)$/o) - { - push(@$refs, new_ref($1, $2, $3)); - } - elsif ($l =~ m/^citation (.+) line (\d+) file (.+)$/o) - { - foreach my $c (split(/\s*,\s*/, $1)) - { - ${$citations}{$c} = 1; - } - } - elsif ($l =~ m/^bibcite (.+) line (\d+) file (.+)$/o) - { - push(@$bibcites, $1); - } - elsif ($l =~ m/^begin{$have_star_mode(\**)} line (\d+) file (.+)$/o) - { - $str = $1; - $star = 1; - $star = 0 unless ($2); - $begin = $3; - $file = $4; - $label = ""; - $labelled_env = 0; - while (defined($l = shift(@$txt))) - { - if ($l =~ m/^label (.+) line (\d+) file (.+)$/o) - { - push(@$labels, new_ref($1, $2, $3)); - $label = $1; - $labelled_env = $2; - } - elsif ($l =~ m/^ref (.+) line (\d+) file (.+)$/o) - { - push(@$refs, new_ref($1, $2, $3)); - } - elsif ($l =~ m/^end{$str\*{$star}} line (\d+) file (.+)$/) - { - $end = $1; - $entry = new_math_env($str, $begin, $end, $star, $labelled_env, - $label, $file); - push(@$entries, $entry); - last; - } - } - } - } - return; -} - -# Find environments with both labels and stars -# Input : list of entries -sub star_label -{ - my ($entries) = @_; - print "************************************\n"; - print "** Labels in starred environments **\n"; - print "************************************\n"; - foreach my $e (@$entries) - { - printf("-- %-20s line %4d: remove label %s \n", - $e->{file}, $e->{label_line}, $e->{label}) - if (($e->{star} == 1) && ($e->{label_line} > 0)); - - printf("-- %-20s line %4d: consider using a STAR environment\n", - $e->{file}, $e->{begin}) - if (($e->{star} == 0) && ($e->{label_line} == 0)); - } - print "\n"; - return; -} - -# Find labels without any corrsponding references. -# references must be sorted -sub unused_label -{ - my ($labels, $refs) = @_; - my $found; - - print "*******************\n"; - print "** Unused Labels **\n"; - print "*******************\n"; - foreach my $l (@$labels) - { - $found = 0; - foreach my $r (@$refs) - { - if ($r->{str} eq $l->{str}) - { - $found = 1; - last; - } - elsif ($r->{str} ge $l->{str}) - { - last; - } - } - printf("-- %-20s line %4d: remove label %s\n", - $l->{file}, $l->{line}, $l->{str}) - if (!$found); - } - print "\n"; - return; -} - -# Find bibitems without any corresponding \cite -sub unused_cites -{ - my ($bibcites, $citations) = @_; - print "**********************************\n"; - print "** Uncited Bibliography entries **\n"; - print "**********************************\n"; - foreach my $c (@$bibcites) - { - print("remove bibitem : $c\n") unless exists ${$citations}{$c}; - } - return; -} - -# Find and remove duplicates in an -# array of { str, line } entries. -# Note that the array must be sorted according to str -# Input : ref or label list -# Return the corresponding list -sub rm_duplicate -{ - my ($array) = @_; - my $prev = '___________not_a_true_label______'; - my @uniq_array = - grep { $_->{str} ne $prev && (($prev) = $_->{str}) } @$array; - return \@uniq_array; -} - -# Display all math envs with their characteristics -# Input args -# line of beginning -# line of end -# starred or not -# label -sub disp_msg -{ - my ($entries) = @_; - my @entries = @$entries; - - foreach my $e (@entries) - { - print("env $e->{str} \n"); - print("\tbeginning : $e->{begin}\n\tend : $e->{end}\n"); - print("\tstar environment\n") if ($e->{star} == 1); - print("\tlabelled environement\n") if ($e->{label} > 0); - print("\n"); - } - return; -} - -if (@ARGV != 1) -{ - print("chklref needs exactly one argument.\n"); - exit 0; -} - -my @entries = (); -my @refs = (); -my @labels = (); -my %citations = (); -my @bibcites = (); -my $FIC; - -# Read the whole file to an array because label and end commands -# generally need to be swapped. -open($FIC, '<', $ARGV[0]) or die("open: $!"); -my @txt = <$FIC>; -close($FIC); - -chk_parse(\@txt, \@entries, \@refs, \@labels, \%citations, \@bibcites); - -@labels = sort { $a->{line} cmp $b->{line} } @labels; -@refs = sort { $a->{str} cmp $b->{str} } @refs; -my $uniq_refs = rm_duplicate(\@refs); -star_label(\@entries); -#disp_msg( \@entries ); -unused_label(\@labels, $uniq_refs); -unused_cites(\@bibcites, \%citations); |