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

int Clp_SetOptionChar ( Clp_Parser clp,
int  c,
int  type 
)

Set clp's treatment of character c.

Parameters:
clp the parser
c character
type option character treatment
Returns:
previous option character treatment, or -1 on error
type specifies how CLP treats arguments that begin with character c. Possibilities are:

Clp_NotOption (or 0)
The argument cannot be an option.
Clp_Long
The argument is a long option.
Clp_Short
The argument is a set of short options.
Clp_Short|Clp_Long
The argument is either a long option or, if no matching long option is found, a set of short options.
Clp_LongNegated
The argument is a negated long option. For example, after Clp_SetOptionChar(clp, '^', Clp_LongNegated), the argument "^foo" is equivalent to "--no-foo".
Clp_ShortNegated
The argument is a set of negated short options.
Clp_ShortNegated|Clp_LongNegated
The argument is either a negated long option or, if no matching long option is found, a set of negated short options.
Clp_LongImplicit
The argument may be a long option, where the character c is actually part of the long option name. For example, after Clp_SetOptionChar(clp, 'f', Clp_LongImplicit), the argument "foo" may be equivalent to "--foo".

In UTF-8 mode, c may be any Unicode character. Otherwise, c must be an unsigned char value. The special character 0 assigns type to every character.

It is an error if c is out of range, type is illegal, or there are too many character definitions stored in clp already. The function returns -1 on error.

A double hyphen "--" always introduces a long option. This behavior cannot currently be changed with Clp_SetOptionChar().

Definition at line 674 of file clp.c.

References Clp_Long, Clp_LongImplicit, Clp_LongNegated, Clp_NotOption, Clp_Short, Clp_ShortNegated, and Clp_Parser::internal.

{
    int i, j, long1pos, long1neg;
    int old = Clp_OptionChar(clp, c);
    Clp_Internal *cli = clp->internal;

    if (type != Clp_NotOption && type != Clp_Short && type != Clp_Long
      && type != Clp_ShortNegated && type != Clp_LongNegated
      && type != Clp_LongImplicit && type != (Clp_Short | Clp_Long)
      && type != (Clp_ShortNegated | Clp_LongNegated))
      return -1;
    if (c < 0 || c >= (cli->utf8 ? 0x110000 : 256))
      return -1;

    if (c == 0)
      cli->noclass = 0;
    for (i = 0; i < cli->noclass; ++i)
      if (cli->oclass[i].c == c)
          break;
    if (i == Clp_OclassSize)
      return -1;

    cli->oclass[i].c = c;
    cli->oclass[i].type = type;
    if (cli->noclass == i)
      cli->noclass = i + 1;

    long1pos = long1neg = 0;
    for (i = 0; i < cli->noclass; ++i) {
      if ((cli->oclass[i].type & Clp_Short)
          && (cli->oclass[i].type & Clp_Long))
          long1pos = 1;
      if ((cli->oclass[i].type & Clp_ShortNegated)
          && (cli->oclass[i].type & Clp_LongNegated))
          long1neg = 1;
    }

    if (long1pos != cli->long1pos || long1neg != cli->long1neg) {
      /* Must recheck option set */
      cli->long1pos = long1pos;
      cli->long1neg = long1neg;
      for (i = 0; i < cli->nopt; ++i) {
          cli->iopt[i].lmmpos = cli->iopt[i].lmmneg = 1;
          cli->iopt[i].lmmpos_short = cli->iopt[i].lmmneg_short = 0;
          for (j = 0; j < cli->nopt; ++j)
            compare_options(clp, &cli->opt[i], &cli->iopt[i],
                        &cli->opt[j], &cli->iopt[j]);
      }
    }

    return old;
}


Generated by  Doxygen 1.6.0   Back to index