Fix compiler warnings with clang 16 by not using gnu_printf format
[mesa-waffle.git] / bin / waffle-enum
blob086a545f8bb796ba22421bc600cf18c9b1d2a300
1 #!/bin/bash
3 # Copyright 2012 Intel Corporation
5 # All rights reserved.
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.
28 set -e
30 waffle_enum_h="include/waffle/waffle_enum.h"
32 function prog_name() {
33 echo $(basename "$0")
36 function show_help() {
37 local p="$(prog_name)"
39 echo "NAME"
40 echo " $p - a tool for waffle_enum.h"
41 echo
42 echo "DESCRIPTION"
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."
45 echo
46 echo "USAGE"
47 echo " $p check"
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."
50 echo
51 echo " Possible errors are duplicate values and ill-formed enum"
52 echo " values. Enum values must have form 0x????, where ? is a hex"
53 echo " digit."
54 echo
55 echo " $p -h"
56 echo " Show this help message."
59 function usage_error() {
60 local p="$(prog_name)"
62 echo "$p: usage error. see \`$p -h\`"
63 exit 1
66 function fatal_error() {
67 local p="$(prog_name)"
69 echo "$p: error: $1"
70 exit 1
73 function print_raw_values() {
74 local file_in="$waffle_enum_h"
75 local file_out="$(mktemp)"
77 sed \
78 -e '/WAFFLE_NONE/d' \
79 -e '/WAFFLE_DONT_CARE/d' \
80 -e '/WAFFLE_.*=/!d' \
81 -e 's/^.*=[[:space:]]*\(.*\),.*$/\1/' \
82 < "$file_in" \
83 > "$file_out"
85 echo "$file_out"
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 ]]
96 then
97 return 0
98 else
99 echo "The enum values below are ill-formed."
100 check_syntax_raw "$file_raw_values"
101 exit 1
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 ]]
113 then
114 return 0
115 else
116 echo "The enum values below are duplicates."
117 check_duplicates_raw "$file_raw_values"
118 exit 1
122 function check() {
123 local file_raw_values="$1"
125 check_syntax "$file_raw_values"
126 check_duplicates "$file_raw_values"
129 function main() {
130 if [[ $# != 1 ]]
131 then
132 show_help
133 exit 1
136 case "$1" in
137 "-h")
138 show_help
140 "check")
141 check "$(print_raw_values)"
144 usage_error
146 esac
149 main "$@"