;;; -*- Mode:LISP; Package:USER; Base:10; Fonts:(TR12 TR12I TR12B) -*-

(defun get-item-from-unix (ISIS-link)
  (let ((success  nil))
    (with-open-file-case (instream
			      (unix-input-file ISIS-link)
			      ':direction ':in)
      (fs:file-operation-failure nil)
;				    (format t "File op failure with unix file, link ~a~%" (link-id isis-link)))
      (sys:remote-network-error nil)
;           (format t "Remote network error in /"get-telex-from-unix/"~%"))
      (:no-error
       (when (> (send instream ':length) 100.)
	 (with-open-file-case (outstream
				   (lisp-input-file ISIS-link)
				   ':direction ':out)
	   (fs:file-operation-failure nil)
	   (:no-error
	    (loop repeat (send instream ':length)		;1 now copy data to the LISP file from UNIX.*
		   do (let ((inchar (send instream ':tyi)))
			 (if (null (equal inchar 13.))	; the circle-plus which for some reason is in telexes
			     (send outstream ':tyo inchar))))
	    (send outstream ':string-out
		    (format nil "~%QQQQQ~3%"))
	    (setq success t))))))
    
    (when success
      (clear-unix-file (unix-input-file ISIS-link))
      (setf (state ISIS-Link) 'GOT-ITEM-FROM-UNIX))))

;;1 This clears a unix file by writing a space character to it.*

(defun clear-unix-file (pathname)
  (with-open-file-case (stream
			    pathname
			    ':direction ':out)
    (fs:remote-network-error nil)
    (fs:file-operation-failure nil)
    (:no-error
     (send stream ':tyo (aref " " 0)))))

