From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUtK8-00077X-4W for qemu-devel@nongnu.org; Thu, 27 Aug 2015 05:18:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUtK3-0008EK-UZ for qemu-devel@nongnu.org; Thu, 27 Aug 2015 05:18:20 -0400 Received: from mx2.parallels.com ([199.115.105.18]:60332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUtK3-0008CC-Nc for qemu-devel@nongnu.org; Thu, 27 Aug 2015 05:18:15 -0400 References: <1440632099-5169-1-git-send-email-marcandre.lureau@redhat.com> <1440632099-5169-4-git-send-email-marcandre.lureau@redhat.com> From: "Denis V. Lunev" Message-ID: <55DED5CD.9070407@openvz.org> Date: Thu, 27 Aug 2015 12:18:05 +0300 MIME-Version: 1.0 In-Reply-To: <1440632099-5169-4-git-send-email-marcandre.lureau@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v4 03/13] qga: move string split in separate function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Cc: mdroth@linux.vnet.ibm.com On 08/27/2015 02:34 AM, marcandre.lureau@redhat.com wrote: > 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 Reviewed-by: Denis V. Lunev