MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / arParseCommand

Function arParseCommand

modules/dasSQLITE/sqlite/shell.c:22038–22174  ·  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

22036** SQLITE_ERROR returned.
22037*/
22038static int arParseCommand(
22039 char **azArg, /* Array of arguments passed to dot command */
22040 int nArg, /* Number of entries in azArg[] */
22041 ArCommand *pAr /* Populate this object */
22042){
22043 struct ArSwitch {
22044 const char *zLong;
22045 char cShort;
22046 u8 eSwitch;
22047 u8 bArg;
22048 } aSwitch[] = {
22049 { "create", 'c', AR_CMD_CREATE, 0 },
22050 { "extract", 'x', AR_CMD_EXTRACT, 0 },
22051 { "insert", 'i', AR_CMD_INSERT, 0 },
22052 { "list", 't', AR_CMD_LIST, 0 },
22053 { "remove", 'r', AR_CMD_REMOVE, 0 },
22054 { "update", 'u', AR_CMD_UPDATE, 0 },
22055 { "help", 'h', AR_CMD_HELP, 0 },
22056 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
22057 { "file", 'f', AR_SWITCH_FILE, 1 },
22058 { "append", 'a', AR_SWITCH_APPEND, 1 },
22059 { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
22060 { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 },
22061 { "glob", 'g', AR_SWITCH_GLOB, 0 },
22062 };
22063 int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch);
22064 struct ArSwitch *pEnd = &aSwitch[nSwitch];
22065
22066 if( nArg<=1 ){
22067 utf8_printf(stderr, "Wrong number of arguments. Usage:\n");
22068 return arUsage(stderr);
22069 }else{
22070 char *z = azArg[1];
22071 if( z[0]!='-' ){
22072 /* Traditional style [tar] invocation */
22073 int i;
22074 int iArg = 2;
22075 for(i=0; z[i]; i++){
22076 const char *zArg = 0;
22077 struct ArSwitch *pOpt;
22078 for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){
22079 if( z[i]==pOpt->cShort ) break;
22080 }
22081 if( pOpt==pEnd ){
22082 return arErrorMsg(pAr, "unrecognized option: %c", z[i]);
22083 }
22084 if( pOpt->bArg ){
22085 if( iArg>=nArg ){
22086 return arErrorMsg(pAr, "option requires an argument: %c",z[i]);
22087 }
22088 zArg = azArg[iArg++];
22089 }
22090 if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR;
22091 }
22092 pAr->nArg = nArg-iArg;
22093 if( pAr->nArg>0 ){
22094 pAr->azArg = &azArg[iArg];
22095 }

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