You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

71 lines
2.1 KiB

  1. #!/bin/bash
  2. # Copyright 2019 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. set -e
  6. shopt -s nullglob
  7. winerror="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/winerror.h | sort -Vr | head -n 1)"
  8. [[ -n $winerror ]] || { echo "Unable to find winerror.h" >&2; exit 1; }
  9. ntstatus="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/ntstatus.h | sort -Vr | head -n 1)"
  10. [[ -n $ntstatus ]] || { echo "Unable to find ntstatus.h" >&2; exit 1; }
  11. declare -A errors
  12. {
  13. echo "// Code generated by 'mkerrors.bash'; DO NOT EDIT."
  14. echo
  15. echo "package windows"
  16. echo "import \"syscall\""
  17. echo "const ("
  18. while read -r line; do
  19. unset vtype
  20. if [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?([A-Z][A-Z0-9_]+k?)\)? ]]; then
  21. key="${BASH_REMATCH[1]}"
  22. value="${BASH_REMATCH[3]}"
  23. elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?((0x)?[0-9A-Fa-f]+)L?\)? ]]; then
  24. key="${BASH_REMATCH[1]}"
  25. value="${BASH_REMATCH[3]}"
  26. vtype="${BASH_REMATCH[2]}"
  27. elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +\(\(([A-Z]+)\)((0x)?[0-9A-Fa-f]+)L?\) ]]; then
  28. key="${BASH_REMATCH[1]}"
  29. value="${BASH_REMATCH[3]}"
  30. vtype="${BASH_REMATCH[2]}"
  31. else
  32. continue
  33. fi
  34. [[ -n $key && -n $value ]] || continue
  35. [[ -z ${errors["$key"]} ]] || continue
  36. errors["$key"]="$value"
  37. if [[ -v vtype ]]; then
  38. if [[ $key == FACILITY_* || $key == NO_ERROR ]]; then
  39. vtype=""
  40. elif [[ $vtype == *HANDLE* || $vtype == *HRESULT* ]]; then
  41. vtype="Handle"
  42. else
  43. vtype="syscall.Errno"
  44. fi
  45. last_vtype="$vtype"
  46. else
  47. vtype=""
  48. if [[ $last_vtype == Handle && $value == NO_ERROR ]]; then
  49. value="S_OK"
  50. elif [[ $last_vtype == syscall.Errno && $value == NO_ERROR ]]; then
  51. value="ERROR_SUCCESS"
  52. fi
  53. fi
  54. echo "$key $vtype = $value"
  55. done < "$winerror"
  56. while read -r line; do
  57. [[ $line =~ ^#define\ (STATUS_[^\s]+)\ +\(\(NTSTATUS\)((0x)?[0-9a-fA-F]+)L?\) ]] || continue
  58. echo "${BASH_REMATCH[1]} NTStatus = ${BASH_REMATCH[2]}"
  59. done < "$ntstatus"
  60. echo ")"
  61. } | gofmt > "zerrors_windows.go"