Minor changes as per review

This commit is contained in:
Jari Matilainen 2017-01-13 20:47:27 +00:00
commit 11bc71a2ea
3 changed files with 18 additions and 13 deletions

View file

@ -168,7 +168,7 @@ int strarray_find(char **array, const char *item)
return -1; return -1;
} }
gboolean strarray_find_prefix(char **array, const char *item) int strarray_find_prefix(char **array, const char *item)
{ {
char **tmp; char **tmp;
int index; int index;
@ -176,14 +176,14 @@ gboolean strarray_find_prefix(char **array, const char *item)
g_return_val_if_fail(array != NULL, -1); g_return_val_if_fail(array != NULL, -1);
g_return_val_if_fail(item != NULL, -1); g_return_val_if_fail(item != NULL, -1);
item = g_ascii_strdown(item, -1);
index = 0; index = 0;
for (tmp = array; *tmp != NULL; tmp++, index++) { for (tmp = array; *tmp != NULL; tmp++, index++) {
if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item)) //if (g_str_has_prefix(g_ascii_strdown(*tmp, -1), item))
return TRUE; if (g_ascii_strncasecmp(*tmp, item, length(item)) == 0)
return index;
} }
return FALSE; return -1;
} }
GSList *gslist_find_string(GSList *list, const char *key) GSList *gslist_find_string(GSList *list, const char *key)

View file

@ -101,7 +101,7 @@ char *replace_chars(char *str, char from, char to);
int strarray_find(char **array, const char *item); int strarray_find(char **array, const char *item);
/* return index of element in `array' starting with `item' or -1 if not found */ /* return index of element in `array' starting with `item' or -1 if not found */
gboolean strarray_find_prefix(char **array, const char *item); int strarray_find_prefix(char **array, const char *item);
/* string -> uoff_t */ /* string -> uoff_t */
uoff_t str_to_uofft(const char *str); uoff_t str_to_uofft(const char *str);

View file

@ -462,12 +462,18 @@ void fe_common_core_finish_init(void)
gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest) gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest)
{ {
const WindowType type = window_item_get_type(dest->window->active);
GSList *targets = NULL, *iterator = NULL;
gboolean found = FALSE;
g_return_val_if_fail(array != NULL, FALSE); g_return_val_if_fail(array != NULL, FALSE);
WindowType type = window_item_get_type(dest->window->active);
// we ignore all targets // we ignore all targets
if (strarray_find(array, "*") != -1) if (strarray_find(array, "*") != -1)
return TRUE; return TRUE;
// exit if not a channel or query
else if (type & WI_TYPE_OTHER)
return FALSE;
// we ignore all channels // we ignore all channels
else if (type & WI_TYPE_CHANNEL && strarray_find(array, "#") != -1) else if (type & WI_TYPE_CHANNEL && strarray_find(array, "#") != -1)
return TRUE; return TRUE;
@ -478,17 +484,16 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest)
else if (type & WI_TYPE_PRIVMSG && strarray_find(array, "@") != -1) else if (type & WI_TYPE_PRIVMSG && strarray_find(array, "@") != -1)
return TRUE; return TRUE;
if (dest->server_tag == NULL) g_return_val_if_fail(dest->server_tag != NULL, FALSE);
return FALSE;
char *prefix = g_strdup_printf("%s/", dest->server_tag); char *prefix = g_strdup_printf("%s/", dest->server_tag);
if (!strarray_find_prefix(array, prefix)) { if (strarray_find_prefix(array, prefix) == -1) {
g_free(prefix); g_free(prefix);
return FALSE; return FALSE;
} }
GSList *targets = NULL, *iterator = NULL; g_free(prefix);
gboolean found = FALSE;
// create a list of types to look for // create a list of types to look for
targets = g_slist_append(targets, g_strdup("*")); targets = g_slist_append(targets, g_strdup("*"));
if (type & WI_TYPE_CHANNEL) { if (type & WI_TYPE_CHANNEL) {
@ -514,6 +519,6 @@ gboolean strarray_find_dest(char **array, const TEXT_DEST_REC *dest)
g_slist_foreach(targets, (GFunc)g_free, NULL); g_slist_foreach(targets, (GFunc)g_free, NULL);
g_slist_free(targets); g_slist_free(targets);
g_free(prefix);
return found; return found;
} }