Tim Moore [[EMAIL PROTECTED]] wrote:

> On Wed, 20 Nov 2002, Kick Damien-DKICK1 wrote:

> > <grumble> How to get ahold of 'stdout'?  How to define a 'FILE*',
> > as this is supposed to be an opaque type?  Anyway, I'll keep
> > looking at how to get 'fflush' into an 'extern-alien'.  Thanks a
> > million for the pointer.  I'll keep experimenting with this and
> > see where it gets me.

> stdout is often a C macro.

<nod> Indeed.  And I've also apparently forgotten that "\n" is not
handled by 'printf' by rather by C, even with Helmut Eller's example
of how to do it correctly.  Anyway, I did get an example working that
correctly 'fflush'ed the "stdio" buffers.  In case there are newbies
other than just myself lurking that might find this of interest, with
my apologies to those that already know better and my thanks to
everyone that pointed me in the right direction (esp. Helmut Eller), I
got everything working with the following.

  "f00f.c"

        #include <stdio.h>

        FILE* my_stdout = stdout;

  "f00f.lisp"

        (defpackage f00f
          (:use common-lisp alien c-call))

        (in-package :f00f)

        (defun test ()
          (alien-funcall (extern-alien "printf" 
                                       (function int
                                                 c-string
                                                 int
                                                 double
                                                 char))
                         "int: %d %f %c"
                         1
                         2.3d0
                         (char-int #\newline)))

        (defun test-1 ()
          (alien-funcall (extern-alien "printf"
                                       (function int
                                                 c-string
                                                 int
                                                 int))
                               "this is my example: %d %d\n"
                               6
                               9))

        (defun test-2 ()
          (alien-funcall (extern-alien "printf"
                                       (function int
                                                 c-string
                                                 int
                                                 int))
           "this is my example: %d %d\\n"
           6
           9)
          (alien-funcall (extern-alien "fflush"
                                       (function int
                                                 (* t)))
                         (extern-alien "my_stdout"
                                       (* t))))

        (defun test-3 ()
          (alien-funcall (extern-alien "printf"
                                       (function int
                                                 c-string
                                                 int
                                                 int
                                                 int
                                                 int
                                                 int
                                                 char))
                         "one more try with \\n: %d %d %d %d %d %c"
                         1
                         2
                         3
                         4
                         5
                         (char-int #\newline))
          (alien-funcall (extern-alien "fflush"
                                       (function int
                                                 (* t)))
                         (extern-alien "my_stdout"
                                       (* t))))

  "*cmulisp*" ; an ILISP buffer

        * ;;;Compile /home/kick/tmp/f00f.lisp
         Converted TEST.
        Compiling DEFUN TEST: 
        Converted TEST-1.
        Compiling DEFUN TEST-1: 
        Converted TEST-2.
        Compiling DEFUN TEST-2: 
        Converted TEST-3.
        Compiling DEFUN TEST-3: 
        Byte Compiling Top-Level Form: 
        #p"/home/kick/tmp/f00f.sparcf"
        NIL
        NIL
        * 
        ; Loading #p"/home/kick/tmp/f00f.sparcf".
        T
        * (f00f::test)
        17
        * (f00f::test-2)
        int: 1 2.300000 
        this is my example: 6 9\n
        0
        * (f00f::test-1)
        24
        * (f00f::test-3)
        this is my example: 6 9none more try with \n: 1 2 3 4 5 

        0
        * 

--
Damien Kick

Reply via email to