FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 12-10-2010, 08:00 AM
Dmitry Mishin
 
Default Unify parsing of options

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 | 174 +++++++++----------------------------
1 files changed, 43 insertions(+), 131 deletions(-)

diff --git a/config/tools/ccs_tool/editconf.c b/config/tools/ccs_tool/editconf.c
index 13aa33b..313f83f 100644
--- a/config/tools/ccs_tool/editconf.c
+++ b/config/tools/ccs_tool/editconf.c
@@ -786,16 +786,7 @@ struct option addnode_options[] =
{ NULL, 0, NULL, 0 },
};

-struct option delnode_options[] =
-{
- { "outputfile", required_argument, NULL, 'o'},
- { "configfile", required_argument, NULL, 'c'},
- { "no_ccs", no_argument, NULL, 'C'},
- { "force_ccs", no_argument, NULL, 'F'},
- { NULL, 0, NULL, 0 },
-};
-
-struct option addfence_options[] =
+struct option commonw_options[] =
{
{ "outputfile", required_argument, NULL, 'o'},
{ "configfile", required_argument, NULL, 'c'},
@@ -836,14 +827,41 @@ 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'},
- { "no_ccs", no_argument, NULL, 'C'},
- { "force_ccs", no_argument, NULL, 'F'},
- { NULL, 0, NULL, 0 },
-};
+ int opt;
+
+ memset(ninfo, 0, sizeof(*ninfo));
+ ninfo->tell_ccsd = 1;
+
+ 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 'C':
+ ninfo->tell_ccsd = 0;
+ break;
+
+ case 'F':
+ ninfo->force_ccsd = 1;
+ break;
+
+ case '?':
+ default:
+ return 1;
+ }
+ }
+ return 0;
+}

static int next_nodeid(int startid, int *nodeids, int nodecount)
{
@@ -1087,38 +1105,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));
- ninfo.tell_ccsd = 1;
-
- 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 'C':
- ninfo.tell_ccsd = 0;
- break;
-
- case 'F':
- ninfo.force_ccsd = 1;
- 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)
@@ -1381,41 +1372,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));
- ninfo.tell_ccsd = 1;
-
- 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 'C':
- ninfo.tell_ccsd = 0;
- break;
-
- case 'F':
- ninfo.force_ccsd = 1;
- 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]);
@@ -1546,35 +1510,9 @@ void add_fence(int argc, char **argv)
char *fencename;
char *agentname;
struct option_info ninfo;
- int opt;
-
- memset(&ninfo, 0, sizeof(ninfo));
- ninfo.tell_ccsd = 1;
-
- while ( (opt = getopt_long(argc, argv, "c:CFh?", list_options, NULL)) != EOF)
- {
- switch(opt)
- {
- case 'c':
- ninfo.configfile = strdup(optarg);
- break;
- case 'o':
- ninfo.outputfile = strdup(optarg);
- break;
-
- case 'C':
- ninfo.tell_ccsd = 0;
- break;

- case 'F':
- ninfo.force_ccsd = 1;
- 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]);
@@ -1617,35 +1555,9 @@ void del_fence(int argc, char **argv)
xmlDocPtr doc;
char *fencename;
struct option_info ninfo;
- int opt;
-
- memset(&ninfo, 0, sizeof(ninfo));
- ninfo.tell_ccsd = 1;
-
- while ( (opt = getopt_long(argc, argv, "c:CFhv?", list_options, NULL)) != EOF)
- {
- switch(opt)
- {
- case 'c':
- ninfo.configfile = strdup(optarg);
- break;
- case 'o':
- ninfo.outputfile = strdup(optarg);
- break;
-
- case 'C':
- ninfo.tell_ccsd = 0;
- break;

- case 'F':
- ninfo.force_ccsd = 1;
- 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
 
Old 12-10-2010, 12:42 PM
Dmitry Mishin
 
Default Unify parsing of options

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: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: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
 

Thread Tools




All times are GMT. The time now is 08:43 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org