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.

Defines

#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, char shortName, const char *nextCharArg)
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

Define Documentation

#define _ABS (  )     ((((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 569 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 
) [static, read]
static int handleAlias ( poptContext  con,
const char *  longName,
char  shortName,
const char *  nextCharArg 
) [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]
static void invokeCallbacksPOST ( poptContext  con,
const struct poptOption opt 
) [static]
static void invokeCallbacksPRE ( poptContext  con,
const struct poptOption opt 
) [static]
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:
con context
alias alias to add
flags (unused)
Returns:
0 on success

Definition at line 1112 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:
con context
newItem alias/exec item to add
flags 0 for alias, 1 for exec
Returns:
0 on success

Definition at line 1130 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:
con context
flags 
Returns:
offending option

Definition at line 1173 of file popt.c.

References optionStackEntry::argv, 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:
con context
Returns:
next argument, NULL if no argument is available

Definition at line 1038 of file popt.c.

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

const char** poptGetArgs ( poptContext  con  ) 

Return remaining arguments.

Parameters:
con context
Returns:
argument array, NULL terminated

Definition at line 1054 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 
)
const char* poptGetInvocationName ( poptContext  con  ) 

Return argv[0] from context.

Parameters:
con context
Returns:
argv[0]

Definition at line 1234 of file popt.c.

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

int poptGetNextOpt ( poptContext  con  ) 
char* poptGetOptArg ( poptContext  con  ) 

Return next option argument (if any).

Parameters:
con context
Returns:
option argument, NULL if no argument is available

Definition at line 1028 of file popt.c.

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

const char* poptPeekArg ( poptContext  con  ) 

Peek at current argument.

Parameters:
con context
Returns:
current argument, NULL if no argument is available

Definition at line 1046 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:
arg integer pointer, aligned on int boundary.
argInfo logical operation (see POPT_ARGFLAG_*)
aLong value to use
Returns:
0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION

Definition at line 675 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:
arg integer pointer, aligned on int boundary.
argInfo logical operation (see POPT_ARGFLAG_*)
aLong value to use
Returns:
0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION

Definition at line 637 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:
con context
path single path to search for executables
allowAbsolute absolute 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:
error popt error
Returns:
error string

Definition at line 1183 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:
con context
argc no. of args
argv arg vector
Returns:
new argc

Definition at line 1239 of file popt.c.

References poptContext_s::arg_strip, and PBM_ISSET.

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

Add arguments to context.

Parameters:
con context
argv argument array, NULL terminated
Returns:
0 on success, POPT_ERROR_OPTSTOODEEP on failure

Definition at line 1211 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 634 of file popt.c.


Generated for popt by  doxygen 1.6.1