Extract common core from set_var_value() into helper function
This commit is contained in:
@@ -796,39 +796,21 @@ int do_boolean(char *str, int *value)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* set_ircvariable()
|
||||||
* set_var_value: Given the variable structure and the string representation
|
*
|
||||||
* of the value, this sets the value in the most verbose and error checking
|
* Set the IrcVariable to the provided string value.
|
||||||
* of manors. It displays the results of the set and executes the function
|
|
||||||
* defined in the var structure
|
|
||||||
*/
|
*/
|
||||||
|
static void set_ircvariable(IrcVariable *var, char *value)
|
||||||
void set_var_value(int var_index, char *value, IrcVariableDll *dll)
|
|
||||||
{
|
{
|
||||||
char *rest;
|
char *rest;
|
||||||
IrcVariable *var;
|
|
||||||
int old;
|
|
||||||
#ifdef WANT_DLL
|
|
||||||
if (dll)
|
|
||||||
{
|
|
||||||
var = (IrcVariable *) new_malloc(sizeof(IrcVariable));
|
|
||||||
var->type = dll->type;
|
|
||||||
var->string = dll->string;
|
|
||||||
var->integer = dll->integer;
|
|
||||||
var->int_flags = dll->int_flags;
|
|
||||||
var->flags = dll->flags;
|
|
||||||
var->name = dll->name;
|
|
||||||
var->func = dll->func;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
var = &(irc_variable[var_index]);
|
|
||||||
switch (var->type)
|
switch (var->type)
|
||||||
{
|
{
|
||||||
case BOOL_TYPE_VAR:
|
case BOOL_TYPE_VAR:
|
||||||
if (value && *value && (value = next_arg(value, &rest)))
|
if (value && *value && (value = next_arg(value, &rest)))
|
||||||
{
|
{
|
||||||
old = var->integer;
|
int old = var->integer;
|
||||||
|
|
||||||
if (do_boolean(value, &(var->integer)))
|
if (do_boolean(value, &(var->integer)))
|
||||||
{
|
{
|
||||||
say("Value must be either ON, OFF, or TOGGLE");
|
say("Value must be either ON, OFF, or TOGGLE");
|
||||||
@@ -949,11 +931,7 @@ void set_var_value(int var_index, char *value, IrcVariableDll *dll)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
put_it("%s", convert_output_format(fget_string_var(var->string?FORMAT_SET_FSET:FORMAT_SET_NOVALUE_FSET), "%s %s", var->name, var->string));
|
put_it("%s", convert_output_format(fget_string_var(var->string?FORMAT_SET_FSET:FORMAT_SET_NOVALUE_FSET), "%s %s", var->name, var->string));
|
||||||
#ifdef WANT_DLL
|
break;
|
||||||
goto got_dll;
|
|
||||||
#else
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -968,20 +946,45 @@ void set_var_value(int var_index, char *value, IrcVariableDll *dll)
|
|||||||
var->string : "<EMPTY>");
|
var->string : "<EMPTY>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set_var_value()
|
||||||
|
*
|
||||||
|
* Given the variable index and the string representation of the
|
||||||
|
* value, this sets the value with full verbosity and error-checking.
|
||||||
|
* It displays the results of the set and executes the function
|
||||||
|
* defined in the var structure.
|
||||||
|
*/
|
||||||
|
void set_var_value(int var_index, char *value, IrcVariableDll *dll)
|
||||||
|
{
|
||||||
|
IrcVariable *var;
|
||||||
|
#ifdef WANT_DLL
|
||||||
|
if (dll)
|
||||||
|
{
|
||||||
|
var = (IrcVariable *) new_malloc(sizeof(IrcVariable));
|
||||||
|
var->type = dll->type;
|
||||||
|
var->string = dll->string;
|
||||||
|
var->integer = dll->integer;
|
||||||
|
var->int_flags = dll->int_flags;
|
||||||
|
var->flags = dll->flags;
|
||||||
|
var->name = dll->name;
|
||||||
|
var->func = dll->func;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
var = &irc_variable[var_index];
|
||||||
|
|
||||||
|
set_ircvariable(var, value);
|
||||||
|
|
||||||
#ifdef WANT_DLL
|
#ifdef WANT_DLL
|
||||||
got_dll:
|
|
||||||
if (dll)
|
if (dll)
|
||||||
{
|
{
|
||||||
dll->integer = var->integer;
|
dll->integer = var->integer;
|
||||||
if (var->string)
|
dll->string = var->string;
|
||||||
dll->string = m_strdup(var->string);
|
new_free(&var);
|
||||||
else
|
|
||||||
dll->string = NULL;
|
|
||||||
new_free(&var->string);
|
|
||||||
new_free((char **)&var);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern AliasStack1 *set_stack;
|
extern AliasStack1 *set_stack;
|
||||||
|
|||||||
Reference in New Issue
Block a user