qga: move string split in separate function
The function is going to be reused in a later patch. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Reviewed-by: Denis V. Lunev <den@openvz.org> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
c6c84523cd
commit
23b42894b3
33
qga/main.c
33
qga/main.c
@ -921,6 +921,26 @@ static void ga_print_cmd(QmpCommand *cmd, void *opaque)
|
|||||||
printf("%s\n", qmp_command_name(cmd));
|
printf("%s\n", qmp_command_name(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GList *split_list(gchar *str, const gchar separator)
|
||||||
|
{
|
||||||
|
GList *list = NULL;
|
||||||
|
int i, j, len;
|
||||||
|
|
||||||
|
for (j = 0, i = 0, len = strlen(str); i < len; i++) {
|
||||||
|
if (str[i] == separator) {
|
||||||
|
str[i] = 0;
|
||||||
|
list = g_list_append(list, &str[j]);
|
||||||
|
j = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j < i) {
|
||||||
|
list = g_list_append(list, &str[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *sopt = "hVvdm:p:l:f:F::b:s:t:";
|
const char *sopt = "hVvdm:p:l:f:F::b:s:t:";
|
||||||
@ -953,7 +973,7 @@ int main(int argc, char **argv)
|
|||||||
{ "statedir", 1, NULL, 't' },
|
{ "statedir", 1, NULL, 't' },
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
int opt_ind = 0, ch, daemonize = 0, i, j, len;
|
int opt_ind = 0, ch, daemonize = 0;
|
||||||
GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;
|
GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;
|
||||||
GList *blacklist = NULL;
|
GList *blacklist = NULL;
|
||||||
GAState *s;
|
GAState *s;
|
||||||
@ -1001,16 +1021,7 @@ int main(int argc, char **argv)
|
|||||||
qmp_for_each_command(ga_print_cmd, NULL);
|
qmp_for_each_command(ga_print_cmd, NULL);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
for (j = 0, i = 0, len = strlen(optarg); i < len; i++) {
|
blacklist = g_list_concat(blacklist, split_list(optarg, ','));
|
||||||
if (optarg[i] == ',') {
|
|
||||||
optarg[i] = 0;
|
|
||||||
blacklist = g_list_append(blacklist, &optarg[j]);
|
|
||||||
j = i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (j < i) {
|
|
||||||
blacklist = g_list_append(blacklist, &optarg[j]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
Loading…
Reference in New Issue
Block a user