In article <3f731a2b$0$54828$> ,
says...
> I am using an older C library (Flex scanner) which requires that a variable
> is set as a pointer to a file:
>
> #define FILE _iobuf
> FILE* hFile;
>
> It works great but I would like to add a wrapper so I can parse a string in
> memmory as well.
A Flex scanner will normally use YY_INPUT to get input. You can define
that yourself if you want it to read data in a different fashion than
the usual.
> Presently I do that by saving the string in a temp file and
> then making the original call to the library with the filehandle. This is
> slow and clumsy so I was wondering if there's some way of converting a
> string to an appropiate stream (or _iobuf whatever that is)?
It's OS specific, but in quite a few cases you could also create a pipe
and have it read from the pipe, while something at the other end feeds
the data from the string into the pipe. This would be useful if the
scanner itself needed to be oblivious to the source of the data.
Flex also supports a '-+' argument to create a C++ lexer as a set of
classes. In this case, the lexer class reads from an istream so it
should be quite easy to pass an istringstream instead.
--
Later,
Jerry.
The universe is a figment of its own imagination.