From patchwork Wed Aug 26 10:05:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 510786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A47581401F0 for ; Wed, 26 Aug 2015 20:12:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ZrhgE8bZ; dkim-atps=neutral Received: from localhost ([::1]:37154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUXh5-00035D-Tx for incoming@patchwork.ozlabs.org; Wed, 26 Aug 2015 06:12:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUXaR-0000ds-03 for qemu-devel@nongnu.org; Wed, 26 Aug 2015 06:05:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUXaK-0007A0-Vi for qemu-devel@nongnu.org; Wed, 26 Aug 2015 06:05:42 -0400 Received: from mail-qk0-x22c.google.com ([2607:f8b0:400d:c09::22c]:32838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUXaK-00079t-Rp for qemu-devel@nongnu.org; Wed, 26 Aug 2015 06:05:36 -0400 Received: by qkch123 with SMTP id h123so110394900qkc.0 for ; Wed, 26 Aug 2015 03:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=kJjU7vhbYdykQjoZmG4eAhzbcx2QTkA6PSyg6KrRK1E=; b=ZrhgE8bZ0XZHBD3J89vgMC5ldCRNWqJANVcpHNlo0lCpBeX7UZr/xyqwW+4Xbsd80l EQTS7rkZ00OlFno3kzCmWX1sl2CNuzBQ84j6iz4IQxcKe+smCBlz5m/TKrSPARLmIWsW LOHOp9jRTuONz2IAguFuxFJv5SKOWlo+uRHSbWY5lbJHbttj6VG4kAiTH0u4WjvYMH/k 6fTLjIgRmuPw1e8X0cnrHY2dfQ/x4DxnnxJfqUIH0bI9gvk4Xw5K3jK8RXJ6R7VsJ73l hFaLdcUwqwLiH5lP2EG8ot7/TfINyhB2zcPBnto334+/nYVx82ttKbDjox6ouWT8h05X EPDg== X-Received: by 10.55.53.4 with SMTP id c4mr74473450qka.1.1440583536488; Wed, 26 Aug 2015 03:05:36 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id w191sm16099826qkw.32.2015.08.26.03.05.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Aug 2015 03:05:35 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Wed, 26 Aug 2015 12:05:16 +0200 Message-Id: <1440583525-21632-4-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1440583525-21632-1-git-send-email-marcandre.lureau@redhat.com> References: <1440583525-21632-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c09::22c Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v3 03/12] qga: move string split in separate function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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