Re: gnomification: argument parsing

Nathan> Nethack calls a function gtk_init_nhwindows(int *argc, char
Nathan> **argv), which expects it to remove all windowing system
Nathan> specific commandline arguments from argc and argv before
Nathan> returning.  gnome_init, on the other hand, interprets the
Nathan> commandline arguments, but does not remove them.  What should
Nathan> I do?

As I see it, you have two choices.

The choice I prefer is to integrate nethack's command-line parsing
with Gnome.  This means changing nethack to use the GNU `argp'
library.  However, this might not be feasible, or might be difficult
to do.

The other approach is actually quite similar.  However, instead of
hacking nethack you just have to write some glue code.  The glue code
should include an argp parser that understands all the arguments
nethack understands.  It can then extract the arguments it understands
and construct a command-line which is then passed back to the caller.
Does this make sense?  See gnome-libs/libgnomeui/gnome-init.c for an
example of this technique.  In this file we recognize the arguments
that gtk_init recognizes, and we construct a fake command-line which
is then passed to gtk_init().

If nethack has some really bizarre usage, which can't be easily
described to argp, then you'll have to read through the argp docs and
see what can be done to salvage things.  Contact me if this is the
case, and I'll try to help you figure it out.

I know that many libraries work by extracting command-line options and
returning the pruned list.  However, this is a fundamentally broken
way to approach command-line parsing.  (I can provide examples of
brokenness if desired.)  The argp library solves this by letting you
construct an intelligent parser in pieces.  It has some other benefits
as well.

So while this might seem like a huge pain, I still think it is the
right thing to do.  I'd like to see more programs move to using argp.


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