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

int Clp_AddType ( Clp_Parser clp,
int  val_type,
int  flags,
Clp_ValParseFunc  parser,
void *  user_data 
)

Define a new value type for clp.

Parameters:
clp the parser
val_type value type ID
flags value type flags
parser parser function
user_data user data for parser function
Returns:
0 on success, -1 on failure
Defines argument type val_type in parser clp. The parsing function parser will be passed argument values for type val_type. It should parse the argument into values (usually in clp->val, but sometimes elsewhere), report errors if necessary, and return whether the parse was successful.

Any prior argument parser match val_type is removed. val_type must be greater than zero.

flags specifies additional parsing flags. At the moment the only relevant flag is Clp_DisallowOptions, which means that separated values must not look like options. For example, assume argument --a/-a has mandatory value type Clp_ValStringNotOption (which has Clp_DisallowOptions). Then:

  • --a=--b will parse with value --b.
  • -a--b will parse with value --b.
  • --a --b will not parse, since the mandatory value looks like an option.
  • -a --b will not parse, since the mandatory value looks like an option.

Definition at line 1021 of file clp.c.

References Clp_Parser::internal.

{
    Clp_Internal *cli = clp->internal;
    int vtpos;

    if (val_type <= 0 || !parser)
      return -1;

    vtpos = val_type_binsearch(cli, val_type);

    if (vtpos == cli->nvaltype || cli->valtype[vtpos].val_type != val_type) {
      if (cli->nvaltype != 0 && (cli->nvaltype % Clp_InitialValType) == 0) {
          Clp_ValType *new_valtype =
            (Clp_ValType *) realloc(cli->valtype, sizeof(Clp_ValType) * (cli->nvaltype + Clp_InitialValType));
          if (!new_valtype)
            return -1;
          cli->valtype = new_valtype;
      }
      memmove(&cli->valtype[vtpos + 1], &cli->valtype[vtpos],
            sizeof(Clp_ValType) * (cli->nvaltype - vtpos));
      cli->nvaltype++;
      cli->valtype[vtpos].func = 0;
    }

    if (cli->valtype[vtpos].func == parse_string_list) {
      Clp_StringList *clsl = (Clp_StringList *) cli->valtype[vtpos].user_data;
      free(clsl->items);
      free(clsl->iopt);
      free(clsl);
    }

    cli->valtype[vtpos].val_type = val_type;
    cli->valtype[vtpos].func = parser;
    cli->valtype[vtpos].flags = flags;
    cli->valtype[vtpos].user_data = user_data;
    return 0;
}


Generated by  Doxygen 1.6.0   Back to index