popt/popt.h

ソースコードを見る。

データ構造

struct  poptOption
struct  poptAlias
 A popt alias argument for poptAddAlias(). [詳細]
struct  poptItem_s
 A popt alias or exec argument for poptAddItem(). [詳細]

Auto-generated help/usage

poptOption poptAliasOptions []
 Empty table marker to enable displaying popt alias/exec options.
poptOption poptHelpOptions []
 Auto help table options.

型定義

typedef poptItem_spoptItem
 A popt alias or exec argument for poptAddItem().
typedef poptContext_spoptContext
typedef poptOptionpoptOption
typedef void(*) poptCallbackType (poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
 Table callback prototype.

列挙型

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

関数

poptContext poptGetContext (const char *name, int argc, const char **argv, const struct poptOption *options, int flags)
 Initialize popt context.
void poptResetContext (poptContext con)
 Reinitialize popt context.
int poptGetNextOpt (poptContext con)
 Return value of next option found.
const char * poptGetOptArg (poptContext con)
 Return next option argument (if any).
const char * poptGetArg (poptContext con)
 Return next argument.
const char * poptPeekArg (poptContext con)
 Peek at current argument.
const char ** poptGetArgs (poptContext con)
 Return remaining arguments.
const char * poptBadOption (poptContext con, int flags)
 Return the option which caused the most recent error.
poptContext poptFreeContext (poptContext con)
 Destroy context.
int poptStuffArgs (poptContext con, const char **argv)
 Add arguments to context.
int poptAddAlias (poptContext con, struct poptAlias alias, int flags)
 Add alias to context.
int poptAddItem (poptContext con, poptItem newItem, int flags)
 Add alias/exec item to context.
int poptReadConfigFile (poptContext con, const char *fn)
 Read configuration file.
int poptReadDefaultConfig (poptContext con, int useEnv)
 Read default configuration from /etc/popt and $HOME/.popt.
int poptDupArgv (int argc, const char **argv, int *argcPtr, const char ***argvPtr)
 Duplicate an argument array.
int poptParseArgvString (const char *s, int *argcPtr, const char ***argvPtr)
 Parse a string into an argument array.
int poptConfigFileToString (FILE *fp, char **argstrp, int flags)
 Parses an input configuration file and returns an string that is a command line.
const char * poptStrerror (const int error)
 Return formatted error string for popt failure.
void poptSetExecPath (poptContext con, const char *path, int allowAbsolute)
 Limit search for executables.
void poptPrintHelp (poptContext con, FILE *fp, int flags)
 Print detailed description of options.
void poptPrintUsage (poptContext con, FILE *fp, int flags)
 Print terse description of options.
void poptSetOtherOptionHelp (poptContext con, const char *text)
 Provide text to replace default "[OPTION...]" in help/usage output.
const char * poptGetInvocationName (poptContext con)
 Return argv[0] from context.
int poptStrippedArgv (poptContext con, int argc, char **argv)
 Shuffle argv pointers to remove stripped args, returns new argc.
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.


説明

popt.h で定義されています。


型定義

typedef struct poptItem_s * poptItem

A popt alias or exec argument for poptAddItem().

typedef struct poptContext_s* poptContext

popt.h185 行で定義されています。

typedef struct poptOption* poptOption

popt.h192 行で定義されています。

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

Table callback prototype.

引数:
con context
reason reason for callback
opt option that triggered callback
arg\xrefitem todo 17
data\xrefitem todo 18

popt.h217 行で定義されています。


列挙型

enum poptCallbackReason

列挙型の値:
POPT_CALLBACK_REASON_PRE 
POPT_CALLBACK_REASON_POST 
POPT_CALLBACK_REASON_OPTION 

popt.h197 行で定義されています。

00203            {


関数

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

Initialize popt context.

引数:
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
戻り値:
initialized popt context

popt.c154 行で定義されています。

参照先 invokeCallbacksPRE()optionst.

参照元 main()parse_quota_set()rpc_reg_shutdown_internals().

00156 {
00157     poptContext con = (poptContext)malloc(sizeof(*con));
00158 
00159     if (con == NULL) return NULL;       /* XXX can't happen */
00160     memset(con, 0, sizeof(*con));
00161 
00162     con->os = con->optionStack;
00163     con->os->argc = argc;
00164     /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */
00165     con->os->argv = argv;
00166     /*@=dependenttrans =assignexpose@*/
00167     con->os->argb = NULL;
00168 
00169     if (!(flags & POPT_CONTEXT_KEEP_FIRST))
00170         con->os->next = 1;                      /* skip argv[0] */
00171 
00172     con->leftovers = (const char **)calloc( (argc + 1),
00173                                             sizeof(*con->leftovers) );
00174     /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */
00175     con->options = options;
00176     /*@=dependenttrans =assignexpose@*/
00177     con->aliases = NULL;
00178     con->numAliases = 0;
00179     con->flags = flags;
00180     con->execs = NULL;
00181     con->numExecs = 0;
00182     con->finalArgvAlloced = argc * 2;
00183     con->finalArgv = (const char **)calloc( con->finalArgvAlloced,
00184                                             sizeof(*con->finalArgv) );
00185     con->execAbsolute = 1;
00186     con->arg_strip = NULL;
00187 
00188     if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER"))
00189         con->flags |= POPT_CONTEXT_POSIXMEHARDER;
00190 
00191     if (name) {
00192         char * t = (char *)malloc(strlen(name) + 1);
00193         if (t) con->appName = strcpy(t, name);
00194     }
00195 
00196     /*@-internalglobs@*/
00197     invokeCallbacksPRE(con, con->options);
00198     /*@=internalglobs@*/
00199 
00200     return con;
00201 }

void poptResetContext ( poptContext  con  ) 

Reinitialize popt context.

引数:
con context

popt.c214 行で定義されています。

参照先 _free()poptContext_s::arg_stripoptionStackEntry::argbcleanOSE()optionStackEntry::currAliaspoptContext_s::doExecpoptContext_s::finalArgvpoptContext_s::finalArgvCountoptionStackEntry::nextoptionStackEntry::nextArgoptionStackEntry::nextCharArgpoptContext_s::nextLeftoverpoptContext_s::numLeftoverspoptContext_s::optionStackpoptContext_s::ospoptContext_s::restLeftover.

参照元 poptFreeContext().

00215 {
00216     int i;
00217 
00218     if (con == NULL) return;
00219     while (con->os > con->optionStack) {
00220         cleanOSE(con->os--);
00221     }
00222     con->os->argb = (pbm_set *)PBM_FREE(con->os->argb);
00223     con->os->currAlias = NULL;
00224     con->os->nextCharArg = NULL;
00225     con->os->nextArg = NULL;
00226     con->os->next = 1;                  /* skip argv[0] */
00227 
00228     con->numLeftovers = 0;
00229     con->nextLeftover = 0;
00230     con->restLeftover = 0;
00231     con->doExec = NULL;
00232 
00233     if (con->finalArgv != NULL)
00234     for (i = 0; i < con->finalArgvCount; i++) {
00235         /*@-unqualifiedtrans@*/         /* FIX: typedef double indirection. */
00236         con->finalArgv[i] = (const char *)_free(con->finalArgv[i]);
00237         /*@=unqualifiedtrans@*/
00238     }
00239 
00240     con->finalArgvCount = 0;
00241     con->arg_strip = ( pbm_set *)PBM_FREE(con->arg_strip);
00242     /*@-nullstate@*/    /* FIX: con->finalArgv != NULL */
00243     return;
00244     /*@=nullstate@*/
00245 }

int poptGetNextOpt ( poptContext  con  ) 

Return value of next option found.

引数:
con context
戻り値:
next option val, -1 on last item, POPT_ERROR_* on error

popt.c691 行で定義されています。

参照先 _free()alloca()poptOption::argoptionStackEntry::argboptionStackEntry::argcpoptOption::argInfooptionStackEntry::argvcleanOSE()poptContext_s::doExecerrnoexecCommand()expandNextArg()poptContext_s::finalArgvpoptContext_s::finalArgvAllocedpoptContext_s::finalArgvCountfindOption()poptContext_s::flagsfprintf()handleAlias()handleExec()invokeCallbacksOPTION()invokeCallbacksPOST()poptContext_s::leftoverspoptOption::longNameoptionStackEntry::nextoptionStackEntry::nextArgoptionStackEntry::nextCharArgpoptContext_s::numLeftoverspoptContext_s::optionspoptContext_s::optionStackpoptContext_s::ospoptSaveInt()poptSaveLong()poptStripArg()poptContext_s::restLeftoverpoptOption::shortNamesprintf()poptOption::valxstrdup().

参照元 main()parse_quota_set()rpc_reg_shutdown_internals().

00692 {
00693     const struct poptOption * opt = NULL;
00694     int done = 0;
00695 
00696     if (con == NULL)
00697         return -1;
00698     while (!done) {
00699         const char * origOptString = NULL;
00700         poptCallbackType cb = NULL;
00701         const void * cbData = NULL;
00702         const char * longArg = NULL;
00703         int canstrip = 0;
00704         int shorty = 0;
00705 
00706         while (!con->os->nextCharArg && con->os->next == con->os->argc
00707                 && con->os > con->optionStack) {
00708             cleanOSE(con->os--);
00709         }
00710         if (!con->os->nextCharArg && con->os->next == con->os->argc) {
00711             /*@-internalglobs@*/
00712             invokeCallbacksPOST(con, con->options);
00713             /*@=internalglobs@*/
00714             if (con->doExec) return execCommand(con);
00715             return -1;
00716         }
00717 
00718         /* Process next long option */
00719         if (!con->os->nextCharArg) {
00720             char * localOptString, * optString;
00721             int thisopt;
00722 
00723             /*@-sizeoftype@*/
00724             if (con->os->argb && PBM_ISSET(con->os->next, con->os->argb)) {
00725                 con->os->next++;
00726                 continue;
00727             }
00728             /*@=sizeoftype@*/
00729             thisopt = con->os->next;
00730             if (con->os->argv != NULL)  /* XXX can't happen */
00731             origOptString = con->os->argv[con->os->next++];
00732 
00733             if (origOptString == NULL)  /* XXX can't happen */
00734                 return POPT_ERROR_BADOPT;
00735 
00736             if (con->restLeftover || *origOptString != '-') {
00737                 if (con->flags & POPT_CONTEXT_POSIXMEHARDER)
00738                     con->restLeftover = 1;
00739                 if (con->flags & POPT_CONTEXT_ARG_OPTS) {
00740                     con->os->nextArg = xstrdup(origOptString);
00741                     return 0;
00742                 }
00743                 if (con->leftovers != NULL)     /* XXX can't happen */
00744                     con->leftovers[con->numLeftovers++] = origOptString;
00745                 continue;
00746             }
00747 
00748             /* Make a copy we can hack at */
00749             localOptString = optString =
00750                 strcpy((char *)alloca(strlen(origOptString) + 1),
00751                        origOptString);
00752 
00753             if (optString[0] == '\0')
00754                 return POPT_ERROR_BADOPT;
00755 
00756             if (optString[1] == '-' && !optString[2]) {
00757                 con->restLeftover = 1;
00758                 continue;
00759             } else {
00760                 char *oe;
00761                 int singleDash;
00762 
00763                 optString++;
00764                 if (*optString == '-')
00765                     singleDash = 0, optString++;
00766                 else
00767                     singleDash = 1;
00768 
00769                 /* XXX aliases with arg substitution need "--alias=arg" */
00770                 if (handleAlias(con, optString, '\0', NULL))
00771                     continue;
00772 
00773                 if (handleExec(con, optString, '\0'))
00774                     continue;
00775 
00776                 /* Check for "--long=arg" option. */
00777                 for (oe = optString; *oe && *oe != '='; oe++)
00778                     {};
00779                 if (*oe == '=') {
00780                     *oe++ = '\0';
00781                     /* XXX longArg is mapped back to persistent storage. */
00782                     longArg = origOptString + (oe - localOptString);
00783                 }
00784 
00785                 opt = findOption(con->options, optString, '\0', &cb, &cbData,
00786                                  singleDash);
00787                 if (!opt && !singleDash)
00788                     return POPT_ERROR_BADOPT;
00789             }
00790 
00791             if (!opt) {
00792                 con->os->nextCharArg = origOptString + 1;
00793             } else {
00794                 if (con->os == con->optionStack &&
00795                    opt->argInfo & POPT_ARGFLAG_STRIP)
00796                 {
00797                     canstrip = 1;
00798                     poptStripArg(con, thisopt);
00799                 }
00800                 shorty = 0;
00801             }
00802         }
00803 
00804         /* Process next short option */
00805         /*@-branchstate@*/              /* FIX: W2DO? */
00806         if (con->os->nextCharArg) {
00807             origOptString = con->os->nextCharArg;
00808 
00809             con->os->nextCharArg = NULL;
00810 
00811             if (handleAlias(con, NULL, *origOptString, origOptString + 1))
00812                 continue;
00813 
00814             if (handleExec(con, NULL, *origOptString)) {
00815                 /* Restore rest of short options for further processing */
00816                 origOptString++;
00817                 if (*origOptString != '\0')
00818                     con->os->nextCharArg = origOptString;
00819                 continue;
00820             }
00821 
00822             opt = findOption(con->options, NULL, *origOptString, &cb,
00823                              &cbData, 0);
00824             if (!opt)
00825                 return POPT_ERROR_BADOPT;
00826             shorty = 1;
00827 
00828             origOptString++;
00829             if (*origOptString != '\0')
00830                 con->os->nextCharArg = origOptString;
00831         }
00832         /*@=branchstate@*/
00833 
00834         if (opt == NULL) return POPT_ERROR_BADOPT;      /* XXX can't happen */
00835         if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) {
00836             if (poptSaveInt((int *)opt->arg, opt->argInfo, 1L))
00837                 return POPT_ERROR_BADOPERATION;
00838         } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) {
00839             if (opt->arg) {
00840                 if (poptSaveInt((int *)opt->arg, opt->argInfo, (long)opt->val))
00841                     return POPT_ERROR_BADOPERATION;
00842             }
00843         } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
00844             con->os->nextArg = (const char *)_free(con->os->nextArg);
00845             /*@-usedef@*/       /* FIX: W2DO? */
00846             if (longArg) {
00847             /*@=usedef@*/
00848                 longArg = expandNextArg(con, longArg);
00849                 con->os->nextArg = longArg;
00850             } else if (con->os->nextCharArg) {
00851                 longArg = expandNextArg(con, con->os->nextCharArg);
00852                 con->os->nextArg = longArg;
00853                 con->os->nextCharArg = NULL;
00854             } else {
00855                 while (con->os->next == con->os->argc &&
00856                        con->os > con->optionStack) {
00857                     cleanOSE(con->os--);
00858                 }
00859                 if (con->os->next == con->os->argc) {
00860                     if (!(opt->argInfo & POPT_ARGFLAG_OPTIONAL))
00861                         /*@-compdef@*/  /* FIX: con->os->argv not defined */
00862                         return POPT_ERROR_NOARG;
00863                         /*@=compdef@*/
00864                     con->os->nextArg = NULL;
00865                 } else {
00866 
00867                     /*
00868                      * Make sure this isn't part of a short arg or the
00869                      * result of an alias expansion.
00870                      */
00871                     if (con->os == con->optionStack &&
00872                         (opt->argInfo & POPT_ARGFLAG_STRIP) &&
00873                         canstrip) {
00874                         poptStripArg(con, con->os->next);
00875                     }
00876                 
00877                     if (con->os->argv != NULL) {        /* XXX can't happen */
00878                         /* XXX watchout: subtle side-effects live here. */
00879                         longArg = con->os->argv[con->os->next++];
00880                         longArg = expandNextArg(con, longArg);
00881                         con->os->nextArg = longArg;
00882                     }
00883                 }
00884             }
00885             longArg = NULL;
00886 
00887             if (opt->arg) {
00888                 switch (opt->argInfo & POPT_ARG_MASK) {
00889                 case POPT_ARG_STRING:
00890                     /* XXX memory leak, hard to plug */
00891                     *((const char **) opt->arg) = (con->os->nextArg)
00892                         ? xstrdup(con->os->nextArg) : NULL;
00893                     /*@switchbreak@*/ break;
00894 
00895                 case POPT_ARG_INT:
00896                 case POPT_ARG_LONG:
00897                 {   long aLong = 0;
00898                     char *end;
00899 
00900                     if (con->os->nextArg) {
00901                         aLong = strtol(con->os->nextArg, &end, 0);
00902                         if (!(end && *end == '\0'))
00903                             return POPT_ERROR_BADNUMBER;
00904                     }
00905 
00906                     if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
00907                         if (aLong == LONG_MIN || aLong == LONG_MAX)
00908                             return POPT_ERROR_OVERFLOW;
00909                         if (poptSaveLong((long *)opt->arg, opt->argInfo, aLong))
00910                             return POPT_ERROR_BADOPERATION;
00911                     } else {
00912                         if (aLong > INT_MAX || aLong < INT_MIN)
00913                             return POPT_ERROR_OVERFLOW;
00914                         if (poptSaveInt((int *)opt->arg, opt->argInfo, aLong))
00915                             return POPT_ERROR_BADOPERATION;
00916                     }
00917                 }   /*@switchbreak@*/ break;
00918 
00919                 case POPT_ARG_FLOAT:
00920                 case POPT_ARG_DOUBLE:
00921                 {   double aDouble = 0.0;
00922                     char *end;
00923 
00924                     if (con->os->nextArg) {
00925                         /*@-mods@*/
00926                         int saveerrno = errno;
00927                         errno = 0;
00928                         aDouble = strtod(con->os->nextArg, &end);
00929                         if (errno == ERANGE)
00930                             return POPT_ERROR_OVERFLOW;
00931                         errno = saveerrno;
00932                         /*@=mods@*/
00933                         if (*end != '\0')
00934                             return POPT_ERROR_BADNUMBER;
00935                     }
00936 
00937                     if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) {
00938                         *((double *) opt->arg) = aDouble;
00939                     } else {
00940 #ifndef _ABS
00941 #define _ABS(a) ((((a) - 0.0) < DBL_EPSILON) ? -(a) : (a))
00942 #endif
00943                         if ((_ABS(aDouble) - FLT_MAX) > DBL_EPSILON)
00944                             return POPT_ERROR_OVERFLOW;
00945                         if ((FLT_MIN - _ABS(aDouble)) > DBL_EPSILON)
00946                             return POPT_ERROR_OVERFLOW;
00947                         *((float *) opt->arg) = aDouble;
00948                     }
00949                 }   /*@switchbreak@*/ break;
00950                 default:
00951                     fprintf(stdout,
00952                         POPT_("option type (%d) not implemented in popt\n"),
00953                         (opt->argInfo & POPT_ARG_MASK));
00954                     exit(EXIT_FAILURE);
00955                     /*@notreached@*/ /*@switchbreak@*/ break;
00956                 }
00957             }
00958         }
00959 
00960         if (cb) {
00961             /*@-internalglobs@*/
00962             invokeCallbacksOPTION(con, con->options, opt, cbData, shorty);
00963             /*@=internalglobs@*/
00964         } else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL))
00965             done = 1;
00966 
00967         if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) {
00968             con->finalArgvAlloced += 10;
00969             con->finalArgv = (const char **)realloc(con->finalArgv,
00970                             sizeof(*con->finalArgv) * con->finalArgvAlloced);
00971         }
00972 
00973         if (con->finalArgv != NULL)
00974         {   char *s = (char *)malloc(
00975                 (opt->longName ? strlen(opt->longName) : 0) + 3);
00976             if (s != NULL) {    /* XXX can't happen */
00977                 if (opt->longName)
00978                     sprintf(s, "%s%s",
00979                         ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"),
00980                         opt->longName);
00981                 else
00982                     sprintf(s, "-%c", opt->shortName);
00983                 con->finalArgv[con->finalArgvCount++] = s;
00984             } else
00985                 con->finalArgv[con->finalArgvCount++] = NULL;
00986         }
00987 
00988         if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE)
00989             /*@-ifempty@*/ ; /*@=ifempty@*/
00990         else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL)
00991             /*@-ifempty@*/ ; /*@=ifempty@*/
00992         else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) {
00993             if (con->finalArgv != NULL && con->os->nextArg)
00994                 con->finalArgv[con->finalArgvCount++] =
00995                         /*@-nullpass@*/ /* LCL: con->os->nextArg != NULL */
00996                         xstrdup(con->os->nextArg);
00997                         /*@=nullpass@*/
00998         }
00999     }
01000 
01001     return (opt ? opt->val : -1);       /* XXX can't happen */
01002 }

const char* poptGetOptArg ( poptContext  con  ) 

Return next option argument (if any).

引数:
con context
戻り値:
option argument, NULL if no argument is available

popt.c1005 行で定義されています。

参照先 optionStackEntry::nextArgpoptContext_s::os.

参照元 main()parse_quota_set().

01006 {
01007     const char * ret = NULL;
01008     /*@-branchstate@*/
01009     if (con) {
01010         ret = con->os->nextArg;
01011         con->os->nextArg = NULL;
01012     }
01013     /*@=branchstate@*/
01014     return ret;
01015 }

const char* poptGetArg ( poptContext  con  ) 

Return next argument.

引数:
con context
戻り値:
next argument, NULL if no argument is available

popt.c1017 行で定義されています。

参照先 poptContext_s::leftoverspoptContext_s::nextLeftoverpoptContext_s::numLeftovers.

参照元 main()parse_quota_set().

01018 {
01019     const char * ret = NULL;
01020     if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
01021         ret = con->leftovers[con->nextLeftover++];
01022     return ret;
01023 }

const char* poptPeekArg ( poptContext  con  ) 

Peek at current argument.

引数:
con context
戻り値:
current argument, NULL if no argument is available

popt.c1025 行で定義されています。

参照先 poptContext_s::leftoverspoptContext_s::nextLeftoverpoptContext_s::numLeftovers.

参照元 main()parse_quota_set().

01026 {
01027     const char * ret = NULL;
01028     if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
01029         ret = con->leftovers[con->nextLeftover];
01030     return ret;
01031 }

const char** poptGetArgs ( poptContext  con  ) 

Return remaining arguments.

引数:
con context
戻り値:
argument array, NULL terminated

popt.c1034 行で定義されています。

参照先 poptContext_s::leftoverspoptContext_s::nextLeftoverpoptContext_s::numLeftovers.

参照元 main().

01035 {
01036     if (con == NULL ||
01037         con->leftovers == NULL || con->numLeftovers == con->nextLeftover)
01038         return NULL;
01039 
01040     /* some apps like [like RPM ;-) ] need this NULL terminated */
01041     con->leftovers[con->numLeftovers] = NULL;
01042 
01043     /*@-nullret -nullstate @*/  /* FIX: typedef double indirection. */
01044     return (con->leftovers + con->nextLeftover);
01045     /*@=nullret =nullstate @*/
01046 }

const char* poptBadOption ( poptContext  con,
int  flags 
)

Return the option which caused the most recent error.

引数:
con context
flags 
戻り値:
offending option

popt.c1157 行で定義されています。

参照先 optionStackEntry::argvoptionStackEntry::nextpoptContext_s::optionStackpoptContext_s::os.

参照元 main()rpc_reg_shutdown_internals().

01158 {
01159     struct optionStackEntry * os = NULL;
01160 
01161     if (con != NULL)
01162         os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
01163 
01164     /*@-nullderef@*/    /* LCL: os->argv != NULL */
01165     return (os && os->argv ? os->argv[os->next - 1] : NULL);
01166     /*@=nullderef@*/
01167 }

poptContext poptFreeContext ( poptContext  con  ) 

Destroy context.

引数:
con context
戻り値:
NULL always

popt.c1049 行で定義されています。

参照先 _free()poptContext_s::aliasespoptContext_s::appNamepoptContext_s::arg_stripoptionStackEntry::argbpoptOption::argDescrippoptItem_s::argvpoptOption::descrippoptContext_s::execPathpoptContext_s::execspoptContext_s::finalArgvpoptContext_s::leftoverspoptOption::longNamepoptContext_s::numAliasespoptContext_s::numExecspoptItem_s::optionpoptContext_s::ospoptContext_s::otherHelppoptResetContext().

参照元 main().

01050 {
01051     poptItem item;
01052     int i;
01053 
01054     if (con == NULL) return con;
01055     poptResetContext(con);
01056     con->os->argb = (pbm_set *)_free(con->os->argb);
01057 
01058     if (con->aliases != NULL)
01059     for (i = 0; i < con->numAliases; i++) {
01060         item = con->aliases + i;
01061         /*@-modobserver -observertrans -dependenttrans@*/
01062         item->option.longName = (const char *)_free(item->option.longName);
01063         item->option.descrip = (const char *)_free(item->option.descrip);
01064         item->option.argDescrip = (const char *)_free(item->option.argDescrip);
01065         /*@=modobserver =observertrans =dependenttrans@*/
01066         item->argv = (const char **)_free(item->argv);
01067     }
01068     con->aliases = (poptItem)_free(con->aliases);
01069 
01070     if (con->execs != NULL)
01071     for (i = 0; i < con->numExecs; i++) {
01072         item = con->execs + i;
01073         /*@-modobserver -observertrans -dependenttrans@*/
01074         item->option.longName = (const char *)_free(item->option.longName);
01075         item->option.descrip = (const char *)_free(item->option.descrip);
01076         item->option.argDescrip = (const char *)_free(item->option.argDescrip);
01077         /*@=modobserver =observertrans =dependenttrans@*/
01078         item->argv = (const char **)_free(item->argv);
01079     }
01080     con->execs = (poptItem)_free(con->execs);
01081 
01082     con->leftovers = (const char **)_free(con->leftovers);
01083     con->finalArgv = (const char **)_free(con->finalArgv);
01084     con->appName = (const char *)_free(con->appName);
01085     con->otherHelp = (const char *)_free(con->otherHelp);
01086     con->execPath = (const char *)_free(con->execPath);
01087     con->arg_strip = (pbm_set *)PBM_FREE(con->arg_strip);
01088     
01089     con = (poptContext)_free(con);
01090     return con;
01091 }

int poptStuffArgs ( poptContext  con,
const char **  argv 
)

Add arguments to context.

引数:
con context
argv argument array, NULL terminated
戻り値:
0 on success, POPT_ERROR_OPTSTOODEEP on failure

popt.c1197 行で定義されています。

参照先 optionStackEntry::argboptionStackEntry::argcoptionStackEntry::argvoptionStackEntry::currAliasoptionStackEntry::nextoptionStackEntry::nextArgoptionStackEntry::nextCharArgpoptContext_s::optionStackpoptContext_s::ospoptDupArgv()optionStackEntry::stuffed.

01198 {
01199     int argc;
01200     int rc;
01201 
01202     if ((con->os - con->optionStack) == POPT_OPTION_DEPTH)
01203         return POPT_ERROR_OPTSTOODEEP;
01204 
01205     for (argc = 0; argv[argc]; argc++)
01206         {};
01207 
01208     con->os++;
01209     con->os->next = 0;
01210     con->os->nextArg = NULL;
01211     con->os->nextCharArg = NULL;
01212     con->os->currAlias = NULL;
01213     rc = poptDupArgv(argc, argv, &con->os->argc, &con->os->argv);
01214     con->os->argb = NULL;
01215     con->os->stuffed = 1;
01216 
01217     return rc;
01218 }

int poptAddAlias ( poptContext  con,
struct poptAlias  alias,
int  flags 
)

Add alias to context.

TODO:
Pass alias by reference, not value.
非推奨:
Use poptAddItem instead.
引数:
con context
alias alias to add
flags (unused)
戻り値:
0 on success

popt.c1093 行で定義されています。

参照先 alloca()poptAlias::argcpoptAlias::argvpoptAlias::longNamepoptAddItem()poptAlias::shortName.

01095 {
01096     poptItem item = (poptItem)alloca(sizeof(*item));
01097     memset(item, 0, sizeof(*item));
01098     item->option.longName = alias.longName;
01099     item->option.shortName = alias.shortName;
01100     item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN;
01101     item->option.arg = 0;
01102     item->option.val = 0;
01103     item->option.descrip = NULL;
01104     item->option.argDescrip = NULL;
01105     item->argc = alias.argc;
01106     item->argv = alias.argv;
01107     return poptAddItem(con, item, 0);
01108 }

int poptAddItem ( poptContext  con,
poptItem  newItem,
int  flags 
)

Add alias/exec item to context.

引数:
con context
newItem alias/exec item to add
flags 0 for alias, 1 for exec
戻り値:
0 on success

popt.c1112 行で定義されています。

参照先 poptContext_s::aliasespoptOption::argpoptItem_s::argcpoptOption::argDescrippoptOption::argInfopoptItem_s::argvpoptOption::descrippoptContext_s::execspoptOption::longNamepoptContext_s::numAliasespoptContext_s::numExecspoptItem_s::optionpoptOption::shortNamepoptOption::valxstrdup().

参照元 poptAddAlias().

01113 {
01114     poptItem * items, item;
01115     int * nitems;
01116 
01117     switch (flags) {
01118     case 1:
01119         items = &con->execs;
01120         nitems = &con->numExecs;
01121         break;
01122     case 0:
01123         items = &con->aliases;
01124         nitems = &con->numAliases;
01125         break;
01126     default:
01127         return 1;
01128         /*@notreached@*/ break;
01129     }
01130 
01131     *items = (poptItem)realloc((*items), ((*nitems) + 1) * sizeof(**items));
01132     if ((*items) == NULL)
01133         return 1;
01134 
01135     item = (*items) + (*nitems);
01136 
01137     item->option.longName =
01138         (newItem->option.longName ? xstrdup(newItem->option.longName) : NULL);
01139     item->option.shortName = newItem->option.shortName;
01140     item->option.argInfo = newItem->option.argInfo;
01141     item->option.arg = newItem->option.arg;
01142     item->option.val = newItem->option.val;
01143     item->option.descrip =
01144         (newItem->option.descrip ? xstrdup(newItem->option.descrip) : NULL);
01145     item->option.argDescrip =
01146        (newItem->option.argDescrip ? xstrdup(newItem->option.argDescrip) : NULL);
01147     item->argc = newItem->argc;
01148     item->argv = newItem->argv;
01149 
01150     (*nitems)++;
01151 
01152     return 0;
01153 }

int poptReadConfigFile ( poptContext  con,
const char *  fn 
)

Read configuration file.

引数:
con context
fn file name to read
戻り値:
0 on success, POPT_ERROR_ERRNO on failure

poptconfig.c95 行で定義されています。

参照先 alloca()bufconfigLine()errnofd.

参照元 poptReadDefaultConfig().

00096 {
00097     const char * file, * chptr, * end;
00098     char * buf;
00099 /*@dependent@*/ char * dst;
00100     int fd, rc;
00101     off_t fileLength;
00102 
00103     fd = open(fn, O_RDONLY);
00104     if (fd < 0)
00105         return (errno == ENOENT ? 0 : POPT_ERROR_ERRNO);
00106 
00107     fileLength = lseek(fd, 0, SEEK_END);
00108     if (fileLength == -1 || lseek(fd, 0, 0) == -1) {
00109         rc = errno;
00110         (void) close(fd);
00111         /*@-mods@*/
00112         errno = rc;
00113         /*@=mods@*/
00114         return POPT_ERROR_ERRNO;
00115     }
00116 
00117     file = alloca(fileLength + 1);
00118     if (read(fd, (char *)file, fileLength) != fileLength) {
00119         rc = errno;
00120         (void) close(fd);
00121         /*@-mods@*/
00122         errno = rc;
00123         /*@=mods@*/
00124         return POPT_ERROR_ERRNO;
00125     }
00126     if (close(fd) == -1)
00127         return POPT_ERROR_ERRNO;
00128 
00129 /*@-boundswrite@*/
00130     dst = buf = alloca(fileLength + 1);
00131 
00132     chptr = file;
00133     end = (file + fileLength);
00134     /*@-infloops@*/     /* LCL: can't detect chptr++ */
00135     while (chptr < end) {
00136         switch (*chptr) {
00137           case '\n':
00138             *dst = '\0';
00139             dst = buf;
00140             while (*dst && isspace(*dst)) dst++;
00141             if (*dst && *dst != '#')
00142                 configLine(con, dst);
00143             chptr++;
00144             /*@switchbreak@*/ break;
00145           case '\\':
00146             *dst++ = *chptr++;
00147             if (chptr < end) {
00148                 if (*chptr == '\n') 
00149                     dst--, chptr++;     
00150                     /* \ at the end of a line does not insert a \n */
00151                 else
00152                     *dst++ = *chptr++;
00153             }
00154             /*@switchbreak@*/ break;
00155           default:
00156             *dst++ = *chptr++;
00157             /*@switchbreak@*/ break;
00158         }
00159     }
00160     /*@=infloops@*/
00161 /*@=boundswrite@*/
00162 
00163     return 0;
00164 }

int poptReadDefaultConfig ( poptContext  con,
int  useEnv 
)

Read default configuration from /etc/popt and $HOME/.popt.

引数:
con context
useEnv (unused)
戻り値:
0 on success, POPT_ERROR_ERRNO on failure

poptconfig.c166 行で定義されています。

参照先 alloca()poptContext_s::appNamefnpoptReadConfigFile().

00167 {
00168     char * fn, * home;
00169     int rc;
00170 
00171     /*@-type@*/
00172     if (!con->appName) return 0;
00173     /*@=type@*/
00174 
00175     rc = poptReadConfigFile(con, "/etc/popt");
00176     if (rc) return rc;
00177 #if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
00178     if (getuid() != geteuid()) return 0;
00179 #endif
00180 
00181     if ((home = getenv("HOME"))) {
00182         fn = alloca(strlen(home) + 20);
00183         strcpy(fn, home);
00184         strcat(fn, "/.popt");
00185         rc = poptReadConfigFile(con, fn);
00186         if (rc) return rc;
00187     }
00188 
00189     return 0;
00190 }

int poptDupArgv ( int  argc,
const char **  argv,
int *  argcPtr,
const char ***  argvPtr 
)

Duplicate an argument array.

覚え書き:
: The argument array is malloc'd as a single area, so only argv must be free'd.
引数:
argc no. of arguments
argv argument array
戻り値:
argcPtr address of returned no. of arguments
argvPtr address of returned argument array
戻り値:
0 on success, POPT_ERROR_NOARG on failure

poptparse.c14 行で定義されています。

参照元 handleAlias()poptParseArgvString()poptStuffArgs().

00016 {
00017     size_t nb = (argc + 1) * sizeof(*argv);
00018     const char ** argv2;
00019     char * dst;
00020     int i;
00021 
00022     if (argc <= 0 || argv == NULL)      /* XXX can't happen */
00023         return POPT_ERROR_NOARG;
00024     for (i = 0; i < argc; i++) {
00025         if (argv[i] == NULL)
00026             return POPT_ERROR_NOARG;
00027         nb += strlen(argv[i]) + 1;
00028     }
00029         
00030     dst = malloc(nb);
00031     if (dst == NULL)                    /* XXX can't happen */
00032         return POPT_ERROR_MALLOC;
00033     argv2 = (void *) dst;
00034     dst += (argc + 1) * sizeof(*argv);
00035 
00036     /*@-branchstate@*/
00037     for (i = 0; i < argc; i++) {
00038         argv2[i] = dst;
00039         dst += strlen(strcpy(dst, argv[i])) + 1;
00040     }
00041     /*@=branchstate@*/
00042     argv2[argc] = NULL;
00043 
00044     if (argvPtr) {
00045         *argvPtr = argv2;
00046     } else {
00047         free(argv2);
00048         argv2 = NULL;
00049     }
00050     if (argcPtr)
00051         *argcPtr = argc;
00052     return 0;
00053 }

int poptParseArgvString ( const char *  s,
int *  argcPtr,
const char ***  argvPtr 
)

Parse a string into an argument array.

The parse allows ', ", and \ quoting, but ' is treated the same as " and both may include \ quotes.

覚え書き:
: The argument array is malloc'd as a single area, so only argv must be free'd.
引数:
s string to parse
戻り値:
argcPtr address of returned no. of arguments
argvPtr address of returned argument array

poptparse.c57 行で定義されています。

参照先 alloca()bufpoptDupArgv().

参照元 configLine()net_rpc_shell()process_cmd().

00058 {
00059     const char * src;
00060     char quote = '\0';
00061     int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA;
00062     const char ** argv = malloc(sizeof(*argv) * argvAlloced);
00063     int argc = 0;
00064     int buflen = strlen(s) + 1;
00065     char * buf = memset(alloca(buflen), 0, buflen);
00066     int rc = POPT_ERROR_MALLOC;
00067 
00068     if (argv == NULL) return rc;
00069     argv[argc] = buf;
00070 
00071     for (src = s; *src != '\0'; src++) {
00072         if (quote == *src) {
00073             quote = '\0';
00074         } else if (quote != '\0') {
00075             if (*src == '\\') {
00076                 src++;
00077                 if (!*src) {
00078                     rc = POPT_ERROR_BADQUOTE;
00079                     goto exit;
00080                 }
00081                 if (*src != quote) *buf++ = '\\';
00082             }
00083             *buf++ = *src;
00084         } else if (isspace(*src)) {
00085             if (*argv[argc] != '\0') {
00086                 buf++, argc++;
00087                 if (argc == argvAlloced) {
00088                     argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
00089                     argv = realloc(argv, sizeof(*argv) * argvAlloced);
00090                     if (argv == NULL) goto exit;
00091                 }
00092                 argv[argc] = buf;
00093             }
00094         } else switch (*src) {
00095           case '"':
00096           case '\'':
00097             quote = *src;
00098             /*@switchbreak@*/ break;
00099           case '\\':
00100             src++;
00101             if (!*src) {
00102                 rc = POPT_ERROR_BADQUOTE;
00103                 goto exit;
00104             }
00105             /*@fallthrough@*/
00106           default:
00107             *buf++ = *src;
00108             /*@switchbreak@*/ break;
00109         }
00110     }
00111 
00112     if (strlen(argv[argc])) {
00113         argc++, buf++;
00114     }
00115 
00116     rc = poptDupArgv(argc, argv, argcPtr, argvPtr);
00117 
00118 exit:
00119     if (argv) free(argv);
00120     return rc;
00121 }

int poptConfigFileToString ( FILE *  fp,
char **  argstrp,
int  flags 
)

Parses an input configuration file and returns an string that is a command line.

For use with popt. You must free the return value when done.

Given the file:

# this line is ignored
    #   this one too
aaa
  bbb
    ccc
bla=bla

this_is   =   fdsafdas
     bad_line=
  reall bad line
  reall bad line  = again
5555=   55555
  test = with lots of spaces

The result is:

--aaa --bbb --ccc --bla="bla" --this_is="fdsafdas" --5555="55555" --test="with lots of spaces"

Passing this to poptParseArgvString() yields an argv of:

'--aaa'
'--bbb'
'--ccc'
'--bla=bla'
'--this_is=fdsafdas'
'--5555=55555'
'--test=with lots of spaces'

バグ:
NULL is returned if file line is too long.

Silently ignores invalid lines.

引数:
fp file handle to read
*argstrp return string of options (malloc'd)
flags unused
戻り値:
0 on success
参照:
poptParseArgvString

poptparse.c129 行で定義されています。

参照先 linet.

00130 {
00131     char line[999];
00132     char * argstr;
00133     char * p;
00134     char * q;
00135     char * x;
00136     int t;
00137     int argvlen = 0;
00138     size_t maxlinelen = sizeof(line);
00139     size_t linelen;
00140     int maxargvlen = 480;
00141     int linenum = 0;
00142 
00143     *argstrp = NULL;
00144 
00145     /*   |   this_is   =   our_line
00146      *       p             q      x
00147      */
00148 
00149     if (fp == NULL)
00150         return POPT_ERROR_NULLARG;
00151 
00152     argstr = calloc(maxargvlen, sizeof(*argstr));
00153     if (argstr == NULL) return POPT_ERROR_MALLOC;
00154 
00155     while (fgets(line, (int)maxlinelen, fp) != NULL) {
00156         linenum++;
00157         p = line;
00158 
00159         /* loop until first non-space char or EOL */
00160         while( *p != '\0' && isspace(*p) )
00161             p++;
00162 
00163         linelen = strlen(p);
00164         if (linelen >= maxlinelen-1)
00165             return POPT_ERROR_OVERFLOW; /* XXX line too long */
00166 
00167         if (*p == '\0' || *p == '\n') continue; /* line is empty */
00168         if (*p == '#') continue;                /* comment line */
00169 
00170         q = p;
00171 
00172         while (*q != '\0' && (!isspace(*q)) && *q != '=')
00173             q++;
00174 
00175         if (isspace(*q)) {
00176             /* a space after the name, find next non space */
00177             *q++='\0';
00178             while( *q != '\0' && isspace((int)*q) ) q++;
00179         }
00180         if (*q == '\0') {
00181             /* single command line option (ie, no name=val, just name) */
00182             q[-1] = '\0';               /* kill off newline from fgets() call */
00183             argvlen += (t = q - p) + (sizeof(" --")-1);
00184             if (argvlen >= maxargvlen) {
00185                 maxargvlen = (t > maxargvlen) ? t*2 : maxargvlen*2;
00186                 argstr = realloc(argstr, maxargvlen);
00187                 if (argstr == NULL) return POPT_ERROR_MALLOC;
00188             }
00189             strcat(argstr, " --");
00190             strcat(argstr, p);
00191             continue;
00192         }
00193         if (*q != '=')
00194             continue;   /* XXX for now, silently ignore bogus line */
00195 
00196         /* *q is an equal sign. */
00197         *q++ = '\0';
00198 
00199         /* find next non-space letter of value */
00200         while (*q != '\0' && isspace(*q))
00201             q++;
00202         if (*q == '\0')
00203             continue;   /* XXX silently ignore missing value */
00204 
00205         /* now, loop and strip all ending whitespace */
00206         x = p + linelen;
00207         while (isspace(*--x))
00208             *x = 0;     /* null out last char if space (including fgets() NL) */
00209 
00210         /* rest of line accept */
00211         t = x - p;
00212         argvlen += t + (sizeof("' --='")-1);
00213         if (argvlen >= maxargvlen) {
00214             maxargvlen = (t > maxargvlen) ? t*2 : maxargvlen*2;
00215             argstr = realloc(argstr, maxargvlen);
00216             if (argstr == NULL) return POPT_ERROR_MALLOC;
00217         }
00218         strcat(argstr, " --");
00219         strcat(argstr, p);
00220         strcat(argstr, "=\"");
00221         strcat(argstr, q);
00222         strcat(argstr, "\"");
00223     }
00224 
00225     *argstrp = argstr;
00226     return 0;
00227 }

const char* poptStrerror ( const int  error  ) 

Return formatted error string for popt failure.

引数:
error popt error
戻り値:
error string

popt.c1169 行で定義されています。

参照先 errnostrerror().

参照元 main()net_rpc_shell()process_cmd()rpc_reg_shutdown_internals().

01170 {
01171     switch (error) {
01172       case POPT_ERROR_NOARG:
01173         return POPT_("missing argument");
01174       case POPT_ERROR_BADOPT:
01175         return POPT_("unknown option");
01176       case POPT_ERROR_BADOPERATION:
01177         return POPT_("mutually exclusive logical operations requested");
01178       case POPT_ERROR_NULLARG:
01179         return POPT_("opt->arg should not be NULL");
01180       case POPT_ERROR_OPTSTOODEEP:
01181         return POPT_("aliases nested too deeply");
01182       case POPT_ERROR_BADQUOTE:
01183         return POPT_("error in parameter quoting");
01184       case POPT_ERROR_BADNUMBER:
01185         return POPT_("invalid numeric value");
01186       case POPT_ERROR_OVERFLOW:
01187         return POPT_("number too large or too small");
01188       case POPT_ERROR_MALLOC:
01189         return POPT_("memory allocation failed");
01190       case POPT_ERROR_ERRNO:
01191         return strerror(errno);
01192       default:
01193         return POPT_("unknown error");
01194     }
01195 }

void poptSetExecPath ( poptContext  con,
const char *  path,
int  allowAbsolute 
)

Limit search for executables.

引数:
con context
path single path to search for executables
allowAbsolute absolute paths only?

popt.c52 行で定義されています。

参照先 _free()poptContext_s::execAbsolutepoptContext_s::execPathxstrdup().

00053 {
00054     con->execPath = (const char *)_free(con->execPath);
00055     con->execPath = xstrdup(path);
00056     con->execAbsolute = allowAbsolute;
00057     /*@-nullstate@*/ /* LCL: con->execPath can be NULL? */
00058     return;
00059     /*@=nullstate@*/
00060 }

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

Print detailed description of options.

引数:
con context
fp ouput file handle
flags (unused)

popthelp.c502 行で定義されています。

参照先 fprintf()maxArgWidth()poptContext_s::optionspoptContext_s::otherHelpshowHelpIntro()singleTableHelp().

参照元 displayArgs()main()usage().

00503 {
00504     int leftColWidth;
00505 
00506     (void) showHelpIntro(con, fp);
00507     if (con->otherHelp)
00508         fprintf(fp, " %s\n", con->otherHelp);
00509     else
00510         fprintf(fp, " %s\n", POPT_("[OPTION...]"));
00511 
00512     leftColWidth = maxArgWidth(con->options, NULL);
00513     singleTableHelp(con, fp, con->options, leftColWidth, NULL);
00514 }

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

Print terse description of options.

引数:
con context
fp ouput file handle
flags (unused)

popthelp.c705 行で定義されています。

参照先 poptContext_s::aliasesalloca()poptContext_s::execsfprintf()itemUsage()poptContext_s::numAliasespoptContext_s::numExecspoptContext_s::optionspoptContext_s::otherHelpshowHelpIntro()showShortOptions()singleTableUsage().

参照元 displayArgs()main()parse_quota_set().

00706 {
00707     poptDone done = memset(alloca(sizeof(*done)), 0, sizeof(*done));
00708     int cursor;
00709 
00710     done->nopts = 0;
00711     done->maxopts = 64;
00712     cursor = done->maxopts * sizeof(*done->opts);
00713 /*@-boundswrite@*/
00714     done->opts = memset(alloca(cursor), 0, cursor);
00715     done->opts[done->nopts++] = (const void *) con->options;
00716 /*@=boundswrite@*/
00717 
00718     cursor = showHelpIntro(con, fp);
00719     cursor += showShortOptions(con->options, fp, NULL);
00720     cursor = singleTableUsage(con, fp, cursor, con->options, NULL, done);
00721     cursor = itemUsage(fp, cursor, con->aliases, con->numAliases, NULL);
00722     cursor = itemUsage(fp, cursor, con->execs, con->numExecs, NULL);
00723 
00724     if (con->otherHelp) {
00725         cursor += strlen(con->otherHelp) + 1;
00726         if (cursor > 79) fprintf(fp, "\n       ");
00727         fprintf(fp, " %s", con->otherHelp);
00728     }
00729 
00730     fprintf(fp, "\n");
00731 }

void poptSetOtherOptionHelp ( poptContext  con,
const char *  text 
)

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

引数:
con context
text replacement text

popthelp.c733 行で定義されています。

参照先 _free()poptContext_s::otherHelpxstrdup().

参照元 main()parse_quota_set().

00734 {
00735     con->otherHelp = _free(con->otherHelp);
00736     con->otherHelp = xstrdup(text);
00737 }

const char* poptGetInvocationName ( poptContext  con  ) 

Return argv[0] from context.

引数:
con context
戻り値:
argv[0]

popt.c1220 行で定義されています。

参照先 optionStackEntry::argvpoptContext_s::os.

参照元 set_logfile().

01221 {
01222     return (con->os->argv ? con->os->argv[0] : "");
01223 }

int poptStrippedArgv ( poptContext  con,
int  argc,
char **  argv 
)

Shuffle argv pointers to remove stripped args, returns new argc.

引数:
con context
argc no. of args
argv arg vector
戻り値:
new argc

popt.c1226 行で定義されています。

参照先 poptContext_s::arg_strip.

01227 {
01228     int numargs = argc;
01229     int j = 1;
01230     int i;
01231     
01232     /*@-sizeoftype@*/
01233     if (con->arg_strip)
01234     for (i = 1; i < argc; i++) {
01235         if (PBM_ISSET(i, con->arg_strip))
01236             numargs--;
01237     }
01238     
01239     for (i = 1; i < argc; i++) {
01240         if (con->arg_strip && PBM_ISSET(i, con->arg_strip))
01241             continue;
01242         argv[j] = (j < numargs) ? argv[i] : NULL;
01243         j++;
01244     }
01245     /*@=sizeoftype@*/
01246     
01247     return numargs;
01248 }

int poptSaveLong ( long *  arg,
int  argInfo,
long  aLong 
)

Save a long, performing logical operation with value.

警告:
Alignment check may be too strict on certain platorms.
引数:
arg integer pointer, aligned on int boundary.
argInfo logical operation (see POPT_ARGFLAG_*)
aLong value to use
戻り値:
0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION

popt.c633 行で定義されています。

参照元 poptGetNextOpt().

00634 {
00635     /* XXX Check alignment, may fail on funky platforms. */
00636     if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
00637         return POPT_ERROR_NULLARG;
00638 
00639     if (argInfo & POPT_ARGFLAG_NOT)
00640         aLong = ~aLong;
00641     switch (argInfo & POPT_ARGFLAG_LOGICALOPS) {
00642     case 0:
00643         *arg = aLong;
00644         break;
00645     case POPT_ARGFLAG_OR:
00646         *arg |= aLong;
00647         break;
00648     case POPT_ARGFLAG_AND:
00649         *arg &= aLong;
00650         break;
00651     case POPT_ARGFLAG_XOR:
00652         *arg ^= aLong;
00653         break;
00654     default:
00655         return POPT_ERROR_BADOPERATION;
00656         /*@notreached@*/ break;
00657     }
00658     return 0;
00659 }

int poptSaveInt ( int *  arg,
int  argInfo,
long  aLong 
)

Save an integer, performing logical operation with value.

警告:
Alignment check may be too strict on certain platorms.
引数:
arg integer pointer, aligned on int boundary.
argInfo logical operation (see POPT_ARGFLAG_*)
aLong value to use
戻り値:
0 on success, POPT_ERROR_NULLARG/POPT_ERROR_BADOPERATION

popt.c661 行で定義されています。

参照元 poptGetNextOpt().

00662 {
00663     /* XXX Check alignment, may fail on funky platforms. */
00664     if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1)))
00665         return POPT_ERROR_NULLARG;
00666 
00667     if (argInfo & POPT_ARGFLAG_NOT)
00668         aLong = ~aLong;
00669     switch (argInfo & POPT_ARGFLAG_LOGICALOPS) {
00670     case 0:
00671         *arg = aLong;
00672         break;
00673     case POPT_ARGFLAG_OR:
00674         *arg |= aLong;
00675         break;
00676     case POPT_ARGFLAG_AND:
00677         *arg &= aLong;
00678         break;
00679     case POPT_ARGFLAG_XOR:
00680         *arg ^= aLong;
00681         break;
00682     default:
00683         return POPT_ERROR_BADOPERATION;
00684         /*@notreached@*/ break;
00685     }
00686     return 0;
00687 }


変数

struct poptOption poptAliasOptions[]

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

popthelp.c46 行で定義されています。

参照元 singleTableHelp().

struct poptOption poptHelpOptions[]

Auto help table options.

popthelp.c55 行で定義されています。

参照元 getArgDescrip().


Sambaに対してSat Aug 29 21:24:02 2009に生成されました。  doxygen 1.4.7