[EMAIL PROTECTED] 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.
_______________________________________________
Help-flex mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-flex