A SearchStream contains one or more Search objects.
The general approach is that you use Search streams to create and process streams of many Search objects. Given a Search stream, you can parse it to get the Search objects from it. Use the parse() routine to get the next Search object in a Search stream. You can use SearchStream_IsEOS() to check whether the last object has been parsed.
You can use filtering functions for a Search stream to specify that certain Search attributes are allowed or denied. If an attribute is allowed, you can parse and print that attribute for Search objects in the stream. If it is denied, you cannot parse or print that attribute of Search objects in the stream.
Search streams can be disk or memory based.
When you create a SearchStream, you need to specify if you will be printing or parsing the Search stream, and if you will be using a memory- or disk-based stream. The functions you need to use will depend on what you will be doing with the Search stream.
For creating a Search streams into which you will be printing Searches, the functions are:
Creates a disk-based stream ready for printing.
Creates a memory-based stream ready for printing.
Creates a generic application-defined stream ready for printing. The given ”write_fn’ is used to print the stream.
To create Search stream from a file or a string containing Search, use the following functions:
Creates a disk-based stream ready for parsing. The stream is created from an input containing Search syntax.
Creates a memory-based stream ready for parsing. The stream is created from an input containing Search syntax.
SearchStream objects have a caller-data field, which you can use as you like:
void *caller_data; /* hook to be used by caller */
Use SearchStream_Parse() to get the Search objects from the Search stream, and use SearchStream_Print() to write Search objects to the Search stream.
When you’ve finished with the stream, close it by using SearchStream_Finish(). Use SearchStream_SetFinishFn() to trigger the given finish_fn function.
The following example code takes a Search stream in stdin and prints each Search in the stream to stdout. Notice that this code uses Search_ParseInitFile() to create the SearchStream to parse the input file, and uses Search_PrintInitFile() to create the stream to print the Searches to stdout.
SearchStream *searchin = Search_ParseInitFile(stdin); SearchStream *searchout = Search_PrintInitFile(stdout); Search *s; while (!SearchStream_IsEOS(searchin)) { if ((s = SearchStream_Parse(searchin)) { SearchStream_print(searchout, s); Search_Free(s); } } |