1
/* ---------------------------------------------------------------------
2
* Definition of Popt functions vk_popt.h
3
* This is a seriously hacked version of the popt libraries.
4
* No credit to me, all thanks and many apologies to the Red Hat team
5
* ---------------------------------------------------------------------
6
* popt is Copyright (C) 1998 Red Hat Software and distributed under
7
* an X11-style license, which is in turn compatible the GNU GPL v.2.
8
* See the file COPYING for the full license details.
18
#include <vk_option.h>
20
#define OPTION_DEPTH 10
22
/* options can't follow args */
23
#define PCONTEXT_POSIXMEHARDER (1 << 2)
25
/* vkPoptOption can be: table of options | option | TABLE_END
26
TABLE_END: none set of: shortFlag && longFlag && arg
27
table: arg = array of options, helptxt = table title
30
typedef struct _vkPoptOption {
31
int optKey; /* eg. VIEW-LOG */
32
VkOPTION::ArgType argType; /* option type: ARG_*** */
33
char shortFlag; /* '\0' || 'h' */
34
const char* longFlag; /* NULL || --help */
35
struct _vkPoptOption* arg; /* table holds ptr to */
36
const char* helptxt; /* help text */
37
const char* helpdesc; /* eg. <file> */
38
int objectId; /* used to call obj->checkOptArg() */
41
#define TABLE_END { -1, VkOPTION::NOT_POPT, '\0', NULL, NULL, NULL, NULL, -1 }
42
vkPoptOption nullOpt();
45
typedef struct vkPoptContext_s* vkPoptContext;
51
/* initialize popt context.
52
- argc no. of arguments
54
- options address of popt option table
55
- returns initialized popt context */
56
vkPoptContext vkPoptGetContext( int argc, const char ** argv,
57
const vkPoptOption * options );
59
/* get next option opt_ret
60
returns 1 on success, -1 on last item, PERROR_* on error */
61
int vkPoptGetNextOpt( vkPoptContext con, char *arg_val,
62
const vkPoptOption** opt/*OUT*/ );
64
/* return current option's argument,
65
or NULL if no more options are available */
66
const char * vkPoptGetArg( vkPoptContext con );
68
/* return remaining argument array, terminated with NULL */
69
const char ** vkPoptGetArgs( vkPoptContext con );
71
/* peek at current option's argument */
72
const char * vkPoptPeekArg( vkPoptContext con );
74
/* return the offending option which caused the most recent error */
75
const char * vkPoptBadOption( vkPoptContext con );
77
/* destroy context. return NULL always */
78
vkPoptContext vkPoptFreeContext( vkPoptContext con );
80
/* print detailed description of options.
81
fp == ouput file handle */
82
void vkPoptPrintHelp( vkPoptContext con, FILE * fp,
83
const char * tableName );
89
/*--------------------------------------------------*/
90
/* wrapper to free(3), hides const compilation noise,
91
permit NULL, return NULL always */
92
static inline void * _free( const void * p )
100
struct optionStackEntry {
104
const char * nextArg;
105
const char * nextCharArg;
109
struct vkPoptContext_s {
110
struct optionStackEntry optionStack[OPTION_DEPTH];
111
struct optionStackEntry * os;
112
const char ** leftovers;
115
const vkPoptOption * options;
118
const char ** finalArgv;
120
int finalArgvAlloced;