#! /bin/sh # Replace tabs with eight spaces # # @Authors: Christopher Hylands # # @Version: $Id: rmtabs 53042 2009-04-10 20:31:21Z cxh $ # # @Copyright (c) 1997-2009 The Regents of the University of California. # All rights reserved. # # Permission is hereby granted, without written agreement and without # license or royalty fees, to use, copy, modify, and distribute this # software and its documentation for any purpose, provided that the # above copyright notice and the following two paragraphs appear in all # copies of this software. # # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY # FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES # ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF # THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE # PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF # CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, # ENHANCEMENTS, OR MODIFICATIONS. # # PT_COPYRIGHT_VERSION_2 # COPYRIGHTENDKEY # This script can be used to fix many cvs managed files at once. # Before running this script, you must: # 1. Create a doit function that does the editing you want # 2. Set up the files variable so it contains a list of the files # 3. Set up a grep statement that will identify files you want to change # 4. Adjust the log message for the cvs commit command # Then try out fix-files with the -n option, which only prints, but # does not actually make the change. # # Usage: rmtrailinspace [-n] [-d] printonly=no # We don't use getopt here because it is not included in the basic # cygwin bash download (12/01) if [ "$1" = "-h" ]; then echo "$0: Usage: $0 [-d] [-n] [filenames . . .]" echo " -d debug" echo " -n Print only, don't modify files" exit 3 fi if [ "$1" = "-n" ]; then printonly=yes shift fi if [ "$1" = "-d" ]; then set -x shift fi # Handle -d -n if [ "$1" = "-n" ]; then printonly=yes shift fi TMPFILE=/tmp/rmtrailingspace.tmp.$$ filesupdated=/tmp/rmtrailingspace_filesupdated.$$ # doit is a shell function doit() { sed -e 's/ / /g' < $file > $TMPFILE diff $file $TMPFILE } EGREPMATCH=" " LOGMESSAGE="Replaced tabs with eight spaces" topdir=`pwd` for fullfile in $@ do cd $topdir echo "Now processing: $fullfile" egrep "$EGREPMATCH" $fullfile retval=$? if [ $retval = 0 ]; then # There was a difference, so we might want to check this sucker out file=`basename $fullfile` dirname=`dirname $fullfile` cd $dirname if [ -d SCCS -o -d RCS ]; then echo "Error: SCCS or RCS directory" exit 2 fi doit if [ "$printonly" = "no" ]; then cp $TMPFILE $file echo "Not running svn commit, just copying" #svn commit -m "Removing tabs" $file echo $fullfile >> $filesupdated else echo "Would update and commit $fullfile" fi fi done if [ "$printonly" = "no" ]; then echo "Thes files should be checked in:" cat $filesupdated fi rm -f $TMPFILE $filesupdated