MCPcopy Create free account
hub / github.com/audacity/audacity / arParseCommand

Function arParseCommand

lib-src/sqlite/shell.c:16278–16412  ·  view source on GitHub ↗

** Parse the command line for an ".ar" command. The results are written into ** structure (*pAr). SQLITE_OK is returned if the command line is parsed ** successfully, otherwise an error message is written to stderr and ** SQLITE_ERROR returned. */

Source from the content-addressed store, hash-verified

16276** SQLITE_ERROR returned.
16277*/
16278static int arParseCommand(
16279 char **azArg, /* Array of arguments passed to dot command */
16280 int nArg, /* Number of entries in azArg[] */
16281 ArCommand *pAr /* Populate this object */
16282){
16283 struct ArSwitch {
16284 const char *zLong;
16285 char cShort;
16286 u8 eSwitch;
16287 u8 bArg;
16288 } aSwitch[] = {
16289 { "create", 'c', AR_CMD_CREATE, 0 },
16290 { "extract", 'x', AR_CMD_EXTRACT, 0 },
16291 { "insert", 'i', AR_CMD_INSERT, 0 },
16292 { "list", 't', AR_CMD_LIST, 0 },
16293 { "update", 'u', AR_CMD_UPDATE, 0 },
16294 { "help", 'h', AR_CMD_HELP, 0 },
16295 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
16296 { "file", 'f', AR_SWITCH_FILE, 1 },
16297 { "append", 'a', AR_SWITCH_APPEND, 1 },
16298 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
16299 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
16300 };
16301 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
16302 struct ArSwitch *pEnd = &aSwitch[nSwitch];
16303
16304 if( nArg<=1 ){
16305 utf8_printf(stderr, "Wrong number of arguments. Usage:\n");
16306 return arUsage(stderr);
16307 }else{
16308 char *z = azArg[1];
16309 if( z[0]!='-' ){
16310 /* Traditional style [tar] invocation */
16311 int i;
16312 int iArg = 2;
16313 for(i=0; z[i]; i++){
16314 const char *zArg = 0;
16315 struct ArSwitch *pOpt;
16316 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
16317 if( z[i]==pOpt->cShort ) break;
16318 }
16319 if( pOpt==pEnd ){
16320 return arErrorMsg(pAr, "unrecognized option: %c", z[i]);
16321 }
16322 if( pOpt->bArg ){
16323 if( iArg>=nArg ){
16324 return arErrorMsg(pAr, "option requires an argument: %c",z[i]);
16325 }
16326 zArg = azArg[iArg++];
16327 }
16328 if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR;
16329 }
16330 pAr->nArg = nArg-iArg;
16331 if( pAr->nArg>0 ){
16332 pAr->azArg = &azArg[iArg];
16333 }
16334 }else{
16335 /* Non-traditional invocation */

Callers 1

arDotCommandFunction · 0.85

Calls 5

utf8_printfFunction · 0.85
arUsageFunction · 0.85
arErrorMsgFunction · 0.85
arProcessSwitchFunction · 0.85
strlen30Function · 0.85

Tested by

no test coverage detected