Quoting Rick Jones <rick.jones2@xxxxxx>: > Randima Niroshini wrote: > > Hi all, > > > > I would like to know on passing commandline arguments in different > contexts > > using GOption. > > For an example passing one argument( 1 & 2) and multiple arguments(3) with > > excluded parameter as follows. > > 1) ./parser --scan [FILE] > > 2) ./parser --parse [FILE] > > However, it should be also possible to execute bothoptions at once,without > > specifying expected file name twice. > > 3) ./parser --parse --scan [FILE] > > > > 1 & 2 cases are pretty straightforward to handle with GOption, but would > like to > > hear about a mechanism to handle the 3 rd case. > > Am I correct in assuming you want --parse --scan [file] to have the same > effect as --parse [file] and --scan [file] ? Yes > > > but,according to the way I used GOption command line parsing, I cannot > achieve > > the above. > > > > Here's the code I used.. > > > > gboolean gbverbose = FALSE; > > gboolean gbversion = FALSE; > > gchar *gcparse = FALSE; > > gchar *gcscan=FALSE; > > > > GError *error = NULL; > > > > GOptionEntry options[] = { > > { "verbose", 0, 0, G_OPTION_ARG_NONE, &gbverbose, "Add verbose output > to > > standard log", NULL }, > > { "version", 0, 0, G_OPTION_ARG_NONE, &gbversion, "Print version > information > > on standard output", NULL }, > > { "parse", 0, 0, G_OPTION_ARG_FILENAME, &gcparse, "Parse the program, > print > > errors on standard error", NULL }, > > { "scan", 0, 0, G_OPTION_ARG_FILENAME, &gscan, "Scan the file", NULL } > > { NULL } > > }; > > > > I think you want to use callback functions. the callback function for > scan and/or parse would check if an argument was passed and if so, set > the filename it woudl also set a flag that said that option was seen. > > it would also check if the flag for having seen the other option was set > and based on that set or not the apropriate gcparse or gcscan variable > when there was an argument passed. > > at least that would be my first take -- I tried this flag set already and failed since when I say --parse --scan [FILE], it assigns gcparse to "--scan" and no value assigned to gcscan. Anyway, will look at call back functions. > > rick jones > _______________________________________________ > > gtk-list@xxxxxxxxx > http://mail.gnome.org/mailman/listinfo/gtk-list > Thanks, Randima _______________________________________________ gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list