popt.c revision 10e23eebca4175a8dfe3a788b2bebacb1fcfce54
110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/** \ingroup popt 210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * \file popt/popt.c 310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* (C) 1998-2002 Red Hat, Inc. -- Licensing details are in the COPYING 610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project file accompanying popt source distributions, available from 710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ftp://ftp.rpm.org/pub/rpm/dist */ 810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#undef MYDEBUG 1010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 1110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include "system.h" 1210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 1310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#if HAVE_FLOAT_H 1410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include <float.h> 1510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 1610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include <math.h> 1710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 1810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include "findme.h" 1910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#include "poptint.h" 2010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 2110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#ifdef MYDEBUG 2210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@unchecked@*/ 2310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint _popt_debug = 0; 2410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 2510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 2610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#if !defined(HAVE_STRERROR) && !defined(__LCLINT__) 2710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic char * strerror(int errno) 2810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 2910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project extern int sys_nerr; 3010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project extern char * sys_errlist[]; 3110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 3210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((0 <= errno) && (errno < sys_nerr)) 3310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return sys_errlist[errno]; 3410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else 3510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("unknown errno"); 3610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 3710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 3810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 3910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#ifdef MYDEBUG 4010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@unused@*/ 4110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic void prtcon(const char *msg, poptContext con) 4210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 4310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (msg) fprintf(stderr, "%s", msg); 4410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project fprintf(stderr, "\tcon %p os %p nextCharArg \"%s\" nextArg \"%s\" argv[%d] \"%s\"\n", 4510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con, con->os, 4610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (con->os->nextCharArg ? con->os->nextCharArg : ""), 4710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (con->os->nextArg ? con->os->nextArg : ""), 4810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next, 4910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (con->os->argv && con->os->argv[con->os->next] 5010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ? con->os->argv[con->os->next] : "")); 5110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 5210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 5310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 5410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid poptSetExecPath(poptContext con, const char * path, int allowAbsolute) 5510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 5610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->execPath = _free(con->execPath); 5710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->execPath = xstrdup(path); 5810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->execAbsolute = allowAbsolute; 5910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullstate@*/ /* LCL: con->execPath not NULL */ 6010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return; 6110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullstate@*/ 6210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 6310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 6410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic void invokeCallbacksPRE(poptContext con, const struct poptOption * opt) 6510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@globals internalState@*/ 6610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies internalState@*/ 6710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 6810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt != NULL) 6910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (; opt->longName || opt->shortName || opt->arg; opt++) { 7010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->arg == NULL) continue; /* XXX program error. */ 7110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 7210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project void * arg = opt->arg; 7310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-branchstate@*/ 7410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX sick hack to preserve pretense of ABI. */ 7510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (arg == poptHelpOptions) arg = poptHelpOptionsI18N; 7610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=branchstate@*/ 7710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Recurse on included sub-tables. */ 7810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project invokeCallbacksPRE(con, arg); 7910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && 8010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (opt->argInfo & POPT_CBFLAG_PRE)) 8110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { /*@-castfcnptr@*/ 8210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptCallbackType cb = (poptCallbackType)opt->arg; 8310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=castfcnptr@*/ 8410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Perform callback. */ 8510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-noeffectuncon @*/ 8610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cb(con, POPT_CALLBACK_REASON_PRE, NULL, NULL, opt->descrip); 8710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=noeffectuncon @*/ 8810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 8910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 9010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 9110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 9210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic void invokeCallbacksPOST(poptContext con, const struct poptOption * opt) 9310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@globals internalState@*/ 9410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies internalState@*/ 9510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 9610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt != NULL) 9710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (; opt->longName || opt->shortName || opt->arg; opt++) { 9810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->arg == NULL) continue; /* XXX program error. */ 9910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 10010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project void * arg = opt->arg; 10110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-branchstate@*/ 10210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX sick hack to preserve pretense of ABI. */ 10310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (arg == poptHelpOptions) arg = poptHelpOptionsI18N; 10410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=branchstate@*/ 10510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Recurse on included sub-tables. */ 10610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project invokeCallbacksPOST(con, arg); 10710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && 10810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (opt->argInfo & POPT_CBFLAG_POST)) 10910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { /*@-castfcnptr@*/ 11010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptCallbackType cb = (poptCallbackType)opt->arg; 11110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=castfcnptr@*/ 11210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Perform callback. */ 11310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-noeffectuncon @*/ 11410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cb(con, POPT_CALLBACK_REASON_POST, NULL, NULL, opt->descrip); 11510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=noeffectuncon @*/ 11610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 11710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 11810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 11910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 12010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic void invokeCallbacksOPTION(poptContext con, 12110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const struct poptOption * opt, 12210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const struct poptOption * myOpt, 12310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@null@*/ const void * myData, int shorty) 12410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@globals internalState@*/ 12510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies internalState@*/ 12610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 12710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const struct poptOption * cbopt = NULL; 12810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 12910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt != NULL) 13010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (; opt->longName || opt->shortName || opt->arg; opt++) { 13110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 13210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project void * arg = opt->arg; 13310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-branchstate@*/ 13410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX sick hack to preserve pretense of ABI. */ 13510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (arg == poptHelpOptions) arg = poptHelpOptionsI18N; 13610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=branchstate@*/ 13710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Recurse on included sub-tables. */ 13810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->arg != NULL) /* XXX program error */ 13910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project invokeCallbacksOPTION(con, opt->arg, myOpt, myData, shorty); 14010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK && 14110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project !(opt->argInfo & POPT_CBFLAG_SKIPOPTION)) { 14210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Save callback info. */ 14310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cbopt = opt; 14410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if (cbopt != NULL && 14510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ((myOpt->shortName && opt->shortName && shorty && 14610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project myOpt->shortName == opt->shortName) || 14710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (myOpt->longName && opt->longName && 14810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullpass@*/ /* LCL: opt->longName != NULL */ 14910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project !strcmp(myOpt->longName, opt->longName))) 15010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullpass@*/ 15110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ) 15210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { /*@-castfcnptr@*/ 15310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptCallbackType cb = (poptCallbackType)cbopt->arg; 15410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=castfcnptr@*/ 15510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const void * cbData = (cbopt->descrip ? cbopt->descrip : myData); 15610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Perform callback. */ 15710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (cb != NULL) { /* XXX program error */ 15810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-noeffectuncon @*/ 15910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cb(con, POPT_CALLBACK_REASON_OPTION, myOpt, 16010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg, cbData); 16110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=noeffectuncon @*/ 16210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 16310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Terminate (unless explcitly continuing). */ 16410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(cbopt->argInfo & POPT_CBFLAG_CONTINUE)) 16510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return; 16610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 16710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 16810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 16910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 17010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source ProjectpoptContext poptGetContext(const char * name, int argc, const char ** argv, 17110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const struct poptOption * options, int flags) 17210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 17310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptContext con = malloc(sizeof(*con)); 17410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 17510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con == NULL) return NULL; /* XXX can't happen */ 17610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project memset(con, 0, sizeof(*con)); 17710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 17810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os = con->optionStack; 17910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->argc = argc; 18010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */ 18110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->argv = argv; 18210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=dependenttrans =assignexpose@*/ 18310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->argb = NULL; 18410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 18510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(flags & POPT_CONTEXT_KEEP_FIRST)) 18610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next = 1; /* skip argv[0] */ 18710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 18810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->leftovers = calloc( (argc + 1), sizeof(*con->leftovers) ); 18910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-dependenttrans -assignexpose@*/ /* FIX: W2DO? */ 19010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->options = options; 19110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=dependenttrans =assignexpose@*/ 19210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->aliases = NULL; 19310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->numAliases = 0; 19410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->flags = flags; 19510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->execs = NULL; 19610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->numExecs = 0; 19710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgvAlloced = argc * 2; 19810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv = calloc( con->finalArgvAlloced, sizeof(*con->finalArgv) ); 19910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->execAbsolute = 1; 20010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->arg_strip = NULL; 20110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 20210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (getenv("POSIXLY_CORRECT") || getenv("POSIX_ME_HARDER")) 20310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->flags |= POPT_CONTEXT_POSIXMEHARDER; 20410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 20510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (name) { 20610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char * t = malloc(strlen(name) + 1); 20710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (t) con->appName = strcpy(t, name); 20810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 20910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 21010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-internalglobs@*/ 21110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project invokeCallbacksPRE(con, con->options); 21210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=internalglobs@*/ 21310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 21410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return con; 21510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 21610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 21710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic void cleanOSE(/*@special@*/ struct optionStackEntry *os) 21810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@uses os @*/ 21910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@releases os->nextArg, os->argv, os->argb @*/ 22010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies os @*/ 22110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 22210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project os->nextArg = _free(os->nextArg); 22310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project os->argv = _free(os->argv); 22410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project os->argb = PBM_FREE(os->argb); 22510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 22610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 22710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 22810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectvoid poptResetContext(poptContext con) 22910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 23010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int i; 23110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 23210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con == NULL) return; 23310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project while (con->os > con->optionStack) { 23410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cleanOSE(con->os--); 23510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 23610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->argb = PBM_FREE(con->os->argb); 23710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->currAlias = NULL; 23810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = NULL; 23910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = NULL; 24010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next = 1; /* skip argv[0] */ 24110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 24210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->numLeftovers = 0; 24310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->nextLeftover = 0; 24410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->restLeftover = 0; 24510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->doExec = NULL; 24610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 24710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->finalArgv != NULL) 24810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = 0; i < con->finalArgvCount; i++) { 24910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-unqualifiedtrans@*/ /* FIX: typedef double indirection. */ 25010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv[i] = _free(con->finalArgv[i]); 25110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=unqualifiedtrans@*/ 25210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 25310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 25410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgvCount = 0; 25510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->arg_strip = PBM_FREE(con->arg_strip); 25610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullstate@*/ /* FIX: con->finalArgv != NULL */ 25710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return; 25810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullstate@*/ 25910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 26010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 26110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 26210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* Only one of longName, shortName should be set, not both. */ 26310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 26410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic int handleExec(/*@special@*/ poptContext con, 26510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@null@*/ const char * longName, char shortName) 26610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@uses con->execs, con->numExecs, con->flags, con->doExec, 26710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv, con->finalArgvAlloced, con->finalArgvCount @*/ 26810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies con @*/ 26910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 27010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptItem item; 27110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int i; 27210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 27310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->execs == NULL || con->numExecs <= 0) /* XXX can't happen */ 27410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 27510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 27610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = con->numExecs - 1; i >= 0; i--) { 27710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item = con->execs + i; 27810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (longName && !(item->option.longName && 27910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project !strcmp(longName, item->option.longName))) 28010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 28110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else if (shortName != item->option.shortName) 28210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 28310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 28410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 28510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (i < 0) return 0; 28610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 28710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 28810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->flags & POPT_CONTEXT_NO_EXEC) 28910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 1; 29010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 29110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->doExec == NULL) { 29210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->doExec = con->execs + i; 29310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 1; 29410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 29510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 29610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* We already have an exec to do; remember this option for next 29710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project time 'round */ 29810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((con->finalArgvCount + 1) >= (con->finalArgvAlloced)) { 29910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgvAlloced += 10; 30010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv = realloc(con->finalArgv, 30110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sizeof(*con->finalArgv) * con->finalArgvAlloced); 30210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 30310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 30410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project i = con->finalArgvCount++; 30510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->finalArgv != NULL) /* XXX can't happen */ 30610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { char *s = malloc((longName ? strlen(longName) : 0) + 3); 30710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (s != NULL) { /* XXX can't happen */ 30810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (longName) 30910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sprintf(s, "--%s", longName); 31010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else 31110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sprintf(s, "-%c", shortName); 31210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv[i] = s; 31310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else 31410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv[i] = NULL; 31510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 31610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 31710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullstate@*/ /* FIX: con->finalArgv[] == NULL */ 31810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 1; 31910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullstate@*/ 32010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 32110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 32210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 32310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* Only one of longName, shortName may be set at a time */ 32410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic int handleAlias(/*@special@*/ poptContext con, 32510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@null@*/ const char * longName, char shortName, 32610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@exposed@*/ /*@null@*/ const char * nextCharArg) 32710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@uses con->aliases, con->numAliases, con->optionStack, con->os, 32810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->currAlias, con->os->currAlias->option.longName @*/ 32910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies con @*/ 33010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 33110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptItem item = con->os->currAlias; 33210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int rc; 33310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int i; 33410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 33510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (item) { 33610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (longName && (item->option.longName && 33710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project !strcmp(longName, item->option.longName))) 33810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 33910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (shortName && shortName == item->option.shortName) 34010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 34110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 34210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 34310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->aliases == NULL || con->numAliases <= 0) /* XXX can't happen */ 34410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 34510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 34610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = con->numAliases - 1; i >= 0; i--) { 34710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item = con->aliases + i; 34810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (longName && !(item->option.longName && 34910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project !strcmp(longName, item->option.longName))) 35010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 35110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else if (shortName != item->option.shortName) 35210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 35310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 35410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 35510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (i < 0) return 0; 35610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 35710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((con->os - con->optionStack + 1) == POPT_OPTION_DEPTH) 35810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_OPTSTOODEEP; 35910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 36010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundsread@*/ 36110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (nextCharArg && *nextCharArg) 36210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = nextCharArg; 36310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundsread@*/ 36410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 36510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os++; 36610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next = 0; 36710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->stuffed = 0; 36810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = NULL; 36910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = NULL; 37010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->currAlias = con->aliases + i; 37110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = poptDupArgv(con->os->currAlias->argc, con->os->currAlias->argv, 37210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project &con->os->argc, &con->os->argv); 37310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->argb = NULL; 37410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 37510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return (rc ? rc : 1); 37610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 37710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 37810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-bounds -boundswrite @*/ 37910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic int execCommand(poptContext con) 38010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@globals internalState @*/ 38110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies internalState @*/ 38210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 38310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptItem item = con->doExec; 38410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char ** argv; 38510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int argc = 0; 38610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int rc; 38710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 38810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (item == NULL) /*XXX can't happen*/ 38910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_NOARG; 39010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 39110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (item->argv == NULL || item->argc < 1 || 39210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (!con->execAbsolute && strchr(item->argv[0], '/'))) 39310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_NOARG; 39410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 39510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argv = malloc(sizeof(*argv) * 39610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (6 + item->argc + con->numLeftovers + con->finalArgvCount)); 39710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (argv == NULL) return POPT_ERROR_MALLOC; 39810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 39910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!strchr(item->argv[0], '/') && con->execPath != NULL) { 40010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char *s = alloca(strlen(con->execPath) + strlen(item->argv[0]) + sizeof("/")); 40110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sprintf(s, "%s/%s", con->execPath, item->argv[0]); 40210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argv[argc] = s; 40310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else 40410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argv[argc] = findProgramPath(item->argv[0]); 40510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (argv[argc++] == NULL) return POPT_ERROR_NOARG; 40610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 40710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (item->argc > 1) { 40810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project memcpy(argv + argc, item->argv + 1, sizeof(*argv) * (item->argc - 1)); 40910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argc += (item->argc - 1); 41010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 41110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 41210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->finalArgv != NULL && con->finalArgvCount > 0) { 41310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project memcpy(argv + argc, con->finalArgv, 41410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sizeof(*argv) * con->finalArgvCount); 41510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argc += con->finalArgvCount; 41610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 41710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 41810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->leftovers != NULL && con->numLeftovers > 0) { 41910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project memcpy(argv + argc, con->leftovers, sizeof(*argv) * con->numLeftovers); 42010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argc += con->numLeftovers; 42110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 42210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 42310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argv[argc] = NULL; 42410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 42510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#if defined(hpux) || defined(__hpux) 42610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = setresgid(getgid(), getgid(),-1); 42710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (rc) return POPT_ERROR_ERRNO; 42810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = setresuid(getuid(), getuid(),-1); 42910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (rc) return POPT_ERROR_ERRNO; 43010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#else 43110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* 43210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * XXX " ... on BSD systems setuid() should be preferred over setreuid()" 43310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * XXX sez' Timur Bakeyev <mc@bat.ru> 43410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * XXX from Norbert Warmuth <nwarmuth@privat.circular.de> 43510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 43610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#if defined(HAVE_SETUID) 43710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = setgid(getgid()); 43810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (rc) return POPT_ERROR_ERRNO; 43910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = setuid(getuid()); 44010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (rc) return POPT_ERROR_ERRNO; 44110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#elif defined (HAVE_SETREUID) 44210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = setregid(getgid(), getgid()); 44310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (rc) return POPT_ERROR_ERRNO; 44410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = setreuid(getuid(), getuid()); 44510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (rc) return POPT_ERROR_ERRNO; 44610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#else 44710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ; /* Can't drop privileges */ 44810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 44910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 45010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 45110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (argv[0] == NULL) 45210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_NOARG; 45310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 45410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#ifdef MYDEBUG 45510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectif (_popt_debug) 45610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { const char ** avp; 45710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project fprintf(stderr, "==> execvp(%s) argv[%d]:", argv[0], argc); 45810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (avp = argv; *avp; avp++) 45910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project fprintf(stderr, " '%s'", *avp); 46010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project fprintf(stderr, "\n"); 46110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 46210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 46310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 46410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = execvp(argv[0], (char *const *)argv); 46510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 46610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_ERRNO; 46710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 46810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=bounds =boundswrite @*/ 46910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 47010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 47110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@observer@*/ /*@null@*/ static const struct poptOption * 47210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source ProjectfindOption(const struct poptOption * opt, /*@null@*/ const char * longName, 47310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char shortName, 47410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@null@*/ /*@out@*/ poptCallbackType * callback, 47510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@null@*/ /*@out@*/ const void ** callbackData, 47610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int singleDash) 47710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies *callback, *callbackData */ 47810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 47910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const struct poptOption * cb = NULL; 48010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 48110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* This happens when a single - is given */ 48210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (singleDash && !shortName && (longName && *longName == '\0')) 48310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project shortName = '-'; 48410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 48510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (; opt->longName || opt->shortName || opt->arg; opt++) { 48610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 48710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { 48810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const struct poptOption * opt2; 48910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project void * arg = opt->arg; 49010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 49110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-branchstate@*/ 49210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX sick hack to preserve pretense of ABI. */ 49310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (arg == poptHelpOptions) arg = poptHelpOptionsI18N; 49410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=branchstate@*/ 49510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Recurse on included sub-tables. */ 49610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (arg == NULL) continue; /* XXX program error */ 49710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project opt2 = findOption(arg, longName, shortName, callback, 49810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project callbackData, singleDash); 49910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt2 == NULL) continue; 50010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Sub-table data will be inheirited if no data yet. */ 50110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(callback && *callback)) return opt2; 50210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(callbackData && *callbackData == NULL)) return opt2; 50310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-observertrans -dependenttrans @*/ 50410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *callbackData = opt->descrip; 50510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=observertrans =dependenttrans @*/ 50610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return opt2; 50710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_CALLBACK) { 50810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cb = opt; 50910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if (longName && opt->longName && 51010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (!singleDash || (opt->argInfo & POPT_ARGFLAG_ONEDASH)) && 51110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullpass@*/ /* LCL: opt->longName != NULL */ 51210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project !strcmp(longName, opt->longName)) 51310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullpass@*/ 51410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { 51510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 51610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if (shortName && shortName == opt->shortName) { 51710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 51810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 51910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 52010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 52110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!opt->longName && !opt->shortName) 52210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return NULL; 52310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-modobserver -mods @*/ 52410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (callback) *callback = NULL; 52510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (callbackData) *callbackData = NULL; 52610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (cb) { 52710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (callback) 52810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-castfcnptr@*/ 52910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *callback = (poptCallbackType)cb->arg; 53010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=castfcnptr@*/ 53110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(cb->argInfo & POPT_CBFLAG_INC_DATA)) { 53210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (callbackData) 53310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-observertrans@*/ /* FIX: typedef double indirection. */ 53410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *callbackData = cb->descrip; 53510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=observertrans@*/ 53610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 53710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 53810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=modobserver =mods @*/ 53910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 54010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return opt; 54110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 54210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 54310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 54410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic const char * findNextArg(/*@special@*/ poptContext con, 54510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project unsigned argx, int delete_arg) 54610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@uses con->optionStack, con->os, 54710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next, con->os->argb, con->os->argc, con->os->argv @*/ 54810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies con @*/ 54910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 55010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project struct optionStackEntry * os = con->os; 55110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char * arg; 55210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 55310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project do { 55410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int i; 55510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project arg = NULL; 55610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project while (os->next == os->argc && os > con->optionStack) os--; 55710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (os->next == os->argc && os == con->optionStack) break; 55810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (os->argv != NULL) 55910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = os->next; i < os->argc; i++) { 56010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-sizeoftype@*/ 56110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (os->argb && PBM_ISSET(i, os->argb)) 56210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@innercontinue@*/ continue; 56310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (*os->argv[i] == '-') 56410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@innercontinue@*/ continue; 56510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (--argx > 0) 56610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@innercontinue@*/ continue; 56710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project arg = os->argv[i]; 56810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (delete_arg) { 56910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (os->argb == NULL) os->argb = PBM_ALLOC(os->argc); 57010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (os->argb != NULL) /* XXX can't happen */ 57110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project PBM_SET(i, os->argb); 57210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 57310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@innerbreak@*/ break; 57410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=sizeoftype@*/ 57510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 57610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (os > con->optionStack) os--; 57710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } while (arg == NULL); 57810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return arg; 57910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 58010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 58110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 58210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic /*@only@*/ /*@null@*/ const char * 58310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source ProjectexpandNextArg(/*@special@*/ poptContext con, const char * s) 58410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@uses con->optionStack, con->os, 58510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next, con->os->argb, con->os->argc, con->os->argv @*/ 58610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies con @*/ 58710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 58810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char * a = NULL; 58910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project size_t alen; 59010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char *t, *te; 59110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project size_t tn = strlen(s) + 1; 59210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char c; 59310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 59410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project te = t = malloc(tn);; 59510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (t == NULL) return NULL; /* XXX can't happen */ 59610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project while ((c = *s++) != '\0') { 59710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project switch (c) { 59810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#if 0 /* XXX can't do this */ 59910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case '\\': /* escape */ 60010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project c = *s++; 60110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@switchbreak@*/ break; 60210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#endif 60310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case '!': 60410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(s[0] == '#' && s[1] == ':' && s[2] == '+')) 60510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@switchbreak@*/ break; 60610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX Make sure that findNextArg deletes only next arg. */ 60710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (a == NULL) { 60810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((a = findNextArg(con, 1, 1)) == NULL) 60910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@switchbreak@*/ break; 61010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 61110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project s += 3; 61210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 61310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project alen = strlen(a); 61410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project tn += alen; 61510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *te = '\0'; 61610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project t = realloc(t, tn); 61710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project te = t + strlen(t); 61810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project strncpy(te, a, alen); te += alen; 61910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 62010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@notreached@*/ /*@switchbreak@*/ break; 62110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project default: 62210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@switchbreak@*/ break; 62310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 62410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *te++ = c; 62510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 62610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *te = '\0'; 62710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project t = realloc(t, strlen(t) + 1); /* XXX memory leak, hard to plug */ 62810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return t; 62910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 63010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 63110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 63210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectstatic void poptStripArg(/*@special@*/ poptContext con, int which) 63310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@uses con->arg_strip, con->optionStack @*/ 63410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@defines con->arg_strip @*/ 63510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@modifies con @*/ 63610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 63710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-sizeoftype@*/ 63810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->arg_strip == NULL) 63910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->arg_strip = PBM_ALLOC(con->optionStack[0].argc); 64010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->arg_strip != NULL) /* XXX can't happen */ 64110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project PBM_SET(which, con->arg_strip); 64210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=sizeoftype@*/ 64310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-compdef@*/ /* LCL: con->arg_strip udefined? */ 64410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return; 64510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=compdef@*/ 64610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 64710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 64810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint poptSaveLong(long * arg, int argInfo, long aLong) 64910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 65010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX Check alignment, may fail on funky platforms. */ 65110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1))) 65210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_NULLARG; 65310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 65410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (argInfo & POPT_ARGFLAG_NOT) 65510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project aLong = ~aLong; 65610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project switch (argInfo & POPT_ARGFLAG_LOGICALOPS) { 65710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case 0: 65810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg = aLong; 65910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 66010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARGFLAG_OR: 66110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg |= aLong; 66210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 66310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARGFLAG_AND: 66410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg &= aLong; 66510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 66610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARGFLAG_XOR: 66710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg ^= aLong; 66810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 66910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project default: 67010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPERATION; 67110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@notreached@*/ break; 67210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 67310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 67410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 67510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 67610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint poptSaveInt(/*@null@*/ int * arg, int argInfo, long aLong) 67710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 67810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX Check alignment, may fail on funky platforms. */ 67910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1))) 68010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_NULLARG; 68110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 68210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (argInfo & POPT_ARGFLAG_NOT) 68310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project aLong = ~aLong; 68410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project switch (argInfo & POPT_ARGFLAG_LOGICALOPS) { 68510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case 0: 68610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg = aLong; 68710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 68810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARGFLAG_OR: 68910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg |= aLong; 69010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 69110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARGFLAG_AND: 69210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg &= aLong; 69310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 69410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARGFLAG_XOR: 69510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *arg ^= aLong; 69610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 69710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project default: 69810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPERATION; 69910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@notreached@*/ break; 70010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 70110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 70210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 70310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 70410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 70510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ 70610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint poptGetNextOpt(poptContext con) 70710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 70810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const struct poptOption * opt = NULL; 70910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int done = 0; 71010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 71110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con == NULL) 71210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return -1; 71310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project while (!done) { 71410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char * origOptString = NULL; 71510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptCallbackType cb = NULL; 71610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const void * cbData = NULL; 71710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char * longArg = NULL; 71810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int canstrip = 0; 71910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int shorty = 0; 72010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 72110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project while (!con->os->nextCharArg && con->os->next == con->os->argc 72210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project && con->os > con->optionStack) { 72310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cleanOSE(con->os--); 72410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 72510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!con->os->nextCharArg && con->os->next == con->os->argc) { 72610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-internalglobs@*/ 72710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project invokeCallbacksPOST(con, con->options); 72810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=internalglobs@*/ 72910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->doExec) return execCommand(con); 73010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return -1; 73110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 73210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 73310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Process next long option */ 73410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!con->os->nextCharArg) { 73510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char * localOptString, * optString; 73610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int thisopt; 73710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 73810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-sizeoftype@*/ 73910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os->argb && PBM_ISSET(con->os->next, con->os->argb)) { 74010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next++; 74110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 74210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 74310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=sizeoftype@*/ 74410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project thisopt = con->os->next; 74510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os->argv != NULL) /* XXX can't happen */ 74610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project origOptString = con->os->argv[con->os->next++]; 74710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 74810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (origOptString == NULL) /* XXX can't happen */ 74910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPT; 75010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 75110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->restLeftover || *origOptString != '-' || 75210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (*origOptString == '-' && origOptString[1] == '\0')) 75310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { 75410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->flags & POPT_CONTEXT_POSIXMEHARDER) 75510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->restLeftover = 1; 75610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->flags & POPT_CONTEXT_ARG_OPTS) { 75710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = xstrdup(origOptString); 75810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 75910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 76010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->leftovers != NULL) /* XXX can't happen */ 76110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->leftovers[con->numLeftovers++] = origOptString; 76210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 76310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 76410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 76510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Make a copy we can hack at */ 76610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project localOptString = optString = 76710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project strcpy(alloca(strlen(origOptString) + 1), origOptString); 76810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 76910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (optString[0] == '\0') 77010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPT; 77110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 77210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (optString[1] == '-' && !optString[2]) { 77310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->restLeftover = 1; 77410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 77510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else { 77610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char *oe; 77710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int singleDash; 77810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 77910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project optString++; 78010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (*optString == '-') 78110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project singleDash = 0, optString++; 78210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else 78310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project singleDash = 1; 78410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 78510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX aliases with arg substitution need "--alias=arg" */ 78610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (handleAlias(con, optString, '\0', NULL)) 78710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 78810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 78910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (handleExec(con, optString, '\0')) 79010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 79110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 79210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Check for "--long=arg" option. */ 79310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (oe = optString; *oe && *oe != '='; oe++) 79410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project {}; 79510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (*oe == '=') { 79610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *oe++ = '\0'; 79710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX longArg is mapped back to persistent storage. */ 79810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project longArg = origOptString + (oe - localOptString); 79910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 80010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 80110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project opt = findOption(con->options, optString, '\0', &cb, &cbData, 80210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project singleDash); 80310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!opt && !singleDash) 80410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPT; 80510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 80610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 80710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!opt) { 80810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = origOptString + 1; 80910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else { 81010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os == con->optionStack && 81110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project opt->argInfo & POPT_ARGFLAG_STRIP) 81210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { 81310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project canstrip = 1; 81410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptStripArg(con, thisopt); 81510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 81610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project shorty = 0; 81710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 81810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 81910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 82010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Process next short option */ 82110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-branchstate@*/ /* FIX: W2DO? */ 82210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os->nextCharArg) { 82310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project origOptString = con->os->nextCharArg; 82410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 82510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = NULL; 82610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 82710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (handleAlias(con, NULL, *origOptString, origOptString + 1)) 82810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 82910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 83010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (handleExec(con, NULL, *origOptString)) { 83110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* Restore rest of short options for further processing */ 83210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project origOptString++; 83310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (*origOptString != '\0') 83410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = origOptString; 83510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 83610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 83710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 83810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project opt = findOption(con->options, NULL, *origOptString, &cb, 83910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project &cbData, 0); 84010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!opt) 84110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPT; 84210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project shorty = 1; 84310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 84410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project origOptString++; 84510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (*origOptString != '\0') 84610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = origOptString; 84710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 84810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=branchstate@*/ 84910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 85010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt == NULL) return POPT_ERROR_BADOPT; /* XXX can't happen */ 85110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) { 85210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (poptSaveInt((int *)opt->arg, opt->argInfo, 1L)) 85310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPERATION; 85410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) { 85510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->arg) { 85610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (poptSaveInt((int *)opt->arg, opt->argInfo, (long)opt->val)) 85710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPERATION; 85810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 85910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { 86010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = _free(con->os->nextArg); 86110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-usedef@*/ /* FIX: W2DO? */ 86210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (longArg) { 86310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=usedef@*/ 86410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project longArg = expandNextArg(con, longArg); 86510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = longArg; 86610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if (con->os->nextCharArg) { 86710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project longArg = expandNextArg(con, con->os->nextCharArg); 86810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = longArg; 86910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = NULL; 87010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else { 87110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project while (con->os->next == con->os->argc && 87210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os > con->optionStack) { 87310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project cleanOSE(con->os--); 87410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 87510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os->next == con->os->argc) { 87610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(opt->argInfo & POPT_ARGFLAG_OPTIONAL)) 87710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-compdef@*/ /* FIX: con->os->argv not defined */ 87810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_NOARG; 87910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=compdef@*/ 88010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = NULL; 88110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else { 88210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 88310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* 88410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * Make sure this isn't part of a short arg or the 88510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project * result of an alias expansion. 88610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project */ 88710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os == con->optionStack && 88810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (opt->argInfo & POPT_ARGFLAG_STRIP) && 88910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project canstrip) { 89010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptStripArg(con, con->os->next); 89110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 89210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 89310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os->argv != NULL) { /* XXX can't happen */ 89410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX watchout: subtle side-effects live here. */ 89510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project longArg = con->os->argv[con->os->next++]; 89610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project longArg = expandNextArg(con, longArg); 89710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = longArg; 89810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 89910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 90010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 90110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project longArg = NULL; 90210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 90310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->arg) { 90410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project switch (opt->argInfo & POPT_ARG_MASK) { 90510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARG_STRING: 90610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* XXX memory leak, hard to plug */ 90710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *((const char **) opt->arg) = (con->os->nextArg) 90810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ? xstrdup(con->os->nextArg) : NULL; 90910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@switchbreak@*/ break; 91010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 91110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARG_INT: 91210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARG_LONG: 91310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { long aLong = 0; 91410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char *end; 91510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 91610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os->nextArg) { 91710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project aLong = strtol(con->os->nextArg, &end, 0); 91810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (!(end && *end == '\0')) 91910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADNUMBER; 92010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 92110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 92210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) { 92310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (aLong == LONG_MIN || aLong == LONG_MAX) 92410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_OVERFLOW; 92510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (poptSaveLong((long *)opt->arg, opt->argInfo, aLong)) 92610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPERATION; 92710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else { 92810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (aLong > INT_MAX || aLong < INT_MIN) 92910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_OVERFLOW; 93010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (poptSaveInt((int *)opt->arg, opt->argInfo, aLong)) 93110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADOPERATION; 93210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 93310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } /*@switchbreak@*/ break; 93410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 93510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARG_FLOAT: 93610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ARG_DOUBLE: 93710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { double aDouble = 0.0; 93810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project char *end; 93910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 94010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->os->nextArg) { 94110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-mods@*/ 94210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int saveerrno = errno; 94310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project errno = 0; 94410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project aDouble = strtod(con->os->nextArg, &end); 94510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (errno == ERANGE) 94610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_OVERFLOW; 94710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project errno = saveerrno; 94810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=mods@*/ 94910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (*end != '\0') 95010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_BADNUMBER; 95110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 95210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 95310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_DOUBLE) { 95410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *((double *) opt->arg) = aDouble; 95510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else { 95610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project#define _ABS(a) ((((a) - 0.0) < DBL_EPSILON) ? -(a) : (a)) 95710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((_ABS(aDouble) - FLT_MAX) > DBL_EPSILON) 95810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_OVERFLOW; 95910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((FLT_MIN - _ABS(aDouble)) > DBL_EPSILON) 96010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_OVERFLOW; 96110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *((float *) opt->arg) = aDouble; 96210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 96310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } /*@switchbreak@*/ break; 96410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project default: 96510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project fprintf(stdout, 96610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project POPT_("option type (%d) not implemented in popt\n"), 96710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (opt->argInfo & POPT_ARG_MASK)); 96810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project exit(EXIT_FAILURE); 96910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@notreached@*/ /*@switchbreak@*/ break; 97010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 97110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 97210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 97310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 97410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (cb) { 97510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-internalglobs@*/ 97610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project invokeCallbacksOPTION(con, con->options, opt, cbData, shorty); 97710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=internalglobs@*/ 97810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else if (opt->val && ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_VAL)) 97910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project done = 1; 98010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 98110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((con->finalArgvCount + 2) >= (con->finalArgvAlloced)) { 98210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgvAlloced += 10; 98310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv = realloc(con->finalArgv, 98410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sizeof(*con->finalArgv) * con->finalArgvAlloced); 98510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 98610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 98710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->finalArgv != NULL) 98810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project { char *s = malloc((opt->longName ? strlen(opt->longName) : 0) + 3); 98910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (s != NULL) { /* XXX can't happen */ 99010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->longName) 99110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sprintf(s, "%s%s", 99210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ((opt->argInfo & POPT_ARGFLAG_ONEDASH) ? "-" : "--"), 99310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project opt->longName); 99410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else 99510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project sprintf(s, "-%c", opt->shortName); 99610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv[con->finalArgvCount++] = s; 99710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } else 99810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv[con->finalArgvCount++] = NULL; 99910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 100010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 100110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (opt->arg && (opt->argInfo & POPT_ARG_MASK) == POPT_ARG_NONE) 100210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-ifempty@*/ ; /*@=ifempty@*/ 100310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_VAL) 100410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-ifempty@*/ ; /*@=ifempty@*/ 100510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project else if ((opt->argInfo & POPT_ARG_MASK) != POPT_ARG_NONE) { 100610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->finalArgv != NULL && con->os->nextArg) 100710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv[con->finalArgvCount++] = 100810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullpass@*/ /* LCL: con->os->nextArg != NULL */ 100910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project xstrdup(con->os->nextArg); 101010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullpass@*/ 101110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 101210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 101310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 101410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return (opt ? opt->val : -1); /* XXX can't happen */ 101510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 101610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 101710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 101810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectconst char * poptGetOptArg(poptContext con) 101910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 102010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char * ret = NULL; 102110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-branchstate@*/ 102210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con) { 102310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ret = con->os->nextArg; 102410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = NULL; 102510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 102610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=branchstate@*/ 102710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return ret; 102810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 102910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 103010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectconst char * poptGetArg(poptContext con) 103110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 103210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char * ret = NULL; 103310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers) 103410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ret = con->leftovers[con->nextLeftover++]; 103510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return ret; 103610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 103710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 103810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectconst char * poptPeekArg(poptContext con) 103910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 104010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project const char * ret = NULL; 104110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers) 104210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project ret = con->leftovers[con->nextLeftover]; 104310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return ret; 104410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 104510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 104610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 104710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectconst char ** poptGetArgs(poptContext con) 104810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 104910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con == NULL || 105010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->leftovers == NULL || con->numLeftovers == con->nextLeftover) 105110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return NULL; 105210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 105310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /* some apps like [like RPM ;-) ] need this NULL terminated */ 105410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->leftovers[con->numLeftovers] = NULL; 105510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 105610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullret -nullstate @*/ /* FIX: typedef double indirection. */ 105710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return (con->leftovers + con->nextLeftover); 105810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullret =nullstate @*/ 105910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 106010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 106110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 106210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source ProjectpoptContext poptFreeContext(poptContext con) 106310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 106410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptItem item; 106510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int i; 106610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 106710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con == NULL) return con; 106810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptResetContext(con); 106910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->argb = _free(con->os->argb); 107010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 107110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->aliases != NULL) 107210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = 0; i < con->numAliases; i++) { 107310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item = con->aliases + i; 107410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-modobserver -observertrans -dependenttrans@*/ 107510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.longName = _free(item->option.longName); 107610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.descrip = _free(item->option.descrip); 107710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.argDescrip = _free(item->option.argDescrip); 107810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=modobserver =observertrans =dependenttrans@*/ 107910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->argv = _free(item->argv); 108010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 108110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->aliases = _free(con->aliases); 108210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 108310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->execs != NULL) 108410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = 0; i < con->numExecs; i++) { 108510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item = con->execs + i; 108610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-modobserver -observertrans -dependenttrans@*/ 108710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.longName = _free(item->option.longName); 108810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.descrip = _free(item->option.descrip); 108910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.argDescrip = _free(item->option.argDescrip); 109010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=modobserver =observertrans =dependenttrans@*/ 109110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->argv = _free(item->argv); 109210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 109310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->execs = _free(con->execs); 109410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 109510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->leftovers = _free(con->leftovers); 109610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->finalArgv = _free(con->finalArgv); 109710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->appName = _free(con->appName); 109810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->otherHelp = _free(con->otherHelp); 109910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->execPath = _free(con->execPath); 110010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->arg_strip = PBM_FREE(con->arg_strip); 110110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 110210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con = _free(con); 110310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return con; 110410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 110510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 110610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint poptAddAlias(poptContext con, struct poptAlias alias, 110710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@unused@*/ int flags) 110810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 110910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptItem item = alloca(sizeof(*item)); 111010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project memset(item, 0, sizeof(*item)); 111110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.longName = alias.longName; 111210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.shortName = alias.shortName; 111310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.argInfo = POPT_ARGFLAG_DOC_HIDDEN; 111410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.arg = 0; 111510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.val = 0; 111610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.descrip = NULL; 111710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.argDescrip = NULL; 111810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->argc = alias.argc; 111910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->argv = alias.argv; 112010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return poptAddItem(con, item, 0); 112110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 112210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 112310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 112410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-mustmod@*/ /* LCL: con not modified? */ 112510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint poptAddItem(poptContext con, poptItem newItem, int flags) 112610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 112710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project poptItem * items, item; 112810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int * nitems; 112910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 113010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project switch (flags) { 113110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case 1: 113210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project items = &con->execs; 113310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project nitems = &con->numExecs; 113410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 113510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case 0: 113610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project items = &con->aliases; 113710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project nitems = &con->numAliases; 113810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project break; 113910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project default: 114010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 1; 114110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@notreached@*/ break; 114210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 114310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 114410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project *items = realloc((*items), ((*nitems) + 1) * sizeof(**items)); 114510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((*items) == NULL) 114610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 1; 114710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 114810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item = (*items) + (*nitems); 114910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 115010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.longName = 115110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (newItem->option.longName ? xstrdup(newItem->option.longName) : NULL); 115210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.shortName = newItem->option.shortName; 115310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.argInfo = newItem->option.argInfo; 115410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.arg = newItem->option.arg; 115510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.val = newItem->option.val; 115610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.descrip = 115710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (newItem->option.descrip ? xstrdup(newItem->option.descrip) : NULL); 115810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->option.argDescrip = 115910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (newItem->option.argDescrip ? xstrdup(newItem->option.argDescrip) : NULL); 116010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->argc = newItem->argc; 116110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project item->argv = newItem->argv; 116210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 116310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project (*nitems)++; 116410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 116510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return 0; 116610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 116710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=mustmod@*/ 116810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 116910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 117010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectconst char * poptBadOption(poptContext con, int flags) 117110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 117210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project struct optionStackEntry * os = NULL; 117310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 117410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con != NULL) 117510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os; 117610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 117710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-nullderef@*/ /* LCL: os->argv != NULL */ 117810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return (os && os->argv ? os->argv[os->next - 1] : NULL); 117910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=nullderef@*/ 118010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 118110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 118210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectconst char * poptStrerror(const int error) 118310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 118410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project switch (error) { 118510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_NOARG: 118610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("missing argument"); 118710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_BADOPT: 118810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("unknown option"); 118910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_BADOPERATION: 119010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("mutually exclusive logical operations requested"); 119110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_NULLARG: 119210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("opt->arg should not be NULL"); 119310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_OPTSTOODEEP: 119410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("aliases nested too deeply"); 119510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_BADQUOTE: 119610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("error in parameter quoting"); 119710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_BADNUMBER: 119810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("invalid numeric value"); 119910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_OVERFLOW: 120010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("number too large or too small"); 120110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_MALLOC: 120210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("memory allocation failed"); 120310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project case POPT_ERROR_ERRNO: 120410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return strerror(errno); 120510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project default: 120610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_("unknown error"); 120710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 120810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 120910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 121010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint poptStuffArgs(poptContext con, const char ** argv) 121110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 121210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int argc; 121310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int rc; 121410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 121510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if ((con->os - con->optionStack) == POPT_OPTION_DEPTH) 121610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return POPT_ERROR_OPTSTOODEEP; 121710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 121810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (argc = 0; argv[argc]; argc++) 121910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project {}; 122010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 122110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os++; 122210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->next = 0; 122310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextArg = NULL; 122410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->nextCharArg = NULL; 122510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->currAlias = NULL; 122610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project rc = poptDupArgv(argc, argv, &con->os->argc, &con->os->argv); 122710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->argb = NULL; 122810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project con->os->stuffed = 1; 122910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 123010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return rc; 123110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 123210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 123310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectconst char * poptGetInvocationName(poptContext con) 123410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 123510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return (con->os->argv ? con->os->argv[0] : ""); 123610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 123710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 123810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@-boundswrite@*/ 123910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Projectint poptStrippedArgv(poptContext con, int argc, char ** argv) 124010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project{ 124110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int numargs = argc; 124210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int j = 1; 124310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project int i; 124410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 124510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@-sizeoftype@*/ 124610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->arg_strip) 124710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = 1; i < argc; i++) { 124810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (PBM_ISSET(i, con->arg_strip)) 124910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project numargs--; 125010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 125110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 125210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project for (i = 1; i < argc; i++) { 125310e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project if (con->arg_strip && PBM_ISSET(i, con->arg_strip)) 125410e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project continue; 125510e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project argv[j] = (j < numargs) ? argv[i] : NULL; 125610e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project j++; 125710e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project } 125810e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project /*@=sizeoftype@*/ 125910e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project 126010e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project return numargs; 126110e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project} 126210e23eebca4175a8dfe3a788b2bebacb1fcfce54The Android Open Source Project/*@=boundswrite@*/ 1263