From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWqSw-0006uR-2M for qemu-devel@nongnu.org; Tue, 01 Sep 2015 14:39:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWqSs-0006DC-0e for qemu-devel@nongnu.org; Tue, 01 Sep 2015 14:39:29 -0400 Received: from e19.ny.us.ibm.com ([129.33.205.209]:51597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWqSr-0006D5-SP for qemu-devel@nongnu.org; Tue, 01 Sep 2015 14:39:25 -0400 Received: from /spool/local by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Sep 2015 14:39:25 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 5746B6E804A for ; Tue, 1 Sep 2015 14:31:05 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t81IdKPE61800640 for ; Tue, 1 Sep 2015 18:39:20 GMT Received: from d01av02.pok.ibm.com (localhost [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t81IdKxs024427 for ; Tue, 1 Sep 2015 14:39:20 -0400 From: Michael Roth Date: Tue, 1 Sep 2015 13:38:48 -0500 Message-Id: <1441132743-26228-12-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1441132743-26228-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1441132743-26228-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 11/26] qga: move string split in separate function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau The function is going to be reused in a later patch. Signed-off-by: Marc-André Lureau Reviewed-by: Michael Roth Reviewed-by: Denis V. Lunev Signed-off-by: Michael Roth --- qga/main.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/qga/main.c b/qga/main.c index 10bb2f7..e75022c 100644 --- a/qga/main.c +++ b/qga/main.c @@ -921,6 +921,26 @@ static void ga_print_cmd(QmpCommand *cmd, void *opaque) 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) { 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' }, { 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; GList *blacklist = NULL; GAState *s; @@ -1001,16 +1021,7 @@ int main(int argc, char **argv) qmp_for_each_command(ga_print_cmd, NULL); exit(EXIT_SUCCESS); } - for (j = 0, i = 0, len = strlen(optarg); i < len; i++) { - 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]); - } + blacklist = g_list_concat(blacklist, split_list(optarg, ',')); break; } #ifdef _WIN32 -- 1.9.1