本文整理汇总了C++中OPTST_GET_ARGTYPE函数的典型用法代码示例。如果您正苦于以下问题:C++ OPTST_GET_ARGTYPE函数的具体用法?C++ OPTST_GET_ARGTYPE怎么用?C++ OPTST_GET_ARGTYPE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OPTST_GET_ARGTYPE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:verm,项目名称:gsoc-ntp-2013,代码行数:62,代码来源:usage.c
示例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);
}
开发者ID:cooljeanius,项目名称:apple-gdb-1824,代码行数:58,代码来源:usage.c
示例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);
}
开发者ID:verm,项目名称:gsoc-ntp-2013,代码行数:59,代码来源:usage.c
示例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;
}
}
}
}
开发者ID:cernekee,项目名称:ocserv,代码行数:38,代码来源:restore.c
示例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);
}
开发者ID:gokzy,项目名称:netbsd-src,代码行数:49,代码来源:makeshell.c
示例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);
}
开发者ID:Distrotech,项目名称:autogen,代码行数:53,代码来源:usage.c
示例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;
}
}
开发者ID:Distrotech,项目名称:ntp,代码行数:57,代码来源:autoopts.c
示例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 );
}
开发者ID:2014-class,项目名称:freerouter,代码行数:52,代码来源:usage.c
示例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 );
}
开发者ID:Leon555,项目名称:Mac-src-essentials,代码行数:48,代码来源:makeshell.c
示例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;
}
开发者ID:Distrotech,项目名称:sharutils,代码行数:71,代码来源:configfile.c
示例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);
}
开发者ID:1and1get2,项目名称:tcpreplay,代码行数:47,代码来源:makeshell.c
示例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;
}
}
开发者ID:cernekee,项目名称:ocserv,代码行数:56,代码来源:restore.c
示例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;
}
开发者ID:Leon555,项目名称:Mac-src-essentials,代码行数:48,代码来源:sort.c
示例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;
}
开发者ID:2asoft,项目名称:freebsd,代码行数:48,代码来源:sort.c
示例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);
}
开发者ID:VargMon,项目名称:netbsd-cvs-mirror,代码行数:26,代码来源:find.c
示例16: optionFindNextValue
/*=export_func optionFindNextValue
*
* FIXME: the handling of 'pzName' and 'pzVal' is just wrong.
*
* what: find a hierarcicaly valued option instance
* arg: + const tOptDesc* + odesc + an option with a nested arg type +
* arg: + const tOptionValue* + pPrevVal + the last entry +
* arg: + char const* + name + name of value to find +
* arg: + char const* + value + the matching value +
*
* ret_type: const tOptionValue*
* ret_desc: a compound value structure
*
* doc:
* This routine will find the next entry in a nested value option or
* configurable. It will search through the list and return the next entry
* that matches the criteria.
*
* 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
=*/
tOptionValue const *
optionFindNextValue(const tOptDesc * odesc, const tOptionValue * pPrevVal,
char const * pzName, char const * pzVal)
{
bool old_found = false;
tOptionValue* res = NULL;
(void)pzName;
(void)pzVal;
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 ct = argl->useCt;
void** poptv = (void**)argl->apzArgs;
while (--ct >= 0) {
tOptionValue* pOV = *(poptv++);
if (old_found) {
res = pOV;
break;
}
if (pOV == pPrevVal)
old_found = true;
}
if (res == NULL)
errno = ENOENT;
} while (false);
return res;
}
开发者ID:Distrotech,项目名称:sharutils,代码行数:67,代码来源:configfile.c
示例17: prt_extd_usage
/**
* Print extended usage. Usage/help was requested.
*
* @param opts the program option descriptor
* @param od the option descriptor
* @param title the title for the options
*/
static void
prt_extd_usage(tOptions * opts, tOptDesc * od, char const * title)
{
if ( ((opts->fOptSet & OPTPROC_VENDOR_OPT) != 0)
&& (od->optActualValue == VENDOR_OPTION_VALUE)) {
prt_vendor_opts(opts, title);
return;
}
/*
* IF there are option conflicts or dependencies,
* THEN print them here.
*/
if ((od->pOptMust != NULL) || (od->pOptCant != NULL))
prt_conflicts(opts, od);
/*
* IF there is a disablement string
* THEN print the disablement info
*/
if (od->pz_DisableName != NULL )
fprintf(option_usage_fp, zDis + tab_skip_ct, od->pz_DisableName);
/*
* Check for argument types that have callbacks with magical properties
*/
switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_NUMERIC:
/*
* IF the numeric option has a special callback,
* THEN call it, requesting the range or other special info
*/
if ( (od->pOptProc != NULL)
&& (od->pOptProc != optionNumericVal) ) {
(*(od->pOptProc))(OPTPROC_EMIT_USAGE, od);
}
break;
case OPARG_TYPE_FILE:
(*(od->pOptProc))(OPTPROC_EMIT_USAGE, od);
break;
}
/*
* IF the option defaults to being enabled,
* THEN print that out
*/
if (od->fOptState & OPTST_INITENABLED)
fputs(zEnab + tab_skip_ct, option_usage_fp);
/*
* IF the option is in an equivalence class
* AND not the designated lead
* THEN print equivalence and leave it at that.
*/
if ( (od->optEquivIndex != NO_EQUIVALENT)
&& (od->optEquivIndex != od->optActualIndex ) ) {
fprintf(option_usage_fp, zalt_opt + tab_skip_ct,
opts->pOptDesc[ od->optEquivIndex ].pz_Name);
return;
}
/*
* IF this particular option can NOT be preset
* AND some form of presetting IS allowed,
* AND it is not an auto-managed option (e.g. --help, et al.)
* THEN advise that this option may not be preset.
*/
if ( ((od->fOptState & OPTST_NO_INIT) != 0)
&& ( (opts->papzHomeList != NULL)
|| (opts->pzPROGNAME != NULL)
)
&& (od->optIndex < opts->presetOptCt)
)
fputs(zNoPreset + tab_skip_ct, option_usage_fp);
/*
* Print the appearance requirements.
*/
if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_MEMBERSHIP)
fputs(zMembers + tab_skip_ct, option_usage_fp);
else switch (od->optMinCt) {
case 1:
case 0:
switch (od->optMaxCt) {
case 0: fputs(zPreset + tab_skip_ct, option_usage_fp); break;
case NOLIMIT: fputs(zNoLim + tab_skip_ct, option_usage_fp); break;
case 1: break;
/*
* IF the max is more than one but limited, print "UP TO" message
*/
//.........这里部分代码省略.........
开发者ID:verm,项目名称:gsoc-ntp-2013,代码行数:101,代码来源:usage.c
示例18: prt_entry
/**
* print one option entry to the save file.
*
* @param[in] fp the file pointer for the save file
* @param[in] od the option descriptor to print
* @param[in] l_arg the last argument for the option
*/
static void
prt_entry(FILE * fp, tOptDesc * od, char const * l_arg)
{
int space_ct;
/*
* There is an argument. Pad the name so values line up.
* Not disabled *OR* this got equivalenced to another opt,
* then use current option name.
* Otherwise, there must be a disablement name.
*/
{
char const * pz =
(! DISABLED_OPT(od) || (od->optEquivIndex != NO_EQUIVALENT))
? od->pz_Name
: od->pz_DisableName;
space_ct = 17 - strlen(pz);
fputs(pz, fp);
}
if ( (l_arg == NULL)
&& (OPTST_GET_ARGTYPE(od->fOptState) != OPARG_TYPE_NUMERIC))
goto end_entry;
fputs(" = ", fp);
while (space_ct-- > 0) fputc(' ', fp);
/*
* IF the option is numeric only,
* THEN the char pointer is really the number
*/
if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_NUMERIC)
fprintf(fp, "%d", (int)(t_word)l_arg);
else {
for (;;) {
char const * eol = strchr(l_arg, NL);
/*
* IF this is the last line
* THEN bail and print it
*/
if (eol == NULL)
break;
/*
* Print the continuation and the text from the current line
*/
(void)fwrite(l_arg, (size_t)(eol - l_arg), (size_t)1, fp);
l_arg = eol+1; /* advance the Last Arg pointer */
fputs("\\\n", fp);
}
/*
* Terminate the entry
*/
fputs(l_arg, fp);
}
end_entry:
fputc(NL, fp);
}
开发者ID:cernekee,项目名称:ocserv,代码行数:69,代码来源:save.c
示例19: optionSaveFile
/*=export_func optionSaveFile
*
* what: saves the option state to a file
*
* arg: tOptions*, opts, program options descriptor
*
* doc:
*
* This routine will save the state of option processing to a file. The name
* of that file can be specified with the argument to the @code{--save-opts}
* option, or by appending the @code{rcfile} attribute to the last
* @code{homerc} attribute. If no @code{rcfile} attribute was specified, it
* will default to @code{[email protected]{programname}rc}. If you wish to specify another
* file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro.
*
* The recommend usage is as follows:
* @example
* optionProcess(&progOptions, argc, argv);
* if (i_want_a_non_standard_place_for_this)
* SET_OPT_SAVE_OPTS("myfilename");
* optionSaveFile(&progOptions);
* @end example
*
* err:
*
* If no @code{homerc} file was specified, this routine will silently return
* and do nothing. If the output file cannot be created or updated, a message
* will be printed to @code{stderr} and the routine will return.
=*/
void
optionSaveFile(tOptions * opts)
{
tOptDesc * od;
int ct;
FILE * fp = open_sv_file(opts);
if (fp == NULL)
return;
/*
* FOR each of the defined options, ...
*/
ct = opts->presetOptCt;
od = opts->pOptDesc;
do {
tOptDesc * p;
/*
* IF the option has not been defined
* OR it does not take an initialization value
* OR it is equivalenced to another option
* THEN continue (ignore it)
*
* Equivalenced options get picked up when the equivalenced-to
* option is processed.
*/
if (UNUSED_OPT(od))
continue;
if ((od->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0)
continue;
if ( (od->optEquivIndex != NO_EQUIVALENT)
&& (od->optEquivIndex != od->optIndex))
continue;
/*
* The option argument data are found at the equivalenced-to option,
* but the actual option argument type comes from the original
* option descriptor. Be careful!
*/
p = ((od->fOptState & OPTST_EQUIVALENCE) != 0)
? (opts->pOptDesc + od->optActualIndex) : od;
switch (OPTST_GET_ARGTYPE(od->fOptState)) {
case OPARG_TYPE_NONE:
prt_no_arg_opt(fp, p, od);
break;
case OPARG_TYPE_NUMERIC:
prt_entry(fp, p, (void*)(p->optArg.argInt));
break;
case OPARG_TYPE_STRING:
prt_str_arg(fp, p);
break;
case OPARG_TYPE_ENUMERATION:
prt_enum_arg(fp, p);
break;
case OPARG_TYPE_MEMBERSHIP:
prt_set_arg(fp, p);
break;
case OPARG_TYPE_BOOLEAN:
prt_entry(fp, p, p->optArg.argBool ? "true" : "false");
break;
case OPARG_TYPE_HIERARCHY:
//.........这里部分代码省略.........
开发者ID:cernekee,项目名称:ocserv,代码行数:101,代码来源:save.c
示例20: emitSetup
static void
emitSetup( tOptions* pOpts )
{
tOptDesc* pOptDesc = pOpts->pOptDesc;
int optionCt = pOpts->presetOptCt;
char const* pzFmt;
char const* pzDefault;
for (;optionCt > 0; pOptDesc++, --optionCt) {
char zVal[16];
/*
* Options that are either usage documentation or are compiled out
* are not to be processed.
*/
if (SKIP_OPT(pOptDesc) || (pOptDesc->pz_NAME == NULL))
continue;
if (pOptDesc->optMaxCt > 1)
pzFmt = zMultiDef;
else pzFmt = zSingleDef;
/*
* IF this is an enumeration/bitmask option, then convert the value
* to a string before printing the default value.
*/
switch (OPTST_GET_ARGTYPE(pOptDesc->fOptState)) {
case OPARG_TYPE_ENUMERATION:
(*(pOptDesc->pOptProc))(OPTPROC_EMIT_SHELL, pOptDesc );
pzDefault = pOptDesc->optArg.argString;
break;
/*
* Numeric and membership bit options are just printed as a number.
*/
case OPARG_TYPE_NUMERIC:
snprintf( z
|
请发表评论