From: ············@hotmail.com
Subject: Windows Console Functions
Date: 
Message-ID: <1102959348.566867.284520@c13g2000cwb.googlegroups.com>
Does anyone know an easy way to write colored text to a windows console
using Corman Lisp? (Colored ascii stuff) I suspect that I may be able
to create a .dll in C++ and then access that in Corman Lisp using the
FFI, but I don't know much about .dll's or the FFI yet.
thanks,
Kevin Clancy

From: Ken Dyck
Subject: Re: Windows Console Functions
Date: 
Message-ID: <1102966352.282809.15960@z14g2000cwz.googlegroups.com>
> Does anyone know an easy way to write colored text to a windows
console
> using Corman Lisp? (Colored ascii stuff)

It has been a little while since I played around with Corman Lisp, but
if I remember correctly, you should be able to use Windows' console API
directly from Corman Lisp without creating an intermediate DLL. Most
(possibly all) of the Win32 API is available in the WIN32 package. If
the console API is not included, you can use the C Function Definition
Parser described in chapter 13 of the Corman Lisp manual to import it.

You might have more luck asking in the Corman Lisp message boards
(http://www.artofprogramming.com/bb/index.php)

The console API is described here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/console_functions.asp

The SetConsoleTextAttribute() function might be a reasonable place to
start.

Ken
From: Carl Shapiro
Subject: Re: Windows Console Functions
Date: 
Message-ID: <ouyy8g2aqyz.fsf@panix3.panix.com>
············@hotmail.com writes:

> Does anyone know an easy way to write colored text to a windows console
> using Corman Lisp? (Colored ascii stuff) I suspect that I may be able
> to create a .dll in C++ and then access that in Corman Lisp using the
> FFI, but I don't know much about .dll's or the FFI yet.

You don't need to create a DLL to access the console API as one
already exists for you, KERNEL32.DLL.  If you are not familiar with
the console API, start by reading up on WriteConsoleOutput and the
CHAR_INFO structure to figure out how the pieces of the puzzle fit
together.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/writing_characters_or_colors_to_consecutive_cells.asp?frame=true
From: Edi Weitz
Subject: FFI: Passing C structs by value (Was: Windows Console Functions)
Date: 
Message-ID: <uvfaow0d5.fsf_-_@agharta.de>
On 13 Dec 2004 15:22:12 -0500, Carl Shapiro <·············@panix.com> wrote:

> ············@hotmail.com writes:
>
>> Does anyone know an easy way to write colored text to a windows
>> console using Corman Lisp? (Colored ascii stuff) I suspect that I
>> may be able to create a .dll in C++ and then access that in Corman
>> Lisp using the FFI, but I don't know much about .dll's or the FFI
>> yet.
>
> You don't need to create a DLL to access the console API as one
> already exists for you, KERNEL32.DLL.  If you are not familiar with
> the console API, start by reading up on WriteConsoleOutput and the
> CHAR_INFO structure to figure out how the pieces of the puzzle fit
> together.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/writing_characters_or_colors_to_consecutive_cells.asp?frame=true

The problem with most of the functions in the console API is that they
pass a COORD struct by value.  Maybe I'm missing something simple but
I have yet to figure out how to call such functions from CL.  Can
someone provide an example for AllegroCL, LispWorks, or Corman Lisp?

Thanks,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Wade Humeniuk
Subject: Re: FFI: Passing C structs by value (Was: Windows Console Functions)
Date: 
Message-ID: <h8gAd.21591$KO5.13645@clgrps13>
Edi Weitz wrote:

> 
> The problem with most of the functions in the console API is that they
> pass a COORD struct by value.  Maybe I'm missing something simple but
> I have yet to figure out how to call such functions from CL.  Can
> someone provide an example for AllegroCL, LispWorks, or Corman Lisp?
> 

This seems to work for LW:

(fli:define-c-struct point (x :int) (y :int))

(fli:define-foreign-callable (xpoint :result-type :int)
     ((point point))
   (fli:foreign-slot-value point 'x))

(fli:define-foreign-function xpoint
     ((point point))
   :result-type :int)

CL-USER 18 > (setf point (fli:allocate-foreign-object :type 'point))
#<Pointer to type (:STRUCT POINT) = #x007F11F8>

CL-USER 19 > (setf (fli:foreign-slot-value point 'x) 65199)
65199

CL-USER 20 > (fli:dereference point :copy-foreign-object nil)
#<Foreign-Structure (:STRUCT POINT) : addr #x007F11F8>

CL-USER 21 > (xpoint (fli:dereference point :copy-foreign-object nil))
65199

CL-USER 22 > (fli:dereference point)

Error: Attempted to dereference a pointer to aggregate type (:STRUCT POINT).
   1 (abort) Return to level 0.
   2 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options


The trick seems to use fli:dereference with :copy-foreign-object to nil.  The
default is :error

Wade
From: Edi Weitz
Subject: Re: FFI: Passing C structs by value
Date: 
Message-ID: <u7jn1b29m.fsf@agharta.de>
On Tue, 28 Dec 2004 16:49:17 GMT, Wade Humeniuk <····················@telus.net> wrote:

> Edi Weitz wrote:
>
>> The problem with most of the functions in the console API is that
>> they pass a COORD struct by value.  Maybe I'm missing something
>> simple but I have yet to figure out how to call such functions from
>> CL.  Can someone provide an example for AllegroCL, LispWorks, or
>> Corman Lisp?
>
> This seems to work for LW:
>
> [snip]

Great, thanks!  It works fine for me.  Just for the record here's an
example with a "real" foreign library which was created with Visual
Studio and the following code:

  struct a__struct {
    int a; int b; 
  } a_struct;

  extern "C" __declspec(dllexport) int add_contents (a__struct a_struct) {
    return (a_struct.a + a_struct.b);
  }

In LispWorks:

  CL-USER 1 > (fli:define-c-struct a-struct (a :int) (b :int))
  (:STRUCT A-STRUCT)

  CL-USER 2 > (fli:define-foreign-function (add-contents "add_contents")
                  ((a-struct a-struct))
                :result-type :int
                :module "C:\\Documents and Settings\\edi\\My Documents\\Visual Studio Projects\\test\\Debug\\test.dll")
  ADD-CONTENTS

  CL-USER 3 > (defparameter *a* (fli:allocate-foreign-object :type 'a-struct))
  *A*

  CL-USER 4 > (setf (fli:foreign-slot-value *a* 'a) 20
                    (fli:foreign-slot-value *a* 'b) 22)
  22

  CL-USER 5 > (add-contents (fli:dereference *a* :copy-foreign-object nil))
  42

Yup.

Thanks again,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: John Thingstad
Subject: Re: Windows Console Functions
Date: 
Message-ID: <opsiyl8qt6pqzri1@mjolner.upc.no>
On 13 Dec 2004 09:35:48 -0800, <············@hotmail.com> wrote:

> Does anyone know an easy way to write colored text to a windows console
> using Corman Lisp? (Colored ascii stuff) I suspect that I may be able
> to create a .dll in C++ and then access that in Corman Lisp using the
> FFI, but I don't know much about .dll's or the FFI yet.
> thanks,
> Kevin Clancy
>

Been a while since I looked at this but I seem to remember that there is
a ANSII console driver hooked to the console.
Consult the DOS documentation. (If you have any)
There should be some escape codes that prints text in color.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Pascal Bourguignon
Subject: Re: Windows Console Functions
Date: 
Message-ID: <87pt1engmt.fsf@thalassa.informatimago.com>
"John Thingstad" <··············@chello.no> writes:

> On 13 Dec 2004 09:35:48 -0800, <············@hotmail.com> wrote:
> 
> > Does anyone know an easy way to write colored text to a windows console
> > using Corman Lisp? (Colored ascii stuff) I suspect that I may be able
> > to create a .dll in C++ and then access that in Corman Lisp using the
> > FFI, but I don't know much about .dll's or the FFI yet.
> > thanks,
> > Kevin Clancy
> >
> 
> Been a while since I looked at this but I seem to remember that there is
> a ANSII console driver hooked to the console.
> Consult the DOS documentation. (If you have any)
> There should be some escape codes that prints text in color.

ANSI codes are defined by ISO-6429 or ECMA-048, the later text being
available gratis on the Web.  In this archive:
ftp://ftp.informatimago.com/pub/free/develop/lisp/ecma-048.tar.gz
http://informatimago.free.fr/archives/develop/lisp/ecma-048.tar.gz
you'll find the Ecma-048.pdf converted to text, and a clisp program to
parse the standard text and generate lisp and shell functions to
generate the codes.  It's not definitive, but you can use it to
generate whatever you need from the Ecma-048 standard.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.