mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-19 08:11:21 +00:00
major update to arg/option parsing APIs and documentation
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6953 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
23
app.c
23
app.c
@@ -1105,7 +1105,7 @@ int ast_app_group_match_get_count(char *groupmatch, char *category)
|
||||
return count;
|
||||
}
|
||||
|
||||
int ast_separate_app_args(char *buf, char delim, char **array, int arraylen)
|
||||
unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)
|
||||
{
|
||||
int argc;
|
||||
char *scan;
|
||||
@@ -1523,41 +1523,40 @@ 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)
|
||||
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
|
||||
{
|
||||
char *s;
|
||||
int curarg;
|
||||
int argloc;
|
||||
unsigned int argloc;
|
||||
char *arg;
|
||||
int res = 0;
|
||||
|
||||
flags->flags = 0;
|
||||
ast_clear_flag(flags, AST_FLAGS_ALL);
|
||||
|
||||
if (!optstr)
|
||||
return 0;
|
||||
|
||||
s = optstr;
|
||||
while (*s) {
|
||||
curarg = *s & 0x7f;
|
||||
flags->flags |= options[curarg].flag;
|
||||
curarg = *s++ & 0x7f;
|
||||
ast_set_flag(flags, options[curarg].flag);
|
||||
argloc = options[curarg].arg_index;
|
||||
s++;
|
||||
if (*s == '(') {
|
||||
/* Has argument */
|
||||
s++;
|
||||
arg = s;
|
||||
while (*s && (*s != ')')) s++;
|
||||
while (*++s && (*s != ')'));
|
||||
if (*s) {
|
||||
if (argloc)
|
||||
args[argloc - 1] = arg;
|
||||
*s = '\0';
|
||||
s++;
|
||||
*s++ = '\0';
|
||||
} else {
|
||||
ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
|
||||
res = -1;
|
||||
}
|
||||
} else if (argloc)
|
||||
} else if (argloc) {
|
||||
args[argloc - 1] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user