3 # Copyright 2012 Intel Corporation
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
10 # - Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 waffle_enum_h
="include/waffle/waffle_enum.h"
32 function prog_name
() {
36 function show_help
() {
37 local p
="$(prog_name)"
40 echo " $p - a tool for waffle_enum.h"
43 echo " This script validates the enum values in waffle_enum.h. It must"
44 echo " be called from the top of the waffle repo."
48 echo " Check waffle_enum.h for errors. If there is an error, then"
49 echo " print a diagnostic message and exit 1. Otherwise, exit 0."
51 echo " Possible errors are duplicate values and ill-formed enum"
52 echo " values. Enum values must have form 0x????, where ? is a hex"
56 echo " Show this help message."
59 function usage_error
() {
60 local p
="$(prog_name)"
62 echo "$p: usage error. see \`$p -h\`"
66 function fatal_error
() {
67 local p
="$(prog_name)"
73 function print_raw_values
() {
74 local file_in
="$waffle_enum_h"
75 local file_out
="$(mktemp)"
79 -e '/WAFFLE_DONT_CARE/d' \
81 -e 's/^.*=[[:space:]]*\(.*\),.*$/\1/' \
88 function check_syntax_raw
() {
89 sed -e '/^0x[[:xdigit:]]\{4\}$/d' "$1"
92 function check_syntax
() {
93 local file_raw_values
="$1"
95 if [[ "$(check_syntax_raw "$file_raw_values" | wc -l)" = 0 ]]
99 echo "The enum values below are ill-formed."
100 check_syntax_raw
"$file_raw_values"
105 function check_duplicates_raw
() {
106 sort < "$1" |
uniq --repeated
109 function check_duplicates
() {
110 local file_raw_values
="$1"
112 if [[ "$(check_duplicates_raw "$file_raw_values" | wc -l)" = 0 ]]
116 echo "The enum values below are duplicates."
117 check_duplicates_raw
"$file_raw_values"
123 local file_raw_values
="$1"
125 check_syntax
"$file_raw_values"
126 check_duplicates
"$file_raw_values"
141 check
"$(print_raw_values)"