From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAGVC-000727-JN for qemu-devel@nongnu.org; Wed, 01 Jul 2015 07:48:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAGV9-0005NQ-CA for qemu-devel@nongnu.org; Wed, 01 Jul 2015 07:48:30 -0400 Received: from mail-qg0-x22f.google.com ([2607:f8b0:400d:c04::22f]:35964) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAGV9-0005ND-7g for qemu-devel@nongnu.org; Wed, 01 Jul 2015 07:48:27 -0400 Received: by qgeg89 with SMTP id g89so17036668qge.3 for ; Wed, 01 Jul 2015 04:48:26 -0700 (PDT) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 1 Jul 2015 13:47:41 +0200 Message-Id: <1435751267-26378-7-git-send-email-marcandre.lureau@gmail.com> In-Reply-To: <1435751267-26378-1-git-send-email-marcandre.lureau@gmail.com> References: <1435751267-26378-1-git-send-email-marcandre.lureau@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 06/12] qga: move option parsing to seperate function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , mdroth@linux.vnet.ibm.com Move option parsing out of giant main(). Signed-off-by: Marc-André Lureau --- qga/main.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/qga/main.c b/qga/main.c index b776d16..b965f61 100644 --- a/qga/main.c +++ b/qga/main.c @@ -941,19 +941,25 @@ static GList *split_list(gchar *str, const gchar separator) return list; } -int main(int argc, char **argv) -{ - const char *sopt = "hVvdm:p:l:f:F::b:s:t:"; - char *method = NULL, *device_path = NULL; - char *log_filepath = NULL; - char *pid_filepath = NULL; +static char *device_path; +static char *method; +static char *log_filepath; +static char *pid_filepath; #ifdef CONFIG_FSFREEZE - char *fsfreeze_hook = NULL; +static char *fsfreeze_hook; #endif - char *state_dir = NULL; +static char *state_dir; #ifdef _WIN32 - const char *service = NULL; +static const char *service; #endif +static GList *blacklist; +static int daemonize; +static GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; + +static void option_parse(int argc, char **argv) +{ + const char *sopt = "hVvdm:p:l:f:F::b:s:t:D"; + int opt_ind = 0, ch; const struct option lopt[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, @@ -973,14 +979,7 @@ int main(int argc, char **argv) { "statedir", 1, NULL, 't' }, { NULL, 0, NULL, 0 } }; - int opt_ind = 0, ch, daemonize = 0; - GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; - GList *blacklist = NULL; - GAState *s; - module_call_init(MODULE_INIT_QAPI); - - init_dfl_pathnames(); while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch (ch) { case 'm': @@ -1058,6 +1057,16 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } } +} + +int main(int argc, char **argv) +{ + GAState *s; + + module_call_init(MODULE_INIT_QAPI); + + init_dfl_pathnames(); + option_parse(argc, argv); if (pid_filepath == NULL) { pid_filepath = g_strdup(dfl_pathnames.pidfile); -- 2.4.3