int flags;
};
-poptContext poptGetContext(char * name ,int argc, char ** argv,
+poptContext poptGetContext(char * name ,int argc, char ** argv,
struct poptOption * options, int flags) {
poptContext con = malloc(sizeof(*con));
con->aliases = NULL;
con->numAliases = 0;
con->flags = 0;
-
+
if (!name)
con->appName = NULL;
else
int i;
while (!done) {
- while (!con->os->nextCharArg && con->os->next == con->os->argc
+ while (!con->os->nextCharArg && con->os->next == con->os->argc
&& con->os > con->optionStack)
con->os--;
if (!con->os->nextCharArg && con->os->next == con->os->argc)
return -1;
if (!con->os->nextCharArg) {
-
+
origOptString = con->os->argv[con->os->next++];
if (con->restLeftover || *origOptString != '-') {
return POPT_ERROR_BADOPT;
/* Make a copy we can hack at */
- localOptString = optString =
- strcpy(malloc(strlen(origOptString) + 1),
+ localOptString = optString =
+ strcpy(malloc(strlen(origOptString) + 1),
origOptString);
if (optString[1] == '-' && !optString[2]) {
} else if (optString[1] == '-') {
optString += 2;
- if (!con->os->currAlias || !con->os->currAlias->longName ||
+ if (!con->os->currAlias || !con->os->currAlias->longName ||
strcmp(con->os->currAlias->longName, optString)) {
i = con->numAliases - 1;
if (i >= 0) {
free(localOptString);
- if ((con->os - con->optionStack + 1)
+ if ((con->os - con->optionStack + 1)
== POPT_OPTION_DEPTH)
return POPT_ERROR_OPTSTOODEEP;
free(localOptString);
return POPT_ERROR_BADOPT;
}
- } else
+ } else
con->os->nextCharArg = origOptString + 1;
free(localOptString);
}
-
+
if (con->os->nextCharArg) {
origOptString = con->os->nextCharArg;
con->os->nextCharArg = NULL;
- if (!con->os->currAlias || *origOptString !=
+ if (!con->os->currAlias || *origOptString !=
con->os->currAlias->shortName) {
i = con->numAliases - 1;
}
opt = con->options;
- while ((opt->longName || opt->shortName) &&
+ while ((opt->longName || opt->shortName) &&
*origOptString != opt->shortName) opt++;
if (!opt->longName && !opt->shortName) return POPT_ERROR_BADOPT;
con->os->nextCharArg = origOptString;
}
- if (opt->arg && opt->argInfo == POPT_ARG_NONE)
+ if (opt->arg && opt->argInfo == POPT_ARG_NONE)
*((int *)opt->arg) = 1;
else if (opt->argInfo != POPT_ARG_NONE) {
if (longArg) {
} else if (con->os->nextCharArg) {
con->os->nextArg = con->os->nextCharArg;
con->os->nextCharArg = NULL;
- } else {
- while (con->os->next == con->os->argc &&
+ } else {
+ while (con->os->next == con->os->argc &&
con->os > con->optionStack)
con->os--;
if (con->os->next == con->os->argc)
case POPT_ARG_INT:
case POPT_ARG_LONG:
aLong = strtol(con->os->nextArg, &end, 0);
- if (*end)
+ if (*end)
return POPT_ERROR_BADNUMBER;
if (aLong == LONG_MIN || aLong == LONG_MAX)
if (!con->aliases)
con->aliases = malloc(sizeof(newAlias) * con->numAliases);
else
- con->aliases = realloc(con->aliases,
+ con->aliases = realloc(con->aliases,
sizeof(newAlias) * con->numAliases);
alias = con->aliases + aliasNum;
-
+
*alias = newAlias;
if (alias->longName)
- alias->longName = strcpy(malloc(strlen(alias->longName) + 1),
+ alias->longName = strcpy(malloc(strlen(alias->longName) + 1),
alias->longName);
else
alias->longName = NULL;
int nameLength = strlen(con->appName);
char * opt;
struct poptAlias alias;
-
+
if (strncmp(line, con->appName, nameLength)) return;
line += nameLength;
if (!*line || !isspace(*line)) return;
if (fd < 0) {
if (errno == ENOENT)
return 0;
- else
+ else
return POPT_ERROR_ERRNO;
}
case '\\':
*dst++ = *chptr++;
if (chptr < end) {
- if (*chptr == '\n')
- dst--, chptr++;
+ if (*chptr == '\n')
+ dst--, chptr++;
/* \ at the end of a line does not insert a \n */
else
*dst++ = *chptr++;
alias.longName = envValue + 2;
alias.shortName = '\0';
} else if (*envValue == '-' && strlen(envValue) == 2) {
- alias.longName = NULL;
+ alias.longName = NULL;
alias.shortName = envValue[1];
} else {
skip = 1;