本文整理汇总了C++中OPTST_GET_ARGTYPE函数的典型用法代码示例。如果您正苦于以下问题:C++ OPTST_GET_ARGTYPE函数的具体用法?C++ OPTST_GET_ARGTYPE怎么用?C++ OPTST_GET_ARGTYPE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OPTST_GET_ARGTYPE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prt_one_usage
/**
* Print the usage information for a single option.
*
* @param opts the program option descriptor
* @param od the option descriptor
* @param at names of the option argument types
*/
static void
prt_one_usage(tOptions * opts, tOptDesc * od, arg_types_t * at)
{
prt_preamble(opts, od, at);
{
char z[80];
char const * atyp;
/*
* Determine the argument type string first on its usage, then,
* when the option argument is required, base the type string on the
* argument type.
*/
if (od->fOptState & OPTST_ARG_OPTIONAL) {
atyp = at->pzOpt;
} else switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_NONE: atyp = at->pzNo; break;
case OPARG_TYPE_ENUMERATION: atyp = at->pzKey; break;
case OPARG_TYPE_FILE: atyp = at->pzFile; break;
case OPARG_TYPE_MEMBERSHIP: atyp = at->pzKeyL; break;
case OPARG_TYPE_BOOLEAN: atyp = at->pzBool; break;
case OPARG_TYPE_NUMERIC: atyp = at->pzNum; break;
case OPARG_TYPE_HIERARCHY: atyp = at->pzNest; break;
case OPARG_TYPE_STRING: atyp = at->pzStr; break;
case OPARG_TYPE_TIME: atyp = at->pzTime; break;
default: goto bogus_desc;
}
#ifdef _WIN32
if (at->pzOptFmt == zGnuOptFmt)
snprintf(z, sizeof(z), "--%s%s", od->pz_Name, atyp);
else if (at->pzOptFmt == zGnuOptFmt + 2)
snprintf(z, sizeof(z), "%s%s", od->pz_Name, atyp);
else
#endif
snprintf(z, sizeof(z), at->pzOptFmt, atyp, od->pz_Name,
(od->optMinCt != 0) ? at->pzReq : at->pzOpt);
fprintf(option_usage_fp, line_fmt_buf, z, od->pzText);
switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_ENUMERATION:
case OPARG_TYPE_MEMBERSHIP:
displayEnum = (od->pOptProc != NULL) ? true : displayEnum;
}
}
return;
bogus_desc:
fprintf(stderr, zbad_od, opts->pzProgName, od->pz_Name);
exit(EX_SOFTWARE);
}
示例2: prt_one_vendor
/**
* Print the usage information for a single vendor option.
*
* @param pOpts the program option descriptor
* @param pOD the option descriptor
* @param pAT names of the option argument types
*/
static void
prt_one_vendor(tOptions * pOptions, tOptDesc * pOD,
arg_types_t * pAT, char const * usefmt)
{
prt_preamble(pOptions, pOD, pAT);
{
char z[ 80 ];
char const * pzArgType;
/*
* Determine the argument type string first on its usage, then,
* when the option argument is required, base the type string on the
* argument type.
*/
if (pOD->fOptState & OPTST_ARG_OPTIONAL) {
pzArgType = pAT->pzOpt;
} else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break;
case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break;
case OPARG_TYPE_FILE: pzArgType = pAT->pzFile; break;
case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break;
case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break;
case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break;
case OPARG_TYPE_HIERARCHY: pzArgType = pAT->pzNest; break;
case OPARG_TYPE_STRING: pzArgType = pAT->pzStr; break;
case OPARG_TYPE_TIME: pzArgType = pAT->pzTime; break;
default: goto bogus_desc;
}
while (IS_WHITESPACE_CHAR(*pzArgType)) pzArgType++;
if (*pzArgType == NUL)
snprintf(z, sizeof(z), "%s", pOD->pz_Name);
else
snprintf(z, sizeof(z), "%s=%s", pOD->pz_Name, pzArgType);
fprintf(option_usage_fp, usefmt, z, pOD->pzText);
switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
case OPARG_TYPE_ENUMERATION:
case OPARG_TYPE_MEMBERSHIP:
displayEnum = (pOD->pOptProc != NULL) ? AG_TRUE : displayEnum;
}
}
return;
bogus_desc:
fprintf(stderr, zInvalOptDesc, pOD->pz_Name);
exit(EX_SOFTWARE);
}
示例3: prt_one_vendor
/**
* Print the usage information for a single vendor option.
*
* @param[in] opts the program option descriptor
* @param[in] od the option descriptor
* @param[in] argtp names of the option argument types
* @param[in] usefmt format for primary usage line
*/
static void
prt_one_vendor(tOptions * opts, tOptDesc * od,
arg_types_t * argtp, char const * usefmt)
{
prt_preamble(opts, od, argtp);
{
char z[ 80 ];
char const * pzArgType;
/*
* Determine the argument type string first on its usage, then,
* when the option argument is required, base the type string on the
* argument type.
*/
if (od->fOptState & OPTST_ARG_OPTIONAL) {
pzArgType = argtp->pzOpt;
} else switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_NONE: pzArgType = argtp->pzNo; break;
case OPARG_TYPE_ENUMERATION: pzArgType = argtp->pzKey; break;
case OPARG_TYPE_FILE: pzArgType = argtp->pzFile; break;
case OPARG_TYPE_MEMBERSHIP: pzArgType = argtp->pzKeyL; break;
case OPARG_TYPE_BOOLEAN: pzArgType = argtp->pzBool; break;
case OPARG_TYPE_NUMERIC: pzArgType = argtp->pzNum; break;
case OPARG_TYPE_HIERARCHY: pzArgType = argtp->pzNest; break;
case OPARG_TYPE_STRING: pzArgType = argtp->pzStr; break;
case OPARG_TYPE_TIME: pzArgType = argtp->pzTime; break;
default: goto bogus_desc;
}
pzArgType = SPN_WHITESPACE_CHARS(pzArgType);
if (*pzArgType == NUL)
snprintf(z, sizeof(z), "%s", od->pz_Name);
else
snprintf(z, sizeof(z), "%s=%s", od->pz_Name, pzArgType);
fprintf(option_usage_fp, usefmt, z, od->pzText);
switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_ENUMERATION:
case OPARG_TYPE_MEMBERSHIP:
displayEnum = (od->pOptProc != NULL) ? true : displayEnum;
}
}
return;
bogus_desc:
fprintf(stderr, zbad_od, opts->pzProgName, od->pz_Name);
ao_bug(zbad_arg_type_msg);
}
示例4: fixupSavedOptionArgs
/*
* optionFixupSavedOpts Really, it just wipes out option state for
* options that are troublesome to copy. viz., stacked strings and
* hierarcicaly valued option args. We do duplicate string args that
* have been marked as allocated though.
*/
static void
fixupSavedOptionArgs(tOptions* pOpts)
{
tOptions* p = pOpts->pSavedState;
tOptDesc* pOD = pOpts->pOptDesc;
int ct = pOpts->optCt;
/*
* Make sure that allocated stuff is only referenced in the
* archived copy of the data.
*/
for (; ct-- > 0; pOD++) {
switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
case OPARG_TYPE_STRING:
if (pOD->fOptState & OPTST_STACKED) {
tOptDesc* q = p->pOptDesc + (pOD - pOpts->pOptDesc);
q->optCookie = NULL;
}
if (pOD->fOptState & OPTST_ALLOC_ARG) {
tOptDesc* q = p->pOptDesc + (pOD - pOpts->pOptDesc);
AGDUPSTR(q->optArg.argString, pOD->optArg.argString, "arg");
}
break;
case OPARG_TYPE_HIERARCHY:
{
tOptDesc* q = p->pOptDesc + (pOD - pOpts->pOptDesc);
q->optCookie = NULL;
}
}
}
}
示例5: emit_action
static void
emit_action(tOptions * opts, tOptDesc * od)
{
if (od->pOptProc == optionPrintVersion)
printf(ECHO_N_EXIT, opts->pzPROGNAME, VER_STR);
else if (od->pOptProc == optionPagedUsage)
printf(PAGE_USAGE_TEXT, opts->pzPROGNAME);
else if (od->pOptProc == optionLoadOpt) {
printf(LVL3_CMD, NO_LOAD_WARN);
printf(LVL3_CMD, YES_NEED_OPT_ARG);
} else if (od->pz_NAME == NULL) {
if (od->pOptProc == NULL) {
printf(LVL3_CMD, NO_SAVE_OPTS);
printf(LVL3_CMD, OK_NEED_OPT_ARG);
} else
printf(ECHO_N_EXIT, opts->pzPROGNAME, LONG_USE_STR);
} else {
if (od->optMaxCt == 1)
printf(SGL_ARG_FMT, opts->pzPROGNAME, od->pz_NAME);
else {
if ((unsigned)od->optMaxCt < NOLIMIT)
printf(CHK_MAX_COUNT, opts->pzPROGNAME,
od->pz_NAME, od->optMaxCt);
printf(MULTI_ARG_FMT, opts->pzPROGNAME, od->pz_NAME);
}
/*
* Fix up the args.
*/
if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_NONE) {
printf(SET_MULTI_ARG, opts->pzPROGNAME, od->pz_NAME);
printf(LVL3_CMD, NO_ARG_NEEDED);
} else if (od->fOptState & OPTST_ARG_OPTIONAL) {
printf(SET_MULTI_ARG, opts->pzPROGNAME, od->pz_NAME);
printf(LVL3_CMD, OK_NEED_OPT_ARG);
} else {
printf(LVL3_CMD, YES_NEED_OPT_ARG);
}
}
fputs(zOptionEndSelect, stdout);
}
示例6: prt_prog_detail
/**
* Print program details.
* @param[in] opts the program option descriptor
*/
static void
prt_prog_detail(tOptions * opts)
{
bool need_intro = (opts->papzHomeList == NULL);
/*
* Display all the places we look for config files, if we have
* a list of directories to search.
*/
if (! need_intro)
prt_ini_list(opts->papzHomeList, opts->pzRcName, opts->pzProgPath);
/*
* Let the user know about environment variable settings
*/
if ((opts->fOptSet & OPTPROC_ENVIRON) != 0) {
if (need_intro)
fputs(zPresetIntro, option_usage_fp);
fprintf(option_usage_fp, zExamineFmt, opts->pzPROGNAME);
}
/*
* IF we found an enumeration,
* THEN hunt for it again. Call the handler proc with a NULL
* option struct pointer. That tells it to display the keywords.
*/
if (displayEnum) {
int ct = opts->optCt;
int optNo = 0;
tOptDesc * od = opts->pOptDesc;
fputc(NL, option_usage_fp);
fflush(option_usage_fp);
do {
switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_ENUMERATION:
case OPARG_TYPE_MEMBERSHIP:
(*(od->pOptProc))(OPTPROC_EMIT_USAGE, od);
}
} while (od++, optNo++, (--ct > 0));
}
/*
* If there is a detail string, now is the time for that.
*/
if (opts->pzDetail != NULL)
fputs(opts->pzDetail, option_usage_fp);
}
示例7: nextOption
/*
* nextOption
*
* Find the option descriptor and option argument (if any) for the
* next command line argument. DO NOT modify the descriptor. Put
* all the state in the state argument so that the option can be skipped
* without consequence (side effect).
*/
static tSuccess
nextOption(tOptions* pOpts, tOptState* pOptState)
{
{
tSuccess res;
res = findOptDesc(pOpts, pOptState);
if (! SUCCESSFUL(res))
return res;
}
if ( ((pOptState->flags & OPTST_DEFINED) != 0)
&& ((pOptState->pOD->fOptState & OPTST_NO_COMMAND) != 0)) {
fprintf(stderr, zNotCmdOpt, pOptState->pOD->pz_Name);
return FAILURE;
}
pOptState->flags |= (pOptState->pOD->fOptState & OPTST_PERSISTENT_MASK);
/*
* Figure out what to do about option arguments. An argument may be
* required, not associated with the option, or be optional. We detect the
* latter by examining for an option marker on the next possible argument.
* Disabled mode option selection also disables option arguments.
*/
{
enum { ARG_NONE, ARG_MAY, ARG_MUST } arg_type = ARG_NONE;
tSuccess res;
if ((pOptState->flags & OPTST_DISABLED) != 0)
arg_type = ARG_NONE;
else if (OPTST_GET_ARGTYPE(pOptState->flags) == OPARG_TYPE_NONE)
arg_type = ARG_NONE;
else if (pOptState->flags & OPTST_ARG_OPTIONAL)
arg_type = ARG_MAY;
else
arg_type = ARG_MUST;
switch (arg_type) {
case ARG_MUST: res = next_opt_arg_must(pOpts, pOptState); break;
case ARG_MAY: res = next_opt_arg_may( pOpts, pOptState); break;
case ARG_NONE: res = next_opt_arg_none(pOpts, pOptState); break;
}
return res;
}
}
示例8: printProgramDetails
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* PROGRAM DETAILS
*/
static void
printProgramDetails( tOptions* pOptions )
{
ag_bool initIntro = AG_TRUE;
/*
* Display all the places we look for config files
*/
printInitList( pOptions->papzHomeList, &initIntro,
pOptions->pzRcName, pOptions->pzProgPath );
/*
* Let the user know about environment variable settings
*/
if ((pOptions->fOptSet & OPTPROC_ENVIRON) != 0) {
if (initIntro)
fputs( zPresetIntro, option_usage_fp );
fprintf( option_usage_fp, zExamineFmt, pOptions->pzPROGNAME );
}
/*
* IF we found an enumeration,
* THEN hunt for it again. Call the handler proc with a NULL
* option struct pointer. That tells it to display the keywords.
*/
if (displayEnum) {
int ct = pOptions->optCt;
int optNo = 0;
tOptDesc* pOD = pOptions->pOptDesc;
fputc( '\n', option_usage_fp );
fflush( option_usage_fp );
do {
switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
case OPARG_TYPE_ENUMERATION:
case OPARG_TYPE_MEMBERSHIP:
(*(pOD->pOptProc))( NULL, pOD );
}
} while (pOD++, optNo++, (--ct > 0));
}
/*
* If there is a detail string, now is the time for that.
*/
if (pOptions->pzDetail != NULL)
fputs( pOptions->pzDetail, option_usage_fp );
}
示例9: printOptionAction
static void
printOptionAction( tOptions* pOpts, tOptDesc* pOptDesc )
{
if (pOptDesc->pOptProc == optionPrintVersion)
printf( zTextExit, pOpts->pzPROGNAME, "VERSION" );
else if (pOptDesc->pOptProc == optionPagedUsage)
printf( zPagedUsageExit, pOpts->pzPROGNAME );
else if (pOptDesc->pOptProc == optionLoadOpt) {
printf( zCmdFmt, "echo 'Warning: Cannot load options files' >&2" );
printf( zCmdFmt, "OPT_ARG_NEEDED=YES" );
} else if (pOptDesc->pz_NAME == NULL) {
if (pOptDesc->pOptProc == NULL) {
printf( zCmdFmt, "echo 'Warning: Cannot save options files' "
">&2" );
printf( zCmdFmt, "OPT_ARG_NEEDED=OK" );
} else
printf( zTextExit, pOpts->pzPROGNAME, "LONGUSAGE" );
} else {
if (pOptDesc->optMaxCt == 1)
printf( zSingleArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
else {
if ((unsigned)pOptDesc->optMaxCt < NOLIMIT)
printf( zCountTest, pOpts->pzPROGNAME,
pOptDesc->pz_NAME, pOptDesc->optMaxCt );
printf( zMultiArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
}
/*
* Fix up the args.
*/
if (OPTST_GET_ARGTYPE(pOptDesc->fOptState) == OPARG_TYPE_NONE) {
printf( zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
} else if (pOptDesc->fOptState & OPTST_ARG_OPTIONAL) {
printf( zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME );
} else {
fputs( zMustArg, stdout );
}
}
fputs( zOptionEndSelect, stdout );
}
示例10: optionFindValue
/*=export_func optionFindValue
*
* what: find a hierarcicaly valued option instance
* arg: + const tOptDesc* + odesc + an option with a nested arg type +
* arg: + char const* + name + name of value to find +
* arg: + char const* + val + the matching value +
*
* ret_type: const tOptionValue*
* ret_desc: a compound value structure
*
* doc:
* This routine will find an entry in a nested value option or configurable.
* It will search through the list and return a matching entry.
*
* err:
* The returned result is NULL and errno is set:
* @itemize @bullet
* @item
* @code{EINVAL} - the @code{pOptValue} does not point to a valid
* hierarchical option value.
* @item
* @code{ENOENT} - no entry matched the given name.
* @end itemize
=*/
const tOptionValue *
optionFindValue(const tOptDesc * odesc, char const * name, char const * val)
{
const tOptionValue * res = NULL;
if ( (odesc == NULL)
|| (OPTST_GET_ARGTYPE(odesc->fOptState) != OPARG_TYPE_HIERARCHY)) {
errno = EINVAL;
}
else if (odesc->optCookie == NULL) {
errno = ENOENT;
}
else do {
tArgList* argl = odesc->optCookie;
int argct = argl->useCt;
void ** poptv = (void**)(argl->apzArgs);
if (argct == 0) {
errno = ENOENT;
break;
}
if (name == NULL) {
res = (tOptionValue*)*poptv;
break;
}
while (--argct >= 0) {
const tOptionValue * ov = *(poptv++);
const tOptionValue * rv = optionGetValue(ov, name);
if (rv == NULL)
continue;
if (val == NULL) {
res = ov;
break;
}
}
if (res == NULL)
errno = ENOENT;
} while (false);
return res;
}
示例11: emit_action
static void
emit_action(tOptions * pOpts, tOptDesc* pOptDesc)
{
if (pOptDesc->pOptProc == optionPrintVersion)
printf(zTextExit, pOpts->pzPROGNAME, VER_STR);
else if (pOptDesc->pOptProc == optionPagedUsage)
printf(zPagedUsageExit, pOpts->pzPROGNAME);
else if (pOptDesc->pOptProc == optionLoadOpt) {
printf(zCmdFmt, NO_LOAD_WARN);
printf(zCmdFmt, YES_NEED_OPT_ARG);
} else if (pOptDesc->pz_NAME == NULL) {
if (pOptDesc->pOptProc == NULL) {
printf(zCmdFmt, NO_SAVE_OPTS);
printf(zCmdFmt, OK_NEED_OPT_ARG);
} else
printf(zTextExit, pOpts->pzPROGNAME, LONG_USE_STR);
} else {
if (pOptDesc->optMaxCt == 1)
printf(SGL_ARG_FMT, pOpts->pzPROGNAME, pOptDesc->pz_NAME);
else {
if ((unsigned)pOptDesc->optMaxCt < NOLIMIT)
printf(zCountTest, pOpts->pzPROGNAME,
pOptDesc->pz_NAME, pOptDesc->optMaxCt);
printf(MULTI_ARG_FMT, pOpts->pzPROGNAME, pOptDesc->pz_NAME);
}
/*
* Fix up the args.
*/
if (OPTST_GET_ARGTYPE(pOptDesc->fOptState) == OPARG_TYPE_NONE) {
printf(zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME);
} else if (pOptDesc->fOptState & OPTST_ARG_OPTIONAL) {
printf(zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME);
} else {
fputs(zMustArg, stdout);
}
}
fputs(zOptionEndSelect, stdout);
}
示例12: optionFree
/*=export_func optionFree
*
* what: free allocated option processing memory
* arg: tOptions*, pOpts, program options descriptor
*
* doc: AutoOpts sometimes allocates memory and puts pointers to it in the
* option state structures. This routine deallocates all such memory.
*
* err: As long as memory has not been corrupted,
* this routine is always successful.
=*/
void
optionFree(tOptions* pOpts)
{
free_saved_state:
{
tOptDesc* p = pOpts->pOptDesc;
int ct = pOpts->optCt;
do {
if (p->fOptState & OPTST_ALLOC_ARG) {
AGFREE(p->optArg.argString);
p->optArg.argString = NULL;
p->fOptState &= ~OPTST_ALLOC_ARG;
}
switch (OPTST_GET_ARGTYPE(p->fOptState)) {
case OPARG_TYPE_STRING:
#ifdef WITH_LIBREGEX
if ( (p->fOptState & OPTST_STACKED)
&& (p->optCookie != NULL)) {
p->optArg.argString = ".*";
optionUnstackArg(pOpts, p);
}
#else
/* leak memory */;
#endif
break;
case OPARG_TYPE_HIERARCHY:
if (p->optCookie != NULL)
unload_arg_list(p->optCookie);
break;
}
p->optCookie = NULL;
} while (p++, --ct > 0);
}
if (pOpts->pSavedState != NULL) {
tOptions * p = (tOptions*)pOpts->pSavedState;
memcpy(pOpts, p, sizeof(*p));
memcpy(pOpts->pOptDesc, p+1, (size_t)p->optCt * sizeof(tOptDesc));
AGFREE(pOpts->pSavedState);
pOpts->pSavedState = NULL;
goto free_saved_state;
}
}
示例13: checkShortOpts
/*
* Process a string of short options glued together. If the last one
* does or may take an argument, the do the argument processing and leave.
*/
static tSuccess
checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS,
char** ppzOpts, int* pOptsIdx )
{
while (*pzArg != NUL) {
if (FAILED( shortOptionFind( pOpts, (tAoUC)*pzArg, pOS )))
return FAILURE;
/*
* See if we can have an arg.
*/
if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
pzArg++;
} else if (pOS->pOD->fOptState & OPTST_ARG_OPTIONAL) {
/*
* Take an argument if it is not attached and it does not
* start with a hyphen.
*/
if (pzArg[1] != NUL)
return SUCCESS;
pzArg = pOpts->origArgVect[ pOpts->curOptIdx ];
if (*pzArg != '-')
ppzOpts[ (*pOptsIdx)++ ] =
pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
return SUCCESS;
} else {
/*
* IF we need another argument, be sure it is there and
* take it.
*/
if (pzArg[1] == NUL) {
if (pOpts->curOptIdx >= pOpts->origArgCt)
return FAILURE;
ppzOpts[ (*pOptsIdx)++ ] =
pOpts->origArgVect[ (pOpts->curOptIdx)++ ];
}
return SUCCESS;
}
}
return SUCCESS;
}
示例14: short_opt_ck
/*
* Process a string of short options glued together. If the last one
* does or may take an argument, the do the argument processing and leave.
*/
static tSuccess
short_opt_ck(tOptions * opts, char * arg_txt, tOptState * pOS,
char ** opt_txt, uint32_t * opt_idx)
{
while (*arg_txt != NUL) {
if (FAILED(opt_find_short(opts, (uint8_t)*arg_txt, pOS)))
return FAILURE;
/*
* See if we can have an arg.
*/
if (OPTST_GET_ARGTYPE(pOS->pOD->fOptState) == OPARG_TYPE_NONE) {
arg_txt++;
} else if (pOS->pOD->fOptState & OPTST_ARG_OPTIONAL) {
/*
* Take an argument if it is not attached and it does not
* start with a hyphen.
*/
if (arg_txt[1] != NUL)
return SUCCESS;
arg_txt = opts->origArgVect[ opts->curOptIdx ];
if (*arg_txt != '-')
opt_txt[ (*opt_idx)++ ] =
opts->origArgVect[ (opts->curOptIdx)++ ];
return SUCCESS;
} else {
/*
* IF we need another argument, be sure it is there and
* take it.
*/
if (arg_txt[1] == NUL) {
if (opts->curOptIdx >= opts->origArgCt)
return FAILURE;
opt_txt[ (*opt_idx)++ ] =
opts->origArgVect[ (opts->curOptIdx)++ ];
}
return SUCCESS;
}
}
return SUCCESS;
}
示例15: get_opt_arg
/**
* Process option. Figure out whether or not to look for an option argument.
*
* @param[in,out] opts the program option descriptor
* @param[in,out] o_st the option processing state
* @returns SUCCESS or FAILURE
*/
LOCAL tSuccess
get_opt_arg(tOptions * opts, tOptState * o_st)
{
o_st->flags |= (o_st->pOD->fOptState & OPTST_PERSISTENT_MASK);
/*
* Disabled options and options specified to not have arguments
* are handled with the "none" procedure. Otherwise, check the
* optional flag and call either the "may" or "must" function.
*/
if ( ((o_st->flags & OPTST_DISABLED) != 0)
|| (OPTST_GET_ARGTYPE(o_st->flags) == OPARG_TYPE_NONE))
return get_opt_arg_none(opts, o_st);
if (o_st->flags & OPTST_ARG_OPTIONAL)
return get_opt_arg_may( opts, o_st);
return get_opt_arg_must(opts, o_st);
}