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. */

  /* prevent runaway processes; assume that the program will finish */
  /* executing in a few seconds.  If the program is still running after */
  /* 30 seconds, assume it is running out of control and die. */
  signal(SIGALRM, die);

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

/* 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, probably with printf() */

  html_end();   /* send appropriate HTML end footers ( ) */
  list_clear(&entries);   /* free up the pointers in the linked list */
  exit(0);   /* exit successfully */

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: Sun Aug 13 16:24:41 1995