[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] applications/HLA_TestsSuite test_FOMParse_cmdli...
From: |
certi-cvs |
Subject: |
[certi-cvs] applications/HLA_TestsSuite test_FOMParse_cmdli... |
Date: |
Wed, 29 Oct 2008 17:15:24 +0000 |
CVSROOT: /sources/certi
Module name: applications
Changes by: Eric NOULARD <erk> 08/10/29 17:15:24
Modified files:
HLA_TestsSuite : test_FOMParse_cmdline.c test_FOMParse.ggo
test_FOMParse_cmdline.h test_FOMParse.cc
Log message:
Simplify test
which does not subscribe or publish but only join/resign
and retrieve id (object class, attribute, interaction class, parameter)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse_cmdline.c?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse.ggo?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse_cmdline.h?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/HLA_TestsSuite/test_FOMParse.cc?cvsroot=certi&r1=1.4&r2=1.5
Patches:
Index: test_FOMParse_cmdline.c
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse_cmdline.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- test_FOMParse_cmdline.c 21 Oct 2008 10:30:29 -0000 1.2
+++ test_FOMParse_cmdline.c 29 Oct 2008 17:15:23 -0000 1.3
@@ -1,5 +1,5 @@
/*
- File autogenerated by gengetopt version 2.22.1
+ File autogenerated by gengetopt version 2.21
generated with the following command:
gengetopt -i test_FOMParse.ggo -F test_FOMParse_cmdline -G
@@ -32,17 +32,14 @@
" -f, --fedfile=STRING The FED file (XML or FED) to be used",
" -n, --fedname=STRING The Federation name",
" -j, --joinname=STRING The federate name used to join the federation",
- " -c, --classname=STRING The object class to subscribe to (or publish)",
- " -a, --attname=STRING The attribute name to subscribe to (or publish)",
+ " -o, --objectclass=STRING The object class to subscribe to (or publish)",
+ " -a, --attribute=STRING The attribute name to subscribe to (or
publish)",
+ " -i, --interaction=STRING The interaction class name to subscribe to (or
\n publish)",
+ " -p, --parameter=STRING The parameter name to subscribe to (or
publish)",
" -v, --verbose verbose mode (default=off)",
0
};
-typedef enum {ARG_NO
- , ARG_FLAG
- , ARG_STRING
-} cmdline_parser_arg_type;
-
static
void clear_given (struct gengetopt_args_info *args_info);
static
@@ -66,8 +63,10 @@
args_info->fedfile_given = 0 ;
args_info->fedname_given = 0 ;
args_info->joinname_given = 0 ;
- args_info->classname_given = 0 ;
- args_info->attname_given = 0 ;
+ args_info->objectclass_given = 0 ;
+ args_info->attribute_given = 0 ;
+ args_info->interaction_given = 0 ;
+ args_info->parameter_given = 0 ;
args_info->verbose_given = 0 ;
}
@@ -80,10 +79,14 @@
args_info->fedname_orig = NULL;
args_info->joinname_arg = NULL;
args_info->joinname_orig = NULL;
- args_info->classname_arg = NULL;
- args_info->classname_orig = NULL;
- args_info->attname_arg = NULL;
- args_info->attname_orig = NULL;
+ args_info->objectclass_arg = NULL;
+ args_info->objectclass_orig = NULL;
+ args_info->attribute_arg = NULL;
+ args_info->attribute_orig = NULL;
+ args_info->interaction_arg = NULL;
+ args_info->interaction_orig = NULL;
+ args_info->parameter_arg = NULL;
+ args_info->parameter_orig = NULL;
args_info->verbose_flag = 0;
}
@@ -91,16 +94,16 @@
static
void init_args_info(struct gengetopt_args_info *args_info)
{
-
-
args_info->help_help = gengetopt_args_info_help[0] ;
args_info->version_help = gengetopt_args_info_help[1] ;
args_info->fedfile_help = gengetopt_args_info_help[2] ;
args_info->fedname_help = gengetopt_args_info_help[3] ;
args_info->joinname_help = gengetopt_args_info_help[4] ;
- args_info->classname_help = gengetopt_args_info_help[5] ;
- args_info->attname_help = gengetopt_args_info_help[6] ;
- args_info->verbose_help = gengetopt_args_info_help[7] ;
+ args_info->objectclass_help = gengetopt_args_info_help[5] ;
+ args_info->attribute_help = gengetopt_args_info_help[6] ;
+ args_info->interaction_help = gengetopt_args_info_help[7] ;
+ args_info->parameter_help = gengetopt_args_info_help[8] ;
+ args_info->verbose_help = gengetopt_args_info_help[9] ;
}
@@ -110,26 +113,20 @@
printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
}
-static void print_help_common(void) {
+void
+cmdline_parser_print_help (void)
+{
+ int i = 0;
cmdline_parser_print_version ();
if (strlen(gengetopt_args_info_purpose) > 0)
printf("\n%s\n", gengetopt_args_info_purpose);
- if (strlen(gengetopt_args_info_usage) > 0)
- printf("\n%s\n", gengetopt_args_info_usage);
-
- printf("\n");
+ printf("\n%s\n\n", gengetopt_args_info_usage);
if (strlen(gengetopt_args_info_description) > 0)
- printf("%s\n\n", gengetopt_args_info_description);
-}
+ printf("%s\n", gengetopt_args_info_description);
-void
-cmdline_parser_print_help (void)
-{
- int i = 0;
- print_help_common();
while (gengetopt_args_info_help[i])
printf("%s\n", gengetopt_args_info_help[i++]);
}
@@ -142,102 +139,99 @@
init_args_info (args_info);
}
-void
-cmdline_parser_params_init(struct cmdline_parser_params *params)
+struct cmdline_parser_params *
+cmdline_parser_params_init()
{
+ struct cmdline_parser_params *params =
+ (struct cmdline_parser_params *)malloc(sizeof(struct
cmdline_parser_params));
+
if (params)
{
params->override = 0;
- params->initialize = 1;
- params->check_required = 1;
+ params->initialize = 0;
+ params->check_required = 0;
params->check_ambiguity = 0;
- params->print_errors = 1;
}
-}
-struct cmdline_parser_params *
-cmdline_parser_params_create(void)
-{
- struct cmdline_parser_params *params =
- (struct cmdline_parser_params *)malloc(sizeof(struct
cmdline_parser_params));
- cmdline_parser_params_init(params);
return params;
}
static void
-free_string_field (char **s)
-{
- if (*s)
- {
- free (*s);
- *s = 0;
- }
-}
-
-
-static void
cmdline_parser_release (struct gengetopt_args_info *args_info)
{
- free_string_field (&(args_info->fedfile_arg));
- free_string_field (&(args_info->fedfile_orig));
- free_string_field (&(args_info->fedname_arg));
- free_string_field (&(args_info->fedname_orig));
- free_string_field (&(args_info->joinname_arg));
- free_string_field (&(args_info->joinname_orig));
- free_string_field (&(args_info->classname_arg));
- free_string_field (&(args_info->classname_orig));
- free_string_field (&(args_info->attname_arg));
- free_string_field (&(args_info->attname_orig));
-
-
-
- clear_given (args_info);
-}
-
-
-static void
-write_into_file(FILE *outfile, const char *opt, const char *arg, char
*values[])
-{
- if (arg) {
- fprintf(outfile, "%s=\"%s\"\n", opt, arg);
- } else {
- fprintf(outfile, "%s\n", opt);
+ if (args_info->fedfile_arg)
+ {
+ free (args_info->fedfile_arg); /* free previous argument */
+ args_info->fedfile_arg = 0;
}
-}
-
-
-int
-cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
-{
- int i = 0;
-
- if (!outfile)
+ if (args_info->fedfile_orig)
{
- fprintf (stderr, "%s: cannot dump options to stream\n",
CMDLINE_PARSER_PACKAGE);
- return EXIT_FAILURE;
+ free (args_info->fedfile_orig); /* free previous argument */
+ args_info->fedfile_orig = 0;
+ }
+ if (args_info->fedname_arg)
+ {
+ free (args_info->fedname_arg); /* free previous argument */
+ args_info->fedname_arg = 0;
+ }
+ if (args_info->fedname_orig)
+ {
+ free (args_info->fedname_orig); /* free previous argument */
+ args_info->fedname_orig = 0;
+ }
+ if (args_info->joinname_arg)
+ {
+ free (args_info->joinname_arg); /* free previous argument */
+ args_info->joinname_arg = 0;
+ }
+ if (args_info->joinname_orig)
+ {
+ free (args_info->joinname_orig); /* free previous argument */
+ args_info->joinname_orig = 0;
+ }
+ if (args_info->objectclass_arg)
+ {
+ free (args_info->objectclass_arg); /* free previous argument */
+ args_info->objectclass_arg = 0;
+ }
+ if (args_info->objectclass_orig)
+ {
+ free (args_info->objectclass_orig); /* free previous argument */
+ args_info->objectclass_orig = 0;
+ }
+ if (args_info->attribute_arg)
+ {
+ free (args_info->attribute_arg); /* free previous argument */
+ args_info->attribute_arg = 0;
+ }
+ if (args_info->attribute_orig)
+ {
+ free (args_info->attribute_orig); /* free previous argument */
+ args_info->attribute_orig = 0;
+ }
+ if (args_info->interaction_arg)
+ {
+ free (args_info->interaction_arg); /* free previous argument */
+ args_info->interaction_arg = 0;
+ }
+ if (args_info->interaction_orig)
+ {
+ free (args_info->interaction_orig); /* free previous argument */
+ args_info->interaction_orig = 0;
+ }
+ if (args_info->parameter_arg)
+ {
+ free (args_info->parameter_arg); /* free previous argument */
+ args_info->parameter_arg = 0;
+ }
+ if (args_info->parameter_orig)
+ {
+ free (args_info->parameter_orig); /* free previous argument */
+ args_info->parameter_orig = 0;
}
- if (args_info->help_given)
- write_into_file(outfile, "help", 0, 0 );
- if (args_info->version_given)
- write_into_file(outfile, "version", 0, 0 );
- if (args_info->fedfile_given)
- write_into_file(outfile, "fedfile", args_info->fedfile_orig, 0);
- if (args_info->fedname_given)
- write_into_file(outfile, "fedname", args_info->fedname_orig, 0);
- if (args_info->joinname_given)
- write_into_file(outfile, "joinname", args_info->joinname_orig, 0);
- if (args_info->classname_given)
- write_into_file(outfile, "classname", args_info->classname_orig, 0);
- if (args_info->attname_given)
- write_into_file(outfile, "attname", args_info->attname_orig, 0);
- if (args_info->verbose_given)
- write_into_file(outfile, "verbose", 0, 0 );
-
-
- i = EXIT_SUCCESS;
- return i;
+ clear_given (args_info);
}
int
@@ -254,9 +248,68 @@
return EXIT_FAILURE;
}
- i = cmdline_parser_dump(outfile, args_info);
+ if (args_info->help_given) {
+ fprintf(outfile, "%s\n", "help");
+ }
+ if (args_info->version_given) {
+ fprintf(outfile, "%s\n", "version");
+ }
+ if (args_info->fedfile_given) {
+ if (args_info->fedfile_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "fedfile", args_info->fedfile_orig);
+ } else {
+ fprintf(outfile, "%s\n", "fedfile");
+ }
+ }
+ if (args_info->fedname_given) {
+ if (args_info->fedname_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "fedname", args_info->fedname_orig);
+ } else {
+ fprintf(outfile, "%s\n", "fedname");
+ }
+ }
+ if (args_info->joinname_given) {
+ if (args_info->joinname_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "joinname", args_info->joinname_orig);
+ } else {
+ fprintf(outfile, "%s\n", "joinname");
+ }
+ }
+ if (args_info->objectclass_given) {
+ if (args_info->objectclass_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "objectclass",
args_info->objectclass_orig);
+ } else {
+ fprintf(outfile, "%s\n", "objectclass");
+ }
+ }
+ if (args_info->attribute_given) {
+ if (args_info->attribute_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "attribute", args_info->attribute_orig);
+ } else {
+ fprintf(outfile, "%s\n", "attribute");
+ }
+ }
+ if (args_info->interaction_given) {
+ if (args_info->interaction_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "interaction",
args_info->interaction_orig);
+ } else {
+ fprintf(outfile, "%s\n", "interaction");
+ }
+ }
+ if (args_info->parameter_given) {
+ if (args_info->parameter_orig) {
+ fprintf(outfile, "%s=\"%s\"\n", "parameter", args_info->parameter_orig);
+ } else {
+ fprintf(outfile, "%s\n", "parameter");
+ }
+ }
+ if (args_info->verbose_given) {
+ fprintf(outfile, "%s\n", "verbose");
+ }
+
fclose (outfile);
+ i = EXIT_SUCCESS;
return i;
}
@@ -266,7 +319,9 @@
cmdline_parser_release (args_info);
}
-/** @brief replacement of strdup, which is not standard */
+
+/* gengetopt_strdup() */
+/* strdup.c replacement of strdup, which is not standard */
char *
gengetopt_strdup (const char *s)
{
@@ -313,7 +368,6 @@
params.initialize = initialize;
params.check_required = check_required;
params.check_ambiguity = 0;
- params.print_errors = 1;
result = cmdline_parser_internal (argc, argv, args_info, ¶ms, NULL);
@@ -809,7 +863,7 @@
int print_errors, struct custom_getopt_data *d)
{
char c = *d->nextchar++;
- const char *temp = strchr(optstring, c);
+ char *temp = strchr(optstring, c);
/* Increment `custom_optind' when we start to process its last
character. */
if (*d->nextchar == '\0')
@@ -990,106 +1044,6 @@
opt_index);
}
-
-static char *package_name = 0;
-
-/**
- * @brief updates an option
- * @param field the generic pointer to the field to update
- * @param orig_field the pointer to the orig field
- * @param field_given the pointer to the number of occurrence of this option
- * @param prev_given the pointer to the number of occurrence already seen
- * @param value the argument for this option (if null no arg was specified)
- * @param possible_values the possible values for this option (if specified)
- * @param default_value the default value (in case the option only accepts
fixed values)
- * @param arg_type the type of this option
- * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
- * @param override @see cmdline_parser_params.override
- * @param no_free whether to free a possible previous value
- * @param multiple_option whether this is a multiple option
- * @param long_opt the corresponding long option
- * @param short_opt the corresponding short option (or '-' if none)
- * @param additional_error possible further error specification
- */
-static
-int update_arg(void *field, char **orig_field,
- unsigned int *field_given, unsigned int *prev_given,
- char *value, char *possible_values[], const char *default_value,
- cmdline_parser_arg_type arg_type,
- int check_ambiguity, int override,
- int no_free, int multiple_option,
- const char *long_opt, char short_opt,
- const char *additional_error)
-{
- char *stop_char = 0;
- const char *val = value;
- int found;
- char **string_field;
-
- stop_char = 0;
- found = 0;
-
- if (!multiple_option && prev_given && (*prev_given || (check_ambiguity &&
*field_given)))
- {
- if (short_opt != '-')
- fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
- package_name, long_opt, short_opt,
- (additional_error ? additional_error : ""));
- else
- fprintf (stderr, "%s: `--%s' option given more than once%s\n",
- package_name, long_opt,
- (additional_error ? additional_error : ""));
- return 1; /* failure */
- }
-
-
- if (field_given && *field_given && ! override)
- return 0;
- if (prev_given)
- (*prev_given)++;
- if (field_given)
- (*field_given)++;
- if (possible_values)
- val = possible_values[found];
-
- switch(arg_type) {
- case ARG_FLAG:
- *((int *)field) = !*((int *)field);
- break;
- case ARG_STRING:
- if (val) {
- string_field = (char **)field;
- if (!no_free && *string_field)
- free (*string_field); /* free previous string */
- *string_field = gengetopt_strdup (val);
- }
- break;
- default:
- break;
- };
-
-
- /* store the original value */
- switch(arg_type) {
- case ARG_NO:
- case ARG_FLAG:
- break;
- default:
- if (value && orig_field) {
- if (no_free) {
- *orig_field = value;
- } else {
- if (*orig_field)
- free (*orig_field); /* free previous string */
- *orig_field = gengetopt_strdup (value);
- }
- }
- };
-
- return 0; /* OK */
-}
-
-
int
cmdline_parser_internal (int argc, char * const *argv, struct
gengetopt_args_info *args_info,
struct cmdline_parser_params *params, const char
*additional_error)
@@ -1104,8 +1058,6 @@
int check_required;
int check_ambiguity;
- package_name = argv[0];
-
override = params->override;
initialize = params->initialize;
check_required = params->check_required;
@@ -1118,12 +1070,13 @@
optarg = 0;
optind = 0;
- opterr = params->print_errors;
+ opterr = 1;
optopt = '?';
while (1)
{
int option_index = 0;
+ char *stop_char;
static struct option long_options[] = {
{ "help", 0, NULL, 'h' },
@@ -1131,18 +1084,21 @@
{ "fedfile", 1, NULL, 'f' },
{ "fedname", 1, NULL, 'n' },
{ "joinname", 1, NULL, 'j' },
- { "classname", 1, NULL, 'c' },
- { "attname", 1, NULL, 'a' },
+ { "objectclass", 1, NULL, 'o' },
+ { "attribute", 1, NULL, 'a' },
+ { "interaction", 1, NULL, 'i' },
+ { "parameter", 1, NULL, 'p' },
{ "verbose", 0, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
+ stop_char = 0;
custom_optarg = optarg;
custom_optind = optind;
custom_opterr = opterr;
custom_optopt = optopt;
- c = custom_getopt_long (argc, argv, "hVf:n:j:c:a:v", long_options,
&option_index);
+ c = custom_getopt_long (argc, argv, "hVf:n:j:o:a:i:p:v", long_options,
&option_index);
optarg = custom_optarg;
optind = custom_optind;
@@ -1164,76 +1120,145 @@
exit (EXIT_SUCCESS);
case 'f': /* The FED file (XML or FED) to be used. */
-
-
- if (update_arg( (void *)&(args_info->fedfile_arg),
- &(args_info->fedfile_orig), &(args_info->fedfile_given),
- &(local_args_info.fedfile_given), optarg, 0, 0, ARG_STRING,
- check_ambiguity, override, 0, 0,
- "fedfile", 'f',
- additional_error))
+ if (local_args_info.fedfile_given || (check_ambiguity &&
args_info->fedfile_given))
+ {
+ fprintf (stderr, "%s: `--fedfile' (`-f') option given more than
once%s\n", argv[0], (additional_error ? additional_error : ""));
goto failure;
-
+ }
+ if (args_info->fedfile_given && ! override)
+ continue;
+ local_args_info.fedfile_given = 1;
+ args_info->fedfile_given = 1;
+ if (args_info->fedfile_arg)
+ free (args_info->fedfile_arg); /* free previous string */
+ args_info->fedfile_arg = gengetopt_strdup (optarg);
+ if (args_info->fedfile_orig)
+ free (args_info->fedfile_orig); /* free previous string */
+ args_info->fedfile_orig = gengetopt_strdup (optarg);
break;
- case 'n': /* The Federation name. */
-
- if (update_arg( (void *)&(args_info->fedname_arg),
- &(args_info->fedname_orig), &(args_info->fedname_given),
- &(local_args_info.fedname_given), optarg, 0, 0, ARG_STRING,
- check_ambiguity, override, 0, 0,
- "fedname", 'n',
- additional_error))
+ case 'n': /* The Federation name. */
+ if (local_args_info.fedname_given || (check_ambiguity &&
args_info->fedname_given))
+ {
+ fprintf (stderr, "%s: `--fedname' (`-n') option given more than
once%s\n", argv[0], (additional_error ? additional_error : ""));
goto failure;
-
+ }
+ if (args_info->fedname_given && ! override)
+ continue;
+ local_args_info.fedname_given = 1;
+ args_info->fedname_given = 1;
+ if (args_info->fedname_arg)
+ free (args_info->fedname_arg); /* free previous string */
+ args_info->fedname_arg = gengetopt_strdup (optarg);
+ if (args_info->fedname_orig)
+ free (args_info->fedname_orig); /* free previous string */
+ args_info->fedname_orig = gengetopt_strdup (optarg);
break;
- case 'j': /* The federate name used to join the federation. */
-
- if (update_arg( (void *)&(args_info->joinname_arg),
- &(args_info->joinname_orig), &(args_info->joinname_given),
- &(local_args_info.joinname_given), optarg, 0, 0, ARG_STRING,
- check_ambiguity, override, 0, 0,
- "joinname", 'j',
- additional_error))
+ case 'j': /* The federate name used to join the federation. */
+ if (local_args_info.joinname_given || (check_ambiguity &&
args_info->joinname_given))
+ {
+ fprintf (stderr, "%s: `--joinname' (`-j') option given more than
once%s\n", argv[0], (additional_error ? additional_error : ""));
goto failure;
-
+ }
+ if (args_info->joinname_given && ! override)
+ continue;
+ local_args_info.joinname_given = 1;
+ args_info->joinname_given = 1;
+ if (args_info->joinname_arg)
+ free (args_info->joinname_arg); /* free previous string */
+ args_info->joinname_arg = gengetopt_strdup (optarg);
+ if (args_info->joinname_orig)
+ free (args_info->joinname_orig); /* free previous string */
+ args_info->joinname_orig = gengetopt_strdup (optarg);
break;
- case 'c': /* The object class to subscribe to (or publish). */
-
- if (update_arg( (void *)&(args_info->classname_arg),
- &(args_info->classname_orig), &(args_info->classname_given),
- &(local_args_info.classname_given), optarg, 0, 0, ARG_STRING,
- check_ambiguity, override, 0, 0,
- "classname", 'c',
- additional_error))
+ case 'o': /* The object class to subscribe to (or publish). */
+ if (local_args_info.objectclass_given || (check_ambiguity &&
args_info->objectclass_given))
+ {
+ fprintf (stderr, "%s: `--objectclass' (`-o') option given more
than once%s\n", argv[0], (additional_error ? additional_error : ""));
goto failure;
-
+ }
+ if (args_info->objectclass_given && ! override)
+ continue;
+ local_args_info.objectclass_given = 1;
+ args_info->objectclass_given = 1;
+ if (args_info->objectclass_arg)
+ free (args_info->objectclass_arg); /* free previous string */
+ args_info->objectclass_arg = gengetopt_strdup (optarg);
+ if (args_info->objectclass_orig)
+ free (args_info->objectclass_orig); /* free previous string */
+ args_info->objectclass_orig = gengetopt_strdup (optarg);
break;
- case 'a': /* The attribute name to subscribe to (or publish). */
-
- if (update_arg( (void *)&(args_info->attname_arg),
- &(args_info->attname_orig), &(args_info->attname_given),
- &(local_args_info.attname_given), optarg, 0, 0, ARG_STRING,
- check_ambiguity, override, 0, 0,
- "attname", 'a',
- additional_error))
+ case 'a': /* The attribute name to subscribe to (or publish). */
+ if (local_args_info.attribute_given || (check_ambiguity &&
args_info->attribute_given))
+ {
+ fprintf (stderr, "%s: `--attribute' (`-a') option given more
than once%s\n", argv[0], (additional_error ? additional_error : ""));
goto failure;
-
+ }
+ if (args_info->attribute_given && ! override)
+ continue;
+ local_args_info.attribute_given = 1;
+ args_info->attribute_given = 1;
+ if (args_info->attribute_arg)
+ free (args_info->attribute_arg); /* free previous string */
+ args_info->attribute_arg = gengetopt_strdup (optarg);
+ if (args_info->attribute_orig)
+ free (args_info->attribute_orig); /* free previous string */
+ args_info->attribute_orig = gengetopt_strdup (optarg);
break;
- case 'v': /* verbose mode. */
+ case 'i': /* The interaction class name to subscribe to (or
publish). */
+ if (local_args_info.interaction_given || (check_ambiguity &&
args_info->interaction_given))
+ {
+ fprintf (stderr, "%s: `--interaction' (`-i') option given more
than once%s\n", argv[0], (additional_error ? additional_error : ""));
+ goto failure;
+ }
+ if (args_info->interaction_given && ! override)
+ continue;
+ local_args_info.interaction_given = 1;
+ args_info->interaction_given = 1;
+ if (args_info->interaction_arg)
+ free (args_info->interaction_arg); /* free previous string */
+ args_info->interaction_arg = gengetopt_strdup (optarg);
+ if (args_info->interaction_orig)
+ free (args_info->interaction_orig); /* free previous string */
+ args_info->interaction_orig = gengetopt_strdup (optarg);
+ break;
- if (update_arg((void *)&(args_info->verbose_flag), 0,
&(args_info->verbose_given),
- &(local_args_info.verbose_given), optarg, 0, 0, ARG_FLAG,
- check_ambiguity, override, 1, 0, "verbose", 'v',
- additional_error))
+ case 'p': /* The parameter name to subscribe to (or publish). */
+ if (local_args_info.parameter_given || (check_ambiguity &&
args_info->parameter_given))
+ {
+ fprintf (stderr, "%s: `--parameter' (`-p') option given more
than once%s\n", argv[0], (additional_error ? additional_error : ""));
goto failure;
+ }
+ if (args_info->parameter_given && ! override)
+ continue;
+ local_args_info.parameter_given = 1;
+ args_info->parameter_given = 1;
+ if (args_info->parameter_arg)
+ free (args_info->parameter_arg); /* free previous string */
+ args_info->parameter_arg = gengetopt_strdup (optarg);
+ if (args_info->parameter_orig)
+ free (args_info->parameter_orig); /* free previous string */
+ args_info->parameter_orig = gengetopt_strdup (optarg);
+ break;
+ case 'v': /* verbose mode. */
+ if (local_args_info.verbose_given || (check_ambiguity &&
args_info->verbose_given))
+ {
+ fprintf (stderr, "%s: `--verbose' (`-v') option given more than
once%s\n", argv[0], (additional_error ? additional_error : ""));
+ goto failure;
+ }
+ if (args_info->verbose_given && ! override)
+ continue;
+ local_args_info.verbose_given = 1;
+ args_info->verbose_given = 1;
+ args_info->verbose_flag = !(args_info->verbose_flag);
break;
+
case 0: /* Long option with no short option */
case '?': /* Invalid option. */
/* `getopt_long' already printed an error message. */
Index: test_FOMParse.ggo
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse.ggo,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- test_FOMParse.ggo 21 Oct 2008 10:30:34 -0000 1.2
+++ test_FOMParse.ggo 29 Oct 2008 17:15:23 -0000 1.3
@@ -13,6 +13,8 @@
option "fedfile" f "The FED file (XML or FED) to be used" string
required
option "fedname" n "The Federation name" string required
option "joinname" j "The federate name used to join the federation" string
optional
-option "classname" c "The object class to subscribe to (or publish)" string
optional
-option "attname" a "The attribute name to subscribe to (or publish)" string
optional
+option "objectclass" o "The object class to subscribe to (or publish)"
string optional
+option "attribute" a "The attribute name to subscribe to (or publish)"
string optional
+option "interaction" i "The interaction class name to subscribe to (or
publish)" string optional
+option "parameter" p "The parameter name to subscribe to (or publish)"
string optional
option "verbose" v "verbose mode" flag off
Index: test_FOMParse_cmdline.h
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse_cmdline.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- test_FOMParse_cmdline.h 21 Oct 2008 10:30:32 -0000 1.2
+++ test_FOMParse_cmdline.h 29 Oct 2008 17:15:23 -0000 1.3
@@ -1,6 +1,6 @@
/** @file test_FOMParse_cmdline.h
* @brief The header file for the command line option parser
- * generated by GNU Gengetopt version 2.22.1
+ * generated by GNU Gengetopt version 2.21
* http://www.gnu.org/software/gengetopt.
* DO NOT modify this file, since it can be overwritten
* @author GNU Gengetopt by Lorenzo Bettini */
@@ -13,8 +13,6 @@
#include "config.h"
#endif
-#include <stdio.h> /* for FILE */
-
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -43,23 +41,31 @@
char * joinname_arg; /**< @brief The federate name used to join the
federation. */
char * joinname_orig; /**< @brief The federate name used to join the
federation original value given at command line. */
const char *joinname_help; /**< @brief The federate name used to join the
federation help description. */
- char * classname_arg; /**< @brief The object class to subscribe to
(or publish). */
- char * classname_orig; /**< @brief The object class to subscribe to
(or publish) original value given at command line. */
- const char *classname_help; /**< @brief The object class to subscribe to (or
publish) help description. */
- char * attname_arg; /**< @brief The attribute name to subscribe to (or
publish). */
- char * attname_orig; /**< @brief The attribute name to subscribe to (or
publish) original value given at command line. */
- const char *attname_help; /**< @brief The attribute name to subscribe to (or
publish) help description. */
+ char * objectclass_arg; /**< @brief The object class to subscribe to
(or publish). */
+ char * objectclass_orig; /**< @brief The object class to subscribe to
(or publish) original value given at command line. */
+ const char *objectclass_help; /**< @brief The object class to subscribe to
(or publish) help description. */
+ char * attribute_arg; /**< @brief The attribute name to subscribe to
(or publish). */
+ char * attribute_orig; /**< @brief The attribute name to subscribe to
(or publish) original value given at command line. */
+ const char *attribute_help; /**< @brief The attribute name to subscribe to
(or publish) help description. */
+ char * interaction_arg; /**< @brief The interaction class name to
subscribe to (or publish). */
+ char * interaction_orig; /**< @brief The interaction class name to
subscribe to (or publish) original value given at command line. */
+ const char *interaction_help; /**< @brief The interaction class name to
subscribe to (or publish) help description. */
+ char * parameter_arg; /**< @brief The parameter name to subscribe to
(or publish). */
+ char * parameter_orig; /**< @brief The parameter name to subscribe to
(or publish) original value given at command line. */
+ const char *parameter_help; /**< @brief The parameter name to subscribe to
(or publish) help description. */
int verbose_flag; /**< @brief verbose mode (default=off). */
const char *verbose_help; /**< @brief verbose mode help description. */
- unsigned int help_given ; /**< @brief Whether help was given. */
- unsigned int version_given ; /**< @brief Whether version was given. */
- unsigned int fedfile_given ; /**< @brief Whether fedfile was given. */
- unsigned int fedname_given ; /**< @brief Whether fedname was given. */
- unsigned int joinname_given ; /**< @brief Whether joinname was given.
*/
- unsigned int classname_given ; /**< @brief Whether classname was
given. */
- unsigned int attname_given ; /**< @brief Whether attname was given. */
- unsigned int verbose_given ; /**< @brief Whether verbose was given. */
+ int help_given ; /**< @brief Whether help was given. */
+ int version_given ; /**< @brief Whether version was given. */
+ int fedfile_given ; /**< @brief Whether fedfile was given. */
+ int fedname_given ; /**< @brief Whether fedname was given. */
+ int joinname_given ; /**< @brief Whether joinname was given. */
+ int objectclass_given ; /**< @brief Whether objectclass was given. */
+ int attribute_given ; /**< @brief Whether attribute was given. */
+ int interaction_given ; /**< @brief Whether interaction was given. */
+ int parameter_given ; /**< @brief Whether parameter was given. */
+ int verbose_given ; /**< @brief Whether verbose was given. */
} ;
@@ -67,10 +73,9 @@
struct cmdline_parser_params
{
int override; /**< @brief whether to override possibly already present
options (default 0) */
- int initialize; /**< @brief whether to initialize the option structure
gengetopt_args_info (default 1) */
- int check_required; /**< @brief whether to check that all required options
were provided (default 1) */
+ int initialize; /**< @brief whether to initialize the option structure
gengetopt_args_info (default 0) */
+ int check_required; /**< @brief whether to check that all required options
were provided (default 0) */
int check_ambiguity; /**< @brief whether to check for options already
specified in the option structure gengetopt_args_info (default 0) */
- int print_errors; /**< @brief whether getopt_long should print an error
message for a bad option (default 1) */
} ;
/** @brief the purpose string of the program */
@@ -118,15 +123,6 @@
struct cmdline_parser_params *params);
/**
- * Save the contents of the option struct into an already open FILE stream.
- * @param outfile the stream where to dump options
- * @param args_info the option struct to dump
- * @return 0 if everything went fine, NON 0 if an error took place
- */
-int cmdline_parser_dump(FILE *outfile,
- struct gengetopt_args_info *args_info);
-
-/**
* Save the contents of the option struct into a (text) file.
* This file can be read by the config file parser (if generated by gengetopt)
* @param filename the file where to save
@@ -146,18 +142,11 @@
void cmdline_parser_print_version(void);
/**
- * Initializes all the fields a cmdline_parser_params structure
- * to their default values
- * @param params the structure to initialize
- */
-void cmdline_parser_params_init(struct cmdline_parser_params *params);
-
-/**
* Allocates dynamically a cmdline_parser_params structure and initializes
- * all its fields to their default values
- * @return the created and initialized cmdline_parser_params structure
+ * all its fields to 0
+ * @return the initialized cmdline_parser_params structure
*/
-struct cmdline_parser_params *cmdline_parser_params_create(void);
+struct cmdline_parser_params *cmdline_parser_params_init();
/**
* Initializes the passed gengetopt_args_info structure's fields
Index: test_FOMParse.cc
===================================================================
RCS file: /sources/certi/applications/HLA_TestsSuite/test_FOMParse.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- test_FOMParse.cc 21 Oct 2008 11:38:37 -0000 1.4
+++ test_FOMParse.cc 29 Oct 2008 17:15:24 -0000 1.5
@@ -31,6 +31,11 @@
private:
string federationName;
string federationFile;
+
+ RTI::ObjectClassHandle objectClassId;
+ RTI::AttributeHandle attributeId;
+ RTI::InteractionClassHandle interactionClassId;
+ RTI::ParameterHandle parameterId;
bool verbose;
public:
@@ -47,14 +52,17 @@
virtual ~ParseFederate() throw (RTI::FederateInternalError) {
};
- void
+ bool
create() {
+ bool retval = false;
+
try {
myRTIamb.createFederationExecution(federationName.c_str(),
federationFile.c_str());
if (verbose) {
cout << "createFederationExecution SUCCESS." <<
endl;
}
+ retval = true;
} catch ( RTI::FederationExecutionAlreadyExists& e) {
cout << "--> Federation already created by another
federate." << endl;
} catch ( RTI::Exception &e ) {
@@ -63,12 +71,16 @@
} catch ( ... ) {
cerr << "Error: Unknown non-RTI exception." << endl;
}
+
+ return retval;
} /* end of create */
- void
+ bool
destroy() {
+ bool retval = false;
try {
myRTIamb.destroyFederationExecution(federationName.c_str());
+ retval = true;
} catch (RTI::FederatesCurrentlyJoined) {
cout << "Federates currently joined." << endl;
} catch ( RTI::Exception &e ) {
@@ -77,9 +89,12 @@
} catch ( ... ) {
cerr << "Error: Unknown non-RTI exception." << endl;
}
+ return retval;
} /* end of destroy */
- void join(std::string federateName) {
+ bool
+ join(std::string federateName) {
+ bool retval = false;
try {
if (verbose) {
cout << "Try to join federation as <" <<
federateName << ">...";
@@ -90,6 +105,7 @@
if (verbose) {
cout << "SUCCESS." << endl;
}
+ retval = true;
} catch (RTI::FederateAlreadyExecutionMember& e) {
cerr << "Federate already execution member" << endl;
} catch ( RTI::Exception &e ) {
@@ -98,10 +114,12 @@
} catch ( ... ) {
cerr << "Error: Unknown non-RTI exception." << endl;
}
+ return retval;
} /* end of join */
- void resign() {
-
+ bool
+ resign() {
+ bool retval = false;
try {
if (verbose) {
cout << "Try to resign from federation...";
@@ -110,61 +128,110 @@
if (verbose) {
cout << "SUCCESS." << endl;
}
+ retval = true;
} catch ( RTI::Exception &e ) {
cerr << "RTI exception: " << e._name << " ["
<< (e._reason ? e._reason : "undefined") << "]." <<
endl;
} catch ( ... ) {
cerr << "Error: Unknown non-RTI exception." << endl;
}
+ return retval;
} /* end of resign */
- void publish() {
+ bool
+ getObjectHandles(const std::string& className, const std::string&
attributeName) {
+ bool retval = true;
- } /* end of publish */
+ if (verbose) {
+ cout << "Getting object handles..." <<endl;
+ }
+ try {
+ objectClassId =
myRTIamb.getObjectClassHandle(className.c_str());
+ cout << " " << className << " ID = " << objectClassId
<< endl;
+ } catch (RTI::Exception& e) {
+ cerr << " Unable to obtain class handle for object
class <"<< className <<">" <<endl;
+ retval = false;
+ }
+
+ if (attributeName.length()>0) {
+ try {
+ attributeId =
myRTIamb.getAttributeHandle(attributeName.c_str(),objectClassId);
+ cout << " " << attributeName << " ID = " <<
attributeId << endl;
+ } catch (RTI::Exception& e){
+ cerr << " Unable to obtain attribute handle
for object class attribute <"<< attributeName<<">" <<endl;
+ retval = false;
+ }
+ }
+ return retval;
+ } /* end of getClassHandles */
+
+ bool
+ getInteractionHandles(std::string className, std::string parameterName)
{
+ bool retval = false;
- void subscribe(std::string className, std::string attributeName) {
- RTI::ObjectClassHandle classId;
- RTI::AttributeHandle attId;
if (verbose) {
- cout << "Getting handles..." <<endl;
+ cout << "Getting interaction handles..." <<endl;
}
try {
- classId =
myRTIamb.getObjectClassHandle(className.c_str());
- cout << " " << className << " ID = " << classId <<
endl;
+ interactionClassId =
myRTIamb.getInteractionClassHandle(className.c_str());
+ cout << " " << className << " ID = " <<
interactionClassId << endl;
} catch (RTI::Exception& e) {
- cerr << " Unable to obtain class handle for class
<"<< className<<">" <<endl;
+ cerr << " Unable to obtain class handle for
interaction class <"<< className <<">" <<endl;
+ retval = false;
}
+
+ if (parameterName.length()>0) {
try {
- attId =
myRTIamb.getAttributeHandle(attributeName.c_str(),classId);
- cout << " " << attributeName << " ID = " << attId <<
endl;
+ parameterId =
myRTIamb.getParameterHandle(parameterName.c_str(),interactionClassId);
+ cout << " " << parameterName << " ID = " <<
parameterId << endl;
} catch (RTI::Exception& e){
- cerr << " Unable to obtain attribute handle for
attribute <"<< attributeName<<">" <<endl;
+ cerr << " Unable to obtain attribute handle
for interaction class parameter <"<< parameterName<<">" <<endl;
+ retval = false;
+ }
}
+ return retval;
+ } /* end of getInteractionHandles */
+
+ bool
+ publish() {
+ bool retval = false;
+ return retval;
+ } /* end of publish */
+ bool
+ subscribe() {
+ bool retval = false;
// Add attribute handle to the attribute set
// Before, we create the Set with one attribute
auto_ptr<RTI::AttributeHandleSet>
attributes(RTI::AttributeHandleSetFactory::create(1));
- attributes->add(attId);
+ attributes->add(attributeId);
try {
-
myRTIamb.subscribeObjectClassAttributes(classId,*attributes);
+
myRTIamb.subscribeObjectClassAttributes(objectClassId,*attributes);
+ retval = true;
} catch (RTI::Exception& e) {
cerr << "Unable to subscribe" << endl;
}
+ return retval;
} /* end of subscribe */
- void unsubscribe(std::string className) {
+ bool
+ unsubscribe(std::string className) {
+ bool retval = true;
RTI::ObjectClassHandle classId;
try {
classId =
myRTIamb.getObjectClassHandle(className.c_str());
} catch (RTI::Exception& e) {
cerr << "Unable to obtain class handle for class <"<<
className<<">" <<endl;
+ retval = false;
}
try {
myRTIamb.unsubscribeObjectClass(classId);
} catch (RTI::Exception& e) {
cerr << "Unable to unsubscribe" << endl;
+ retval = false;
}
+ return retval;
} /* end of unsubscribe */
void
@@ -197,8 +264,10 @@
RTI::RTIambassador myRTIamb;
};
-int main(int argc, char **argv) {
+int
+main(int argc, char **argv) {
+ bool status = true;
// Command line arguments handling (generated with gengetopt)
gengetopt_args_info args ;
if (cmdline_parser(argc, argv, &args))
@@ -207,27 +276,38 @@
ParseFederate parseFederate(std::string(args.fedfile_arg),
std::string(args.fedname_arg),args.verbose_flag);
- parseFederate.create();
+ status &= parseFederate.create();
+
if (args.joinname_given) {
- parseFederate.join(std::string(args.joinname_arg));
+ status &= parseFederate.join(std::string(args.joinname_arg));
}
- if (args.classname_given && args.attname_given) {
- parseFederate.subscribe(std::string(args.classname_arg),
- std::string(args.attname_arg));
+ if (args.joinname_given && args.objectclass_given) {
+ if (args.attribute_given) {
+ status &=
parseFederate.getObjectHandles(std::string(args.objectclass_arg),
+
std::string(args.attribute_arg));
+ } else {
+ status &=
parseFederate.getObjectHandles(std::string(args.objectclass_arg),
+
std::string(""));
+ }
}
- parseFederate.tickRTI(1,2);
-
- if (args.classname_given && args.attname_given) {
- parseFederate.unsubscribe(std::string(args.classname_arg));
+ if (args.joinname_given && args.interaction_given) {
+ if (args.parameter_given) {
+ status &=
parseFederate.getInteractionHandles(std::string(args.interaction_arg),
+ std::string(args.parameter_arg));
+ } else {
+ status &=
parseFederate.getInteractionHandles(std::string(args.interaction_arg),
+
std::string(""));
}
+ }
+
+ parseFederate.tickRTI(1,2);
if (args.joinname_given) {
- parseFederate.resign();
+ status &= parseFederate.resign();
}
- parseFederate.destroy();
-
- return 0;
+ status &= parseFederate.destroy();
+ return status ? 0 : 1;
}