Reformat the /SET code

This commit is contained in:
Berke Viktor 2012-10-15 16:00:07 +02:00
parent 32eeec02ff
commit 13449c282a
1 changed files with 33 additions and 3 deletions

View File

@ -1072,17 +1072,25 @@ cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[])
} }
if ((strchr (var, '*') || strchr (var, '?')) && !*val) if ((strchr (var, '*') || strchr (var, '?')) && !*val)
{
wild = TRUE; wild = TRUE;
}
if (*val == '=') if (*val == '=')
{
val++; val++;
}
do do
{ {
if (wild) if (wild)
{
found = !match (var, vars[i].name); found = !match (var, vars[i].name);
}
else else
{
found = g_ascii_strcasecmp (var, vars[i].name); found = g_ascii_strcasecmp (var, vars[i].name);
}
if (found == 0) if (found == 0)
{ {
@ -1094,9 +1102,13 @@ cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{ {
strncpy ((char *) &prefs + vars[i].offset, val, vars[i].len); strncpy ((char *) &prefs + vars[i].offset, val, vars[i].len);
((char *) &prefs)[vars[i].offset + vars[i].len - 1] = 0; ((char *) &prefs)[vars[i].offset + vars[i].len - 1] = 0;
if (!quiet) if (!quiet)
{
PrintTextf (sess, "%s set to: %s\n", var, (char *) &prefs + vars[i].offset); PrintTextf (sess, "%s set to: %s\n", var, (char *) &prefs + vars[i].offset);
} else }
}
else
{ {
set_showval (sess, &vars[i], tbuf); set_showval (sess, &vars[i], tbuf);
} }
@ -1108,26 +1120,44 @@ cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (vars[i].type == TYPE_BOOL) if (vars[i].type == TYPE_BOOL)
{ {
if (atoi (val)) if (atoi (val))
{
*((int *) &prefs + vars[i].offset) = 1; *((int *) &prefs + vars[i].offset) = 1;
}
else else
{
*((int *) &prefs + vars[i].offset) = 0; *((int *) &prefs + vars[i].offset) = 0;
}
if (!g_ascii_strcasecmp (val, "YES") || !g_ascii_strcasecmp (val, "ON")) if (!g_ascii_strcasecmp (val, "YES") || !g_ascii_strcasecmp (val, "ON"))
{
*((int *) &prefs + vars[i].offset) = 1; *((int *) &prefs + vars[i].offset) = 1;
}
if (!g_ascii_strcasecmp (val, "NO") || !g_ascii_strcasecmp (val, "OFF")) if (!g_ascii_strcasecmp (val, "NO") || !g_ascii_strcasecmp (val, "OFF"))
{
*((int *) &prefs + vars[i].offset) = 0; *((int *) &prefs + vars[i].offset) = 0;
} else }
}
else
{ {
if (or) if (or)
{
*((int *) &prefs + vars[i].offset) |= atoi (val); *((int *) &prefs + vars[i].offset) |= atoi (val);
}
else if (off) else if (off)
{
*((int *) &prefs + vars[i].offset) &= ~(atoi (val)); *((int *) &prefs + vars[i].offset) &= ~(atoi (val));
}
else else
{
*((int *) &prefs + vars[i].offset) = atoi (val); *((int *) &prefs + vars[i].offset) = atoi (val);
} }
}
if (!quiet) if (!quiet)
{
PrintTextf (sess, "%s set to: %d\n", var, PrintTextf (sess, "%s set to: %d\n", var,
*((int *) &prefs + vars[i].offset)); *((int *) &prefs + vars[i].offset));
} else }
}
else
{ {
set_showval (sess, &vars[i], tbuf); set_showval (sess, &vars[i], tbuf);
} }