Path: blob/main/vendor/golang.org/x/sys/windows/mkerrors.bash
2880 views
#!/bin/bash12# Copyright 2019 The Go Authors. All rights reserved.3# Use of this source code is governed by a BSD-style4# license that can be found in the LICENSE file.56set -e7shopt -s nullglob89winerror="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/winerror.h | sort -Vr | head -n 1)"10[[ -n $winerror ]] || { echo "Unable to find winerror.h" >&2; exit 1; }11ntstatus="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/ntstatus.h | sort -Vr | head -n 1)"12[[ -n $ntstatus ]] || { echo "Unable to find ntstatus.h" >&2; exit 1; }1314declare -A errors1516{17echo "// Code generated by 'mkerrors.bash'; DO NOT EDIT."18echo19echo "package windows"20echo "import \"syscall\""21echo "const ("2223while read -r line; do24unset vtype25if [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?([A-Z][A-Z0-9_]+k?)\)? ]]; then26key="${BASH_REMATCH[1]}"27value="${BASH_REMATCH[3]}"28elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?((0x)?[0-9A-Fa-f]+)L?\)? ]]; then29key="${BASH_REMATCH[1]}"30value="${BASH_REMATCH[3]}"31vtype="${BASH_REMATCH[2]}"32elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +\(\(([A-Z]+)\)((0x)?[0-9A-Fa-f]+)L?\) ]]; then33key="${BASH_REMATCH[1]}"34value="${BASH_REMATCH[3]}"35vtype="${BASH_REMATCH[2]}"36else37continue38fi39[[ -n $key && -n $value ]] || continue40[[ -z ${errors["$key"]} ]] || continue41errors["$key"]="$value"42if [[ -v vtype ]]; then43if [[ $key == FACILITY_* || $key == NO_ERROR ]]; then44vtype=""45elif [[ $vtype == *HANDLE* || $vtype == *HRESULT* ]]; then46vtype="Handle"47else48vtype="syscall.Errno"49fi50last_vtype="$vtype"51else52vtype=""53if [[ $last_vtype == Handle && $value == NO_ERROR ]]; then54value="S_OK"55elif [[ $last_vtype == syscall.Errno && $value == NO_ERROR ]]; then56value="ERROR_SUCCESS"57fi58fi5960echo "$key $vtype = $value"61done < "$winerror"6263while read -r line; do64[[ $line =~ ^#define\ (STATUS_[^\s]+)\ +\(\(NTSTATUS\)((0x)?[0-9a-fA-F]+)L?\) ]] || continue65echo "${BASH_REMATCH[1]} NTStatus = ${BASH_REMATCH[2]}"66done < "$ntstatus"6768echo ")"69} | gofmt > "zerrors_windows.go"707172