(FILECREATED "21-SEP-77 11:36:36" <KRL1>PSOF.;4 2805   

     changes to:  GetStringFromFile PutStringOnFile

     previous date: "21-SEP-77 11:21:48" <KRL1>PSOF.;3)


(PRETTYCOMPRINT PSOFCOMS)

(RPAQQ PSOFCOMS ((F: (GetStringFromFile PutStringOnFile))))
(PRETTYCOMPRINT (F: (GetStringFromFile PutStringOnFile)))
(DEFINEQ

(GetStringFromFile
  [LAMBDA (handle)
    [CLISP:(BLOCKRECORD STRINGDEST ((LENGTH BITS 14]   (* ht: "21-SEP-77 11:32")

          (* Returns a temporary string pointer to the string designated by handle, which was created by PutStringOnFile.
	  Note that the 14 above is the number of bits that we can store in 2 bytes, not the max number of bytes in a LISP 
	  string.)


    (PROG ((COREADR (HLOC handle)))
          (RETURN (ASSEMBLE NIL
			    (CQ (CONSTANT (CONCAT)))
			    [CQ2 (VAG (LOGOR (LLSH (fetch LENGTH of COREADR)
						   25Q)
					     (IPLUS 2 (ITIMES 5 (LOC COREADR]
			    (MOVEM 2 , 0 (1])

(PutStringOnFile
  [LAMBDA (ptr oldHandle)
    [CLISP:(BLOCKRECORD INTEGER ((I INTEGER)))
      (BLOCKRECORD STRINGDEST ((LENGTH BITS 14]        (* ht: "21-SEP-77 11:35")

          (* Note that 14 is the number of length bits we can store in 2 bytes, not the length field of a LISP string pointer,
	  which is 15)


    (if ~oldHandle
	then oldHandle←(create FileHandle))
    (PROG [COREADR (STRINGLENGTH (CONSTANT (IPLUS 10000000)))
		   (BYTEPTR (CONSTANT (IPLUS 10000000]
          (ASSEMBLE NIL
		    (CQ (SELECTQ (NTYP ptr)
				 (30Q ptr)
				 [14Q (CDR (VAG (IPLUS 2 (LOC ptr]
				 (ERROR ptr "not atom or string")))
		    (PUSHJ CP , UPATM)                 (* Now 4 has #bytes, 3 has bytepointer to firstbyte-1)
		    (CQ STRINGLENGTH)                  (* Length might be large, so use box)
		    (MOVEM 4 , 0 (1))
		    (CQ BYTEPTR)
		    (MOVEM 3 , 0 (1)))
          (COREADR←(HLOC (AllocateFileObject (6+STRINGLENGTH:I)/5 NIL
					     (CONSTANT (KrlTypeCode 'CharacterString))
					     NIL oldHandle)))

          (* Now copy characters from BYTEPTR to a "string" beginning at COREADR. STRINGLENGTH will be stored in the first 2 
	  bytes of COREADR, so the string is actually STRINGLENGTH+2 bytes long, hence the constant 6 instead of 4 above.)


          (COREADR:LENGTH←STRINGLENGTH:I)              (* Store the length in the first two bytes.)
          (ASSEMBLE NIL
		    (CQ (VAG (fetch I of STRINGLENGTH)))
		    (MOVE 5 , 1)
		    (CQ COREADR)
		    (HRLI 1 , 260700Q)                 (* The destination byte pointer)
		    (CQ2 BYTEPTR)
		    (MOVE 2 , 0 (2))
		LP  (ILDB 3 , 2)
		    (IDPB 3 , 1)
		    (SOJG 5 , LP))
          (RETURN oldHandle])
)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (332 2781 (GetStringFromFile 344 . 997) (PutStringOnFile 1001 . 2778)))))
STOP