popt  1.16
Data Structures | Macros | Typedefs | Functions | Variables
popthelp.c File Reference
#include "system.h"
#include <sys/ioctl.h>
#include <wchar.h>
#include "poptint.h"
Include dependency graph for popthelp.c:

Go to the source code of this file.

Data Structures

struct  columns_s
 
struct  poptDone_s
 Keep track of option tables already processed. More...
 

Macros

#define POPT_USE_TIOCGWINSZ
 
#define POPT_WCHAR_HACK
 
#define _POPTHELP_MAXLINE   ((size_t)79)
 
#define prtlong   (opt->longName != NULL) /* XXX splint needs a clue */
 
#define prtlong   (opt->longName != NULL) /* XXX splint needs a clue */
 

Typedefs

typedef struct columns_scolumns_t
 
typedef struct poptDone_spoptDone
 Keep track of option tables already processed. More...
 

Functions

static void displayArgs (poptContext con, enum poptCallbackReason foo, struct poptOption *key, const char *arg, void *data)
 Display arguments. More...
 
static size_t maxColumnWidth (FILE *fp)
 Return no. More...
 
static size_t stringDisplayWidth (const char *s)
 Determine number of display characters in a string. More...
 
static const char * getTableTranslationDomain (const struct poptOption *opt)
 
static const char * getArgDescrip (const struct poptOption *opt, const char *translation_domain)
 
static char * singleOptionDefaultValue (size_t lineLength, const struct poptOption *opt, const char *translation_domain)
 Display default value for an option. More...
 
static void singleOptionHelp (FILE *fp, columns_t columns, const struct poptOption *opt, const char *translation_domain)
 Display help text for an option. More...
 
static size_t maxArgWidth (const struct poptOption *opt, const char *translation_domain)
 Find display width for longest argument string. More...
 
static void itemHelp (FILE *fp, poptItem items, int nitems, columns_t columns, const char *translation_domain)
 Display popt alias and exec help. More...
 
static void singleTableHelp (poptContext con, FILE *fp, const struct poptOption *table, columns_t columns, const char *translation_domain)
 Display help text for a table of options. More...
 
static size_t showHelpIntro (poptContext con, FILE *fp)
 
void poptPrintHelp (poptContext con, FILE *fp, int flags)
 Print detailed description of options. More...
 
static size_t singleOptionUsage (FILE *fp, columns_t columns, const struct poptOption *opt, const char *translation_domain)
 Display usage text for an option. More...
 
static size_t itemUsage (FILE *fp, columns_t columns, poptItem item, int nitems, const char *translation_domain)
 Display popt alias and exec usage. More...
 
static size_t singleTableUsage (poptContext con, FILE *fp, columns_t columns, const struct poptOption *opt, const char *translation_domain, poptDone done)
 Display usage text for a table of options. More...
 
static size_t showShortOptions (const struct poptOption *opt, FILE *fp, char *str)
 Return concatenated short options for display. More...
 
void poptPrintUsage (poptContext con, FILE *fp, int flags)
 Print terse description of options. More...
 
void poptSetOtherOptionHelp (poptContext con, const char *text)
 Provide text to replace default "[OPTION...]" in help/usage output. More...
 

Variables

struct poptOption poptAliasOptions []
 Empty table marker to enable displaying popt alias/exec options. More...
 
struct poptOption poptHelpOptions []
 Auto help table options. More...
 
static struct poptOption poptHelpOptions2 []
 
struct poptOptionpoptHelpOptionsI18N = poptHelpOptions2
 

Macro Definition Documentation

◆ _POPTHELP_MAXLINE

#define _POPTHELP_MAXLINE   ((size_t)79)

Definition at line 100 of file popthelp.c.

Referenced by maxColumnWidth().

◆ POPT_USE_TIOCGWINSZ

#define POPT_USE_TIOCGWINSZ

Definition at line 13 of file popthelp.c.

◆ POPT_WCHAR_HACK

#define POPT_WCHAR_HACK

Definition at line 18 of file popthelp.c.

◆ prtlong [1/2]

#define prtlong   (opt->longName != NULL) /* XXX splint needs a clue */

◆ prtlong [2/2]

#define prtlong   (opt->longName != NULL) /* XXX splint needs a clue */

Typedef Documentation

◆ columns_t

typedef struct columns_s * columns_t

◆ poptDone

typedef struct poptDone_s * poptDone

Keep track of option tables already processed.

Function Documentation

◆ displayArgs()

static void displayArgs ( poptContext  con,
enum poptCallbackReason  foo,
struct poptOption key,
const char *  arg,
void *  data 
)
static

Display arguments.

Parameters
concontext
foo(unused)
keyoption(s)
arg(unused)
data(unused)

Definition at line 36 of file popthelp.c.

References poptFreeContext(), poptPrintHelp(), poptPrintUsage(), and poptOption::shortName.

◆ getArgDescrip()

static const char* getArgDescrip ( const struct poptOption opt,
const char *  translation_domain 
)
static
Parameters
optoption(s)
translation_domaintranslation domain

< EXPERIMENTAL: return (*arg) (argc, argv)

< dupe'd arg appended to realloc'd argv array.

< no arg

< arg should take value val

< arg ==> int

< arg ==> short

< arg ==> long

< arg ==> long long

< arg will be saved as string

< arg ==> float

< arg ==> double

< EXPERIMENTAL: return (*arg) (argc, argv)

< dupe'd arg appended to realloc'd argv array.

Definition at line 174 of file popthelp.c.

References poptOption::argDescrip, D_, N_, POPT_, POPT_ARG_ARGV, POPT_ARG_DOUBLE, POPT_ARG_FLOAT, POPT_ARG_INT, POPT_ARG_LONG, POPT_ARG_LONGLONG, POPT_ARG_MAINCALL, POPT_ARG_NONE, POPT_ARG_SHORT, POPT_ARG_STRING, POPT_ARG_VAL, and poptArgType.

Referenced by maxArgWidth(), singleOptionHelp(), and singleOptionUsage().

◆ getTableTranslationDomain()

static const char* getTableTranslationDomain ( const struct poptOption opt)
static
Parameters
optoption(s)

< set the translation domain for this table and any included tables; arg points to the domain string

Definition at line 158 of file popthelp.c.

References poptOption::arg, poptOption::argInfo, poptOption::longName, POPT_ARG_INTL_DOMAIN, and poptOption::shortName.

Referenced by singleTableHelp().

◆ itemHelp()

static void itemHelp ( FILE *  fp,
poptItem  items,
int  nitems,
columns_t  columns,
const char *  translation_domain 
)
static

Display popt alias and exec help.

Parameters
fpoutput file handle
itemsalias/exec array
nitemsno. of alias/exec entries
columnsoutput display width control
translation_domaintranslation domain

< don't show in help/usage

Definition at line 570 of file popthelp.c.

References F_ISSET, poptOption::longName, poptItem_s::option, poptOption::shortName, and singleOptionHelp().

Referenced by singleTableHelp().

◆ itemUsage()

static size_t itemUsage ( FILE *  fp,
columns_t  columns,
poptItem  item,
int  nitems,
const char *  translation_domain 
)
static

Display popt alias and exec usage.

Parameters
fpoutput file handle
columnsoutput display width control
itemalias/exec array
nitemsno. of ara/exec entries
translation_domaintranslation domain

< set the translation domain for this table and any included tables; arg points to the domain string

< don't show in help/usage

Definition at line 755 of file popthelp.c.

References poptOption::arg, columns_s::cur, F_ISSET, poptOption::longName, poptItem_s::option, POPT_ARG_INTL_DOMAIN, poptArgType, poptOption::shortName, and singleOptionUsage().

Referenced by poptPrintUsage().

◆ maxArgWidth()

static size_t maxArgWidth ( const struct poptOption opt,
const char *  translation_domain 
)
static

Find display width for longest argument string.

Parameters
optoption(s)
translation_domaintranslation domain
Returns
display width

< arg points to table

< don't show in help/usage

< allow -longoption

< arg may be missing

Definition at line 519 of file popthelp.c.

References poptOption::arg, F_ISSET, getArgDescrip(), poptOption::longName, columns_s::max, POPT_ARG_INCLUDE_TABLE, poptArgType, poptOption::shortName, and stringDisplayWidth().

Referenced by poptPrintHelp().

◆ maxColumnWidth()

static size_t maxColumnWidth ( FILE *  fp)
static

Return no.

of columns in output window.

Parameters
fpFILE
Returns
no. of columns

Definition at line 112 of file popthelp.c.

References _POPTHELP_MAXLINE.

Referenced by poptPrintHelp(), and poptPrintUsage().

◆ poptPrintHelp()

void poptPrintHelp ( poptContext  con,
FILE *  fp,
int  flags 
)

Print detailed description of options.

Parameters
concontext
fpouput file handle
flags(unused)

Definition at line 663 of file popthelp.c.

References columns_s::cur, columns_s::max, maxArgWidth(), maxColumnWidth(), poptContext_s::options, poptContext_s::otherHelp, POPT_, POPT_fprintf(), showHelpIntro(), and singleTableHelp().

Referenced by displayArgs().

◆ poptPrintUsage()

void poptPrintUsage ( poptContext  con,
FILE *  fp,
int  flags 
)

Print terse description of options.

Parameters
concontext
fpouput file handle
flags(unused)

Definition at line 884 of file popthelp.c.

References poptContext_s::aliases, columns_s::cur, poptContext_s::execs, itemUsage(), columns_s::max, maxColumnWidth(), poptContext_s::numAliases, poptContext_s::numExecs, poptContext_s::options, poptContext_s::otherHelp, showHelpIntro(), showShortOptions(), and singleTableUsage().

Referenced by displayArgs().

◆ poptSetOtherOptionHelp()

void poptSetOtherOptionHelp ( poptContext  con,
const char *  text 
)

Provide text to replace default "[OPTION...]" in help/usage output.

Parameters
concontext
textreplacement text

Definition at line 921 of file popthelp.c.

References _free(), poptContext_s::otherHelp, and xstrdup().

◆ showHelpIntro()

static size_t showHelpIntro ( poptContext  con,
FILE *  fp 
)
static
Parameters
concontext
fpoutput file handle

< pay attention to argv[0]

Definition at line 642 of file popthelp.c.

References optionStackEntry::argv, poptContext_s::flags, poptContext_s::optionStack, POPT_, POPT_CONTEXT_KEEP_FIRST, and POPT_fprintf().

Referenced by poptPrintHelp(), and poptPrintUsage().

◆ showShortOptions()

static size_t showShortOptions ( const struct poptOption opt,
FILE *  fp,
char *  str 
)
static

Return concatenated short options for display.

Todo:
Sub-tables should be recursed.
Parameters
optoption(s)
fpoutput file handle
Return values
strconcatenation of short options
Returns
length of display string

< don't show in help/usage

< arg points to table

Definition at line 845 of file popthelp.c.

References poptOption::arg, F_ISSET, poptOption::longName, POPT_ARG_INCLUDE_TABLE, poptArgType, and poptOption::shortName.

Referenced by poptPrintUsage().

◆ singleOptionDefaultValue()

static char* singleOptionDefaultValue ( size_t  lineLength,
const struct poptOption opt,
const char *  translation_domain 
)
static

Display default value for an option.

Parameters
lineLengthdisplay positions remaining
optoption(s)
translation_domaintranslation domain
Returns

< arg should take value val

< arg ==> int

< arg ==> short

< arg ==> long

< arg ==> long long

< arg ==> float

< arg ==> double

< EXPERIMENTAL: return (*arg) (argc, argv)

< dupe'd arg appended to realloc'd argv array.

< arg will be saved as string

< no arg

Definition at line 227 of file popthelp.c.

References _free(), poptOption::arg, poptArg_u::argv, D_, poptArg_u::doublep, poptArg_u::floatp, poptArg_u::intp, poptArg_u::longlongp, poptArg_u::longp, POPT_ARG_ARGV, POPT_ARG_DOUBLE, POPT_ARG_FLOAT, POPT_ARG_INT, POPT_ARG_LONG, POPT_ARG_LONGLONG, POPT_ARG_MAINCALL, POPT_ARG_NONE, POPT_ARG_SHORT, POPT_ARG_STRING, POPT_ARG_VAL, poptArgType, poptArg_u::ptr, poptArg_u::shortp, and stpcpy().

Referenced by singleOptionHelp().

◆ singleOptionHelp()

static void singleOptionHelp ( FILE *  fp,
columns_t  columns,
const struct poptOption opt,
const char *  translation_domain 
)
static

Display help text for an option.

Parameters
fpoutput file handle
columnsoutput display width control
optoption(s)
translation_domaintranslation domain

< permit –[no]opt prefix toggle

< allow -longoption

< EXPERIMENTAL: return (*arg) (argc, argv)

< allow -longoption

< permit –[no]opt prefix toggle

< arg may be missing

< show default value in –help

< no arg

< arg should take value val

< arg ==> int

< arg ==> short

< arg ==> long

< arg ==> long long

< arg ==> float

< arg ==> double

< arg will be saved as string

< EXPERIMENTAL: return (*arg) (argc, argv)

< dupe'd arg appended to realloc'd argv array.

< arg may be missing

Definition at line 307 of file popthelp.c.

References _free(), _isspaceptr, poptOption::argDescrip, columns_s::cur, D_, poptOption::descrip, F_ISSET, getArgDescrip(), poptOption::longName, columns_s::max, POPT_ARG_ARGV, POPT_ARG_DOUBLE, POPT_ARG_FLOAT, POPT_ARG_INT, POPT_ARG_LONG, POPT_ARG_LONGLONG, POPT_ARG_MAINCALL, POPT_ARG_NONE, POPT_ARG_SHORT, POPT_ARG_STRING, POPT_ARG_VAL, POPT_ARGFLAG_AND, POPT_ARGFLAG_OR, POPT_ARGFLAG_XOR, POPT_fprintf(), POPT_next_char(), POPT_prev_char(), poptArgType, prtlong, poptOption::shortName, singleOptionDefaultValue(), stpcpy(), stringDisplayWidth(), poptOption::val, and xstrdup().

Referenced by itemHelp(), and singleTableHelp().

◆ singleOptionUsage()

static size_t singleOptionUsage ( FILE *  fp,
columns_t  columns,
const struct poptOption opt,
const char *  translation_domain 
)
static

Display usage text for an option.

Parameters
fpoutput file handle
columnsoutput display width control
optoption(s)
translation_domaintranslation domain

< allow -longoption

< allow -longoption

Definition at line 689 of file popthelp.c.

References columns_s::cur, F_ISSET, getArgDescrip(), poptOption::longName, columns_s::max, prtlong, poptOption::shortName, and stringDisplayWidth().

Referenced by itemUsage(), and singleTableUsage().

◆ singleTableHelp()

static void singleTableHelp ( poptContext  con,
FILE *  fp,
const struct poptOption table,
columns_t  columns,
const char *  translation_domain 
)
static

Display help text for a table of options.

Parameters
concontext
fpoutput file handle
tableoption(s)
columnsoutput display width control
translation_domaintranslation domain

< don't show in help/usage

< arg points to table

Definition at line 597 of file popthelp.c.

References poptContext_s::aliases, poptOption::arg, D_, poptOption::descrip, poptContext_s::execs, F_ISSET, getTableTranslationDomain(), itemHelp(), poptOption::longName, poptContext_s::numAliases, poptContext_s::numExecs, POPT_ARG_INCLUDE_TABLE, POPT_fprintf(), poptArgType, poptOption::shortName, and singleOptionHelp().

Referenced by poptPrintHelp().

◆ singleTableUsage()

static size_t singleTableUsage ( poptContext  con,
FILE *  fp,
columns_t  columns,
const struct poptOption opt,
const char *  translation_domain,
poptDone  done 
)
static

Display usage text for a table of options.

Parameters
concontext
fpoutput file handle
columnsoutput display width control
optoption(s)
translation_domaintranslation domain
donetables already processed
Returns

< set the translation domain for this table and any included tables; arg points to the domain string

< arg points to table

< don't show in help/usage

Definition at line 798 of file popthelp.c.

References poptOption::arg, columns_s::cur, F_ISSET, poptOption::longName, poptDone_s::maxopts, poptDone_s::nopts, poptDone_s::opts, POPT_ARG_INCLUDE_TABLE, POPT_ARG_INTL_DOMAIN, poptArgType, poptOption::shortName, and singleOptionUsage().

Referenced by poptPrintUsage().

◆ stringDisplayWidth()

static size_t stringDisplayWidth ( const char *  s)
inlinestatic

Determine number of display characters in a string.

Parameters
sstring
Returns
no. of display characters.

Definition at line 135 of file popthelp.c.

References POPT_next_char().

Referenced by maxArgWidth(), singleOptionHelp(), and singleOptionUsage().

Variable Documentation

◆ poptAliasOptions

struct poptOption poptAliasOptions[]
Initial value:
= {
{ NULL, '\0', 0, NULL, 0, NULL, NULL }
}

Empty table marker to enable displaying popt alias/exec options.

Definition at line 64 of file popthelp.c.

◆ poptHelpOptions

struct poptOption poptHelpOptions[]
Initial value:
= {
{ NULL, '\0', 5U , (void *)displayArgs, 0, NULL, NULL },
{ "help", '?', 0, NULL, (int)'?', "Show this help message" , NULL },
{ "usage", '\0', 0, NULL, (int)'u', "Display brief usage message" , NULL },
{ NULL, '\0', 0, NULL, 0, NULL, NULL }
}
static void displayArgs(poptContext con, enum poptCallbackReason foo, struct poptOption *key, const char *arg, void *data)
Display arguments.
Definition: popthelp.c:36

Auto help table options.

Definition at line 73 of file popthelp.c.

◆ poptHelpOptions2

struct poptOption poptHelpOptions2[]
static
Initial value:
= {
{ NULL, '\0', 6U , PACKAGE, 0, NULL, NULL},
{ NULL, '\0', 5U , (void *)displayArgs, 0, NULL, NULL },
{ "help", '?', 0, NULL, (int)'?', "Show this help message" , NULL },
{ "usage", '\0', 0, NULL, (int)'u', "Display brief usage message" , NULL },
{ "", '\0', 0, NULL, 0, "Terminate options" , NULL },
{ NULL, '\0', 0, NULL, 0, NULL, NULL }
}
static void displayArgs(poptContext con, enum poptCallbackReason foo, struct poptOption *key, const char *arg, void *data)
Display arguments.
Definition: popthelp.c:36

Definition at line 81 of file popthelp.c.

◆ poptHelpOptionsI18N

struct poptOption* poptHelpOptionsI18N = poptHelpOptions2

Definition at line 97 of file popthelp.c.


Generated for popt by  doxygen 1.8.13