
(/VERSIONCHECK 2) 

(DEFUN |TEXTFILE;read!;$S;1| (|f| $) (SPADCALL |f| (QREFELT $ 8))) 

(DEFUN |TEXTFILE;readIfCan!;$U;2| (|f| $) (SPADCALL |f| (QREFELT $ 11))) 

(DEFUN |TEXTFILE;readLine!;$S;3| (|f| $)
  (PROG (|s|)
    (RETURN
     (SEQ
      (COND
       ((NULL (EQUAL (QVELT |f| 2) "input"))
        (|error| "File not in read state"))
       ('T
        (SEQ (LETT |s| (|read-line| (QVELT |f| 1)) |TEXTFILE;readLine!;$S;3|)
             (EXIT
              (COND ((PLACEP |s|) (|error| "End of file")) ('T |s|)))))))))) 

(DEFUN |TEXTFILE;readLineIfCan!;$U;4| (|f| $)
  (PROG (|s|)
    (RETURN
     (SEQ
      (COND
       ((NULL (EQUAL (QVELT |f| 2) "input"))
        (|error| "File not in read state"))
       ('T
        (SEQ
         (LETT |s| (|read-line| (QVELT |f| 1)) |TEXTFILE;readLineIfCan!;$U;4|)
         (EXIT (COND ((PLACEP |s|) (CONS 1 "failed")) ('T (CONS 0 |s|))))))))))) 

(DEFUN |TEXTFILE;write!;$2S;5| (|f| |x| $)
  (SEQ
   (COND
    ((NULL (EQUAL (QVELT |f| 2) "output")) (|error| "File not in write state"))
    ('T (SEQ (PRINTEXP |x| (QVELT |f| 1)) (EXIT |x|)))))) 

(DEFUN |TEXTFILE;writeLine!;$S;6| (|f| $)
  (SEQ
   (COND
    ((NULL (EQUAL (QVELT |f| 2) "output")) (|error| "File not in write state"))
    ('T (SEQ (TERPRI (QVELT |f| 1)) (EXIT "")))))) 

(DEFUN |TEXTFILE;writeLine!;$2S;7| (|f| |x| $)
  (SEQ
   (COND
    ((NULL (EQUAL (QVELT |f| 2) "output")) (|error| "File not in write state"))
    ('T (SEQ (PRINTEXP |x| (QVELT |f| 1)) (TERPRI (QVELT |f| 1)) (EXIT |x|)))))) 

(DEFUN |TEXTFILE;endOfFile?;$B;8| (|f| $)
  (COND ((OR (EQUAL (QVELT |f| 2) "output") (NULL (EOFP (QVELT |f| 1)))) 'NIL)
        ('T 'T))) 

(DEFUN |TextFile| #1=()
  (PROG #1#
    (RETURN
     (PROG (#2=#:G1842)
       (RETURN
        (COND
         ((LETT #2# (HGET |$ConstructorCache| '|TextFile|) . #3=(|TextFile|))
          (|CDRwithIncrement| (CDAR #2#)))
         ('T
          (UNWIND-PROTECT
              (PROG1
                  (CDDAR
                   (HPUT |$ConstructorCache| '|TextFile|
                         (LIST (CONS NIL (CONS 1 (|TextFile;|))))))
                (LETT #2# T . #3#))
            (COND ((NOT #2#) (HREM |$ConstructorCache| '|TextFile|))))))))))) 

(DEFUN |TextFile;| ()
  (PROG (|dv$| $ |pv$|)
    (RETURN
     (PROGN
      (LETT |dv$| '(|TextFile|) . #1=(|TextFile|))
      (LETT $ (GETREFV 21) . #1#)
      (QSETREFV $ 0 |dv$|)
      (QSETREFV $ 3 (LETT |pv$| (|buildPredVector| 0 0 NIL) . #1#))
      (|haddProp| |$ConstructorCache| '|TextFile| NIL (CONS 1 $))
      (|stuffDomainSlots| $)
      (QSETREFV $ 6
                (|Record| (|:| |fileName| (|FileName|))
                          (|:| |fileState| (|SExpression|))
                          (|:| |fileIOmode| (|String|))))
      $)))) 

(MAKEPROP '|TextFile| '|infovec|
          (LIST
           '#(NIL NIL NIL NIL NIL (|File| 7) '|Rep| (|String|)
              |TEXTFILE;readLine!;$S;3| |TEXTFILE;read!;$S;1|
              (|Union| 7 '"failed") |TEXTFILE;readLineIfCan!;$U;4|
              |TEXTFILE;readIfCan!;$U;2| |TEXTFILE;write!;$2S;5|
              |TEXTFILE;writeLine!;$S;6| |TEXTFILE;writeLine!;$2S;7|
              (|Boolean|) |TEXTFILE;endOfFile?;$B;8| (|FileName|)
              (|SingleInteger|) (|OutputForm|))
           '#(|writeLine!| 0 |write!| 11 |readLineIfCan!| 17 |readLine!| 22
              |readIfCan!| 27 |read!| 32 |endOfFile?| 37)
           'NIL
           (CONS (|makeByteWordVec2| 1 '(0 0 0 0))
                 (CONS '#(NIL |SetCategory&| |BasicType&| NIL)
                       (CONS
                        '#((|FileCategory| 18 7) (|SetCategory|) (|BasicType|)
                           (|CoercibleTo| 20))
                        (|makeByteWordVec2| 17
                                            '(2 0 7 0 7 15 1 0 7 0 14 2 0 7 0 7
                                              13 1 0 10 0 11 1 0 7 0 8 1 0 10 0
                                              12 1 0 7 0 9 1 0 16 0 17)))))
           '|lookupIncomplete|)) 

(MAKEPROP '|TextFile| 'NILADIC T) 
