1# Copyright (c) 2007 The NetBSD Foundation, Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8#    notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice, this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26function warn(msg) {
27    print FILENAME "[" FNR "]: " msg > "/dev/stderr"
28    error = 1
29}
30
31BEGIN {
32    skip = 0
33    error = 0
34}
35
36/NO_CHECK_STYLE_BEGIN/ {
37    skip = 1
38    next
39}
40
41/NO_CHECK_STYLE_END/ {
42    skip = 0
43    next
44}
45
46/NO_CHECK_STYLE/ {
47    next
48}
49
50{
51    if (skip)
52        next
53}
54
55/#ifdef/ {
56    warn("Undesired usage of #ifdef; use #if defined()")
57}
58
59/#ifndef/ {
60    warn("Undesired usage of #ifndef; use #if !defined()")
61}
62
63/assert[ \t]*\(/ {
64    warn("Use the macros in sanity.hpp instead of assert");
65}
66
67/include.*assert/ {
68    warn("Do not include assert.h nor cassert");
69}
70
71/std::endl/ {
72    warn("Use \\n instead of std::endl");
73}
74
75/\/\*/ {
76    warn("Do not use C-style comments");
77}
78
79END {
80    if (skip)
81        warn("Missing NO_CHECK_STYLE_END");
82    if (error)
83        exit 1
84}
85
86# vim: syntax=awk:expandtab:shiftwidth=4:softtabstop=4
87