Files
secondo/Tools/pd/checkpd
2026-01-23 17:03:45 +08:00

197 lines
5.2 KiB
Plaintext

# This file is part of the PD system
# Copyright (C) 1998 Ralf Hartmut Gueting, Fachbereich Informatik, FernUniversitaet Hagen
# 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 2
# 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.
# !/bin/sh
# Script for checking of correctness with respect to pd and latex
#
#
MAXLINES=80
IGNORE_INCLUDES="true"
# check the first argument to be '--strong'
# using this argument, too long lines will be treated as errors
# instead of warnings
STRONG=false
VERYSTRONG=false
VERBOSE=true
if [ "$1" = "--strong" ]; then
STRONG=true
shift
else
if [ "$1" = "--verystrong" ]; then
VERYSTRONG="true"
shift
fi
fi
if [ "$1" = "--quiet" ]; then
VERBOSE=false
shift
fi
ARGS=$*
if [ -z "$ARGS" ]
then
FILESCPP=$(find $PWD -name '*.cpp')
FILESH=$(find $PWD -name '*.h')
FILESPL=$(find $PWD -name '*.pl')
MYFILES="$FILESCPP $FILESH $FILESPL"
else
MYFILES=""
for G in $ARGS
do
MYFILES="$MYFILES $PWD/$G"
done
fi
TEMPDIR="$PWD/.checkpd"
HERE="$PWD"
if [ ! -d "$TEMPDIR" ]; then
mkdir "$TEMPDIR"
if [ $? -ne 0 ]; then
echo "cannot create temp directory"
exit -1
fi
EXIST=FALSE
else
EXIST=TRUE
fi
cd "$TEMPDIR"
PROCESSED=0
PDFAILED=0
LATEXFAILED=0
LINEFAILED=0
NOTFOUND=0
TABCONTAMINATED=0
TABSYM=$(echo -e "\t")
for F in $MYFILES
do
if [ ! -e "$F" ]; then
NOTFOUND=$(expr $NOTFOUND + 1)
else
PROCESSED=$(expr $PROCESSED + 1)
S=$((pdtabs <"$F" | maketex >/dev/null) 2>&1)
if [ $? -ne 0 ]
then
echo "pdcheck for $F failed"
if [ "$VERBOSE" = "true" ]; then
echo "message : $S"
echo -e "\n"
fi
PDFAILED=$(expr $PDFAILED + 1)
else
{
cat "$PD_HEADER"
pdtabs <$F | maketex
} >"$TEMPDIR"/tmp.tex
latex -interaction=nonstopmode "$TEMPDIR"/tmp.tex >/dev/null
LATEXRET=$?
LATEXOK=0
if [ "$LATEXRET" -ne 0 ]; then
if [ -n "$IGNORE_INCLUDES" ]; then
TEXLOG="$TEMPDIR"/tmp.log
# file errors: ignore them
LEF1=$(cat "$TEXLOG" | grep -i '^! ' | grep -i "cannot determine size of" | wc -l)
LEF2=$(cat "$TEXLOG" | grep -i '^! ' | grep -i 'file .* not found' | wc -l)
LEF=$(expr $LEF1 + $LEF2)
# all latex errors
LATERR=$(cat "$TEXLOG" | grep '^! ' | wc -l)
# non file errors
LE=$(expr $LATERR - $LEF)
if [ "$LE" -gt 0 ]; then
echo -e "LaTeX Error in \"$F\" \n"
LATEXFAILED=$(expr $LATEXFAILED + 1)
LATEXOK=1
cat $TEXLOG
fi
else
echo -e "LaTeX Error in \"$F\" (If the file contains figures we can't avoid this) \n"
LATEXFAILED=$(expr $LATEXFAILED + 1)
LATEXOK=1
fi
fi
if [ $LATEXOK -eq 0 ]; then
if [ "$VERBOSE" = "true" ]; then
linecheck "$MAXLINES" $F
else
linecheck "$MAXLINES" $F >/dev/null
fi
CL="$?"
if [ "$CL" -ne 0 ]; then
if [ \( "$STRONG" = "true" \) -o \( "$VERYSTRONG" = "true" \) ]; then
echo -e "Error: $CL lines too long in \"$F\""
else
echo -e "Warning: $CL lines too long in \"$F\""
fi
LINEFAILED=$(expr $LINEFAILED + 1)
else
if [ "$VERBOSE" = "true" ]; then
tabcheck "$F"
else
tabcheck "$F" > /dev/null
fi
TABS=$?
if [ $TABS -gt 0 ]; then
echo -e "Warning: $F contains $TABS tabulators\n"
TABCONTAMINATED=$(expr $TABCONTAMINATED + 1)
fi
fi
fi
rm -f $TEMPDIR/*.dvi $TEMPDIR/*.log $TEMPDIR/*.aux $TEMPDIR/*.tmp $TEMPDIR/*.toc $TEMPDIR/tmp.tex
fi
fi
done
cd "$HERE"
rm -rf "$TEMPDIR"
SUCCESS=$(expr $PROCESSED - $PDFAILED - $LINEFAILED - $LATEXFAILED - $TABCONTAMINATED )
if [ $PROCESSED -gt 0 ]; then
echo "checkpd Statistic:"
if [ "$NOTFOUND" -gt 0 ]; then
echo "files not found : $NOTFOUND "
fi
echo "processed files : $PROCESSED"
echo "pd errors : $PDFAILED"
echo "latex errors : $LATEXFAILED"
echo "too long lines : $LINEFAILED"
echo "tabulators : $TABCONTAMINATED"
echo "files ok : $SUCCESS"
else
if [ "$NOTFOUND" -gt 0 ]; then
echo "checkpd: files not found : $NOTFOUND "
fi
echo "checkpd: no file to check"
fi
if [ "$STRONG" != "true" ]; then
FAILED=$(expr $PDFAILED + $LATEXFAILED)
else
FAILED=$(expr $PDFAILED + $LATEXFAILED + $LINEFAILED )
fi
if [ "$VERYSTRONG" = "true" ]; then
FAILED=$(expr $PDFAILED + $LATEXFAILED + $LINEFAILED + $TABCONTAMINATED )
fi
#FAILED="$PDFAILED"
exit "$FAILED"