#! /bin/sh # -[Wed Aug 25 10:01:23 1999 by cxh]- # Indent Java code using emacs # Usage: jindent [-n] [-d] # -n Print what would happen, but don't checkout or modify files # -d turn on debugging # # The Emacs CC-mode FAQ says: # *Q.* *How do I re-indent the whole file?* # # *A.* Visit the file and hit `C-x h' to mark the whole buffer. Then # hit ` C-\'. # # C-x h mark-whole-buffer # ESC C-\ indent-region #(fset 'jindent # "\C-xh\C-[\C-\\") printonly=no while getopts nd-- opt do case $opt in d) set -x;; n) printonly=yes;; \?) echo "$0: Usage: $0 [-n] [-x] [filenames . . .]" echo " -n Print only" echo " -d debug" exit 3;; esac done shift `expr $OPTIND - 1` emacs=emacs if [ "$PTII" = "" ]; then echo "$0: \$PTII is not set, exiting" exit 4 fi jindent_el=$PTII/util/testsuite/jindent.el if [ ! -f "$jindent_el" ]; then echo "$0: '$jindent_el' not found, exiting" exit 5 fi tmpfile=/tmp/jindent$$.java for file in $@ do cp $file $tmpfile chmod u+w $tmpfile echo "$file" $emacs -q -batch -l $jindent_el $tmpfile -f jindent diff $file $tmpfile status=$? if [ $status -eq 1 ]; then if [ "$printonly" = "yes" ]; then echo "Would be checked out" else if [ -d SCCS ]; then sccs edit $file fi if [ -w $file ]; then echo "$file is now writable, now reindenting" $emacs -q -batch -l $jindent_el $file -f jindent if [ -d SCCS ]; then sccs delget -y"Reindented with jindent" $file else if [ -d CVS ]; then cvs commit -m "Reindented with jindent" $file fi fi else echo "ERROR: could not check out $file" fi fi else echo "No differences, so no need to delget" fi done rm -f $tmpfile