[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/35] hmp: Rewrite strlist_from_comma_list() as hmp_split_at_comm
From: |
Markus Armbruster |
Subject: |
[PULL 17/35] hmp: Rewrite strlist_from_comma_list() as hmp_split_at_comma() |
Date: |
Fri, 3 Feb 2023 09:45:31 +0100 |
Use g_strsplit() for the actual splitting. Give external linkage, so
the next commit can move one of its users to another source file.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20230124121946.1139465-15-armbru@redhat.com>
---
include/monitor/hmp.h | 1 +
monitor/hmp-cmds.c | 27 ++++++++++-----------------
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index 6fafa7ffb4..d60d1305b8 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -19,6 +19,7 @@
bool hmp_handle_error(Monitor *mon, Error *err);
void hmp_help_cmd(Monitor *mon, const char *name);
+strList *hmp_split_at_comma(const char *str);
void hmp_info_name(Monitor *mon, const QDict *qdict);
void hmp_info_version(Monitor *mon, const QDict *qdict);
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index edb50da1ff..2ca869c2ee 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -54,28 +54,21 @@ bool hmp_handle_error(Monitor *mon, Error *err)
}
/*
- * Produce a strList from a comma separated list.
- * A NULL or empty input string return NULL.
+ * Split @str at comma.
+ * A null @str defaults to "".
*/
-static strList *strList_from_comma_list(const char *in)
+strList *hmp_split_at_comma(const char *str)
{
+ char **split = g_strsplit(str ?: "", ",", -1);
strList *res = NULL;
strList **tail = &res;
+ int i;
- while (in && in[0]) {
- char *comma = strchr(in, ',');
- char *value;
-
- if (comma) {
- value = g_strndup(in, comma - in);
- in = comma + 1; /* skip the , */
- } else {
- value = g_strdup(in);
- in = NULL;
- }
- QAPI_LIST_APPEND(tail, value);
+ for (i = 0; split[i]; i++) {
+ QAPI_LIST_APPEND(tail, split[i]);
}
+ g_free(split);
return res;
}
@@ -632,7 +625,7 @@ void hmp_announce_self(Monitor *mon, const QDict *qdict)
migrate_announce_params());
qapi_free_strList(params->interfaces);
- params->interfaces = strList_from_comma_list(interfaces_str);
+ params->interfaces = hmp_split_at_comma(interfaces_str);
params->has_interfaces = params->interfaces != NULL;
params->id = g_strdup(id);
qmp_announce_self(params, NULL);
@@ -1234,7 +1227,7 @@ static StatsFilter *stats_filter(StatsTarget target,
const char *names,
request->provider = provider_idx;
if (names && !g_str_equal(names, "*")) {
request->has_names = true;
- request->names = strList_from_comma_list(names);
+ request->names = hmp_split_at_comma(names);
}
QAPI_LIST_PREPEND(request_list, request);
}
--
2.39.0
- [PULL 08/35] hmp: Drop redundant argument check from add_completion_option(), (continued)
- [PULL 08/35] hmp: Drop redundant argument check from add_completion_option(), Markus Armbruster, 2023/02/03
- [PULL 31/35] monitor: Move target-dependent HMP commands to hmp-cmds-target.c, Markus Armbruster, 2023/02/03
- [PULL 01/35] MAINTAINERS: Cover userfaultfd, Markus Armbruster, 2023/02/03
- [PULL 33/35] monitor: Move remaining QMP stuff from misc.c to qmp-cmds.c, Markus Armbruster, 2023/02/03
- [PULL 25/35] stats: Move QMP commands from monitor/ to stats/, Markus Armbruster, 2023/02/03
- [PULL 34/35] monitor: Loosen coupling between misc.c and monitor.c slightly, Markus Armbruster, 2023/02/03
- [PULL 20/35] migration: Move HMP commands from monitor/ to migration/, Markus Armbruster, 2023/02/03
- [PULL 05/35] audio: Move HMP commands from monitor/ to audio/, Markus Armbruster, 2023/02/03
- [PULL 26/35] stats: Move HMP commands from monitor/ to stats/, Markus Armbruster, 2023/02/03
- [PULL 23/35] tpm: Move HMP commands from monitor/ to softmmu/, Markus Armbruster, 2023/02/03
- [PULL 17/35] hmp: Rewrite strlist_from_comma_list() as hmp_split_at_comma(),
Markus Armbruster <=
- [PULL 16/35] rocker: Move HMP commands from monitor to hw/net/rocker/, Markus Armbruster, 2023/02/03
- [PULL 32/35] monitor: Move remaining HMP commands from misc.c to hmp-cmds.c, Markus Armbruster, 2023/02/03
- [PULL 19/35] net: Move hmp_info_network() to net-hmp-cmds.c, Markus Armbruster, 2023/02/03
- [PULL 22/35] virtio: Move HMP commands from monitor/ to hw/virtio/, Markus Armbruster, 2023/02/03
- [PULL 07/35] char: Factor out qmp_add_client() parts and move to chardev/, Markus Armbruster, 2023/02/03
- [PULL 10/35] hmp: Rename help_cmd() to hmp_help_cmd(), move declaration to hmp.h, Markus Armbruster, 2023/02/03
- [PULL 29/35] monitor: Split file descriptor passing stuff off misc.c, Markus Armbruster, 2023/02/03
- [PULL 27/35] acpi: Move the QMP command from monitor/ to hw/acpi/, Markus Armbruster, 2023/02/03
- [PULL 06/35] char: Move HMP commands from monitor/ to chardev/, Markus Armbruster, 2023/02/03
- [PULL 09/35] readline: Extract readline_add_completion_of() from monitor, Markus Armbruster, 2023/02/03