2005-06-15 18:44:53 +02:00
|
|
|
#include "main.h"
|
2005-10-09 11:35:44 +02:00
|
|
|
#include "misc.h"
|
2005-03-03 13:46:48 +01:00
|
|
|
#include "option.h"
|
|
|
|
#include "variables.h"
|
|
|
|
|
|
|
|
/** Return the string going with the option
|
|
|
|
named 'name'.
|
|
|
|
@param name The name of the option.
|
|
|
|
@return The string_value of the option.
|
|
|
|
@see #Option */
|
|
|
|
gchar*
|
2005-03-23 20:03:26 +01:00
|
|
|
option_string(const gchar *name, OptionList *optionlist)
|
2005-03-03 13:46:48 +01:00
|
|
|
{
|
2005-03-23 20:03:26 +01:00
|
|
|
gpointer element = g_datalist_get_data(&optionlist->datalist, name);
|
|
|
|
|
|
|
|
if(element == NULL)
|
2005-08-04 14:37:50 +02:00
|
|
|
g_warning("option_string: option named %s not found\nMaybe you should delete the .bygfoot directory from your home dir", name);
|
2005-03-23 20:03:26 +01:00
|
|
|
else
|
2005-10-09 11:35:44 +02:00
|
|
|
return ((Option*)element)->string_value;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_OPTION_NOT_FOUND, NULL);
|
2005-06-15 18:44:53 +02:00
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
/** Return the GString pointer going with the option. */
|
2005-10-09 11:35:44 +02:00
|
|
|
gchar**
|
2005-03-23 20:03:26 +01:00
|
|
|
option_string_pointer(const gchar *name, OptionList *optionlist)
|
|
|
|
{
|
|
|
|
gpointer element = g_datalist_get_data(&optionlist->datalist, name);
|
|
|
|
|
|
|
|
if(element == NULL)
|
2005-08-04 14:37:50 +02:00
|
|
|
g_warning("option_string: option named %s not found\nMaybe you should delete the .bygfoot directory from your home dir", name);
|
2005-03-23 20:03:26 +01:00
|
|
|
else
|
2005-10-09 11:35:44 +02:00
|
|
|
return &((Option*)element)->string_value;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_OPTION_NOT_FOUND, NULL);
|
2005-06-15 18:44:53 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the integer going with the option
|
|
|
|
named 'name'.
|
|
|
|
@param name The name of the option.
|
|
|
|
@return The value of the option.
|
|
|
|
@see #Option */
|
|
|
|
gint
|
2005-03-23 20:03:26 +01:00
|
|
|
option_int(const gchar *name, OptionList *optionlist)
|
2005-03-03 13:46:48 +01:00
|
|
|
{
|
2005-03-23 20:03:26 +01:00
|
|
|
gpointer element = g_datalist_get_data(&optionlist->datalist, name);
|
|
|
|
|
|
|
|
if(element == NULL)
|
2005-08-04 14:37:50 +02:00
|
|
|
g_warning("option_int: option named %s not found\nMaybe you should delete the .bygfoot directory from your home dir", name);
|
2005-03-23 20:03:26 +01:00
|
|
|
else
|
|
|
|
return ((Option*)element)->value;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_OPTION_NOT_FOUND, NULL);
|
2005-06-15 18:44:53 +02:00
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
/** Return the address of an options variable. */
|
|
|
|
gint*
|
|
|
|
option_int_pointer(const gchar *name, OptionList *optionlist)
|
|
|
|
{
|
|
|
|
gpointer element = g_datalist_get_data(&optionlist->datalist, name);
|
|
|
|
|
|
|
|
if(element == NULL)
|
2005-08-04 14:37:50 +02:00
|
|
|
g_warning("option_int: option named %s not found\nMaybe you should delete the .bygfoot directory from your home dir", name);
|
2005-03-23 20:03:26 +01:00
|
|
|
else
|
|
|
|
return &((Option*)element)->value;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_OPTION_NOT_FOUND, NULL);
|
2005-06-15 18:44:53 +02:00
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
return NULL;
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the int going with the option named 'name'
|
|
|
|
cast to float and divided by 1000.
|
|
|
|
@param name The name of the option.
|
|
|
|
@return The value of the option cast to float and divided by 1000.
|
|
|
|
@see #Option */
|
|
|
|
gfloat
|
2005-03-23 20:03:26 +01:00
|
|
|
option_float(const gchar *name, OptionList *optionlist)
|
2005-03-03 13:46:48 +01:00
|
|
|
{
|
2005-03-23 20:03:26 +01:00
|
|
|
gpointer element = g_datalist_get_data(&optionlist->datalist, name);
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
if(element == NULL)
|
2005-08-04 14:37:50 +02:00
|
|
|
g_warning("option_float: option named %s not found\nMaybe you should delete the .bygfoot directory from your home dir", name);
|
2005-03-23 20:03:26 +01:00
|
|
|
else
|
2005-09-14 23:16:22 +02:00
|
|
|
return (gfloat)((Option*)element)->value / 100000;
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-06-17 14:57:05 +02:00
|
|
|
main_exit_program(EXIT_OPTION_NOT_FOUND, NULL);
|
2005-06-15 18:44:53 +02:00
|
|
|
|
2005-03-03 13:46:48 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Change the value of a string option in the array.
|
|
|
|
@param name The name of the option.
|
|
|
|
@param option_array The option array.
|
|
|
|
@param new_value The value we set. */
|
|
|
|
void
|
2005-03-23 20:03:26 +01:00
|
|
|
option_set_string(const gchar *name, OptionList *optionlist, const gchar *new_value)
|
2005-03-03 13:46:48 +01:00
|
|
|
{
|
2005-03-23 20:03:26 +01:00
|
|
|
gpointer element = g_datalist_get_data(&optionlist->datalist, name);
|
|
|
|
|
|
|
|
if(element == NULL)
|
2005-08-04 14:37:50 +02:00
|
|
|
g_warning("option_set_string: option named %s not found\nMaybe you should delete the .bygfoot directory from your home dir", name);
|
2005-03-23 20:03:26 +01:00
|
|
|
else
|
2005-10-09 11:35:44 +02:00
|
|
|
misc_string_assign(&((Option*)element)->string_value, new_value);
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Change the value of an int option in the array.
|
|
|
|
@param name The name of the option.
|
|
|
|
@param option_array The option array.
|
|
|
|
@param new_value The value we set. */
|
|
|
|
void
|
2005-03-23 20:03:26 +01:00
|
|
|
option_set_int(const gchar *name, OptionList *optionlist, gint new_value)
|
2005-03-03 13:46:48 +01:00
|
|
|
{
|
2005-03-23 20:03:26 +01:00
|
|
|
gpointer element = g_datalist_get_data(&optionlist->datalist, name);
|
2005-03-03 13:46:48 +01:00
|
|
|
|
2005-03-23 20:03:26 +01:00
|
|
|
if(element == NULL)
|
2005-08-04 14:37:50 +02:00
|
|
|
g_warning("option_set_int: option named %s not found\nMaybe you should delete the .bygfoot directory from your home dir", name);
|
2005-03-23 20:03:26 +01:00
|
|
|
else
|
|
|
|
((Option*)element)->value = new_value;
|
2005-03-03 13:46:48 +01:00
|
|
|
}
|
2005-06-23 23:53:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
/** Add an option to the optionlist with the given values. */
|
|
|
|
void
|
2005-09-29 15:41:16 +02:00
|
|
|
option_add(OptionList *optionlist, const gchar *name,
|
|
|
|
gint int_value, const gchar *string_value)
|
2005-06-23 23:53:57 +02:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
Option new;
|
2005-06-26 13:42:01 +02:00
|
|
|
gpointer element = NULL;
|
|
|
|
|
|
|
|
if(optionlist->list != NULL)
|
|
|
|
g_datalist_get_data(&optionlist->datalist, name);
|
2005-06-23 23:53:57 +02:00
|
|
|
|
|
|
|
if(element != NULL)
|
|
|
|
{
|
|
|
|
g_warning("Option named '%s' already contained in optionlist.", name);
|
|
|
|
main_exit_program(EXIT_GENERAL, NULL);
|
|
|
|
}
|
|
|
|
|
2005-10-09 11:35:44 +02:00
|
|
|
new.name = g_strdup(name);
|
2005-06-23 23:53:57 +02:00
|
|
|
new.value = int_value;
|
2005-10-09 11:35:44 +02:00
|
|
|
new.string_value = (string_value == NULL) ? NULL : g_strdup(string_value);
|
2005-06-23 23:53:57 +02:00
|
|
|
|
2005-06-26 13:42:01 +02:00
|
|
|
if(optionlist->list == NULL)
|
|
|
|
{
|
|
|
|
optionlist->list = g_array_new(FALSE, FALSE, sizeof(Option));
|
|
|
|
g_datalist_init(&optionlist->datalist);
|
|
|
|
}
|
2005-06-23 23:53:57 +02:00
|
|
|
|
2005-06-26 13:42:01 +02:00
|
|
|
g_array_append_val(optionlist->list, new);
|
|
|
|
|
2005-06-23 23:53:57 +02:00
|
|
|
for(i=0;i<optionlist->list->len;i++)
|
2005-09-29 15:41:16 +02:00
|
|
|
g_datalist_set_data(&optionlist->datalist,
|
2005-10-09 11:35:44 +02:00
|
|
|
g_array_index(optionlist->list, Option, i).name,
|
2005-06-23 23:53:57 +02:00
|
|
|
&g_array_index(optionlist->list, Option, i));
|
|
|
|
}
|