returns 'val' element, -1 on last item, POPT_ERROR_* on error */
| 1207 | |
| 1208 | /* returns 'val' element, -1 on last item, POPT_ERROR_* on error */ |
| 1209 | int poptGetNextOpt(poptContext con) |
| 1210 | { |
| 1211 | const struct poptOption * opt = NULL; |
| 1212 | int done = 0; |
| 1213 | |
| 1214 | if (con == NULL) |
| 1215 | return -1; |
| 1216 | while (!done) { |
| 1217 | const char * origOptString = NULL; |
| 1218 | poptCallbackType cb = NULL; |
| 1219 | const void * cbData = NULL; |
| 1220 | const char * longArg = NULL; |
| 1221 | int canstrip = 0; |
| 1222 | int shorty = 0; |
| 1223 | |
| 1224 | while (!con->os->nextCharArg && con->os->next == con->os->argc |
| 1225 | && con->os > con->optionStack) { |
| 1226 | cleanOSE(con->os--); |
| 1227 | } |
| 1228 | if (!con->os->nextCharArg && con->os->next == con->os->argc) { |
| 1229 | invokeCallbacksPOST(con, con->options); |
| 1230 | |
| 1231 | if (con->maincall) { |
| 1232 | (void) (*con->maincall) (con->finalArgvCount, con->finalArgv); |
| 1233 | return -1; |
| 1234 | } |
| 1235 | |
| 1236 | if (con->doExec) return execCommand(con); |
| 1237 | return -1; |
| 1238 | } |
| 1239 | |
| 1240 | /* Process next long option */ |
| 1241 | if (!con->os->nextCharArg) { |
| 1242 | const char * optString; |
| 1243 | size_t optStringLen; |
| 1244 | int thisopt; |
| 1245 | |
| 1246 | if (con->os->argb && PBM_ISSET(con->os->next, con->os->argb)) { |
| 1247 | con->os->next++; |
| 1248 | continue; |
| 1249 | } |
| 1250 | thisopt = con->os->next; |
| 1251 | if (con->os->argv != NULL) /* XXX can't happen */ |
| 1252 | origOptString = con->os->argv[con->os->next++]; |
| 1253 | |
| 1254 | if (origOptString == NULL) /* XXX can't happen */ |
| 1255 | return POPT_ERROR_BADOPT; |
| 1256 | |
| 1257 | if (con->restLeftover || *origOptString != '-' || |
| 1258 | (*origOptString == '-' && origOptString[1] == '\0')) |
| 1259 | { |
| 1260 | if (con->flags & POPT_CONTEXT_POSIXMEHARDER) |
| 1261 | con->restLeftover = 1; |
| 1262 | if (con->flags & POPT_CONTEXT_ARG_OPTS) { |
| 1263 | con->os->nextArg = xstrdup(origOptString); |
| 1264 | return 0; |
| 1265 | } |
| 1266 | if (con->leftovers != NULL) { /* XXX can't happen */ |