aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2007-11-17 12:20:51 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2007-11-17 12:20:51 +0000
commitcd428e473fe4428041722fd373badef890edebd9 (patch)
tree9c5b70884431cf597d3a97955f8f14f972f2bc37
parent1bf1ae6f25ff56894d67999791802aa864eaa02b (diff)
Added (account) set -del.
-rw-r--r--doc/user-guide/commands.xml10
-rw-r--r--root_commands.c44
-rw-r--r--set.c9
-rw-r--r--set.h1
4 files changed, 48 insertions, 16 deletions
diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml
index b7af2027..05b9abea 100644
--- a/doc/user-guide/commands.xml
+++ b/doc/user-guide/commands.xml
@@ -133,6 +133,7 @@
<syntax>account set &lt;account id&gt;</syntax>
<syntax>account set &lt;account id&gt;/&lt;setting&gt;</syntax>
<syntax>account set &lt;account id&gt;/&lt;setting&gt; &lt;value&gt;</syntax>
+ <syntax>account set -del &lt;account id&gt;/&lt;setting&gt;</syntax>
<description>
<para>
@@ -140,7 +141,7 @@
</para>
<para>
- For more infomation about a setting, see <emphasis>help set &lt;setting&gt;</emphasis>.
+ For more infomation about a setting, see <emphasis>help set &lt;setting&gt;</emphasis>. For details about the syntax of this command, see <emphasis>help set</emphasis>.
</para>
<para>
@@ -245,12 +246,15 @@
<bitlbee-command name="set">
<short-description>Miscellaneous settings</short-description>
- <syntax>set [&lt;variable&gt; [&lt;value&gt;]]</syntax>
+ <syntax>set</syntax>
+ <syntax>set &lt;variable&gt;</syntax>
+ <syntax>set &lt;variable&gt; &lt;value&gt;</syntax>
+ <syntax>set -del &lt;variable&gt;</syntax>
<description>
<para>
- Without any arguments, this command lists all the set variables. You can also specify a single argument, a variable name, to get that variable's value. To change this value, specify the new value as the second argument.
+ Without any arguments, this command lists all the set variables. You can also specify a single argument, a variable name, to get that variable's value. To change this value, specify the new value as the second argument. With <emphasis>-del</emphasis> you can reset a setting to its default value.
</para>
<para>
diff --git a/root_commands.c b/root_commands.c
index baaf3354..59852de6 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -367,15 +367,18 @@ static void cmd_account( irc_t *irc, char **cmd )
return;
}
- acc_handle = g_strdup( cmd[2] );
+ if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 )
+ acc_handle = g_strdup( cmd[3] );
+ else
+ acc_handle = g_strdup( cmd[2] );
+
if( ( tmp = strchr( acc_handle, '/' ) ) )
{
*tmp = 0;
set_name = tmp + 1;
}
- a = account_get( irc, acc_handle );
- if( a == NULL )
+ if( ( a = account_get( irc, acc_handle ) ) == NULL )
{
g_free( acc_handle );
irc_usermsg( irc, "Invalid account" );
@@ -399,10 +402,12 @@ static void cmd_account( irc_t *irc, char **cmd )
return;
}
- set_setstr( &a->set, set_name, cmd[3] );
-
if( ( strcmp( cmd[3], "=" ) ) == 0 && cmd[4] )
irc_usermsg( irc, "Warning: Correct syntax: \002account set <variable> <value>\002 (without =)" );
+ else if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 )
+ set_reset( &a->set, set_name );
+ else
+ set_setstr( &a->set, set_name, cmd[3] );
}
if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */
{
@@ -418,7 +423,7 @@ static void cmd_account( irc_t *irc, char **cmd )
while( s )
{
if( s->value || s->def )
- irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def );
+ irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def );
else
irc_usermsg( irc, "%s is empty", s->key );
s = s->next;
@@ -739,20 +744,33 @@ static void cmd_yesno( irc_t *irc, char **cmd )
static void cmd_set( irc_t *irc, char **cmd )
{
+ char *set_name;
+
if( cmd[1] && cmd[2] )
{
- set_setstr( &irc->set, cmd[1], cmd[2] );
-
if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] )
+ {
irc_usermsg( irc, "Warning: Correct syntax: \002set <variable> <value>\002 (without =)" );
+ return;
+ }
+ else if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 )
+ {
+ set_reset( &irc->set, cmd[2] );
+ set_name = cmd[2];
+ }
+ else
+ {
+ set_setstr( &irc->set, cmd[1], cmd[2] );
+ set_name = cmd[1];
+ }
}
if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */
{
- char *s = set_getstr( &irc->set, cmd[1] );
- if( s )
- irc_usermsg( irc, "%s = `%s'", cmd[1], s );
+ char *s = set_getstr( &irc->set, set_name );
+ if( s )
+ irc_usermsg( irc, "%s = `%s'", set_name, s );
else
- irc_usermsg( irc, "%s is empty", cmd[1] );
+ irc_usermsg( irc, "%s is empty", set_name );
}
else
{
@@ -760,7 +778,7 @@ static void cmd_set( irc_t *irc, char **cmd )
while( s )
{
if( s->value || s->def )
- irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def );
+ irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def );
else
irc_usermsg( irc, "%s is empty", s->key );
s = s->next;
diff --git a/set.c b/set.c
index 184c3243..6f09843b 100644
--- a/set.c
+++ b/set.c
@@ -167,6 +167,15 @@ void set_del( set_t **head, char *key )
}
}
+void set_reset( set_t **head, char *key )
+{
+ set_t *s;
+
+ s = set_find( head, key );
+ if( s )
+ set_setstr( head, key, s->def );
+}
+
char *set_eval_int( set_t *set, char *value )
{
char *s = value;
diff --git a/set.h b/set.h
index b6fffed9..7dcbb869 100644
--- a/set.h
+++ b/set.h
@@ -87,6 +87,7 @@ G_MODULE_EXPORT int set_getbool( set_t **head, char *key );
int set_setstr( set_t **head, char *key, char *value );
int set_setint( set_t **head, char *key, int value );
void set_del( set_t **head, char *key );
+void set_reset( set_t **head, char *key );
/* Two very useful generic evaluators. */
char *set_eval_int( set_t *set, char *value );