cgislvar() - enumerate user-defined variable list


#include "cgi.h"

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

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.

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().


#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);


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

Copyright © Thunderstone Software     Last updated: May 19 2023
Copyright © 2023 Thunderstone Software LLC. All rights reserved.