Read an entire file into a list of extended characters.
(vl-read-file filename &key (state 'state)) → (mv okp result len state)
We read the file with read-byte$ instead of read-char$, because this seems perhaps to be more reliable. In particular,
even if the Lisp system wants to use Unicode or some other encoding for
character streams,
Function:
(defun vl-read-file-fn (filename state) (declare (xargs :stobjs (state))) (declare (xargs :guard (stringp filename))) (let ((__function__ 'vl-read-file)) (declare (ignorable __function__)) (b* ((filename (string-fix filename)) ((mv channel state) (open-input-channel filename :byte state)) ((unless channel) (mv nil nil 0 state)) ((mv data len state) (vl-read-file-loop channel filename 1 0)) (state (close-input-channel channel state)) (state (vl-read-file-hook filename data len state))) (mv t data len state))))
Theorem:
(defthm booleanp-of-vl-read-file.okp (b* (((mv ?okp ?result acl2::?len acl2::?state) (vl-read-file-fn filename state))) (booleanp okp)) :rule-classes :type-prescription)
Theorem:
(defthm vl-echarlist-p-of-vl-read-file.result (b* (((mv ?okp ?result acl2::?len acl2::?state) (vl-read-file-fn filename state))) (vl-echarlist-p result)) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-vl-read-file.len (b* (((mv ?okp ?result acl2::?len acl2::?state) (vl-read-file-fn filename state))) (equal len (len result))) :rule-classes :rewrite)
Theorem:
(defthm state-p1-of-vl-read-file.state (implies (force (state-p1 state)) (b* (((mv ?okp ?result acl2::?len acl2::?state) (vl-read-file-fn filename state))) (state-p1 state))) :rule-classes :rewrite)
Theorem:
(defthm true-listp-of-vl-read-file (true-listp (mv-nth 1 (vl-read-file filename))) :rule-classes :type-prescription)
Theorem:
(defthm vl-read-file-when-error (b* (((mv okp result ?state) (vl-read-file filename))) (implies (not okp) (not result))))