blob: 58e0188fb71f802180ea330dd13828884e4d3001 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001#!/bin/bash
2
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.
6
7set -e
8shopt -s nullglob
9
Zack Williamse940c7a2019-08-21 14:25:39 -070010winerror="$(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; }
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000012ntstatus="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/ntstatus.h | sort -Vr | head -n 1)"
13[[ -n $ntstatus ]] || { echo "Unable to find ntstatus.h" >&2; exit 1; }
Zack Williamse940c7a2019-08-21 14:25:39 -070014
15declare -A errors
16
17{
divyadesai19009132020-03-04 12:58:08 +000018 echo "// Code generated by 'mkerrors.bash'; DO NOT EDIT."
Zack Williamse940c7a2019-08-21 14:25:39 -070019 echo
20 echo "package windows"
21 echo "import \"syscall\""
22 echo "const ("
23
24 while read -r line; do
25 unset vtype
26 if [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?([A-Z][A-Z0-9_]+k?)\)? ]]; then
27 key="${BASH_REMATCH[1]}"
28 value="${BASH_REMATCH[3]}"
29 elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?((0x)?[0-9A-Fa-f]+)L?\)? ]]; then
30 key="${BASH_REMATCH[1]}"
31 value="${BASH_REMATCH[3]}"
32 vtype="${BASH_REMATCH[2]}"
33 elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +\(\(([A-Z]+)\)((0x)?[0-9A-Fa-f]+)L?\) ]]; then
34 key="${BASH_REMATCH[1]}"
35 value="${BASH_REMATCH[3]}"
36 vtype="${BASH_REMATCH[2]}"
37 else
38 continue
39 fi
40 [[ -n $key && -n $value ]] || continue
41 [[ -z ${errors["$key"]} ]] || continue
42 errors["$key"]="$value"
43 if [[ -v vtype ]]; then
44 if [[ $key == FACILITY_* || $key == NO_ERROR ]]; then
45 vtype=""
46 elif [[ $vtype == *HANDLE* || $vtype == *HRESULT* ]]; then
47 vtype="Handle"
48 else
49 vtype="syscall.Errno"
50 fi
51 last_vtype="$vtype"
52 else
53 vtype=""
54 if [[ $last_vtype == Handle && $value == NO_ERROR ]]; then
55 value="S_OK"
56 elif [[ $last_vtype == syscall.Errno && $value == NO_ERROR ]]; then
57 value="ERROR_SUCCESS"
58 fi
59 fi
60
61 echo "$key $vtype = $value"
62 done < "$winerror"
63
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000064 while read -r line; do
65 [[ $line =~ ^#define\ (STATUS_[^\s]+)\ +\(\(NTSTATUS\)((0x)?[0-9a-fA-F]+)L?\) ]] || continue
66 echo "${BASH_REMATCH[1]} NTStatus = ${BASH_REMATCH[2]}"
67 done < "$ntstatus"
68
Zack Williamse940c7a2019-08-21 14:25:39 -070069 echo ")"
David Bainbridge86971522019-09-26 22:09:39 +000070} | gofmt > "zerrors_windows.go"