generate_errcodes_src.sh 486 B

12345678910111213141516171819
  1. #!/usr/bin/env bash
  2. #
  3. # Used to generate epgsql_errcodes.erl
  4. #
  5. ERRFILE="https://raw.githubusercontent.com/postgres/postgres/master/src/backend/utils/errcodes.txt"
  6. echo "%% DO NOT EDIT - AUTOGENERATED BY $0 ON $(date +%Y-%m-%dT%H:%M:%S%z)"
  7. echo "-module(epgsql_errcodes)."
  8. echo "-export([to_name/1])."
  9. echo
  10. wget -qO- "$ERRFILE" | awk '
  11. NF == 4 && \
  12. $1 ~ /[0-9A_Z]+/ && \
  13. $2 ~ /[EWS]/ \
  14. {
  15. printf("to_name(<<\"%s\">>) -> %s;\n", $1, $4)
  16. }
  17. END {
  18. print "to_name(_) -> undefined."
  19. }'