/* allow Mutt-like patterns in quick search */
gchar *expand_search_string(const gchar *search_string)
{
- int i, len, new_len = 0;
+ int i = 0;
gchar term_char, save_char;
gchar *cmd_start, *cmd_end;
- gchar *new_str = NULL;
+ GString *matcherstr;
+ gchar *returnstr = NULL;
gchar *copy_str;
gboolean casesens, dontmatch;
/* list of allowed pattern abbreviations */
if (cmds[i].command)
return copy_str;
+ matcherstr = g_string_sized_new(16);
cmd_start = cmd_end = copy_str;
while (cmd_end && *cmd_end) {
/* skip all white spaces */
if (!strcmp(cmd_start, cmds[i].abbreviated)) {
/* restore character */
*cmd_end = save_char;
- len = strlen(cmds[i].command) + 1;
- if (dontmatch)
- len++;
- if (casesens)
- len++;
/* copy command */
- if (new_str) {
- new_len += 1;
- new_str = g_realloc(new_str, new_len);
- strcat(new_str, " ");
+ if (matcherstr->len > 0) {
+ g_string_append(matcherstr, " ");
}
- new_len += (len + 1);
- new_str = g_realloc(new_str, new_len);
- if (new_len == len + 1)
- *new_str = '\0';
if (dontmatch)
- strcat(new_str, "~");
- strcat(new_str, cmds[i].command);
- strcat(new_str, " ");
+ g_string_append(matcherstr, "~");
+ g_string_append(matcherstr, cmds[i].command);
+ g_string_append(matcherstr, " ");
/* stop if no params required */
if (cmds[i].numparams == 0)
save_char = *cmd_end;
*cmd_end = '\0';
- new_len += strlen(cmd_start);
-
- /* do we need to add regexpcase ? */
- if (cmds[i].qualifier)
- new_len += 10; /* "regexpcase " */
-
- if (term_char != '"')
- new_len += 2;
- new_str = g_realloc(new_str, new_len);
-
if (cmds[i].qualifier) {
if (casesens)
- strcat(new_str, "regexp ");
+ g_string_append(matcherstr, "regexp ");
else
- strcat(new_str, "regexpcase ");
+ g_string_append(matcherstr, "regexpcase ");
}
/* do we need to add quotes ? */
if (cmds[i].quotes && term_char != '"')
- strcat(new_str, "\"");
+ g_string_append(matcherstr, "\"");
/* copy actual parameter */
- strcat(new_str, cmd_start);
+ g_string_append(matcherstr, cmd_start);
/* do we need to add quotes ? */
if (cmds[i].quotes && term_char != '"')
- strcat(new_str, "\"");
+ g_string_append(matcherstr, "\"");
/* restore original character */
*cmd_end = save_char;
}
g_free(copy_str);
- return new_str;
+ returnstr = matcherstr->str;
+ g_string_free(matcherstr, FALSE);
+ return returnstr;
}
MatcherList * tmp_list = NULL;
if (search_type == S_SEARCH_EXTENDED) {
- char *newstr;
+ char *newstr = NULL;
newstr = expand_search_string(search_string);
if (newstr) {
else
procmsg_msginfo_free(msginfo);
} else {
- if (tmp_list != NULL && matcherlist_match(tmp_list, msginfo))
+ if ((tmp_list != NULL) && matcherlist_match(tmp_list, msginfo))
not_killed = g_slist_append(not_killed, msginfo);
else
procmsg_msginfo_free(msginfo);
}
}
-
if (search_type == S_SEARCH_EXTENDED && tmp_list != NULL) {
matcherlist_free(tmp_list);
tmp_list = NULL;