GOption-multiple arguments with exclude parameters
- From: Randima Niroshini <randima student unsw edu au>
- To: gtk-list gnome org
- Subject: GOption-multiple arguments with exclude parameters
- Date: Sat, 01 Apr 2006 12:51:16 +1100
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.
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 }
};
GOptionContext *ctx;
/* Add the main entries table to the context, providing a name.
*/
ctx = g_option_context_new("- The file scanning & parsing");
g_option_context_add_main_entries(ctx, options, "Parser");
g_option_context_parse(ctx, &argc, &argv, &error);
g_option_context_free(ctx);
if (error) {
fprintf (stderr, "parser: %s\nTry `parser --help' for more information\n",
error->message);
g_error_free (error);
return 0;
}
...
...
Please let me know any ideas on this.
Thanks,
Randima
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]