** 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. */
| 27156 | ** SQLITE_ERROR returned. |
| 27157 | */ |
| 27158 | static int arParseCommand( |
| 27159 | char **azArg, /* Array of arguments passed to dot command */ |
| 27160 | int nArg, /* Number of entries in azArg[] */ |
| 27161 | ArCommand *pAr /* Populate this object */ |
| 27162 | ){ |
| 27163 | struct ArSwitch { |
| 27164 | const char *zLong; |
| 27165 | char cShort; |
| 27166 | u8 eSwitch; |
| 27167 | u8 bArg; |
| 27168 | } aSwitch[] = { |
| 27169 | { "create", 'c', AR_CMD_CREATE, 0 }, |
| 27170 | { "extract", 'x', AR_CMD_EXTRACT, 0 }, |
| 27171 | { "insert", 'i', AR_CMD_INSERT, 0 }, |
| 27172 | { "list", 't', AR_CMD_LIST, 0 }, |
| 27173 | { "remove", 'r', AR_CMD_REMOVE, 0 }, |
| 27174 | { "update", 'u', AR_CMD_UPDATE, 0 }, |
| 27175 | { "help", 'h', AR_CMD_HELP, 0 }, |
| 27176 | { "verbose", 'v', AR_SWITCH_VERBOSE, 0 }, |
| 27177 | { "file", 'f', AR_SWITCH_FILE, 1 }, |
| 27178 | { "append", 'a', AR_SWITCH_APPEND, 1 }, |
| 27179 | { "directory", 'C', AR_SWITCH_DIRECTORY, 1 }, |
| 27180 | { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 }, |
| 27181 | { "glob", 'g', AR_SWITCH_GLOB, 0 }, |
| 27182 | }; |
| 27183 | int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch); |
| 27184 | struct ArSwitch *pEnd = &aSwitch[nSwitch]; |
| 27185 | |
| 27186 | if( nArg<=1 ){ |
| 27187 | sqlite3_fprintf(stderr, "Wrong number of arguments. Usage:\n"); |
| 27188 | return arUsage(stderr); |
| 27189 | }else{ |
| 27190 | char *z = azArg[1]; |
| 27191 | if( z[0]!='-' ){ |
| 27192 | /* Traditional style [tar] invocation */ |
| 27193 | int i; |
| 27194 | int iArg = 2; |
| 27195 | for(i=0; z[i]; i++){ |
| 27196 | const char *zArg = 0; |
| 27197 | struct ArSwitch *pOpt; |
| 27198 | for(pOpt=&aSwitch[0]; pOpt<pEnd; pOpt++){ |
| 27199 | if( z[i]==pOpt->cShort ) break; |
| 27200 | } |
| 27201 | if( pOpt==pEnd ){ |
| 27202 | return arErrorMsg(pAr, "unrecognized option: %c", z[i]); |
| 27203 | } |
| 27204 | if( pOpt->bArg ){ |
| 27205 | if( iArg>=nArg ){ |
| 27206 | return arErrorMsg(pAr, "option requires an argument: %c",z[i]); |
| 27207 | } |
| 27208 | zArg = azArg[iArg++]; |
| 27209 | } |
| 27210 | if( arProcessSwitch(pAr, pOpt->eSwitch, zArg) ) return SQLITE_ERROR; |
| 27211 | } |
| 27212 | pAr->nArg = nArg-iArg; |
| 27213 | if( pAr->nArg>0 ){ |
| 27214 | pAr->azArg = &azArg[iArg]; |
| 27215 | } |
no test coverage detected