Sun Java System Portal Server 7.1 Developer's Guide

Stream Routines for Parsing and Printing Searchs

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:

Search_PrintInitFile()

Creates a disk-based stream ready for printing.

Search_PrintInitStr()

Creates a memory-based stream ready for printing.

Search_PrintInitFn()

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:

Search_ParseInitFile()

Creates a disk-based stream ready for parsing. The stream is created from an input containing Search syntax.

Search_ParseInitStr()

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);
    }
}

Search_PrintInitFile

NSAPI_PUBLIC SearchStream *S
earch_PrintInitFile(FILE *file)

Creates a disk-based stream ready for printing. 

Search_PrintInitStr

NSAPI_PUBLIC SearchStream *
Search_PrintInitStr(SearchBuffer *memory)

Creates a memory-based stream ready for printing. 

Search_PrintInitFn

NSAPI_PUBLIC SearchStream *Search_PrintInitFn(int
(*write_fn)(void *data,char *buf, int bufsz), void *data)

Creates a generic application-defined stream ready for printing. The given write_fn is used to print the stream.

This function allows you to hook up your own routine for printing. 

Search_ParseInitFile

NSAPI_PUBLIC SearchStream
*Search_ParseInitFile(FILE *fp)

Creates a disk-based stream ready for parsing. The file must contain Search-formatted data. The function reads Search data from the file object fp.

Search_ParseInitStr

NSAPI_PUBLIC SearchStream *
Search_ParseInitStr(char *buf, int bufsz)

Creates a memory-based stream ready for parsing. The character buffer must contain Search-formatted data. 

SearchStream_Finish

NSAPI_PUBLIC int SearchStream_Finish
(SearchStream *)

Closes the stream when you have finished with it. 

SearchStream_SetFinishFn

NSAPI_PUBLIC int SearchStream_SetFinishFn
(SearchStream *, int (*finish_fn)(SearchStream *))

Allows you to hook up a function for cleaning up after the Search stream finishes its business. The finish_fn will be called when SearchStream_Finish() has finished executing.

SearchStream_Print

#define SearchStream_Print(ss, s)

Prints another Search object to the Search stream ss. Returns 0 on success, or non-zero on error.

SearchStream_Parse

#define SearchStream_Parse(ss)

Parses and returns the next Search object in the Search stream. 

SearchStream_IsEOS

#define SearchStream_IsEOS(s)

Returns 1 (true) if the Search stream has been exhausted. 

SearchStream_IsPrinting

#define SearchStream_IsPrinting(s)

Returns 1 (true) if the Search has been set up in a stream by Search_PrintInitFile() or Search_PrintInitStr().

SearchStream_IsParsing

#define SearchStream_IsParsing(s)

Returns 1 (true) if the Search has been setup in a stream by Search_ParseInitFile() or Search_ParseInitStr().