1#!/bin/bash 2 3# This script potentially can be quite intrusive since it 4# unconditionally removes trailing blanks and tabs from essentially all text files 5# in the source tree. So after running this script you should use 6# "git diff" to make sure you agree with the source file changes generated 7# by this script before committing these generated changes. 8 9# Copyright (C) 2016-2019 Alan W. Irwin 10# 11# This file is part of PLplot. 12# 13# PLplot is free software; you can redistribute it and/or modify 14# it under the terms of the GNU Library General Public License as published 15# by the Free Software Foundation; either version 2 of the License, or 16# (at your option) any later version. 17# 18# PLplot is distributed in the hope that it will be useful, 19# but WITHOUT ANY WARRANTY; without even the implied warranty of 20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21# GNU Library General Public License for more details. 22# 23# You should have received a copy of the GNU Library General Public License 24# along with PLplot; if not, write to the Free Software 25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 26 27# Find absolute PATH of script without using readlink (since readlink is 28# not available on all platforms). Followed advice at 29# http://fritzthomas.com/open-source/linux/551-how-to-get-absolute-path-within-shell-script-part2/ 30ORIGINAL_PATH="$(pwd)" 31cd $(dirname "$0") 32# Absolute Path of the script 33SCRIPT_PATH="$(pwd)" 34cd "${ORIGINAL_PATH}" 35 36# Assumption: top-level source tree is parent directory of where script 37# is located. 38SOURCE_TREE=$(dirname "${SCRIPT_PATH}") 39cd "$SOURCE_TREE" 40 41# Remove trailing blanks and tabs for all files in the PLplot source 42# tree with the following exceptions: 43 44# * Exclude this script (since changes on the fly can potentially 45# screw up the results from bash scripts). 46# * Exclude ChangeLog.release since the "git log" command that 47# produces that generates consistent whitespace indentation for 48# otherwise empty lines in the commit message. 49# * Exclude all files in the .git tree (don't want to mess with our repository). 50# * Exclude all binary files (*.pgm, *.gif, *.jpg, *.cgm, *.dbf, 51# *.prj, *.shp, *.shx, and *.fnt) recognized in .gitattributes. 52# * Exclude *.pyc binary files recognized in .gitignore. 53# * Exclude all files in the rpm, and lib trees (may review lib later). 54# * Exclude all *.patch files. 55# * Exclude libqhull/src/mem.h (may review this later when epa_build is updated). 56# * Exclude COPYING.LIB (since we want to preserve exact LGPL licensing text). 57# * Exclude test_tclmatrix.out (since this file is used to compare with a pltcl result 58# that does generate lines with some trailing blanks). 59 60filelist=$(find . -type f |grep -E -v 'remove_trailing_whitespace\.sh|ChangeLog\.release|\.git|\.pgm|\.gif|\.jpg|\.cgm|\.dbf|\.prj|\.shp|\.shx|\.fnt|\.pyc|\.png|rpm/|lib/|\.patch|libqhull/src/mem.h|COPYING.LIB|test_tclmatrix.out' | xargs grep -l $'[\t ][\t ]*$') 61if [ -z "$filelist" ] ; then 62 echo "No files found with trailing whitespace" 63 exit 64fi 65echo "The following list of files have trailing white space" 66echo $filelist 67ANSWER= 68while [ "$ANSWER" != "yes" -a "$ANSWER" != "no" ] ; do 69 echo -n "Remove trailing whitespace from all those files (yes/no)? " 70 read ANSWER 71done 72if [ "$ANSWER" = "no" ] ; then 73 echo "Immediate exit specified!" 74 exit 75fi 76 77sed -i -e $'s?[\t ][\t ]*$??' $filelist 78