Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

clp.h File Reference

Go to the source code of this file.


Data Structures

struct  Clp_Option
struct  Clp_Parser

Defines

#define Clp_NoArg   0
#define Clp_ArgString   1
#define Clp_ArgStringNotOption   2
#define Clp_ArgBool   3
#define Clp_ArgInt   4
#define Clp_ArgUnsigned   5
#define Clp_ArgDouble   6
#define Clp_MaxDefaultType   Clp_ArgDouble
#define Clp_DisallowOptions   (1<<0)
#define Clp_Mandatory   (1<<0)
#define Clp_Optional   (1<<1)
#define Clp_Negate   (1<<2)
#define Clp_AllowDash   (1<<3)
#define Clp_OnlyNegated   (1<<4)
#define Clp_Short   (1<<0)
#define Clp_Long   (1<<1)
#define Clp_ShortNegated   (1<<2)
#define Clp_LongNegated   (1<<3)
#define Clp_LongImplicit   (1<<4)
#define Clp_AllowNumbers   (1<<0)
#define Clp_NotOption   0
#define Clp_Done   -1
#define Clp_BadOption   -2
#define Clp_Error   -3

Typedefs

typedef Clp_Option Clp_Option
typedef Clp_Parser Clp_Parser
typedef Clp_Internal Clp_Internal
typedef Clp_ParserState Clp_ParserState
typedef int(* Clp_ArgParseFunc )(Clp_Parser *, const char *, int, void *)
typedef void(* Clp_ErrorHandler )(char *)

Functions

Clp_ParserClp_NewParser (int argc, char *const argv[], int nopt, Clp_Option *opt)
void Clp_DeleteParser (Clp_Parser *)
Clp_ErrorHandler Clp_SetErrorHandler (Clp_Parser *, Clp_ErrorHandler)
int Clp_SetOptionChar (Clp_Parser *, int c, int option_type)
int Clp_AddType (Clp_Parser *, int type_id, int flags, Clp_ArgParseFunc func, void *user_data)
int Clp_AddStringListType (Clp_Parser *, int type_id, int flags,...)
int Clp_AddStringListTypeVec (Clp_Parser *, int type_id, int flags, int n, char **str, int *val)
char * Clp_ProgramName (Clp_Parser *)
int Clp_Next (Clp_Parser *)
char * Clp_Shift (Clp_Parser *, int allow_dashes)
int Clp_SetOptionProcessing (Clp_Parser *, int option_processing)
Clp_ParserStateClp_NewParserState (void)
void Clp_DeleteParserState (Clp_ParserState *)
void Clp_SaveParser (Clp_Parser *, Clp_ParserState *)
void Clp_RestoreParser (Clp_Parser *, Clp_ParserState *)
int Clp_OptionError (Clp_Parser *, const char *,...)

Define Documentation

#define Clp_AllowDash   (1<<3)
 

Definition at line 35 of file clp.h.

#define Clp_AllowNumbers   (1<<0)
 

Definition at line 47 of file clp.h.

Referenced by finish_string_list(), and main().

#define Clp_ArgBool   3
 

Definition at line 21 of file clp.h.

Referenced by Clp_NewParser().

#define Clp_ArgDouble   6
 

Definition at line 24 of file clp.h.

Referenced by Clp_NewParser().

#define Clp_ArgInt   4
 

Definition at line 22 of file clp.h.

Referenced by Clp_NewParser().

#define Clp_ArgString   1
 

Definition at line 19 of file clp.h.

Referenced by Clp_NewParser().

#define Clp_ArgStringNotOption   2
 

Definition at line 20 of file clp.h.

Referenced by Clp_NewParser().

#define Clp_ArgUnsigned   5
 

Definition at line 23 of file clp.h.

Referenced by Clp_NewParser().

#define Clp_BadOption   -2
 

Definition at line 52 of file clp.h.

Referenced by Clp_Next(), and main().

#define Clp_DisallowOptions   (1<<0)
 

Definition at line 29 of file clp.h.

Referenced by Clp_NewParser(), Clp_Next(), and main().

#define Clp_Done   -1
 

Definition at line 51 of file clp.h.

Referenced by Clp_Next(), and main().

#define Clp_Error   -3
 

Definition at line 53 of file clp.h.

Referenced by Clp_Next().

#define Clp_Long   (1<<1)
 

Definition at line 41 of file clp.h.

Referenced by Clp_SetOptionChar(), and next_argument().

#define Clp_LongImplicit   (1<<4)
 

Definition at line 44 of file clp.h.

Referenced by Clp_SetOptionChar(), and next_argument().

#define Clp_LongNegated   (1<<3)
 

Definition at line 43 of file clp.h.

Referenced by Clp_SetOptionChar(), and next_argument().

#define Clp_Mandatory   (1<<0)
 

Definition at line 32 of file clp.h.

Referenced by Clp_NewParser(), and Clp_Next().

#define Clp_MaxDefaultType   Clp_ArgDouble
 

Definition at line 26 of file clp.h.

#define Clp_Negate   (1<<2)
 

Definition at line 34 of file clp.h.

Referenced by check_duplicated_short_options(), Clp_NewParser(), Clp_Next(), find_prefix_opt(), and find_short().

#define Clp_NoArg   0
 

Definition at line 18 of file clp.h.

#define Clp_NotOption   0
 

Definition at line 50 of file clp.h.

Referenced by Clp_Next(), main(), and next_argument().

#define Clp_OnlyNegated   (1<<4)
 

Definition at line 36 of file clp.h.

Referenced by check_duplicated_short_options(), Clp_NewParser(), find_prefix_opt(), and find_short().

#define Clp_Optional   (1<<1)
 

Definition at line 33 of file clp.h.

Referenced by Clp_NewParser().

#define Clp_Short   (1<<0)
 

Definition at line 40 of file clp.h.

Referenced by Clp_NewParser(), Clp_SetOptionChar(), and next_argument().

#define Clp_ShortNegated   (1<<2)
 

Definition at line 42 of file clp.h.

Referenced by Clp_SetOptionChar(), main(), next_argument(), and switch_to_short_argument().


Typedef Documentation

typedef int(* Clp_ArgParseFunc)(Clp_Parser *, const char *, int, void *)
 

Definition at line 61 of file clp.h.

Referenced by Clp_AddType().

typedef void(* Clp_ErrorHandler)(char *)
 

Definition at line 62 of file clp.h.

Referenced by Clp_SetErrorHandler().

typedef struct Clp_Internal Clp_Internal
 

Definition at line 58 of file clp.h.

typedef struct Clp_Option Clp_Option
 

Definition at line 56 of file clp.h.

typedef struct Clp_Parser Clp_Parser
 

Definition at line 57 of file clp.h.

typedef struct Clp_ParserState Clp_ParserState
 

Definition at line 59 of file clp.h.


Function Documentation

int Clp_AddStringListType Clp_Parser  ,
int    type_id,
int    flags,
...   
 

Definition at line 667 of file clp.c.

References finish_string_list(), Clp_Option::flags, flags, free, Clp_Option::long_name, malloc, name, Clp_Option::option_id, and realloc.

00669                       :
00670         Clp_AddStringListType
00671           (clp, type_id, flags,
00672            char *s_1, int value_1, ..., char *s_n, int value_n, 0);
00673 
00674         Defines type_id as a type in clp.
00675         This type accepts any of the strings s_1, ..., s_n
00676         (or unambiguous abbreviations thereof);
00677         if argument s_i is given, value_i is stored in clp->val.i.
00678         If Clp_AllowNumbers is set in flags,
00679         explicit integers are also allowed.
00680 
00681         Returns 1 on success, 0 on memory allocation errors. */
00682 {
00683   int nitems = 0;
00684   int itemscap = 5;
00685   Clp_Option *items = (Clp_Option *)malloc(sizeof(Clp_Option) * itemscap);
00686   
00687   va_list val;
00688   va_start(val, flags);
00689   
00690   if (!items) goto error;
00691   
00692   /* slurp up the arguments */
00693   while (1) {
00694     int value;
00695     char *name = va_arg(val, char *);
00696     if (!name) break;
00697     value = va_arg(val, int);
00698     
00699     if (nitems >= itemscap) {
00700       Clp_Option *new_items;
00701       itemscap *= 2;
00702       new_items = (Clp_Option *)realloc(items, sizeof(Clp_Option) * itemscap);
00703       if (!new_items) goto error;
00704       items = new_items;
00705     }
00706     
00707     items[nitems].long_name = name;
00708     items[nitems].option_id = value;
00709     items[nitems].flags = 0;
00710     nitems++;
00711   }
00712 
00713   va_end(val);
00714   if (finish_string_list(clp, type_id, flags, items, nitems, itemscap))
00715     return 1;
00716   
00717  error:
00718   va_end(val);
00719   if (items) free(items);
00720   return 0;
00721 }

int Clp_AddStringListTypeVec Clp_Parser  ,
int    type_id,
int    flags,
int    n,
char **    str,
int *    val
 

Definition at line 725 of file clp.c.

References finish_string_list(), flags, free, i, and malloc.

00730 {
00731   int i;
00732   int itemscap = (nitems < 5 ? 5 : nitems);
00733   Clp_Option *items = (Clp_Option *)malloc(sizeof(Clp_Option) * itemscap);
00734   if (!items) return 0;
00735   
00736   /* copy over items */
00737   for (i = 0; i < nitems; i++) {
00738     items[i].long_name = strings[i];
00739     items[i].option_id = values[i];
00740     items[i].flags = 0;
00741   }
00742   
00743   if (finish_string_list(clp, type_id, flags, items, nitems, itemscap))
00744     return 1;
00745   else {
00746     free(items);
00747     return 0;
00748   }
00749 }

int Clp_AddType Clp_Parser  ,
int    type_id,
int    flags,
Clp_ArgParseFunc    func,
void *    user_data
 

Definition at line 470 of file clp.c.

References Clp_Internal::argtype, Clp_ArgParseFunc, Clp_ArgType::flags, flags, Clp_ArgType::func, i, Clp_Parser::internal, Clp_Internal::nargtype, realloc, and Clp_ArgType::thunk.

Referenced by Clp_NewParser(), finish_string_list(), and main().

00479 {
00480   int i;
00481   Clp_Internal *cli = clp->internal;
00482   Clp_ArgType *new_argtype;
00483   int nargtype = cli->nargtype;
00484   assert(nargtype);
00485   
00486   if (type_id <= 0 || !func) return 0;
00487   
00488   while (nargtype <= type_id)
00489     nargtype *= 2;
00490   new_argtype = (Clp_ArgType *)
00491     realloc(cli->argtype, sizeof(Clp_ArgType) * nargtype);
00492   if (!new_argtype) return 0;
00493   cli->argtype = new_argtype;
00494   
00495   for (i = cli->nargtype; i < nargtype; i++)
00496     cli->argtype[i].func = 0;
00497   cli->nargtype = nargtype;
00498   
00499   cli->argtype[type_id].func = func;
00500   cli->argtype[type_id].flags = flags;
00501   cli->argtype[type_id].thunk = thunk;
00502   return 1;
00503 }

void Clp_DeleteParser Clp_Parser  
 

Definition at line 257 of file clp.c.

References Clp_Internal::argtype, free, i, Clp_Parser::internal, Clp_StringList::items, Clp_Internal::long_min_match, Clp_StringList::long_min_match, Clp_Internal::nargtype, and parse_string_list().

00260 {
00261   int i;
00262   Clp_Internal *cli;
00263   if (!clp) return;
00264   
00265   cli = clp->internal;
00266   
00267   /* get rid of any string list types */
00268   for (i = 0; i < cli->nargtype; i++)
00269     if (cli->argtype[i].func == parse_string_list) {
00270       Clp_StringList *clsl = (Clp_StringList *)cli->argtype[i].thunk;
00271       free(clsl->items);
00272       free(clsl->long_min_match);
00273       free(clsl);
00274     }
00275   
00276   free(cli->argtype);
00277   free(cli->long_min_match);
00278   free(cli);
00279   free(clp);
00280 }

void Clp_DeleteParserState Clp_ParserState  
 

Definition at line 774 of file clp.c.

References free.

00775 {
00776   free(save);
00777 }

Clp_Parser* Clp_NewParser int    argc,
char *const    argv[],
int    nopt,
Clp_Option   opt
 

Definition at line 156 of file clp.c.

References Clp_Internal::argc, argc, Clp_Internal::argtype, Clp_Internal::argv, Clp_Internal::both_short_and_long, calculate_long_min_match(), check_duplicated_short_options(), Clp_AddType(), Clp_AnyArgument, Clp_ArgBool, Clp_ArgDouble, Clp_ArgInt, Clp_ArgString, Clp_ArgStringNotOption, Clp_ArgUnsigned, Clp_DisallowOptions, Clp_Mandatory, Clp_Negate, Clp_OnlyNegated, Clp_Optional, Clp_Short, Clp_Internal::current_option, Clp_Internal::error_handler, free, i, Clp_Parser::internal, Clp_Internal::is_short, Clp_Internal::long_min_match, malloc, Clp_Internal::nargtype, Clp_Internal::nopt, Clp_Internal::opt, Clp_Internal::option_class, Clp_Internal::option_processing, parse_bool(), parse_double(), parse_int(), parse_string(), Clp_Internal::program_name, TEST, and Clp_Internal::whole_negated.

Referenced by main().

00159 {
00160   int i;
00161   Clp_Parser *clp = (Clp_Parser *)malloc(sizeof(Clp_Parser));
00162   Clp_Internal *cli = (Clp_Internal *)malloc(sizeof(Clp_Internal));
00163   Clp_LongMinMatch *lmm = (Clp_LongMinMatch *)malloc(sizeof(Clp_LongMinMatch) * nopt);
00164   if (!clp || !cli || !lmm) goto failed;
00165   
00166   clp->internal = cli;
00167   cli->long_min_match = lmm;
00168   
00169   /* Get rid of negative option_ids, which are internal to CLP */
00170   for (i = 0; i < nopt; i++)
00171     if (opt[i].option_id < 0) {
00172       fprintf(stderr, "CLP error: option %d has negative option_id\n", i);
00173       opt[i] = opt[nopt - 1];
00174       nopt--;
00175       i--;
00176     }
00177   
00178   /* Massage the options to make them usable */
00179   for (i = 0; i < nopt; i++) {
00180     /* Enforce invariants */
00181     if (opt[i].arg_type <= 0)
00182       opt[i].flags &= ~Clp_AnyArgument;
00183     if (opt[i].arg_type > 0 && !TEST(&opt[i], Clp_Optional))
00184       opt[i].flags |= Clp_Mandatory;
00185     
00186     /* Nonexistent short options have character 256. We know this won't
00187        equal any character in an argument, even if characters are signed */
00188     if (opt[i].short_name <= 0 || opt[i].short_name > 255)
00189       opt[i].short_name = 256;
00190     
00191     /* Options that start with `no-' should be changed to OnlyNegated */
00192     if (opt[i].long_name && strncmp(opt[i].long_name, "no-", 3) == 0) {
00193       opt[i].long_name += 3;
00194       opt[i].flags |= Clp_Negate | Clp_OnlyNegated;
00195     }
00196   }
00197   
00198   /* Check for duplicated short options */
00199   check_duplicated_short_options(nopt, opt, 0);
00200   check_duplicated_short_options(nopt, opt, 1);
00201   
00202   /* Calculate long options' minimum unambiguous length */
00203   for (i = 0; i < nopt; i++)
00204     if (opt[i].long_name && !TEST(&opt[i], Clp_OnlyNegated))
00205       lmm[i].pos = calculate_long_min_match
00206         (nopt, opt, i, Clp_OnlyNegated, 0);
00207   for (i = 0; i < nopt; i++)
00208     if (opt[i].long_name && TEST(&opt[i], Clp_Negate))
00209       lmm[i].neg = calculate_long_min_match
00210         (nopt, opt, i, Clp_Negate, Clp_Negate);
00211   
00212   /* Set up clp->internal */
00213   cli->opt = opt;
00214   cli->nopt = nopt;
00215   
00216   cli->argtype = (Clp_ArgType *)malloc(sizeof(Clp_ArgType) * 5);
00217   if (!cli->argtype) goto failed;
00218   cli->nargtype = 5;
00219   
00220   cli->argc = argc;
00221   cli->argv = argv;
00222   {
00223     char *slash = strrchr(argv[0], '/');
00224     cli->program_name = slash ? slash + 1 : argv[0];
00225   }
00226   cli->error_handler = 0;
00227   
00228   for (i = 0; i < 256; i++)
00229     cli->option_class[i] = 0;
00230   cli->option_class['-'] = Clp_Short;
00231   cli->both_short_and_long = 0;
00232   
00233   cli->is_short = 0;
00234   cli->whole_negated = 0;
00235   
00236   cli->option_processing = 1;
00237   cli->current_option = 0;
00238   
00239   /* Add default type parsers */
00240   Clp_AddType(clp, Clp_ArgString, 0, parse_string, 0);
00241   Clp_AddType(clp, Clp_ArgStringNotOption, Clp_DisallowOptions, parse_string, 0);
00242   Clp_AddType(clp, Clp_ArgInt, 0, parse_int, 0);
00243   Clp_AddType(clp, Clp_ArgUnsigned, 0, parse_int, (void *)cli);
00244   Clp_AddType(clp, Clp_ArgBool, 0, parse_bool, 0);
00245   Clp_AddType(clp, Clp_ArgDouble, 0, parse_double, 0);
00246   return clp;
00247   
00248  failed:
00249   if (cli && cli->argtype) free(cli->argtype);
00250   if (cli) free(cli);
00251   if (clp) free(clp);
00252   if (lmm) free(lmm);
00253   return 0;
00254 }

Clp_ParserState* Clp_NewParserState void   
 

Definition at line 768 of file clp.c.

References malloc.

00769 {
00770   return (Clp_ParserState *)malloc(sizeof(Clp_ParserState));
00771 }

int Clp_Next Clp_Parser  
 

Definition at line 1042 of file clp.c.

References ambiguity_error(), Clp_Internal::ambiguous, Clp_Internal::ambiguous_values, Clp_Parser::arg, Clp_Option::arg_type, Clp_Internal::argtype, Clp_Internal::argv, Clp_AnyArgument, Clp_BadOption, Clp_DisallowOptions, Clp_Done, Clp_Error, Clp_Mandatory, Clp_Negate, Clp_NotOption, Clp_OptionError(), Clp_RestoreParser(), Clp_SaveParser(), Clp_SetOptionProcessing(), Clp_Internal::could_be_short, Clp_Internal::current_option, Clp_Internal::current_short, find_long(), find_short(), Clp_ArgType::func, Clp_Parser::have_arg, Clp_Parser::internal, Clp_Internal::is_short, Clp_Internal::nargtype, Clp_Parser::negated, Clp_Internal::negated_by_no, next_argument(), Clp_Internal::opt, Clp_Internal::option_chars, Clp_Option::option_id, Clp_Internal::option_processing, switch_to_short_argument(), TEST, Clp_Internal::text, Clp_ArgType::thunk, and Clp_Internal::whole_negated.

Referenced by main().

01062 {
01063   Clp_Internal *cli = clp->internal;
01064   Clp_Option *opt;
01065   Clp_ParserState clpsave;
01066   int complain;
01067   
01068   /** Set up clp **/
01069   cli->current_option = 0;
01070   cli->ambiguous = 0;
01071   
01072   /** Get the next argument or option **/
01073   if (!next_argument(clp, cli->option_processing ? 0 : 2))
01074     return clp->have_arg ? Clp_NotOption : Clp_Done;
01075   
01076   clp->negated = cli->whole_negated;
01077   if (cli->is_short)
01078     opt = find_short(clp, cli->text[0]);
01079   else
01080     opt = find_long(clp, cli->text);
01081   
01082   /** If there's ambiguity between long & short options, and we couldn't find
01083       a long option, look for a short option **/
01084   if (!opt && cli->could_be_short) {
01085     switch_to_short_argument(clp);
01086     opt = find_short(clp, cli->text[0]);
01087   }
01088   
01089   /** If we didn't find an option... **/
01090   if (!opt || (clp->negated && !TEST(opt, Clp_Negate))) {
01091     
01092     /* default processing for the "--" option: turn off option processing
01093        and return the next argument */
01094     if (strcmp(cli->argv[0], "--") == 0) {
01095       Clp_SetOptionProcessing(clp, 0);
01096       return Clp_Next(clp);
01097     }
01098     
01099     /* otherwise, report some error or other */
01100     if (cli->ambiguous)
01101       ambiguity_error(clp, cli->ambiguous, cli->ambiguous_values,
01102                       cli->opt, cli->option_chars,
01103                       "option `%s%s' is ambiguous",
01104                       cli->option_chars, cli->text);
01105     else if (cli->is_short && !cli->could_be_short)
01106       Clp_OptionError(clp, "unrecognized option `%s%c'",
01107                       cli->option_chars, cli->text[0]);
01108     else
01109       Clp_OptionError(clp, "unrecognized option `%s%s'",
01110                       cli->option_chars, cli->text);
01111     return Clp_BadOption;
01112   }
01113   
01114   /** Set the current option **/
01115   cli->current_option = opt;
01116   cli->current_short = cli->is_short;
01117   cli->negated_by_no = clp->negated && !cli->whole_negated;
01118   
01119   /** The no-argument (or should-have-no-argument) case **/
01120   if (clp->negated || !TEST(opt, Clp_AnyArgument)) {
01121     if (clp->have_arg) {
01122       Clp_OptionError(clp, "`%O' can't take an argument");
01123       return Clp_BadOption;
01124     } else
01125       return opt->option_id;
01126   }
01127   
01128   /** Get an argument if we need one, or if it's optional **/
01129   /* Sanity-check the argument type. */
01130   if (opt->arg_type <= 0 || opt->arg_type >= cli->nargtype
01131       || cli->argtype[ opt->arg_type ].func == 0)
01132     return Clp_Error;
01133   
01134   /* complain == 1 only if the argument was explicitly given,
01135      or it is mandatory. */
01136   complain = (clp->have_arg != 0) || TEST(opt, Clp_Mandatory);
01137   Clp_SaveParser(clp, &clpsave);
01138   
01139   if (TEST(opt, Clp_Mandatory) && !clp->have_arg) {
01140     /* Mandatory argument case */
01141     /* Allow arguments to options to start with a dash, but only if the
01142        argument type allows it by not setting Clp_DisallowOptions */
01143     int disallow = TEST(&cli->argtype[opt->arg_type], Clp_DisallowOptions);
01144     next_argument(clp, disallow ? 1 : 2);
01145     if (!clp->have_arg) {
01146       int got_option = cli->text != 0;
01147       Clp_RestoreParser(clp, &clpsave);
01148       if (got_option)
01149         Clp_OptionError(clp, "`%O' requires a non-option argument");
01150       else
01151         Clp_OptionError(clp, "`%O' requires an argument");
01152       return Clp_BadOption;
01153     }
01154     
01155   } else if (cli->is_short && !clp->have_arg && cli->text[1] != 0)
01156     /* The -[option]argument case:
01157        Assume that the rest of the current string is the argument. */
01158     next_argument(clp, 1);
01159   
01160   /** Parse the argument **/
01161   if (clp->have_arg) {
01162     Clp_ArgType *atr = &cli->argtype[ opt->arg_type ];
01163     if (atr->func(clp, clp->arg, complain, atr->thunk) <= 0) {
01164       /* parser failed */
01165       clp->have_arg = 0;
01166       if (TEST(opt, Clp_Mandatory))
01167         return Clp_BadOption;
01168       else
01169         Clp_RestoreParser(clp, &clpsave);
01170     }
01171   }
01172   
01173   return opt->option_id;
01174 }

int Clp_OptionError Clp_Parser  ,
const char *   ,
...   
 

Definition at line 1376 of file clp.c.

References Clp_VaOptionError(), do_error(), and free_build_string().

Referenced by Clp_Next(), handle_extension(), main(), parse_bool(), parse_color(), parse_dimensions(), parse_double(), parse_frame_spec(), parse_int(), parse_position(), parse_rectangle(), parse_scale_factor(), and parse_two_colors().

01377 {
01378   Clp_BuildString *bs;
01379   va_list val;
01380   va_start(val, fmt);
01381   bs = Clp_VaOptionError(clp, 0, fmt, val);
01382   va_end(val);
01383   do_error(clp, bs);
01384   free_build_string(bs);
01385   return 0;
01386 }

char* Clp_ProgramName Clp_Parser  
 

Definition at line 757 of file clp.c.

References Clp_Parser::internal, and Clp_Internal::program_name.

Referenced by main().

00758 {
00759   return clp->internal->program_name;
00760 }

void Clp_RestoreParser Clp_Parser  ,
Clp_ParserState  
 

Definition at line 795 of file clp.c.

References Clp_ParserState::argc, Clp_Internal::argc, Clp_ParserState::argv, Clp_Internal::argv, Clp_Parser::internal, Clp_ParserState::is_short, Clp_Internal::is_short, Clp_ParserState::option_chars, Clp_Internal::option_chars, Clp_ParserState::text, Clp_Internal::text, Clp_ParserState::whole_negated, and Clp_Internal::whole_negated.

Referenced by Clp_Next(), and Clp_Shift().

00797 {
00798   Clp_Internal *cli = clp->internal;
00799   cli->argv = save->argv;
00800   cli->argc = save->argc;
00801   memcpy(cli->option_chars, save->option_chars, 3);
00802   cli->text = save->text;
00803   cli->is_short = save->is_short;
00804   cli->whole_negated = save->whole_negated;
00805 }

void Clp_SaveParser Clp_Parser  ,
Clp_ParserState  
 

Definition at line 781 of file clp.c.

References Clp_Internal::argc, Clp_ParserState::argc, Clp_Internal::argv, Clp_ParserState::argv, Clp_Parser::internal, Clp_Internal::is_short, Clp_ParserState::is_short, Clp_Internal::option_chars, Clp_ParserState::option_chars, Clp_Internal::text, Clp_ParserState::text, Clp_Internal::whole_negated, and Clp_ParserState::whole_negated.

Referenced by Clp_Next(), and Clp_Shift().

00783 {
00784   Clp_Internal *cli = clp->internal;
00785   save->argv = cli->argv;
00786   save->argc = cli->argc;
00787   memcpy(save->option_chars, cli->option_chars, 3);
00788   save->text = cli->text;
00789   save->is_short = cli->is_short;
00790   save->whole_negated = cli->whole_negated;
00791 }

Clp_ErrorHandler Clp_SetErrorHandler Clp_Parser  ,
Clp_ErrorHandler   
 

Referenced by main().

int Clp_SetOptionChar Clp_Parser  ,
int    c,
int    option_type
 

Definition at line 309 of file clp.c.

References Clp_Internal::both_short_and_long, c, Clp_Long, Clp_LongImplicit, Clp_LongNegated, Clp_Short, Clp_ShortNegated, i, Clp_Parser::internal, Clp_Internal::long_min_match, Clp_Internal::nopt, Clp_Internal::opt, and Clp_Internal::option_class.

Referenced by main().

00311                                     :
00312 
00313         0 == Clp_NotOption `character' isn't an option.
00314         Clp_Short       `character' introduces a list of short options.
00315         Clp_Long        `character' introduces a long option.
00316         Clp_ShortNegated `character' introduces a negated list of
00317                         short options.
00318         Clp_LongNegated `character' introduces a negated long option.
00319         Clp_LongImplicit `character' introduces a long option, and *is part
00320                         of the long option itself*.
00321 
00322         Some values are not allowed (Clp_Long | Clp_LongNegated isn't allowed,
00323         for instance). c=0 means ALL characters are that type. Returns 0 on
00324         failure (you gave an illegal option_type), 1 on success. */
00325 {
00326   int i;
00327   Clp_Internal *cli = clp->internal;
00328   
00329   if (option_type < 0 || option_type >= 2*Clp_LongImplicit
00330       || ((option_type & Clp_Short) && (option_type & Clp_ShortNegated))
00331       || ((option_type & Clp_Long) && (option_type & Clp_LongNegated))
00332       || ((option_type & Clp_LongImplicit) && (option_type & (Clp_Short | Clp_ShortNegated | Clp_Long | Clp_LongNegated))))
00333     return 0;
00334   
00335   if (c == 0)
00336     for (i = 1; i < 256; i++)
00337       cli->option_class[i] = option_type;
00338   else
00339     cli->option_class[c] = option_type;
00340 
00341   /* If an option character can introduce either short or long options, then
00342      we need to fix up the long_min_match values. We may have set the
00343      long_min_match for option `--abcde' to 1, if no other option starts with
00344      `a'. But if `-' can introduce either a short option or a long option, AND
00345      a short option `-a' exists, then the long_min_match for `--abcde' must be
00346      set to 2! */
00347   if (!cli->both_short_and_long) {
00348     int either_short = option_type & (Clp_Short | Clp_ShortNegated);
00349     int either_long = option_type & (Clp_Long | Clp_LongNegated);
00350     if (either_short && either_long) {
00351       unsigned char have_short[257];
00352       for (i = 0; i < 256; i++)
00353         have_short[i] = 0;
00354       for (i = 0; i < cli->nopt; i++)
00355         have_short[cli->opt[i].short_name] = 1;
00356       for (i = 0; i < cli->nopt; i++)
00357         if (cli->opt[i].long_name && cli->long_min_match[i].pos == 1) {
00358           /* if `--Cxxxx's short name is `-C', keep long_min_match == 1 */
00359           unsigned char first = (unsigned char)cli->opt[i].long_name[0];
00360           if (have_short[first] && first != cli->opt[i].short_name)
00361             cli->long_min_match[i].pos++;
00362         }
00363       cli->both_short_and_long = 1;
00364     }
00365   }
00366   
00367   return 1;
00368 }

int Clp_SetOptionProcessing Clp_Parser  ,
int    option_processing
 

Definition at line 284 of file clp.c.

References Clp_Parser::internal, and Clp_Internal::option_processing.

Referenced by Clp_Next().

00288 {
00289   Clp_Internal *cli = clp->internal;
00290   int old = cli->option_processing;
00291   cli->option_processing = option_processing;
00292   return old;
00293 }

char* Clp_Shift Clp_Parser   clp,
int    allow_dashes
 

Parse the argument *

Definition at line 1178 of file clp.c.

References Clp_Parser::arg, Clp_RestoreParser(), Clp_SaveParser(), Clp_Parser::have_arg, and next_argument().

Referenced by handle_extension(), and parse_two_colors().

01181 {
01182   Clp_ParserState clpsave;
01183   Clp_SaveParser(clp, &clpsave);
01184   next_argument(clp, allow_dashes ? 2 : 1);
01185   if (!clp->have_arg)
01186     Clp_RestoreParser(clp, &clpsave);
01187   return clp->arg;
01188 }
 

Powered by Plone

This site conforms to the following standards: