pearlmut (12/03/82)
We wanted to play with pipes from Franzlisp, and needed to check if a
pipe was empty, or if it had pending characters in its buffers. We
wrote the following files, which create a C function, load it into Lisp,
and make the proper interface.
The emptyp.l file should be liszt'ed, and the empty.c file must be
compiled with the -c option on.
--------------- The following goes in emptyp.l ---------------
; this is a file to get a function that takes a port and checks if it is
; empty into Lisp.
; Clayton Elwell and Barak Pearlmutter, December 1982
(eval-when (load)
(cond ((null (getd '$Cemptyp))
(cond ((not (probef 'empty.o)) (exec cc -c empty.c)))
(cfasl 'empty.o '_emptyp '$Cemptyp "integer-function"))))
(defun emptyp (p)
(cond ((not (portp p)) (error `(Non port ,p passed to emptyp)))
((zerop ($Cemptyp (maknum p))) nil)
(t t)))
; eof
--------------- The following goes in empty.c ---------------
/*********************************************************************/
/* */
/* This file defines a function that checks if an input port has any */
/* characters pending in it, when properly loaded into Franz Lisp. */
/* NOTE that the Franz Lisp manual is misleading (wrong) in that it */
/* says that when a foreign function is passed an integer, it is */
/* passed the integer. It is actually passed a pointer to the */
/* given integer. */
/* */
/* Clayton Elwell and Barak Pearlmutter */
/* December 1982 */
/* */
/*********************************************************************/
#include <stdio.h>
#include <sys/ioctl.h>
emptyp(fptr)
FILE ***fptr;
{
int count;
ioctl((**fptr)->_file,FIONREAD,&count);
if ((count > 0) || ((**fptr)->_cnt > 0))
{ return(0); }
else { return(1); };
}
--------------- END ---------------