static ESExpResult * term_eval_and (struct _ESExp *f, gint argc, struct _ESExpTerm **argv, gpointer data) { struct _ESExpResult *r, *r1; GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal); struct IterData lambdafoo; gint type=-1; gint bool = TRUE; gint i; const gchar *oper; r (printf ("( and\n")); r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED); oper = "AND"; f->operators = g_slist_prepend (f->operators, (gpointer) oper); for (i = 0; bool && i < argc; i++) { r1 = e_sexp_term_eval (f, argv[i]); if (type == -1) type = r1->type; if (type != r1->type) { e_sexp_result_free (f, r); e_sexp_result_free (f, r1); g_hash_table_destroy (ht); e_sexp_fatal_error (f, "Invalid types in AND"); } else if (r1->type == ESEXP_RES_ARRAY_PTR) { gchar **a1; gint l1, j; a1 = (gchar **) r1->value.ptrarray->pdata; l1 = r1->value.ptrarray->len; for (j = 0; j < l1; j++) { gpointer ptr; gint n; ptr = g_hash_table_lookup (ht, a1[j]); n = GPOINTER_TO_INT (ptr); g_hash_table_insert (ht, a1[j], GINT_TO_POINTER (n + 1)); } } else if (r1->type == ESEXP_RES_BOOL) { bool = bool && r1->value.boolean; } e_sexp_result_free (f, r1); }
/** * e_cal_backend_sexp_match_comp: * @sexp: An #ESExp object. * @comp: Component to match against the expression. * @backend: Backend. * * Matches the given ECalComponent against the expression. * * Returns: TRUE if the component matched the expression, FALSE if not. */ gboolean e_cal_backend_sexp_match_comp (ECalBackendSExp *sexp, ECalComponent *comp, ECalBackend *backend) { ESExpResult *r; gboolean retval; g_return_val_if_fail (E_IS_CAL_BACKEND_SEXP (sexp), FALSE); g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE); g_return_val_if_fail (E_IS_CAL_BACKEND (backend), FALSE); sexp->priv->search_context->comp = g_object_ref (comp); sexp->priv->search_context->backend = g_object_ref (backend); /* if it's not a valid vcard why is it in our db? :) */ if (!sexp->priv->search_context->comp) { g_object_unref (sexp->priv->search_context->backend); return FALSE; } r = e_sexp_eval (sexp->priv->search_sexp); retval = (r && r->type == ESEXP_RES_BOOL && r->value.boolean); g_object_unref (sexp->priv->search_context->comp); g_object_unref (sexp->priv->search_context->backend); e_sexp_result_free (sexp->priv->search_sexp, r); return retval; }
static void e_ews_convert_sexp_to_restriction (ESoapMessage *msg, const gchar *query, EEwsFolderType type) { ESExp *sexp; ESExpResult *r; gint i; sexp = e_sexp_new (); if (type == E_EWS_FOLDER_TYPE_CONTACTS) { for (i = 0; i < G_N_ELEMENTS (contact_symbols); i++) { if (contact_symbols[i].immediate) e_sexp_add_ifunction ( sexp, 0, contact_symbols[i].name, (ESExpIFunc *) contact_symbols[i].func, msg); else e_sexp_add_function ( sexp, 0, contact_symbols[i].name, contact_symbols[i].func, msg); } } else if (type == E_EWS_FOLDER_TYPE_CALENDAR || type == E_EWS_FOLDER_TYPE_TASKS || type == E_EWS_FOLDER_TYPE_MEMOS) { for (i = 0; i < G_N_ELEMENTS (calendar_symbols); i++) { if (calendar_symbols[i].immediate) e_sexp_add_ifunction ( sexp, 0, calendar_symbols[i].name, (ESExpIFunc *) calendar_symbols[i].func, msg); else e_sexp_add_function ( sexp, 0, calendar_symbols[i].name, calendar_symbols[i].func, msg); } } else if (type == E_EWS_FOLDER_TYPE_MAILBOX) { for (i = 0; i < G_N_ELEMENTS (message_symbols); i++) { if (message_symbols[i].immediate) e_sexp_add_ifunction ( sexp, 0, message_symbols[i].name, (ESExpIFunc *) message_symbols[i].func, msg); else e_sexp_add_function ( sexp, 0, message_symbols[i].name, message_symbols[i].func, msg); } } e_sexp_input_text (sexp, query, strlen (query)); e_sexp_parse (sexp); r = e_sexp_eval (sexp); if (!r) return; e_sexp_result_free (sexp, r); e_sexp_unref (sexp); }
/* used in normal functions if they have to abort, and free their arguments */ void e_sexp_resultv_free (struct _ESExp *f, gint argc, struct _ESExpResult **argv) { gint i; for (i = 0; i < argc; i++) { e_sexp_result_free (f, argv[i]); } }
static ESExpResult * e_ews_func_and_or_not (ESExp *f, gint argc, ESExpTerm **argv, gpointer data, match_type type) { ESExpResult *r, *r1; ESoapMessage *msg; gint i; msg = (ESoapMessage *) data; /* "and" and "or" expects atleast two arguments */ if (argc == 0) goto result; if (type == MATCH_AND) { if (argc >= 2) e_soap_message_start_element (msg, "And", NULL, NULL); } else if (type == MATCH_OR) { if (argc >= 2) e_soap_message_start_element (msg, "Or", NULL, NULL); } else if (type == MATCH_NOT) e_soap_message_start_element (msg, "Not", NULL, NULL); for (i = 0; i < argc; i++) { r1 = e_sexp_term_eval (f, argv[i]); e_sexp_result_free (f, r1); } if (argc >= 2 || type == MATCH_NOT) e_soap_message_end_element (msg); result: r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED); return r; }
/** * e_book_backend_sexp_match_contact: * @sexp: an #EBookBackendSExp * @contact: an #EContact * * Checks if @contact matches @sexp. * * Returns: %TRUE if the contact matches, %FALSE otherwise. **/ gboolean e_book_backend_sexp_match_contact (EBookBackendSExp *sexp, EContact *contact) { ESExpResult *r; gboolean retval; if (!contact) { g_warning ("null EContact passed to e_book_backend_sexp_match_contact"); return FALSE; } sexp->priv->search_context->contact = g_object_ref (contact); r = e_sexp_eval (sexp->priv->search_sexp); retval = (r && r->type == ESEXP_RES_BOOL && r->value.boolean); g_object_unref (sexp->priv->search_context->contact); e_sexp_result_free (sexp->priv->search_sexp, r); return retval; }