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