Read an entire file into a list of extended characters.
(vl-read-file filename &key (state 'state)) → (mv okp result 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 state)) ((mv data state) (vl-read-file-loop channel filename 1 0)) (state (close-input-channel channel state))) (mv t data state))))
Theorem:
(defthm booleanp-of-vl-read-file.okp (b* (((mv ?okp ?result acl2::?state) (vl-read-file-fn filename state))) (booleanp okp)) :rule-classes :type-prescription)
Theorem:
(defthm vl-echarlist-p-of-vl-read-file.result (implies (and (force (state-p state)) (force (stringp filename))) (b* (((mv ?okp ?result acl2::?state) (vl-read-file-fn filename state))) (vl-echarlist-p result))) :rule-classes :rewrite)
Theorem:
(defthm state-p1-of-vl-read-file.state (implies (force (state-p1 state)) (b* (((mv ?okp ?result 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))))