示例#1
0
static query_result *
add_result (const char *query_string,
            const char *name,
            const char *misc_value,
            const char *email,
            query_result * results,
            int *rc)
  {
    query_result *r = results;
    if (name != NULL && email != NULL)
      {
        /* perform the query using name, email, and misc fields */
        if (strstr_nocase (name, query_string)
            || strstr_nocase (email, query_string)
            || strstr_nocase (misc_value, query_string))
          {
            r->next = create_query_result ();
            r = r->next;
            r->name = strdup (name);
            r->email = strdup (email);
            r->misc = strdup (misc_value);
            (*rc)++; /* increment results counter */
          }
      }
    return r;
  }
示例#2
0
/* Replaces $ORIG[variable] in given template by given replacement from the original message */
static void
replace_template_variable (GString *text,
                           const gchar *variable,
                           const gchar *replacement)
{
	const gchar *p, *next;
	GString *str;
	gint find_len;
	gchar *find;

	g_return_if_fail (text != NULL);
	g_return_if_fail (variable != NULL);
	g_return_if_fail (*variable);

	find = g_strconcat ("$ORIG[", variable, "]", NULL);

	find_len = strlen (find);
	str = g_string_new ("");
	p = text->str;
	while (next = strstr_nocase (p, find), next) {
		if (p < next)
			g_string_append_len (str, p, next - p);
		if (replacement && *replacement)
			g_string_append (str, replacement);
		p = next + find_len;
	}
	g_string_append (str, p);

	g_string_assign (text, str->str);

	g_string_free (str, TRUE);
	g_free (find);
}
示例#3
0
static ITEM *
search_menu_backwards (MENU * menu)
{
  char *search_string = NULL;
  ITEM *result_item = NULL;

  /* the search string is stored in the menu user pointer */
  search_string = (char *) menu_userptr (menu);

  if (NULL != search_string)
    {
      int i = -1;
      int current_index = -1;
      ITEM **items = NULL;
      int found = 0;
      bool done = FALSE;

      current_index = item_index (current_item (menu));
      items = menu_items (menu);

      /* start search from the item immediately before the current item */
      for (i = current_index - 1; i >= 0 && !found; i--)
        {
          found = strstr_nocase (item_description (items[i]), search_string);
        }

      if (!found)
        {
          int count = -1;
          count = item_count (menu);
          /* start search from the end (i.e. wrap around) */
          for (i = count - 1; i >= current_index && !found; i--)
            {
              found =
                  strstr_nocase (item_description (items[i]), search_string);
            }
        }

      if (found)
        {
          result_item = items[i + 1];
        }
    }

  return result_item;
}
示例#4
0
static bool_t cover_name_filter (const char * name, Index * keywords, bool_t ret_on_empty)
{
    int count = index_count (keywords);
    if (! count)
        return ret_on_empty;

    for (int i = 0; i < count; i ++)
    {
        if (strstr_nocase (name, index_get (keywords, i)))
            return TRUE;
    }

    return FALSE;
}