Logo Search packages:      
Sourcecode: t1utils version File versions  Download package

int Clp_AddStringListType ( Clp_Parser clp,
int  val_type,
int  flags,

Define a new string list value type for clp.

clp the parser
val_type value type ID
flags string list flags
0 on success, -1 on failure
Defines argument type val_type in parser clp. The parsing function sets clp->val.i to an integer. The value string is matched against strings provided in the ellipsis arguments. For example, the Clp_AddStringListType() call below has the same effect as the Clp_AddStringListTypeVec() call:

For example:

 Clp_AddStringListType(clp, 100, Clp_AllowNumbers, "cat", 1,
                       "cattle", 2, "dog", 3, (const char *) NULL);

 const char * const strs[] = { "cat", "cattle", "dog" };
 const int vals[]          = { 1,     2,        3     };
 Clp_AddStringListTypeVec(clp, 100, Clp_AllowNumbers, 3, strs, vals);

The CLP library will not modify any of the passed-in strings. The calling program must not modify or free them either until the parser is destroyed.

Definition at line 1257 of file clp.c.

References Clp_Option::flags, Clp_Option::long_name, and Clp_Option::option_id.

    int nitems = 0;
    int itemscap = 5;
    Clp_Option *items = (Clp_Option *)malloc(sizeof(Clp_Option) * itemscap);

    va_list val;
    va_start(val, flags);

    if (!items)
      goto error;

    /* slurp up the arguments */
    while (1) {
      int value;
      char *name = va_arg(val, char *);
      if (!name)
      value = va_arg(val, int);

      if (nitems >= itemscap) {
          Clp_Option *new_items;
          itemscap *= 2;
          new_items = (Clp_Option *)realloc(items, sizeof(Clp_Option) * itemscap);
          if (!new_items)
            goto error;
          items = new_items;

      items[nitems].long_name = name;
      items[nitems].option_id = value;
      items[nitems].flags = 0;

    if (finish_string_list(clp, val_type, flags, items, nitems, itemscap) >= 0)
      return 0;

    if (items)
    return -1;

Generated by  Doxygen 1.6.0   Back to index