Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!cambridge.apple.com!alms
From: alms@cambridge.apple.com (Andrew L. M. Shalit)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Allegro Lisp question
Message-ID: 
Date: 25 Sep 89 16:55:52 GMT
References: 
Sender: news@cambridge.apple.com
Organization: Apple Computer Inc, Cambridge, MA
Lines: 38
In-reply-to: gf0c+@andrew.cmu.edu's message of 25 Sep 89 05:02:18 GMT

In article  gf0c+@andrew.cmu.edu (Gregory S. Fox) writes:


	There's a special function (%get-string pointer), which takes
   a variable of type 'pointer and returns  [our beloved]  PASCAL string.
   I want it to return a Lisp string  (of type 'string or 'simple-string);
   ie- a string that's longer than 255 bytes.  This is complicated by the
   fact that I don't know how Lisp strings are stored-  I know they are
   allocated arrays, but are they null terminated?

%GET-STRING takes a pointer to a Pascal string as an argument, and
returns a Lisp string as the result.  The Lisp string will never
be longer than 255 characters, because the Pascal string can never
be longer than that.

If you have a longer string, it's probably a CString, that is, a zero-
terminated string.  To convert that to a Lisp string, you could
try something like the following:

(defun get-c-string (pointer)
  "puts bytes from pointer into string until it reaches a zero byte"
  (let* ((new-string (make-array 10
                                 :element-type 'string-char
                                 :fill-pointer 0
                                 :adjustable t))
         (one-char nil))
   (loop
     (setq one-char (%get-byte pointer))
     (when (= one-char 0)
      (return-from get-c-string new-string))
     (vector-push-extend new-string (code-char one-char))
     (setq pointer (%inc-pointer pointer 1)))))

You are basically just going through a loop, getting one character at
a time and adding it into a string.  Make sense?

   -andrew
    alms@cambridge.apple.com