summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2015-05-18 15:44:55 +0000
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2015-05-18 15:44:55 +0000
commit23409c6dd784133f097d88b914e32691c39b94a1 (patch)
tree2ee9b0fbc2774fed19753c843bbf94c7bb5bcaf9 /contrib
parent9ed784d83fcfc5eb464eb9d95277747b4ec8070d (diff)
downloadgcc-23409c6dd784133f097d88b914e32691c39b94a1.tar.gz
check_GNU_style.sh: Don't do 80 char check line by line
2015-05-18 Tom de Vries <tom@codesourcery.com> * check_GNU_style.sh: Add temp files tmp2 and tmp3. (cat_with_prefix): New function, using global variable prefix. (col): Make prefix a global variable. Rewrite to process file at a time rather than line at a time. Print part longer than 80 chars in red. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223297 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'contrib')
-rw-r--r--contrib/ChangeLog7
-rwxr-xr-xcontrib/check_GNU_style.sh70
2 files changed, 59 insertions, 18 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index 8276c9866d9..77d766faa8a 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -1,5 +1,12 @@
2015-05-18 Tom de Vries <tom@codesourcery.com>
+ * check_GNU_style.sh: Add temp files tmp2 and tmp3.
+ (cat_with_prefix): New function, using global variable prefix.
+ (col): Make prefix a global variable. Rewrite to process file at a time
+ rather than line at a time. Print part longer than 80 chars in red.
+
+2015-05-18 Tom de Vries <tom@codesourcery.com>
+
* check_GNU_style.sh (g, ag, vg): Don't cat empty file.
2015-05-18 Tom de Vries <tom@codesourcery.com>
diff --git a/contrib/check_GNU_style.sh b/contrib/check_GNU_style.sh
index ab59b1e6fc0..033a2c91b60 100755
--- a/contrib/check_GNU_style.sh
+++ b/contrib/check_GNU_style.sh
@@ -65,10 +65,12 @@ fi
inp=check_GNU_style.inp
tmp=check_GNU_style.tmp
+tmp2=check_GNU_style.2.tmp
+tmp3=check_GNU_style.3.tmp
# Remove $tmp on exit and various signals.
-trap "rm -f $inp $tmp $stdin_tmp" 0
-trap "rm -f $inp $tmp $stdin_tmp; exit 1" 1 2 3 5 9 13 15
+trap "rm -f $inp $tmp $tmp2 $tmp3 $stdin_tmp" 0
+trap "rm -f $inp $tmp $tmp2 $tmp3 $stdin_tmp; exit 1" 1 2 3 5 9 13 15
if [ $nfiles -eq 1 ]; then
# There's no need for the file prefix if we're dealing only with one file.
@@ -80,6 +82,17 @@ grep $format '^+' $files \
| grep -v ':+++' \
> $inp
+cat_with_prefix ()
+{
+ local f="$1"
+
+ if [ "$prefix" = "" ]; then
+ cat "$f"
+ else
+ awk "{printf "%s%s\n", $prefix, \$0}" $f
+ fi
+}
+
# Grep
g (){
local msg="$1"
@@ -134,10 +147,11 @@ vg (){
col (){
local msg="$1"
+
local first=true
local f
for f in $files; do
- local prefix=""
+ prefix=""
if [ $nfiles -ne 1 ]; then
prefix="$f:"
fi
@@ -148,22 +162,42 @@ col (){
| grep -v ':+++' \
> $tmp
- cat $tmp | while IFS= read -r line; do
- local longline
- # Filter out the line number prefix and the patch line modifier '+'
- # to obtain the bare line, before we use expand.
- longline=$(echo "$line" \
- | sed 's/^[0-9]*:+//' \
- | expand \
- | awk '{ if (length($0) > 80) print $0}')
- if [ "$longline" != "" ]; then
- if $first; then
- printf "\n$msg\n"
- first=false
- fi
- echo "$prefix$line"
+ # Keep only line number prefix and patch modifier '+'.
+ cat "$tmp" \
+ | sed 's/\(^[0-9][0-9]*:+\).*/\1/' \
+ > "$tmp2"
+
+ # Remove line number prefix and patch modifier '+'.
+ # Expand tabs to spaces according to tab positions.
+ # Keep long lines, make short lines empty. Print the part past 80 chars
+ # in red.
+ cat "$tmp" \
+ | sed 's/^[0-9]*:+//' \
+ | expand \
+ | awk '{ \
+ if (length($0) > 80) \
+ printf "%s\033[1;31m%s\033[0m\n", \
+ substr($0,1,80), \
+ substr($0,81); \
+ else \
+ print "" \
+ }' \
+ > "$tmp3"
+
+ # Combine prefix back with long lines.
+ # Filter out empty lines.
+ local found=false
+ paste -d '' "$tmp2" "$tmp3" \
+ | grep -v '^[0-9][0-9]*:+$' \
+ > "$tmp" && found=true
+
+ if $found; then
+ if $first; then
+ printf "\n$msg\n"
+ first=false
fi
- done
+ cat_with_prefix "$tmp"
+ fi
done
}