From: Jocelyn Paine
Subject: File positions in CLisp
Date: 
Message-ID: <1996Jul2.161141@oxvaxd>
I've started using the OS/2 version of CLisp, and I have a question
about discovering where I am in a file.

I'm writing a parser for an extended HTML (isn't everyone?). One thing I
need to do is, when I'm parsing a file and I encounter certain
constructs, to find out the position within the file. This will be
passed on to another program, and will enable it to jump directly to
those locations using an OS/2 'seek'.

So as an example, if my parser were reading the line below, I might want
it to return the byte position of each '<' character.
    <HTML><HEAD><TITLE>My home page</TITLE></HEAD>

Ideally, I want to extend the facilities provided by the input streams
so that there's a function
    (BYTE-POSITION (STREAM) ... )
which tells me the position of the character just read.

I'm wondering what the best way to do this is, because I don't think
standard Lisp input gives one a way to find this out. Of course, one can
write foreign functions in Clisp, but they can't find out how far an
open stream is through a file, because that information is internal to
the Lisp I/O system.

One possibility is to modify the source of the I/O routines.

Another is for me to implement another kind of stream, using foreign
functions. So I write a function to open a file and attach a buffer to
it; a function to read lines into the buffer; a function to find how far
I've read; and so on. That's a lot of work, and I might also have
problems in maintaining the state of these streams between function
calls.

A third possibility is to call CLisp's Rexx interface functions. So I
write one function to connect a Rexx stream to a file and return a
handle to it (how?); another to call 'charin' on that stream; another to
ask for its position.

A fourth might be to run a Rexx program side-by-side with Clisp as a
separate process or thread. The Rexx program would do the file reading,
and the Clisp program would request characters or file-positions from
it (again, how?).

These last three solutions all suffer from the fact that they are
building their own stream system, and so can't take advantage of Lisp's
standard stream facilities, such as WITH-OPEN-FILE.

Does anyone have any suggestions?

Jocelyn

From: Marcus Daniels
Subject: Re: File positions in CLisp
Date: 
Message-ID: <rfiafxia19e.fsf@sayre.sysc.pdx.edu>
>>>>> "JP" == Jocelyn Paine <····@vax.oxford.ac.uk> writes:

JP> I'm wondering what the best way to do this is, because I don't
JP> think standard Lisp input gives one a way to find this out. 

JP> Does anyone have any suggestions?

Why not FILE-POSITION?
From: Kelly Murray
Subject: Re: File positions in CLisp
Date: 
Message-ID: <4rc121$m70@sparky.franz.com>
> I'm writing a parser for an extended HTML (isn't everyone?). One thing I
> need to do is, when I'm parsing a file and I encounter certain
> constructs, to find out the position within the file. This will be
> passed on to another program, and will enable it to jump directly to
> those locations using an OS/2 'seek'.
> ...possible implementions...
> Does anyone have any suggestions?

I'm not sure this will help, but rather than trying to find the
file positions of the input file, create a new file where you
know the file positions when you write.
e.g. (defun copy-html-get-positions (input output)
      (let ((html-position-alist nil)
            (html-item nil))
       (while (setf html-item (read-html input)) 
          (push (cons (file-position output) html-item) 
                html-position-alist)
          (write-html html-item output))
       html-position-alist))

-Kelly Murray  ···@franz.com  
          
From: Marco Antoniotti
Subject: Re: File positions in CLisp
Date: 
Message-ID: <s087msmur5q.fsf@salmon.ICSI.Berkeley.EDU>
In article <··········@sparky.franz.com> ···@math.ufl.edu (Kelly Murray) writes:

   From: ···@math.ufl.edu (Kelly Murray)
   Newsgroups: comp.lang.lisp
   Date: 2 Jul 1996 20:33:05 GMT
   Organization: Franz Inc.
   Reply-To: ···@franz.com
   Path: agate!howland.reston.ans.net!tank.news.pipex.net!pipex!news.mathworks.com!uunet!in2.uu.net!franz.com!math.ufl.edu!kem
   Lines: 22
   Distribution: world
   References: <···············@oxvaxd>

   > I'm writing a parser for an extended HTML (isn't everyone?). One thing I
   > need to do is, when I'm parsing a file and I encounter certain
   > constructs, to find out the position within the file. This will be
   > passed on to another program, and will enable it to jump directly to
   > those locations using an OS/2 'seek'.
   > ...possible implementions...
   > Does anyone have any suggestions?

You can also check out the CL-HTTP stuff at MIT.

-- 
Marco Antoniotti - Resistente Umano
===============================================================================
International Computer Science Institute	| ·······@icsi.berkeley.edu
1947 Center STR, Suite 600			| tel. +1 (510) 643 9153
Berkeley, CA, 94704-1198, USA			|      +1 (510) 642 4274 x149
===============================================================================
	...it is simplicity that is difficult to make.
	...e` la semplicita` che e` difficile a farsi.
				Bertholdt Brecht
From: Howard R. Stearns
Subject: Re: File positions in CLisp
Date: 
Message-ID: <31DA70F7.15FB7483@elwoodcorp.com>
Jocelyn Paine wrote:
> 
> I've started using the OS/2 version of CLisp, and I have a question
> about discovering where I am in a file.
> ...
> Ideally, I want to extend the facilities provided by the input streams
> so that there's a function
>     (BYTE-POSITION (STREAM) ... )
> which tells me the position of the character just read.
> 
> I'm wondering what the best way to do this is, because I don't think
> standard Lisp input gives one a way to find this out. 
> ...
> Jocelyn

What about FILE-POSITION?