(defun read-file (file)
  (with-open-file (s file :direction :input)
    (let ((str (make-string (file-length s))))
      (read-sequence str s)
      str)))

(defun from-file (name)
  (read-from-string (read-file (format nil "enum-lists/~A.lisp" name))))

(defvar *parsed*  (from-file "parsed-enums"))
(defvar *dynamic* (from-file "dynamic-enums"))
(defvar *enums*   (make-hash-table :test 'equal))

(let (all)
  (dolist (enums (list *parsed* *dynamic*))
    (dolist (enum enums)
      (setf (gethash (car enum) *enums*)
            (cdr enum))))
  (maphash (lambda (name val)
             (push (cons name val) all))
           *enums*)
  (with-open-file (s "merged-enums.lisp" :direction :output :if-exists :supersede)
    (dolist (enum (sort all 'string< :key 'car))
      (format s "(defenum ~A ~D)~%" (car enum) (cdr enum)))))
