3 # Copyright 2019 The Go Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file.
10 winerror="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/winerror.h | sort -Vr | head -n 1)"
11 [[ -n $winerror ]] || { echo "Unable to find winerror.h" >&2; exit 1; }
16 echo "// Code generated by 'mkerrors.bash'; DO NOT EDIT."
18 echo "package windows"
19 echo "import \"syscall\""
22 while read -r line; do
24 if [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?([A-Z][A-Z0-9_]+k?)\)? ]]; then
25 key="${BASH_REMATCH[1]}"
26 value="${BASH_REMATCH[3]}"
27 elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?((0x)?[0-9A-Fa-f]+)L?\)? ]]; then
28 key="${BASH_REMATCH[1]}"
29 value="${BASH_REMATCH[3]}"
30 vtype="${BASH_REMATCH[2]}"
31 elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +\(\(([A-Z]+)\)((0x)?[0-9A-Fa-f]+)L?\) ]]; then
32 key="${BASH_REMATCH[1]}"
33 value="${BASH_REMATCH[3]}"
34 vtype="${BASH_REMATCH[2]}"
38 [[ -n $key && -n $value ]] || continue
39 [[ -z ${errors["$key"]} ]] || continue
40 errors["$key"]="$value"
41 if [[ -v vtype ]]; then
42 if [[ $key == FACILITY_* || $key == NO_ERROR ]]; then
44 elif [[ $vtype == *HANDLE* || $vtype == *HRESULT* ]]; then
52 if [[ $last_vtype == Handle && $value == NO_ERROR ]]; then
54 elif [[ $last_vtype == syscall.Errno && $value == NO_ERROR ]]; then
59 echo "$key $vtype = $value"
63 } | gofmt > "zerrors_windows.go"