Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

popt/popt.h File Reference

More...

#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  poptAlias
struct  poptItem_s
struct  poptOption

Arg type identifiers

#define POPT_ARG_NONE   0
#define POPT_ARG_STRING   1
#define POPT_ARG_INT   2
#define POPT_ARG_LONG   3
#define POPT_ARG_INCLUDE_TABLE   4
#define POPT_ARG_CALLBACK   5
#define POPT_ARG_INTL_DOMAIN   6
#define POPT_ARG_VAL   7
#define POPT_ARG_FLOAT   8
#define POPT_ARG_DOUBLE   9
#define POPT_ARG_MASK   0x0000FFFF

Arg modifiers

#define POPT_ARGFLAG_ONEDASH   0x80000000
#define POPT_ARGFLAG_DOC_HIDDEN   0x40000000
#define POPT_ARGFLAG_STRIP   0x20000000
#define POPT_ARGFLAG_OPTIONAL   0x10000000
#define POPT_ARGFLAG_OR   0x08000000
#define POPT_ARGFLAG_NOR   0x09000000
#define POPT_ARGFLAG_AND   0x04000000
#define POPT_ARGFLAG_NAND   0x05000000
#define POPT_ARGFLAG_XOR   0x02000000
#define POPT_ARGFLAG_NOT   0x01000000
#define POPT_ARGFLAG_LOGICALOPS   (POPT_ARGFLAG_OR|POPT_ARGFLAG_AND|POPT_ARGFLAG_XOR)
#define POPT_BIT_SET   (POPT_ARG_VAL|POPT_ARGFLAG_OR)
#define POPT_BIT_CLR   (POPT_ARG_VAL|POPT_ARGFLAG_NAND)
#define POPT_ARGFLAG_SHOW_DEFAULT   0x00800000

Callback modifiers

#define POPT_CBFLAG_PRE   0x80000000
#define POPT_CBFLAG_POST   0x40000000
#define POPT_CBFLAG_INC_DATA   0x20000000
#define POPT_CBFLAG_SKIPOPTION   0x10000000
#define POPT_CBFLAG_CONTINUE   0x08000000

Error return values

#define POPT_ERROR_NOARG   -10
#define POPT_ERROR_BADOPT   -11
#define POPT_ERROR_OPTSTOODEEP   -13
#define POPT_ERROR_BADQUOTE   -15
#define POPT_ERROR_ERRNO   -16
#define POPT_ERROR_BADNUMBER   -17
#define POPT_ERROR_OVERFLOW   -18
#define POPT_ERROR_BADOPERATION   -19
#define POPT_ERROR_NULLARG   -20
#define POPT_ERROR_MALLOC   -21

poptBadOption() flags

#define POPT_BADOPTION_NOALIAS   (1 << 0)

poptGetContext() flags

#define POPT_CONTEXT_NO_EXEC   (1 << 0)
#define POPT_CONTEXT_KEEP_FIRST   (1 << 1)
#define POPT_CONTEXT_POSIXMEHARDER   (1 << 2)
#define POPT_CONTEXT_ARG_OPTS   (1 << 4)

Auto-generated help/usage

#define POPT_AUTOALIAS
#define POPT_AUTOHELP
#define POPT_TABLEEND   { NULL, '\0', 0, 0, 0, NULL, NULL }
poptOption poptAliasOptions []
 Empty table marker to enable displaying popt alias/exec options.

poptOption poptHelpOptions []
 Auto help table options.


Defines

#define POPT_OPTION_DEPTH   10

Typedefs

typedef poptItem_spoptItem
typedef poptContext_spoptContext
typedef poptOption * poptOption
typedef void(* poptCallbackType )(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)

Enumerations

enum  poptCallbackReason { POPT_CALLBACK_REASON_PRE = 0, POPT_CALLBACK_REASON_POST = 1, POPT_CALLBACK_REASON_OPTION = 2 }

Functions

poptContext poptGetContext (const char *name, int argc, const char **argv, const struct poptOption *options, int flags)
void poptResetContext (poptContext con)
int poptGetNextOpt (poptContext con)
const char * poptGetOptArg (poptContext con)
const char * poptGetArg (poptContext con)
const char * poptPeekArg (poptContext con)
const char ** poptGetArgs (poptContext con)
const char * poptBadOption (poptContext con, int flags)
poptContext poptFreeContext (poptContext con)
int poptStuffArgs (poptContext con, const char **argv)
int poptAddAlias (poptContext con, struct poptAlias alias, int flags)
int poptAddItem (poptContext con, poptItem newItem, int flags)
int poptReadConfigFile (poptContext con, const char *fn)
int poptReadDefaultConfig (poptContext con, int useEnv)
int poptDupArgv (int argc, const char **argv, int *argcPtr, const char ***argvPtr)
int poptParseArgvString (const char *s, int *argcPtr, const char ***argvPtr)
int poptConfigFileToString (FILE *fp, char **argstrp, int flags)
const char *const poptStrerror (const int error)
void poptSetExecPath (poptContext con, const char *path, int allowAbsolute)
void poptPrintHelp (poptContext con, FILE *fp, int flags)
void poptPrintUsage (poptContext con, FILE *fp, int flags)
void poptSetOtherOptionHelp (poptContext con, const char *text)
const char * poptGetInvocationName (poptContext con)
int poptStrippedArgv (poptContext con, int argc, char **argv)
int poptSaveLong (long *arg, int argInfo, long aLong)
 Save a long, performing logical operation with value.

int poptSaveInt (int *arg, int argInfo, long aLong)
 Save an integer, performing logical operation with value.


Detailed Description

Definition in file popt.h.


Define Documentation

#define POPT_AUTOALIAS
 

Value:

{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptAliasOptions, \
                        0, "Options implemented via popt alias/exec:", NULL },

Definition at line 164 of file popt.h.

#define POPT_AUTOHELP
 

Value:

{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, \
                        0, "Help options:", NULL },

Definition at line 174 of file popt.h.

#define POPT_OPTION_DEPTH   10
 

Definition at line 14 of file popt.h.

Referenced by handleAlias(), and poptStuffArgs().

#define POPT_TABLEEND   { NULL, '\0', 0, 0, 0, NULL, NULL }
 

Definition at line 177 of file popt.h.


Enumeration Type Documentation

enum poptCallbackReason
 

Enumeration values:
POPT_CALLBACK_REASON_PRE 
POPT_CALLBACK_REASON_POST 
POPT_CALLBACK_REASON_OPTION 

Definition at line 195 of file popt.h.

Referenced by buildArgCallback(), displayArgs(), installArgCallback(), queryArgCallback(), rpmcliAllArgCallback(), and rpmQVSourceArgCallback().


Function Documentation

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 1080 of file popt.c.

References alloca(), poptOption::arg, poptAlias::argc, poptItem_s::argc, poptOption::argDescrip, poptOption::argInfo, poptAlias::argv, poptItem_s::argv, poptOption::descrip, poptAlias::longName, poptOption::longName, poptItem_s::option, POPT_ARGFLAG_DOC_HIDDEN, poptAddItem(), poptAlias::shortName, poptOption::shortName, and poptOption::val.

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 1099 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,
int    flags
 

Return the option which caused the most recent error.

Parameters:
con  context
flags 
Returns:
offending option

Definition at line 1144 of file popt.c.

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

Referenced by main(), and rpmcliInit().

poptContext poptFreeContext poptContext    con
 

Destroy context.

Parameters:
con  context
Returns:
NULL always

Definition at line 1036 of file popt.c.

References _free(), poptContext_s::aliases, poptContext_s::appName, poptContext_s::arg_strip, optionStackEntry::argb, poptOption::argDescrip, poptItem_s::argv, poptOption::descrip, poptContext_s::execPath, poptContext_s::execs, poptContext_s::finalArgv, poptContext_s::leftovers, poptOption::longName, poptContext_s::numAliases, poptContext_s::numExecs, poptItem_s::option, poptContext_s::os, poptContext_s::otherHelp, PBM_FREE, and poptResetContext().

Referenced by doSetupMacro(), main(), parseDescription(), parseFiles(), parseScript(), and rpmcliFini().

const char* poptGetArg poptContext    con
 

Return next argument.

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

Definition at line 1004 of file popt.c.

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

Referenced by main(), parseDescription(), parseFiles(), and parseScript().

const char** poptGetArgs poptContext    con
 

Return remaining arguments.

Parameters:
con  context
Returns:
argument array, NULL terminated

Definition at line 1021 of file popt.c.

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

Referenced by main().

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

Initialize popt context.

Parameters:
name  context name (usually argv[0] program name)
argc  no. of arguments
argv  argument array
options  address of popt option table
flags  or'd POPT_CONTEXT_* bits
Returns:
initialized popt context

Definition at line 153 of file popt.c.

References poptContext_s::aliases, poptContext_s::appName, poptContext_s::arg_strip, optionStackEntry::argb, optionStackEntry::argc, optionStackEntry::argv, argv, poptContext_s::execAbsolute, poptContext_s::execs, poptContext_s::finalArgv, poptContext_s::finalArgvAlloced, poptContext_s::flags, getenv(), 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.

Referenced by doSetupMacro(), main(), parseDescription(), parseFiles(), parseScript(), and rpmcliInit().

const char* poptGetInvocationName poptContext    con
 

Return argv[0] from context.

Parameters:
con  context
Returns:
argv[0]

Definition at line 1207 of file popt.c.

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

int poptGetNextOpt poptContext    con
 

Return value of next option found.

Parameters:
con  context
Returns:
next option val, -1 on last item, POPT_ERROR_* on error

Definition at line 682 of file popt.c.

References _free(), alloca(), poptOption::arg, optionStackEntry::argb, optionStackEntry::argc, poptOption::argInfo, optionStackEntry::argv, cleanOSE(), poptContext_s::doExec, errno, execCommand(), EXIT_FAILURE, expandNextArg(), poptContext_s::finalArgv, poptContext_s::finalArgvAlloced, poptContext_s::finalArgvCount, findOption(), poptContext_s::flags, handleAlias(), handleExec(), invokeCallbacksOPTION(), invokeCallbacksPOST(), poptContext_s::leftovers, poptOption::longName, 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_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().

Referenced by doSetupMacro(), main(), parseDescription(), parseFiles(), parseScript(), and rpmcliInit().

const 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 992 of file popt.c.

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

Referenced by doSetupMacro(), main(), and rpmcliInit().

const char* poptPeekArg poptContext    con
 

Peek at current argument.

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

Definition at line 1012 of file popt.c.

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

Referenced by main(), parseDescription(), parseFiles(), and parseScript().

void poptResetContext poptContext    con
 

Reinitialize popt context.

Parameters:
con  context

Definition at line 211 of file popt.c.

References _free(), poptContext_s::arg_strip, optionStackEntry::argb, cleanOSE(), optionStackEntry::currAlias, poptContext_s::doExec, poptContext_s::finalArgv, poptContext_s::finalArgvCount, optionStackEntry::next, optionStackEntry::nextArg, optionStackEntry::nextCharArg, poptContext_s::nextLeftover, poptContext_s::numLeftovers, poptContext_s::optionStack, poptContext_s::os, PBM_FREE, and poptContext_s::restLeftover.

Referenced by poptFreeContext().

int poptSaveInt int *    arg,
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 652 of file popt.c.

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

Referenced by db3New(), and poptGetNextOpt().

int poptSaveLong long *    arg,
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 624 of file popt.c.

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

Referenced by db3New(), and 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 52 of file popt.c.

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

Referenced by main(), and rpmcliInit().

const char* const poptStrerror const int    error
 

Return formatted error string for popt failure.

Parameters:
error  popt error
Returns:
error string

Definition at line 1156 of file popt.c.

References errno, error(), 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().

Referenced by doSetupMacro(), main(), and rpmcliInit().

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 1213 of file popt.c.

References poptContext_s::arg_strip, argv, 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 1184 of file popt.c.

References optionStackEntry::argb, optionStackEntry::argc, optionStackEntry::argv, 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.

Referenced by queryArgCallback().


Variable Documentation

struct poptOption poptHelpOptions[]
 

Auto help table options.

Definition at line 172 of file popt.h.


Generated on Sun Oct 26 13:02:06 2003 for rpm by doxygen1.2.18