File: remove_trailing_whitespace.sh

package info (click to toggle)
plplot 5.14.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 30,424 kB
  • sloc: ansic: 79,613; xml: 28,583; cpp: 20,037; ada: 19,456; tcl: 12,081; f90: 11,423; ml: 7,276; java: 6,863; python: 6,792; sh: 3,185; perl: 828; lisp: 75; makefile: 48; sed: 33; fortran: 5
file content (74 lines) | stat: -rwxr-xr-x 3,216 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash

# This script potentially can be quite intrusive since it
# unconditionally removes trailing blanks and tabs from essentially all text files
# in the source tree.  So after running this script you should use
# "git diff" to make sure you agree with the source file changes generated
# by this script before committing these generated changes.

# Copyright (C) 2016-2018 Alan W. Irwin
#
# This file is part of PLplot.
#
# PLplot is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PLplot 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 Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with PLplot; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# Find absolute PATH of script without using readlink (since readlink is
# not available on all platforms).  Followed advice at
# http://fritzthomas.com/open-source/linux/551-how-to-get-absolute-path-within-shell-script-part2/
ORIGINAL_PATH="$(pwd)"
cd $(dirname "$0")
# Absolute Path of the script
SCRIPT_PATH="$(pwd)"
cd "${ORIGINAL_PATH}"

# Assumption: top-level source tree is parent directory of where script
# is located.
SOURCE_TREE=$(dirname "${SCRIPT_PATH}")
cd "$SOURCE_TREE"

# Remove trailing blanks and tabs for all files in the PLplot source
# tree with the following exceptions:

# * Exclude this script (since changes on the fly can potentially
#   screw up the results from bash scripts).
# * Exclude all files in the .git tree (don't want to mess with our repository).
# * Exclude all binary files (*.pgm, *.gif, *.jpg, *.cgm, *.dbf,
#   *.prj, *.shp, *.shx, and *.fnt) recognized in .gitattributes.
# * Exclude *.pyc binary files recognized in .gitignore.
# * Exclude all files in the rpm, and lib trees (may review lib later).
# * Exclude all *.patch files.
# * Exclude libqhull/src/mem.h (may review this later when epa_build is updated).
# * Exclude COPYING.LIB (since we want to preserve exact LGPL licensing text).
# * Exclude test_tclmatrix.out (since this file is used to compare with a pltcl result
#   that does generate lines with some trailing blanks).

filelist=$(find . -type f |grep -E -v 'remove_trailing_whitespace.sh|\.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 ]*$')
if [ -z "$filelist" ] ; then
    echo "No files found with trailing whitespace"
    exit
fi
echo "The following list of files have trailing white space"
echo $filelist
ANSWER=
while [ "$ANSWER" != "yes" -a "$ANSWER" != "no" ] ; do
    echo -n "Remove trailing whitespace from all those files (yes/no)? "
    read ANSWER
done
if [ "$ANSWER" = "no" ] ; then
    echo "Immediate exit specified!"
    exit
fi

sed -i -e $'s?[\t ][\t ]*$??' $filelist