Create experimental new options API, various cleanups

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5171 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2005-03-12 05:37:32 +00:00
parent 5dc4b018a4
commit 2deba424d2
7 changed files with 98 additions and 59 deletions

35
app.c
View File

@@ -1455,3 +1455,38 @@ char *ast_read_textfile(const char *filename)
return output;
}
int ast_parseoptions(const struct ast_option *options, struct ast_flags *flags, char **args, char *optstr)
{
char *s;
int curarg;
int argloc;
char *arg;
int res = 0;
flags->flags = 0;
if (!optstr)
return 0;
s = optstr;
while(*s) {
curarg = *s & 0x7f;
flags->flags |= options[curarg].flag;
argloc = options[curarg].argoption;
s++;
if (*s == '(') {
/* Has argument */
s++;
arg = s;
while(*s && (*s != ')')) s++;
if (*s) {
if (argloc)
args[argloc - 1] = arg;
*s = '\0';
s++;
} else {
ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c'\n", curarg);
res = -1;
}
}
}
return res;
}