popt  1.13
Macros | Functions | Variables
popt.c File Reference
#include "system.h"
#include <math.h>
#include "findme.h"
#include "poptint.h"
Include dependency graph for popt.c:

Go to the source code of this file.

Macros

#define _ABS(a)   ((((a) - 0.0) < DBL_EPSILON) ? -(a) : (a))

Functions

static char * strerror (int errno)
void poptSetExecPath (poptContext con, const char *path, int allowAbsolute)
 Limit search for executables.
static void invokeCallbacksPRE (poptContext con, const struct poptOption *opt)
static void invokeCallbacksPOST (poptContext con, const struct poptOption *opt)
static void invokeCallbacksOPTION (poptContext con, const struct poptOption *opt, const struct poptOption *myOpt, const void *myData, int shorty)
poptContext poptGetContext (const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
 Initialize popt context.
static void cleanOSE (struct optionStackEntry *os)
void poptResetContext (poptContext con)
 Reinitialize popt context.
static int handleExec (poptContext con, const char *longName, char shortName)
static int handleAlias (poptContext con, const char *longName, size_t longNameLen, char shortName, const char *nextArg)
static int execCommand (poptContext con)
static struct poptOptionfindOption (const struct poptOption *opt, const char *longName, int longNameLen, char shortName, poptCallbackType *callback, const void **callbackData, int singleDash)
static const char * findNextArg (poptContext con, unsigned argx, int delete_arg)
static const char * expandNextArg (poptContext con, const char *s)
static void poptStripArg (poptContext con, int which)
int poptSaveLong (long *arg, unsigned int argInfo, long aLong)
 Save a long, performing logical operation with value.
int poptSaveInt (int *arg, unsigned int argInfo, long aLong)
 Save an integer, performing logical operation with value.
int poptGetNextOpt (poptContext con)
 Return value of next option found.
char * poptGetOptArg (poptContext con)
 Return next option argument (if any).
const char * poptGetArg (poptContext con)
 Return next argument.
const char * poptPeekArg (poptContext con)
 Peek at current argument.
const char ** poptGetArgs (poptContext con)
 Return remaining arguments.
poptContext poptFreeContext (poptContext con)
 Destroy context.
int poptAddAlias (poptContext con, struct poptAlias alias, int flags)
 Add alias to context.
int poptAddItem (poptContext con, poptItem newItem, int flags)
 Add alias/exec item to context.
const char * poptBadOption (poptContext con, unsigned int flags)
 Return the option which caused the most recent error.
const char * poptStrerror (const int error)
 Return formatted error string for popt failure.
int poptStuffArgs (poptContext con, const char **argv)
 Add arguments to context.
const char * poptGetInvocationName (poptContext con)
 Return argv[0] from context.
int poptStrippedArgv (poptContext con, int argc, char **argv)
 Shuffle argv pointers to remove stripped args, returns new argc.

Variables

static unsigned int seed = 0

Macro Definition Documentation

#define _ABS (   a)    ((((a) - 0.0) < DBL_EPSILON) ? -(a) : (a))

Referenced by poptGetNextOpt().

Function Documentation

static void cleanOSE ( struct optionStackEntry os)
static
static int execCommand ( poptContext  con)
static
static const char* expandNextArg ( poptContext  con,
const char *  s 
)
static

Definition at line 591 of file popt.c.

References findNextArg().

Referenced by poptGetNextOpt().

static const char* findNextArg ( poptContext  con,
unsigned  argx,
int  delete_arg 
)
static
static struct poptOption* findOption ( const struct poptOption opt,
const char *  longName,
int  longNameLen,
char  shortName,
poptCallbackType callback,
const void **  callbackData,
int  singleDash 
)
staticread

< arg points to table

< table-wide callback... must be set first in table; arg points to callback, descrip points to callback data to pass

< allow -longoption

< use data from the include line, not the subtable

Definition at line 485 of file popt.c.

References poptOption::arg, poptOption::argInfo, poptOption::descrip, poptOption::longName, POPT_ARG_CALLBACK, POPT_ARG_INCLUDE_TABLE, POPT_ARG_MASK, POPT_ARGFLAG_ONEDASH, POPT_CBFLAG_INC_DATA, poptHelpOptions, poptHelpOptionsI18N, and poptOption::shortName.

Referenced by poptGetNextOpt().

static int handleAlias ( poptContext  con,
const char *  longName,
size_t  longNameLen,
char  shortName,
const char *  nextArg 
)
static
static int handleExec ( poptContext  con,
const char *  longName,
char  shortName 
)
static
static void invokeCallbacksOPTION ( poptContext  con,
const struct poptOption opt,
const struct poptOption myOpt,
const void *  myData,
int  shorty 
)
static

< arg points to table

< table-wide callback... must be set first in table; arg points to callback, descrip points to callback data to pass

< don't callback with option

< continue callbacks with option

Definition at line 116 of file popt.c.

References poptOption::arg, poptOption::argInfo, poptOption::descrip, poptOption::longName, optionStackEntry::nextArg, poptContext_s::os, POPT_ARG_CALLBACK, POPT_ARG_INCLUDE_TABLE, POPT_ARG_MASK, POPT_CALLBACK_REASON_OPTION, POPT_CBFLAG_CONTINUE, POPT_CBFLAG_SKIPOPTION, poptHelpOptions, poptHelpOptionsI18N, and poptOption::shortName.

Referenced by poptGetNextOpt().

static void invokeCallbacksPOST ( poptContext  con,
const struct poptOption opt 
)
static

< arg points to table

< table-wide callback... must be set first in table; arg points to callback, descrip points to callback data to pass

< call the callback after parse

Definition at line 90 of file popt.c.

References poptOption::arg, poptOption::argInfo, poptOption::descrip, poptOption::longName, POPT_ARG_CALLBACK, POPT_ARG_INCLUDE_TABLE, POPT_ARG_MASK, POPT_CALLBACK_REASON_POST, POPT_CBFLAG_POST, poptHelpOptions, poptHelpOptionsI18N, and poptOption::shortName.

Referenced by poptGetNextOpt().

static void invokeCallbacksPRE ( poptContext  con,
const struct poptOption opt 
)
static

< arg points to table

< table-wide callback... must be set first in table; arg points to callback, descrip points to callback data to pass

< call the callback before parse

Definition at line 64 of file popt.c.

References poptOption::arg, poptOption::argInfo, poptOption::descrip, poptOption::longName, POPT_ARG_CALLBACK, POPT_ARG_INCLUDE_TABLE, POPT_ARG_MASK, POPT_CALLBACK_REASON_PRE, POPT_CBFLAG_PRE, poptHelpOptions, poptHelpOptionsI18N, and poptOption::shortName.

Referenced by poptGetContext().

int poptAddAlias ( poptContext  con,
struct poptAlias  alias,
int  flags 
)

Add alias to context.

Todo:
Pass alias by reference, not value.
Deprecated:
Use poptAddItem instead.
Parameters
concontext
aliasalias to add
flags(unused)
Returns
0 on success

< don't show in help/usage

Definition at line 1136 of file popt.c.

References poptAlias::argc, poptAlias::argv, poptAlias::longName, POPT_ARGFLAG_DOC_HIDDEN, poptAddItem(), and poptAlias::shortName.

int poptAddItem ( poptContext  con,
poptItem  newItem,
int  flags 
)

Add alias/exec item to context.

Parameters
concontext
newItemalias/exec item to add
flags0 for alias, 1 for exec
Returns
0 on success

Definition at line 1154 of file popt.c.

References poptContext_s::aliases, poptOption::arg, poptItem_s::argc, poptOption::argDescrip, poptOption::argInfo, poptItem_s::argv, poptOption::descrip, poptContext_s::execs, poptOption::longName, poptContext_s::numAliases, poptContext_s::numExecs, poptItem_s::option, poptOption::shortName, poptOption::val, and xstrdup().

Referenced by configLine(), and poptAddAlias().

const char* poptBadOption ( poptContext  con,
unsigned int  flags 
)

Return the option which caused the most recent error.

Parameters
concontext
flags
Returns
offending option

< don't go into an alias

Definition at line 1197 of file popt.c.

References optionStackEntry::argv, poptContext_s::execFail, optionStackEntry::next, poptContext_s::optionStack, poptContext_s::os, and POPT_BADOPTION_NOALIAS.

poptContext poptFreeContext ( poptContext  con)
const char* poptGetArg ( poptContext  con)

Return next argument.

Parameters
concontext
Returns
next argument, NULL if no argument is available

Definition at line 1062 of file popt.c.

References poptContext_s::leftovers, poptContext_s::nextLeftover, and poptContext_s::numLeftovers.

const char** poptGetArgs ( poptContext  con)

Return remaining arguments.

Parameters
concontext
Returns
argument array, NULL terminated

Definition at line 1078 of file popt.c.

References poptContext_s::leftovers, poptContext_s::nextLeftover, and poptContext_s::numLeftovers.

poptContext poptGetContext ( const char *  name,
int  argc,
const char **  argv,
const struct poptOption options,
unsigned int  flags 
)

Initialize popt context.

Parameters
namecontext name (usually argv[0] program name)
argcno. of arguments
argvargument array
optionsaddress of popt option table
flagsor'd POPT_CONTEXT_* bits
Returns
initialized popt context

< pay attention to argv[0]

< options can't follow args

Definition at line 162 of file popt.c.

References poptContext_s::aliases, poptContext_s::appName, poptContext_s::arg_strip, optionStackEntry::argb, optionStackEntry::argc, optionStackEntry::argv, poptContext_s::execAbsolute, poptContext_s::execFail, poptContext_s::execs, poptContext_s::finalArgv, poptContext_s::finalArgvAlloced, poptContext_s::flags, invokeCallbacksPRE(), poptContext_s::leftovers, optionStackEntry::next, poptContext_s::numAliases, poptContext_s::numExecs, poptContext_s::options, poptContext_s::optionStack, poptContext_s::os, POPT_CONTEXT_KEEP_FIRST, and POPT_CONTEXT_POSIXMEHARDER.

const char* poptGetInvocationName ( poptContext  con)

Return argv[0] from context.

Parameters
concontext
Returns
argv[0]

Definition at line 1266 of file popt.c.

References optionStackEntry::argv, and poptContext_s::os.

int poptGetNextOpt ( poptContext  con)

Return value of next option found.

Parameters
concontext
Returns
next option val, -1 on last item, POPT_ERROR_* on error

< unknown option

< options can't follow args

< return args as options with value 0

< unknown option

< unknown option

< strip this arg from argv(only applies to long args)

< unknown option

< unknown option

< no arg

< mutually exclusive logical operations requested

< arg should take value val

< mutually exclusive logical operations requested

< no arg

< arg may be missing

< missing argument

< strip this arg from argv(only applies to long args)

< arg may be missing

< arg will be saved as string

< arg will be converted to int

< arg will be converted to long

< invalid numeric value

< arg will be converted to long

< number too large or too small

< mutually exclusive logical operations requested

< number too large or too small

< mutually exclusive logical operations requested

< arg will be converted to float

< arg will be converted to double

< number too large or too small

< invalid numeric value

< arg will be converted to double

< number too large or too small

< number too large or too small

< return (*arg) (argc, argv)

< arg should take value val

< allow -longoption

< no arg

< arg should take value val

< no arg

Definition at line 735 of file popt.c.

References _ABS, _free(), poptOption::arg, optionStackEntry::argb, optionStackEntry::argc, poptOption::argInfo, optionStackEntry::argv, cleanOSE(), poptContext_s::doExec, execCommand(), expandNextArg(), poptContext_s::finalArgv, poptContext_s::finalArgvAlloced, poptContext_s::finalArgvCount, findOption(), poptContext_s::flags, handleAlias(), handleExec(), invokeCallbacksOPTION(), invokeCallbacksPOST(), poptContext_s::leftovers, poptOption::longName, poptContext_s::maincall, optionStackEntry::next, optionStackEntry::nextArg, optionStackEntry::nextCharArg, poptContext_s::numLeftovers, poptContext_s::options, poptContext_s::optionStack, poptContext_s::os, PBM_ISSET, POPT_, POPT_ARG_DOUBLE, POPT_ARG_FLOAT, POPT_ARG_INT, POPT_ARG_LONG, POPT_ARG_MAINCALL, POPT_ARG_MASK, POPT_ARG_NONE, POPT_ARG_STRING, POPT_ARG_VAL, POPT_ARGFLAG_ONEDASH, POPT_ARGFLAG_OPTIONAL, POPT_ARGFLAG_STRIP, POPT_CONTEXT_ARG_OPTS, POPT_CONTEXT_POSIXMEHARDER, POPT_ERROR_BADNUMBER, POPT_ERROR_BADOPERATION, POPT_ERROR_BADOPT, POPT_ERROR_NOARG, POPT_ERROR_OVERFLOW, poptSaveInt(), poptSaveLong(), poptStripArg(), poptContext_s::restLeftover, poptOption::shortName, poptOption::val, and xstrdup().

char* poptGetOptArg ( poptContext  con)

Return next option argument (if any).

Parameters
concontext
Returns
option argument, NULL if no argument is available

Definition at line 1052 of file popt.c.

References optionStackEntry::nextArg, and poptContext_s::os.

const char* poptPeekArg ( poptContext  con)

Peek at current argument.

Parameters
concontext
Returns
current argument, NULL if no argument is available

Definition at line 1070 of file popt.c.

References poptContext_s::leftovers, poptContext_s::nextLeftover, and poptContext_s::numLeftovers.

void poptResetContext ( poptContext  con)
int poptSaveInt ( int *  arg,
unsigned int  argInfo,
long  aLong 
)

Save an integer, performing logical operation with value.

Warning
Alignment check may be too strict on certain platorms.
Parameters
arginteger pointer, aligned on int boundary.
argInfological operation (see POPT_ARGFLAG_*)
aLongvalue to use
Returns
0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION

< opt->arg should not be NULL

< arg will be negated

< arg will be or'ed

< arg will be and'ed

< arg will be xor'ed

< arg will be or'ed

< arg will be and'ed

< arg will be xor'ed

< mutually exclusive logical operations requested

Definition at line 697 of file popt.c.

References POPT_ARGFLAG_AND, POPT_ARGFLAG_LOGICALOPS, POPT_ARGFLAG_NOT, POPT_ARGFLAG_OR, POPT_ARGFLAG_RANDOM, POPT_ARGFLAG_XOR, POPT_ERROR_BADOPERATION, and POPT_ERROR_NULLARG.

Referenced by poptGetNextOpt().

int poptSaveLong ( long *  arg,
unsigned int  argInfo,
long  aLong 
)

Save a long, performing logical operation with value.

Warning
Alignment check may be too strict on certain platorms.
Parameters
arginteger pointer, aligned on int boundary.
argInfological operation (see POPT_ARGFLAG_*)
aLongvalue to use
Returns
0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION

< opt->arg should not be NULL

< arg will be negated

< arg will be or'ed

< arg will be and'ed

< arg will be xor'ed

< arg will be or'ed

< arg will be and'ed

< arg will be xor'ed

< mutually exclusive logical operations requested

Definition at line 659 of file popt.c.

References POPT_ARGFLAG_AND, POPT_ARGFLAG_LOGICALOPS, POPT_ARGFLAG_NOT, POPT_ARGFLAG_OR, POPT_ARGFLAG_RANDOM, POPT_ARGFLAG_XOR, POPT_ERROR_BADOPERATION, and POPT_ERROR_NULLARG.

Referenced by poptGetNextOpt().

void poptSetExecPath ( poptContext  con,
const char *  path,
int  allowAbsolute 
)

Limit search for executables.

Parameters
concontext
pathsingle path to search for executables
allowAbsoluteabsolute paths only?

Definition at line 54 of file popt.c.

References _free(), poptContext_s::execAbsolute, poptContext_s::execPath, and xstrdup().

const char* poptStrerror ( const int  error)

Return formatted error string for popt failure.

Parameters
errorpopt error
Returns
error string

< missing argument

< unknown option

< mutually exclusive logical operations requested

< opt->arg should not be NULL

< aliases nested too deeply

< error in paramter quoting

< invalid numeric value

< number too large or too small

< memory allocation failed

< errno set, use strerror(errno)

Definition at line 1215 of file popt.c.

References POPT_, POPT_ERROR_BADNUMBER, POPT_ERROR_BADOPERATION, POPT_ERROR_BADOPT, POPT_ERROR_BADQUOTE, POPT_ERROR_ERRNO, POPT_ERROR_MALLOC, POPT_ERROR_NOARG, POPT_ERROR_NULLARG, POPT_ERROR_OPTSTOODEEP, POPT_ERROR_OVERFLOW, and strerror().

static void poptStripArg ( poptContext  con,
int  which 
)
static
int poptStrippedArgv ( poptContext  con,
int  argc,
char **  argv 
)

Shuffle argv pointers to remove stripped args, returns new argc.

Parameters
concontext
argcno. of args
argvarg vector
Returns
new argc

Definition at line 1271 of file popt.c.

References poptContext_s::arg_strip, optionStackEntry::argc, and PBM_ISSET.

int poptStuffArgs ( poptContext  con,
const char **  argv 
)

Add arguments to context.

Parameters
concontext
argvargument array, NULL terminated
Returns
0 on success, POPT_ERROR_OPTSTOODEEP on failure

< aliases nested too deeply

Definition at line 1243 of file popt.c.

References optionStackEntry::argb, optionStackEntry::argc, optionStackEntry::argv, optionStackEntry::currAlias, optionStackEntry::next, optionStackEntry::nextArg, optionStackEntry::nextCharArg, poptContext_s::optionStack, poptContext_s::os, POPT_ERROR_OPTSTOODEEP, POPT_OPTION_DEPTH, poptDupArgv(), and optionStackEntry::stuffed.

static char* strerror ( int  errno)
static

Definition at line 27 of file popt.c.

References POPT_.

Referenced by poptStrerror().

Variable Documentation

unsigned int seed = 0
static

Definition at line 656 of file popt.c.


Generated for popt by  doxygen 1.8.1.2