This web page describes a class library written in Ada 95 to help in the decoding of information sent to a CGI program.

Under Construction

A class written in Ada 95 to decode the information in the environment variable QUERY_STRING has the following methods:

Method Responsibility
set set the string that will be parsed.
get_item Return the string associated with the keyword passed as a parameter. If no data then return the null string.

When using the member function get_item the optional third parameter specifies which occurrence of the string associated with a keyword to return. This is to allow the recovery of information attached to identical keywords. In addition the returned string will have had the following substitutions made on it.

Note:
A null string is returned if a keyword is not found.

For example, if the QUERY_STRING contained:

tag=one&name=mike&action=%2B10%25&tag=two&log=/mas/log&tag=three

Then the following program when compiled and run:

with Simple_io, Class_parse, unix_if; 
use  Simple_io, Class_parse, unix_if;
procedure main is
  list : Parse;
begin
  set( list, get_env( "QUERY_STRING" ) );

  put("name   = "); put( get_item( list, "name" )) ; new_line;
  put("action = "); put( get_item( list, "action" )) ; new_line;
  put("log    = "); put( get_item( list, "log" )) ; new_line;
  for i in 1 .. 4 loop
    put("tag(" ); put( i, width=>1 ); put( ")  ");
    put( get_item( list, "tag", i ) ); new_line;
  end loop;
end main;

would produce the following output:

name  = mike
action= +10%
log   = /mas/log
tag  (1) = one
tag  (2) = two
tag  (3) = three
tag  (4) = 

The complete program is:

To view (highlighted keywords) To download (plain ascii text)
cgi_pars.ada cgi_pars.ada


The material in these WWW page(s) is © M.A.Smith Modified 4 January 1996
Comments, suggestions, etc. M.A.Smith@brighton.ac.uk