#!/bin/sh # # original copyright (c) 1991, Tom Verhoeff # # NAME # tex-clean - remove auxiliary LaTeX files # # VERSION # id: tex-clean,v 1.11 2003/11/14 15:37:18 rp Exp $ # based on Tom's version 1.4.1 # # AUTHOR # Tom Verhoeff, Dept. of Math/CS, Eindhoven Univ. of Technology, NL # E-mail: # now maintained by Reinier Post # PATH=/usr/bin:/bin; export PATH PROG=`basename "$0"` USAGE='tex-clean [ -amcdhlnrv ] filename...' PRIMARY='aux blg glo idx ilg lof log lot toc' SECONDARY='dvi ps pdf bbl ind out run.log out.log' OSTYPE=`uname -a | awk '{print $1}'` OSMAJVERSION=`uname -r | cut -c-1` Echon() # echo without newline # this is specific to SunOS ... { if test \( $OSTYPE = 'SunOS' \) -a \( $OSMAJVERSION -gt 4 \) then echo "$@"\\c else echo -n "$@" fi } EchoError() # Print arguments on standard error. { echo >&2 "$@" } EchoList() # Print arguments as comma-separated list enclosed by braces. { Echon "{" separator='' for item do Echon "$separator$item" separator="," done echo "}" } Spread() # Print all characters (but first) of argument separated by spaces. { echo "$1" | sed -e 's/./ &/g' -e 's/...//' } Help() # Print a help message. { echo "" echo " USAGE: $USAGE" echo "" echo " DESCRIPTION: Removes auxiliary LaTeX files of file.tex, i.e." Echon " file." ; EchoList $PRIMARY echo "" echo " OPTIONS:" Echon " -a also removes file." ; EchoList $SECONDARY echo " -c also list clean tex files" echo " -d debugging mode" echo " -h help message only" echo " -n no removal (implies -v)" echo " -o even removes when not newer than corresponding .tex" echo " or when there is no .tex at all" echo " -r recursively process subdirectories also" echo " -v verbose mode" echo "" } # Pre-process command line arguments. OPTIONS='' FILENAMES='' ALL='' LIST_CLEAN='' DEBUG='' NOT_NEWER='' NO_REMOVAL='' RECURSIVE='' VERBOSE='' for arg do case $arg in -*) OPTIONS="$OPTIONS $arg" for c in `Spread $arg` do case $c in a) ALL=$c ;; c) LIST_CLEAN=$c ;; d) DEBUG=$c ;; h) Help exit 0 ;; n) NO_REMOVAL=$c VERBOSE='v' ;; o) NOT_NEWER=$c ;; r) RECURSIVE=$c ;; v) VERBOSE=$c ;; *) echo "$PROG: option \`$c' unknown" echo "$PROG: option \`-h' prints a help message and exits" exit 1 ;; esac done ;; *) FILENAMES="$FILENAMES $arg" ;; esac done if test -z "$FILENAMES" then FILENAMES="." fi if test ! "$ALL" then suffixes="$PRIMARY" else suffixes="$PRIMARY $SECONDARY" fi if test "$NOT_REMOVAL" then RM=':' fi if test "$VERBOSE" then ECHO='echo' fi # Show option selection in debugging mode. if test "$DEBUG" then EchoError "$PROG: Debugging mode set" if test "$ALL" then EchoError "$PROG: All auxiliary files will be processed" fi if test "$NOT_NEWER" then EchoError "$PROG: Also files not newer than the .tex are removed" fi if test "$LIST_CLEAN" then EchoError "$PROG: Clean files are also listed" fi if test "$NO_REMOVAL" then EchoError "$PROG: No files removed, only listed" fi if test "$RECURSIVE" then EchoError "$PROG: Recursing into subdirectories" fi if test "$VERBOSE" then EchoError "$PROG: Verbose mode set" fi EchoError "$PROG: Options=\"$OPTIONS\"" EchoError "$PROG: Files=\"$FILENAMES\"" $ALLEchoError "$PROG: Suffixes=\"$suffixes\"" fi #set -x egrepfilter='\.('"`echo $suffixes | sed 's/ /|/g'`"')' if [ -n "$RECURSIVE" ] then find $FILENAMES -type f -print else for f in $FILENAMES do # Solaris find doesn't know -maxdepth 1 ... find $f -type f -print -o -exec test {} = '$f' ';' -prune done fi | egrep $egrepfilter | sed 's/\(.*\)\.\(.*\)/\1.\2 \1.tex/' | while read f ftex do if [ -n "$NOT_NEWER" -o \( -n \ "`find $ftex -type f ! -newer $f -print -o -prune 2>/dev/null`" \) ] then echo $f [ -n "$NO_REMOVAL" ] || rm $f fi done # End of Script