Re: glib: GOption workaround for use with custom argv's



Owen Taylor schrieb:
> On Tue, 2005-04-05 at 18:37 +0200, Oliver Lange wrote:
> 
>>Hello everyone,
>>
>>I'd like to use GOption for parsing custom argv's, other than the
>>application's main() argv. I wrote a tiny workaround to avoid
>>calls to exit() or g_set_prgname(), with two new functions and
>>without breaking the current glib API.
>>
>>If you like to add this feature, i can send a commented source
>>snippet, which suggests a solution. All easy.
> 
> 
> I think it would be hard to comment without seeing the proposed
> API.
> 					Owen
> 

Okay, here's a detailed description.

About the problem:

  An application shall parse custom commands.

  Imagine a GTK dialog "enter a command". This
  command shall now be parsed, and if possible,
  by creating an argv from the given command line,
  which is then passed to g_option_context_parse(),
  but that's currently not possible, because the
  use of --help would exit() the whole app, and
  it would also assume g_get_prgname() as command
  name, which is not intended in this case.

In the suggested workaround, there are two new functions:

//
// create a context for "custom"-type argv's.
//
GOptionContext *
g_option_context_custom_new (const gchar *parameter_string)
{
  GOptionContext *context;

  if ((context = g_option_context_new(parameter_string)))
  {
    context->custom = TRUE;
  }
  return context;
}

//
// For custom contexts, exit() is not called when it comes
// to usage of the --help option, so this function is called
// after parsing a custom context, to get this information.
//
gboolean
g_option_context_custom_help_used (GOptionContext *context)
{
  return(context->custom_help_used);
}

In addition, there are some minor changes to
g_option_context_parse() and it's sub functions,
therefor i'd need to send a source code for a full
list of changes, all documented.

Cheers,

Oliver 'Bloody' Lange.




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