[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FLEX and input memory stream
From: |
Tim Van Holder |
Subject: |
Re: FLEX and input memory stream |
Date: |
Thu, 02 Jun 2005 16:59:34 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
address@hidden wrote:
> Hi,
> i have made a little parser with flex, for parsing headers of html downloaded
> in memory.
> I wanted to parse directly the file in memory without having to write it down
> to the disk.
> So the html data is in a memory stream opened with open_memstream and i give
> this input to flex by yyin=myMemoryStream.
>
> It seems like flex can't parse streams in memory... Have i done something
> wrong and is there a way to solve the problem?
>From the glibc docs:
— Function: FILE * open_memstream (char **ptr, size_t *sizeloc)
This function opens a stream for writing to a buffer. The buffer is
allocated dynamically (as with malloc; see Unconstrained Allocation) and
grown as necessary.
So open_memstream returns a FILE* for writing only - which is why flex
can't read from it.
If you need to parse a memory buffer, there is yy_scan_string() to do
that. Note that a simple google for 'flex in-memory buffer' yielded
this informative site as first result:
http://aqualinux.chez.tiscali.fr/commun/flex.htm
There is even an example on how to override YY_INPUT to have flex read
directly from a socket.