next up previous contents index
Next: SOIF library written Up: B.3 Using the SOIF Previous: B.3 Using the SOIF

SOIF library written in C

 

The Harvest system comes with a library interface to SOIF processing in harvest/src/common/template. To compile a program using the SOIF library, use the loader options -ltemplate -lutil. The SOIF processing library provides an interface for both parsing and printing SOIF objects, as well as modifying SOIF objects. The SOIF objects are represented as linked lists of attribute-value pairs. Functions are also provided to manipulate these linked lists. The print_template_body() function is useful for writing Essence summarizers. The following is a partial list of the functions supplied in the library:

                         

void init_parse_template_file(FILE *input_file)
Parses a SOIF template taking input from a file.

void init_parse_template_string(char *input_string, int size)
Parses a SOIF template taking input from a memory buffer.

Template *parse_template()
Parses a SOIF template and returns a Template structure.

void finish_parse_template()
Cleans up after parse_template().

int is_parse_end_of_input()
Returns non-zero if the parsing routine has no more data to process.

Buffer *init_print_template(FILE *output_file)
Print SOIF template to memory buffer or to a file if fp is not NULL. Returns NULL if printing to a file; otherwise returns a pointer to the Buffer where the data is stored.

void print_template(Template *t)
Prints a SOIF template into a file or into a buffer. Must call an init_print routine before, and the finish_print routine after.

void print_template_header(Template *t)
Prints a SOIF template header into a file or into a buffer.

void print_template_body(Template *t)
Prints a SOIF template body into a file or into a buffer.

void print_template_trailer(Template *t)
Prints a SOIF template trailer into a file or into a buffer.

void finish_print_template()
Clean up after print_template().

void add_AVList(AVList *list, char *attr, char *value, int vsize)
Adds an attribute-value pair to the given attribute-value pair list.

AVPair *extract_AVPair(AVList *list, char *attr)
Searches for the given attribute in the AVList. Does a case insensitive match on the attributes. Returns NULL on error; otherwise returns the matching AVPair.

The following example reads SOIF objects from stdin, parses them into the Attribute-Value pair list, adds an Attribute-Value pair to the template's list, and finally prints the modified SOIF template to stdout:

        /*
         *  print-template - Reads in templates from stdin and prints it to stdout.
         *  Darren Hardy, University of Colorado - Boulder, February 1994
         */
        #include <stdio.h>
        #include <string.h>
        #include "util.h"
        #include "template.h"

        static void add_print_time(t)
        Template *t;
        {
                char buf[BUFSIZ];

                sprintf(buf, "%d", time(NULL));
                add_AVList(t->list, "Print-Time", buf, strlen(buf));
        }
        int main(argc, argv)
        int argc;
        char *argv[];
        {
                Template *template;
                Buffer *b;

                init_parse_template_file(stdin);                /* Initialize parse */
                while (template = parse_template()) {           /* Read next Template */
                        add_print_time(template);               /* Add new Attribute-Value */
                        b = init_print_template(NULL);          /* Initialize print */
                        print_template(template);               /* Print Template to Buffer */
                        fwrite(b->data, 1, b->length, stdout);  /* Buffer to stdout */
                        finish_print_template();                /* Clean up */
                        free_template(template);                /* Clean up */
                }
                finish_parse_template();                        /* Clean up */
                exit(0);
        }



next up previous contents index
Next: SOIF library written Up: B.3 Using the SOIF Previous: B.3 Using the SOIF



Darren Hardy
Mon Apr 3 15:22:37 MDT 1995