mirror of
https://github.com/irssi/irssi.git
synced 2025-02-02 15:08:01 -05:00
Some fixes to handling +l and +k mode.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@631 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
2e886d62f5
commit
3d124da13b
@ -58,7 +58,7 @@ static int mode_is_set(const char *str, char mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add argument to specified position */
|
/* add argument to specified position */
|
||||||
static void mode_add_arg(GString *str, int pos, const char *arg)
|
static void mode_add_arg(GString *str, int pos, int updating, const char *arg)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@ -71,12 +71,19 @@ static void mode_add_arg(GString *str, int pos, const char *arg)
|
|||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pos = (int) (p-str->str);
|
||||||
|
if (updating && *p != '\0') {
|
||||||
|
/* remove the old argument */
|
||||||
|
p++;
|
||||||
|
while (*p != '\0' && *p != ' ') p++;
|
||||||
|
g_string_erase(str, pos, (int) (p-str->str)-pos);
|
||||||
|
}
|
||||||
|
|
||||||
/* .. GLib shouldn't fail when inserting at the end of the string */
|
/* .. GLib shouldn't fail when inserting at the end of the string */
|
||||||
if (*p == '\0') {
|
if (pos == str->len) {
|
||||||
g_string_append_c(str, ' ');
|
g_string_append_c(str, ' ');
|
||||||
g_string_append(str, arg);
|
g_string_append(str, arg);
|
||||||
} else {
|
} else {
|
||||||
pos = (int) (p-str->str);
|
|
||||||
g_string_insert_c(str, pos, ' ');
|
g_string_insert_c(str, pos, ' ');
|
||||||
g_string_insert(str, pos+1, arg);
|
g_string_insert(str, pos+1, arg);
|
||||||
}
|
}
|
||||||
@ -86,26 +93,33 @@ static void mode_add_arg(GString *str, int pos, const char *arg)
|
|||||||
static void mode_add_sorted(GString *str, char mode, const char *arg)
|
static void mode_add_sorted(GString *str, char mode, const char *arg)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
int argpos = 0;
|
int updating, argpos = 0;
|
||||||
|
|
||||||
/* check that mode isn't already set */
|
/* check that mode isn't already set */
|
||||||
if (mode_is_set(str->str, mode))
|
if (!HAS_MODE_ARG_SET(mode) && mode_is_set(str->str, mode))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
updating = FALSE;
|
||||||
for (p = str->str; *p != '\0' && *p != ' '; p++) {
|
for (p = str->str; *p != '\0' && *p != ' '; p++) {
|
||||||
if (mode < *p)
|
if (mode < *p)
|
||||||
break;
|
break;
|
||||||
|
if (mode == *p) {
|
||||||
|
updating = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (HAS_MODE_ARG_SET(*p))
|
if (HAS_MODE_ARG_SET(*p))
|
||||||
argpos++;
|
argpos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* .. GLib shouldn't fail when inserting at the end of the string */
|
/* .. GLib shouldn't fail when inserting at the end of the string */
|
||||||
if (*p == '\0')
|
if (!updating) {
|
||||||
g_string_append_c(str, mode);
|
if (*p == '\0')
|
||||||
else
|
g_string_append_c(str, mode);
|
||||||
g_string_insert_c(str, (int) (p-str->str), mode);
|
else
|
||||||
|
g_string_insert_c(str, (int) (p-str->str), mode);
|
||||||
|
}
|
||||||
if (arg != NULL)
|
if (arg != NULL)
|
||||||
mode_add_arg(str, argpos+1, arg);
|
mode_add_arg(str, argpos, updating, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove the n'th argument */
|
/* remove the n'th argument */
|
||||||
|
Loading…
Reference in New Issue
Block a user