Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / atf / dist / admin / check-style.sh
blobcf3556795fd8da8fec7f73745f12af1978e0a897
1 #! /bin/sh
3 # Automated Testing Framework (atf)
5 # Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
6 # All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
18 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # A utility to sanity check the coding style of all source files in the
33 # project tree.
36 Prog_Name=${0##*/}
39 # err message
41 err() {
42 echo "${Prog_Name}: ${@}" 1>&2
43 exit 1
47 # warn message
49 warn() {
50 echo "${Prog_Name}: ${@}" 1>&2
54 # guess_topdir
56 # Locates the project's top directory and prints its path. The caller
57 # must verify if the result is correct or not.
59 guess_topdir() {
60 olddir=$(pwd)
61 topdir=$(pwd)
62 while [ ${topdir} != / ]; do
63 if [ -f ./atf-c.h ]; then
64 break
65 else
66 cd ..
67 topdir=$(pwd)
69 done
70 cd ${olddir}
71 echo ${topdir}
75 # find_sources
77 # Locates all source files within the project, relative to the current
78 # directory, and prints their paths.
80 find_sources() {
81 find . \( -name "AUTHORS" -o \
82 -name "COPYING" -o \
83 -name "ChangeLog" -o \
84 -name "NEWS" -o \
85 -name "README" -o \
86 -name "TODO" -o \
87 -name "*.[0-9]" -o \
88 -name "*.ac" -o \
89 -name "*.at" -o \
90 -name "*.awk" -o \
91 -name "*.c" -o \
92 -name "*.cpp" -o \
93 -name "*.h" -o \
94 -name "*.hpp" -o \
95 -name "*.m4" -o \
96 -name "*.sh" \
97 \) -a \( \
98 \! -path "*/atf-[0-9]*" -a \
99 \! -path "*autom4te*" -a \
100 -type f -a \
101 \! -name "aclocal.m4" \
102 \! -name "bconfig.h" \
103 \! -name "libtool.m4" \
104 \! -name "ltoptions.m4" \
105 \! -name "ltsugar.m4" \
106 \! -name "lt~obsolete.m4" \
107 \! -name "*.so.*" \
112 # guess_formats file
114 # Guesses the formats applicable to the given file and prints the resulting
115 # list.
117 guess_formats() {
118 case ${1} in
119 */ltmain.sh)
121 *.[0-9])
122 echo common man
124 *.c|*.h)
125 echo common c
127 *.cpp|*.hpp)
128 echo common cpp
130 *.sh)
131 echo common shell
134 echo common
136 esac
140 # check_file file
142 # Checks the validity of the given file.
144 check_file() {
145 err=0
146 for format in $(guess_formats ${1}); do
147 awk -f ${topdir}/admin/check-style-${format}.awk ${1} || err=1
148 done
150 return ${err}
154 # main [file list]
156 # Entry point.
158 main() {
159 topdir=$(guess_topdir)
160 if [ ! -f ${topdir}/atf-c.h ]; then
161 err "Could not locate the project's top directory"
164 if [ ${#} -gt 0 ]; then
165 sources=${@}
166 else
167 cd ${topdir}
168 sources=$(find_sources)
171 ok=0
172 for file in ${sources}; do
173 file=$(echo ${file} | sed -e "s,\\./,,")
175 if [ ! -f ${file} ]; then
176 err "Could not open ${file}"
177 else
178 check_file ${file} || ok=1
180 done
182 return ${ok}
185 main "${@}"
187 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4