cgislvar() - enumerate user-defined variable list

SYNOPSIS

#include "cgi.h"

char   *cgislvar(sl, n, valp)
CGISL  *sl;
int     n;
char ***valp;


DESCRIPTION
The cgislvar() function is used to iterate through the variables in a CGISL string list. The n parameter indicates which variable in the list to get, starting with 0 for the first variable. *valp will be set to the ""-terminated string list of values for the variable. The name of the variable will be returned, or CHARPN if the value of n is out of range; this indicates the end of the list. Both the variable name and value list are owned by the CGISL object and will be freed when the object is closed.

This function is similar to cgivar, with the exception that it walks through a single (user-defined) variable list instead of multiple (internal) lists.


CAVEATS
As with getcgisl(), a variable's index, name and values may change if the CGISL object is modified; these values should be assumed invalid after calls such as cgisladdvar().


EXAMPLE

#include "cgi.h"

...

{
  char   urlvars[] = "First=this+is+a+test&Second=the+second+value";
  CGISL  *sl;
  int    i;
  char   **vals, *var;

  if ((sl = opencgisl()) == CGISLPN)                  return;/* error */
  if (!cgisladdstr(sl, urlvars))                      return;/* error */
  if (!cgisladdvar(sl, "Third", "the 3rd value"))     return;/* error */
  if (!cgisladdvar(sl, "Third", "another 3rd value")) return;/* error */

  /* now print out the list: */
  for (i = 0; (var = cgislvar(sl, i, &vals)) != CHARPN; i++) {
    printf("%s =", var);
    for ( ; **vals; vals++) printf(" '%s'", *vals);
    printf("\n");
  }
}

Output:

First = 'this is a test'
Second = 'the second value'
Third = 'the 3rd value' 'another 3rd value'


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.