enum.scm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ;; -*- mode: scheme; coding: utf-8 -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2015
  4. ;;;; Christopher Allan Webber <cwebber@dustycloud.org>
  5. ;;;; This file is part of Guile-Squee.
  6. ;;;; Guile-Squee is free software: you can redistribute it and/or modify
  7. ;;;; it under the terms of the GNU Lesser General Public License as
  8. ;;;; published by the Free Software Foundation, either version 3 of the
  9. ;;;; License, or (at your option) any later version.
  10. ;;;; Guile-Squee is distributed in the hope that it will be useful
  11. ;;;; WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. ;;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
  13. ;;;; Public License for more details.
  14. ;;;; You should have received a copy of the GNU Lesser General Public
  15. ;;;; License along with Guile-Squee. If not, see
  16. ;;;; <http://www.gnu.org/licenses/>.
  17. ;;;;
  18. ;;; Commentary:
  19. ;; Enums from libpq-fe.h
  20. ;;; Code:
  21. (define-module (squee enum)
  22. #:use-module (rnrs enums)
  23. #:export (conn-status-enum
  24. conn-status-enum-index
  25. polling-status-enum
  26. polling-status-index
  27. exec-status-enum
  28. exec-status-enum-index
  29. transaction-status-enum
  30. transaction-status-enum-index
  31. verbosity-enum
  32. verbosity-enum-index
  33. ping-enum
  34. ping-enum-index
  35. ;; **repl and error messages only!**
  36. enum-set-ref))
  37. (define conn-status-enum
  38. (make-enumeration
  39. '(connection-ok
  40. connection-bad
  41. connection-started connection-made
  42. connection-awaiting-response connection-auth-ok
  43. connection-auth-ok connection-setenv
  44. connection-ssl-startup
  45. connection-needed)))
  46. (define conn-status-enum-index
  47. (enum-set-indexer conn-status-enum))
  48. (define polling-status-enum
  49. (make-enumeration
  50. '(polling-failed
  51. polling-reading
  52. polling-writing
  53. polling-ok
  54. polling-active)))
  55. (define polling-status-enum-index
  56. (enum-set-indexer polling-status-enum))
  57. (define exec-status-enum
  58. (make-enumeration
  59. '(empty-query
  60. command-ok tuples-ok
  61. copy-out copy-in
  62. bad-response
  63. nonfatal-error fatal-error
  64. copy-both
  65. single-tuple)))
  66. (define exec-status-enum-index
  67. (enum-set-indexer exec-status-enum))
  68. (define transaction-status-enum
  69. (make-enumeration
  70. '(idle active intrans inerror unknown)))
  71. (define transaction-status-enum-index
  72. (enum-set-indexer transaction-status-enum))
  73. (define verbosity-enum
  74. (make-enumeration
  75. '(terse default verbose)))
  76. (define verbosity-enum-index
  77. (enum-set-indexer verbosity-enum))
  78. (define ping-enum
  79. (make-enumeration
  80. '(ok reject no-response no-attempt)))
  81. (define ping-enum-index
  82. (enum-set-indexer ping-enum))
  83. (define (enum-set-ref enum-set k)
  84. "Take an ENUM-SET and get the item at position K
  85. This is O(n) but theoretically we don't use it much.
  86. Again, REPL only!"
  87. (list-ref (enum-set->list enum-set) k))