# 2. Using cgihtml

[ Next | Up to Table of Contents | Previous ]

## 2.1. Basic programming structure

There are standard initialization things that you will want to do when using this library. The following template should give you some idea of how to properly use this library.

    /* template using cgihtml.a library */

    #include <stdio.h>    /* standard io functions */
    #include <signal.h>   /* this and unistd.h for signal trapping */
    #include <unistd.h>
    #include "cgi-lib.h"  /* CGI-related routines */
    #include "html-lib.h" /* HTML-related routines */

    int main()
    {
      llist entries;  /* define a linked list; this is where the entries */
                      /* are stored.                                     */

    /* parse the form data and add it to the list */
      read_cgi_input(&entries);

    /* The data is now in a very usable form.  To search the list entries  */
    /* by name, call the function:                                         */
    /*      cgi_val(entries, "nameofentry")                                */
    /* which returns a pointer to the value associated with "nameofentry". */

      html_header();           /* print HTML MIME header */
      html_begin("Output");    /* send appropriate HTML headers with title */
                               /*   Output                  */

    /* display whatever data you wish here, probably with printf() */

      html_end();   /* send appropriate HTML end footers (

) */ list_clear(&entries); /* free up the pointers in the linked list */ return 0; }

## 2.2. Compiling your program

To compile your program with the library, include the file `cgihtml.a` when linking your object files. For example, if your main object file is program.cgi.o, the following should work successfully:

    cc -o program.cgi program.cgi.o cgihtml.a

[ Next | Up to Table of Contents | Previous ]

Last modified: Mon Jan 20 22:34:30 PST 1997