1#!/bin/sh 2 3# Checks some of the GNU style formatting rules in a set of patches. 4# Copyright (C) 2010, 2012 Free Software Foundation, Inc. 5# Contributed by Sebastian Pop <sebastian.pop@amd.com> 6 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 3 of the License, or 10# (at your option) any later version. 11 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 21usage() { 22 cat <<EOF 23check_GNU_style.sh [patch]... 24 25 Checks the patches for some of the GNU style formatting problems. 26 Please note that these checks are not always accurate, and 27 complete. The reference documentation of the GNU Coding Standards 28 can be found here: http://www.gnu.org/prep/standards_toc.html 29 and there are also some additional coding conventions for GCC: 30 http://gcc.gnu.org/codingconventions.html 31 32EOF 33 exit 1 34} 35 36test $# -eq 0 && usage 37 38tmp=check_GNU_style.tmp 39 40# Remove $tmp on exit and various signals. 41trap "rm -f $tmp" 0 42trap "rm -f $tmp ; exit 1" 1 2 3 5 9 13 15 43 44# Grep 45g (){ 46 msg="$1" 47 arg="$2" 48 shift 2 49 grep -nH '^+' $* \ 50 | grep -v ':+++' \ 51 | egrep --color=always -- "$arg" \ 52 > $tmp && printf "\n$msg\n" 53 cat $tmp 54} 55 56# And Grep 57ag (){ 58 msg="$1" 59 arg1="$2" 60 arg2="$3" 61 shift 3 62 grep -nH '^+' $* \ 63 | grep -v ':+++' \ 64 | egrep --color=always -- "$arg1" \ 65 | egrep --color=always -- "$arg2" \ 66 > $tmp && printf "\n$msg\n" 67 cat $tmp 68} 69 70# reVerse Grep 71vg (){ 72 msg="$1" 73 varg="$2" 74 arg="$3" 75 shift 3 76 grep -nH '^+' $* \ 77 | grep -v ':+++' \ 78 | egrep -v -- "$varg" \ 79 | egrep --color=always -- "$arg" \ 80 > $tmp && printf "\n$msg\n" 81 cat $tmp 82} 83 84col (){ 85 msg="$1" 86 shift 1 87 grep -nH '^+' $* \ 88 | grep -v ':+++' \ 89 | cut -f 2 -d '+' \ 90 | awk '{ if (length ($0) > 80) print $0 }' \ 91 > $tmp 92 if [ -s $tmp ]; then 93 printf "\n$msg\n" 94 cat $tmp 95 fi 96} 97 98col 'Lines should not exceed 80 characters.' $* 99 100g 'Trailing whitespace.' \ 101 '[[:space:]]$' $* 102 103g 'Space before dot.' \ 104 '[[:alnum:]][[:blank:]]+\.' $* 105 106g 'Dot, space, space, new sentence.' \ 107 '[[:alnum:]]\.([[:blank:]]|[[:blank:]]{3,})[[:alnum:]]' $* 108 109g 'Dot, space, space, end of comment.' \ 110 '[[:alnum:]]\.([[:blank:]]{0,1}|[[:blank:]]{3,})\*/' $* 111 112g 'Sentences should end with a dot. Dot, space, space, end of the comment.' \ 113 '[[:alnum:]][[:blank:]]*\*/' $* 114 115vg 'There should be exactly one space between function name and parentheses.' \ 116 '\#define' '[[:alnum:]]([^[:blank:]]|[[:blank:]]{2,})\(' $* 117 118g 'There should be no space before closing parentheses.' \ 119 '[[:graph:]][[:blank:]]+\)' $* 120 121ag 'Braces should be on a separate line.' \ 122 '\{' 'if[[:blank:]]\(|while[[:blank:]]\(|switch[[:blank:]]\(' $* 123 124 125