All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Mishin <dim@parallels.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 4/8] Unify parsing of options
Date: Fri, 10 Dec 2010 16:42:33 +0300	[thread overview]
Message-ID: <1291988557-22348-5-git-send-email-dim@parallels.com> (raw)
In-Reply-To: <1291988557-22348-1-git-send-email-dim@parallels.com>

This patch unifies options parsing for operations, which changes config and
supports only standard options.

Signed-off-by: Dmitry Mishin <dim@parallels.com>
---
 config/tools/ccs_tool/editconf.c |  125 ++++++++++---------------------------
 1 files changed, 34 insertions(+), 91 deletions(-)

diff --git a/config/tools/ccs_tool/editconf.c b/config/tools/ccs_tool/editconf.c
index e431bb3..9d81593 100644
--- a/config/tools/ccs_tool/editconf.c
+++ b/config/tools/ccs_tool/editconf.c
@@ -785,14 +785,7 @@ struct option addnode_options[] =
       { NULL, 0, NULL, 0 },
 };
 
-struct option delnode_options[] =
-{
-      { "outputfile", required_argument, NULL, 'o'},
-      { "configfile", required_argument, NULL, 'c'},
-      { NULL, 0, NULL, 0 },
-};
-
-struct option addfence_options[] =
+struct option commonw_options[] =
 {
       { "outputfile", required_argument, NULL, 'o'},
       { "configfile", required_argument, NULL, 'c'},
@@ -838,12 +831,32 @@ struct option addservice_options[] =
       { NULL, 0, NULL, 0 },
 };
 
-struct option delservice_options[] =
+static int parse_commonw_options(int argc, char **argv,
+	struct option_info *ninfo)
 {
-      { "outputfile", required_argument, NULL, 'o'},
-      { "configfile", required_argument, NULL, 'c'},
-      { NULL, 0, NULL, 0 },
-};
+	int opt;
+
+	memset(ninfo, 0, sizeof(*ninfo));
+
+	while ( (opt = getopt_long(argc, argv, "o:c:CFh?", commonw_options, NULL)) != EOF)
+	{
+		switch(opt)
+		{
+		case 'c':
+			ninfo->configfile = strdup(optarg);
+			break;
+
+		case 'o':
+			ninfo->outputfile = strdup(optarg);
+			break;
+
+		case '?':
+		default:
+			return 1;
+		}
+	}
+	return 0;
+}
 
 static int next_nodeid(int startid, int *nodeids, int nodecount)
 {
@@ -1074,29 +1087,11 @@ void add_node(int argc, char **argv)
 void del_node(int argc, char **argv)
 {
 	struct option_info ninfo;
-	int opt;
 	xmlDoc *doc;
 	xmlNode *root_element;
 
-	memset(&ninfo, 0, sizeof(ninfo));
-
-	while ( (opt = getopt_long(argc, argv, "o:c:CFh?", delnode_options, NULL)) != EOF)
-	{
-		switch(opt)
-		{
-		case 'c':
-			ninfo.configfile = strdup(optarg);
-			break;
-
-		case 'o':
-			ninfo.outputfile = strdup(optarg);
-			break;
-
-		case '?':
-		default:
-			delnode_usage(argv[0]);
-		}
-	}
+	if (parse_commonw_options(argc, argv, &ninfo))
+		delnode_usage(argv[0]);
 
 	/* Get node name parameter */
 	if (optind < argc)
@@ -1350,32 +1345,14 @@ void list_services(int argc, char **argv)
 void add_script(int argc, char **argv)
 {
 	struct option_info ninfo;
-	int opt;
 	xmlDoc *doc;
 	xmlNode *root_element;
 	xmlNode *rm, *rs, *node;
 	char *name;
 	char *sc_file;
 
-	memset(&ninfo, 0, sizeof(ninfo));
-
-	while ( (opt = getopt_long(argc, argv, "o:c:CFh?", addfence_options, NULL)) != EOF)
-	{
-		switch(opt)
-		{
-		case 'c':
-			ninfo.configfile = strdup(optarg);
-			break;
-
-		case 'o':
-			ninfo.outputfile = strdup(optarg);
-			break;
-
-		case '?':
-		default:
-			addscript_usage(argv[0]);
-		}
-	}
+	if (parse_commonw_options(argc, argv, &ninfo))
+		addscript_usage(argv[0]);
 
 	if (argc - optind < 2)
 		addscript_usage(argv[0]);
@@ -1515,26 +1492,9 @@ void add_fence(int argc, char **argv)
 	char *fencename;
 	char *agentname;
 	struct option_info ninfo;
-	int opt;
-
-	memset(&ninfo, 0, sizeof(ninfo));
-
-	while ( (opt = getopt_long(argc, argv, "c:o:CFh?", list_options, NULL)) != EOF)
-	{
-		switch(opt)
-		{
-		case 'c':
-			ninfo.configfile = strdup(optarg);
-			break;
-		case 'o':
-			ninfo.outputfile = strdup(optarg);
-			break;
 
-		case '?':
-		default:
-			addfence_usage(argv[0]);
-		}
-	}
+	if (parse_commonw_options(argc, argv, &ninfo))
+		addfence_usage(argv[0]);
 
 	if (argc - optind < 2)
 		addfence_usage(argv[0]);
@@ -1577,26 +1537,9 @@ void del_fence(int argc, char **argv)
 	xmlDocPtr doc;
 	char *fencename;
 	struct option_info ninfo;
-	int opt;
-
-	memset(&ninfo, 0, sizeof(ninfo));
 
-	while ( (opt = getopt_long(argc, argv, "c:o:CFhv?", list_options, NULL)) != EOF)
-	{
-		switch(opt)
-		{
-		case 'c':
-			ninfo.configfile = strdup(optarg);
-			break;
-		case 'o':
-			ninfo.outputfile = strdup(optarg);
-			break;
-
-		case '?':
-		default:
-			delfence_usage(argv[0]);
-		}
-	}
+	if (parse_commonw_options(argc, argv, &ninfo))
+		delfence_usage(argv[0]);
 
 	if (argc - optind < 1)
 		delfence_usage(argv[0]);
-- 
1.7.1



  parent reply	other threads:[~2010-12-10 13:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-10 13:42 [Cluster-devel] [PATCH 0/8] [STABLE31] sccs_tool enhancement Dmitry Mishin
2010-12-10 13:42 ` [Cluster-devel] [PATCH 1/8] Add "service" object manipulations Dmitry Mishin
2010-12-10 14:49   ` Lon Hohberger
2010-12-10 14:51     ` Lon Hohberger
2010-12-10 13:42 ` [Cluster-devel] [PATCH 2/8] Unify 'del' functions Dmitry Mishin
2010-12-10 13:42 ` [Cluster-devel] [PATCH 3/8] Add "script" object manipulations Dmitry Mishin
2010-12-10 13:42 ` Dmitry Mishin [this message]
2010-12-10 13:42 ` [Cluster-devel] [PATCH 5/8] Added "ip" " Dmitry Mishin
2010-12-10 13:42 ` [Cluster-devel] [PATCH 6/8] Added 'fs' " Dmitry Mishin
2010-12-10 13:42 ` [Cluster-devel] [PATCH 7/8] Added 'failoverdomain' " Dmitry Mishin
2010-12-10 13:42 ` [Cluster-devel] [PATCH 8/8] Added ability to reference domains from services Dmitry Mishin
2010-12-10 14:17 ` [Cluster-devel] [PATCH 0/8] [STABLE31] sccs_tool enhancement Fabio M. Di Nitto
2010-12-15  8:06 ` Fabio M. Di Nitto
  -- strict thread matches above, loose matches on Subject: below --
2010-12-10  9:00 [Cluster-devel] [PATCH 0/8] ccs_tool enhancement Dmitry Mishin
2010-12-10  9:00 ` [Cluster-devel] [PATCH 4/8] Unify parsing of options Dmitry Mishin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291988557-22348-5-git-send-email-dim@parallels.com \
    --to=dim@parallels.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.