help-gengetopt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[help-gengetopt] how to deal with shared parameters for multiple program


From: Erik Sjölund
Subject: [help-gengetopt] how to deal with shared parameters for multiple programs?
Date: Sun, 2 Jan 2011 16:12:19 +0100

Hi,
Suppose you have two different programs that share a subset of the
command line parameters. For instance

option "num1" f "some info" float
option "num2" f "some info" float

The shared command line parameters are used by a function that both
programs use.
One (somewhat sketchy) solution could be:

struct CommonFlags {
  float my_num1;
  float my_num2;
};

void myFunction(struct commonFlags *common_flags) {
}

struct gengetopt_args_info args_info;
  if(cmdline_parser(argc2, argv2, &args_info) != 0) {
    exit(1);
}

CommonFlags common_flags;
common_flags.my_num1 = args_info.num1;
common_flags.my_num2 = args_info.num2;
myFunction(&common_flags);


But it would be nicer if I would not have to define my own struct CommonFlags.

I could avoid that if the two different
struct gengetopt_args_info
that are generated for the two different programs could have some
common struct as a member.
(That common struct would contain the common flags).

I guess this is not possible with the current version of gengetopt.
cheers,
Erik



reply via email to

[Prev in Thread] Current Thread [Next in Thread]