[evolution-data-server] Always build ESExp structure as a GObject descendant
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Always build ESExp structure as a GObject descendant
- Date: Wed, 22 Jun 2016 15:38:38 +0000 (UTC)
commit 074005228ef9c62dae663113611d7740bc88a0b9
Author: Milan Crha <mcrha redhat com>
Date: Wed Jun 22 17:36:57 2016 +0200
Always build ESExp structure as a GObject descendant
Plus some cleanups on top of these ESExp sources.
addressbook/backends/ldap/e-book-backend-ldap.c | 2 +-
addressbook/libebook-contacts/e-book-query.c | 4 +-
addressbook/libedata-book/e-book-backend-sexp.c | 4 +-
.../libedata-book/e-book-backend-sqlitedb.c | 8 +-
addressbook/libedata-book/e-book-backend-summary.c | 6 +-
addressbook/libedata-book/e-book-sqlite.c | 2 +-
calendar/libedata-cal/e-cal-backend-sexp.c | 4 +-
configure.ac | 2 +-
libedataserver/e-sexp.c | 673 ++++++++++----------
libedataserver/e-sexp.h | 127 ++--
10 files changed, 413 insertions(+), 419 deletions(-)
---
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index 9bce28f..93d5f8a 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -3827,7 +3827,7 @@ e_book_backend_ldap_build_query (EBookBackendLDAP *bl,
r = e_sexp_eval (sexp);
e_sexp_result_free (sexp, r);
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
if (data.list) {
if (data.list->next) {
diff --git a/addressbook/libebook-contacts/e-book-query.c b/addressbook/libebook-contacts/e-book-query.c
index 54bafc3..3604bae 100644
--- a/addressbook/libebook-contacts/e-book-query.c
+++ b/addressbook/libebook-contacts/e-book-query.c
@@ -776,14 +776,14 @@ e_book_query_from_string (const gchar *query_string)
e_sexp_input_text (sexp, query_string, strlen (query_string));
if (e_sexp_parse (sexp) == -1) {
- g_warning ("%s: Error in parsing: %s", G_STRFUNC, sexp->error);
+ g_warning ("%s: Error in parsing: %s", G_STRFUNC, e_sexp_get_error (sexp));
return NULL;
}
r = e_sexp_eval (sexp);
e_sexp_result_free (sexp, r);
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
if (list && list->next == NULL) {
retval = list->data;
diff --git a/addressbook/libedata-book/e-book-backend-sexp.c b/addressbook/libedata-book/e-book-backend-sexp.c
index 6d90dbc..0f3ab69 100644
--- a/addressbook/libedata-book/e-book-backend-sexp.c
+++ b/addressbook/libedata-book/e-book-backend-sexp.c
@@ -1086,7 +1086,7 @@ book_backend_sexp_finalize (GObject *object)
priv = E_BOOK_BACKEND_SEXP_GET_PRIVATE (object);
- e_sexp_unref (priv->search_sexp);
+ g_object_unref (priv->search_sexp);
g_free (priv->text);
g_free (priv->search_context);
@@ -1173,7 +1173,7 @@ e_book_backend_sexp_new (const gchar *text)
if (e_sexp_parse (sexp->priv->search_sexp) == -1) {
g_warning (
"%s: Error in parsing: %s",
- G_STRFUNC, sexp->priv->search_sexp->error);
+ G_STRFUNC, e_sexp_get_error (sexp->priv->search_sexp));
g_object_unref (sexp);
sexp = NULL;
}
diff --git a/addressbook/libedata-book/e-book-backend-sqlitedb.c
b/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 10334f6..2f51d2d 100644
--- a/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -3337,7 +3337,7 @@ e_book_backend_sqlitedb_check_summary_query_locked (EBookBackendSqliteDB *ebsdb,
}
e_sexp_result_free (sexp, r);
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
return retval;
}
@@ -4012,13 +4012,13 @@ sexp_to_sql_query (EBookBackendSqliteDB *ebsdb,
e_sexp_input_text (sexp, query, strlen (query));
if (e_sexp_parse (sexp) == -1) {
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
return NULL;
}
r = e_sexp_eval (sexp);
if (!r) {
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
return NULL;
}
@@ -4033,7 +4033,7 @@ sexp_to_sql_query (EBookBackendSqliteDB *ebsdb,
}
e_sexp_result_free (sexp, r);
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
return res;
}
diff --git a/addressbook/libedata-book/e-book-backend-summary.c
b/addressbook/libedata-book/e-book-backend-summary.c
index 063f7ad..2275548 100644
--- a/addressbook/libedata-book/e-book-backend-summary.c
+++ b/addressbook/libedata-book/e-book-backend-summary.c
@@ -1025,7 +1025,7 @@ e_book_backend_summary_is_summary_query (EBookBackendSummary *summary,
esexp_error = e_sexp_parse (sexp);
if (esexp_error == -1) {
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
return FALSE;
}
@@ -1035,7 +1035,7 @@ e_book_backend_summary_is_summary_query (EBookBackendSummary *summary,
e_sexp_result_free (sexp, r);
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
return retval;
}
@@ -1289,7 +1289,7 @@ e_book_backend_summary_search (EBookBackendSummary *summary,
e_sexp_result_free (sexp, r);
- e_sexp_unref (sexp);
+ g_object_unref (sexp);
return retval;
}
diff --git a/addressbook/libedata-book/e-book-sqlite.c b/addressbook/libedata-book/e-book-sqlite.c
index f3f85ad..2eeded2 100644
--- a/addressbook/libedata-book/e-book-sqlite.c
+++ b/addressbook/libedata-book/e-book-sqlite.c
@@ -4561,7 +4561,7 @@ query_preflight_initialize (PreflightContext *context,
e_sexp_result_free (sexp_parser, result);
}
- e_sexp_unref (sexp_parser);
+ g_object_unref (sexp_parser);
EBSQL_NOTE (
PREFLIGHT,
diff --git a/calendar/libedata-cal/e-cal-backend-sexp.c b/calendar/libedata-cal/e-cal-backend-sexp.c
index 0a7588c..af59070 100644
--- a/calendar/libedata-cal/e-cal-backend-sexp.c
+++ b/calendar/libedata-cal/e-cal-backend-sexp.c
@@ -1102,7 +1102,7 @@ cal_backend_sexp_finalize (GObject *object)
priv = E_CAL_BACKEND_SEXP_GET_PRIVATE (object);
- e_sexp_unref (priv->search_sexp);
+ g_object_unref (priv->search_sexp);
g_free (priv->text);
g_free (priv->search_context);
g_mutex_clear (&priv->search_context_lock);
@@ -1203,7 +1203,7 @@ e_cal_backend_sexp_new (const gchar *text)
if (e_sexp_parse (sexp->priv->search_sexp) == -1) {
g_warning (
"%s: Error in parsing: %s",
- G_STRFUNC, sexp->priv->search_sexp->error);
+ G_STRFUNC, e_sexp_get_error (sexp->priv->search_sexp));
g_object_unref (sexp);
sexp = NULL;
}
diff --git a/configure.ac b/configure.ac
index b42a4b5..c76b172 100644
--- a/configure.ac
+++ b/configure.ac
@@ -108,7 +108,7 @@ AC_SUBST(USER_PROMPTER_DBUS_SERVICE_NAME)
dnl ******************************
dnl Libtool versioning
dnl ******************************
-LIBEDATASERVER_CURRENT=21
+LIBEDATASERVER_CURRENT=22
LIBEDATASERVER_REVISION=0
LIBEDATASERVER_AGE=0
diff --git a/libedataserver/e-sexp.c b/libedataserver/e-sexp.c
index 313c74b..f5b922b 100644
--- a/libedataserver/e-sexp.c
+++ b/libedataserver/e-sexp.c
@@ -94,27 +94,38 @@
#define r(x) /* run debug */
#define d(x) /* general debug */
-#ifdef E_SEXP_IS_G_OBJECT
+struct _ESExpPrivate {
+ GScanner *scanner; /* for parsing text version */
+ ESExpTerm *tree; /* root of expression tree */
+
+ /* private stuff */
+ jmp_buf failenv;
+ gchar *error;
+ GSList *operators;
+
+ /* TODO: may also need a pool allocator for term strings, so we dont lose them
+ * in error conditions? */
+ struct _EMemChunk *term_chunks;
+ struct _EMemChunk *result_chunks;
+};
+
G_DEFINE_TYPE (ESExp, e_sexp, G_TYPE_OBJECT)
-#endif
-static struct _ESExpTerm *
- parse_list (ESExp *f,
+static ESExpTerm * parse_list (ESExp *sexp,
gint gotbrace);
-static struct _ESExpTerm *
- parse_value (ESExp *f);
+static ESExpTerm * parse_value (ESExp *sexp);
#ifdef TESTER
-static void parse_dump_term (struct _ESExpTerm *t,
+static void parse_dump_term (ESExpTerm *t,
gint depth);
#endif
typedef gboolean (ESGeneratorFunc) (gint argc,
- struct _ESExpResult **argv,
- struct _ESExpResult *r);
+ ESExpResult **argv,
+ ESExpResult *r);
typedef gboolean (ESOperatorFunc) (gint argc,
- struct _ESExpResult **argv,
- struct _ESExpResult *r);
+ ESExpResult **argv,
+ ESExpResult *r);
/* FIXME: constant _TIME_MAX used in different files, move it somewhere */
#define _TIME_MAX ((time_t) INT_MAX) /* Max valid time_t */
@@ -156,35 +167,44 @@ static const GScannerConfig scanner_config =
FALSE /* scope_0_fallback */,
};
-/* jumps back to the caller of f->failenv, only to be called from inside a callback */
+/* jumps back to the caller of sexp->priv->failenv, only to be called from inside a callback */
void
-e_sexp_fatal_error (struct _ESExp *f,
+e_sexp_fatal_error (ESExp *sexp,
const gchar *why,
...)
{
va_list args;
- if (f->error)
- g_free (f->error);
+ g_warn_if_fail (E_IS_SEXP (sexp));
+ g_warn_if_fail (why != NULL);
+
+ if (sexp->priv->error)
+ g_free (sexp->priv->error);
va_start (args, why);
- f->error = g_strdup_vprintf (why, args);
+ sexp->priv->error = g_strdup_vprintf (why, args);
va_end (args);
- longjmp (f->failenv, 1);
+ longjmp (sexp->priv->failenv, 1);
}
const gchar *
-e_sexp_error (struct _ESExp *f)
+e_sexp_get_error (ESExp *sexp)
{
- return f->error;
+ g_return_val_if_fail (E_IS_SEXP (sexp), NULL);
+
+ return sexp->priv->error;
}
-struct _ESExpResult *
-e_sexp_result_new (struct _ESExp *f,
+ESExpResult *
+e_sexp_result_new (ESExp *sexp,
gint type)
{
- struct _ESExpResult *r = e_memchunk_alloc0 (f->result_chunks);
+ ESExpResult *r;
+
+ g_return_val_if_fail (E_IS_SEXP (sexp), NULL);
+
+ r = e_memchunk_alloc0 (sexp->priv->result_chunks);
r->type = type;
r->occuring_start = 0;
r->occuring_end = _TIME_MAX;
@@ -193,9 +213,11 @@ e_sexp_result_new (struct _ESExp *f,
}
void
-e_sexp_result_free (struct _ESExp *f,
- struct _ESExpResult *t)
+e_sexp_result_free (ESExp *sexp,
+ ESExpResult *t)
{
+ g_return_if_fail (E_IS_SEXP (sexp));
+
if (t == NULL)
return;
@@ -216,19 +238,21 @@ e_sexp_result_free (struct _ESExp *f,
default:
g_return_if_reached ();
}
- e_memchunk_free (f->result_chunks, t);
+ e_memchunk_free (sexp->priv->result_chunks, t);
}
/* used in normal functions if they have to abort, and free their arguments */
void
-e_sexp_resultv_free (struct _ESExp *f,
+e_sexp_resultv_free (ESExp *sexp,
gint argc,
- struct _ESExpResult **argv)
+ ESExpResult **argv)
{
gint i;
+ g_return_if_fail (E_IS_SEXP (sexp));
+
for (i = 0; i < argc; i++) {
- e_sexp_result_free (f, argv[i]);
+ e_sexp_result_free (sexp, argv[i]);
}
}
@@ -261,12 +285,12 @@ htor (gchar *key,
}
static ESExpResult *
-term_eval_and (struct _ESExp *f,
+term_eval_and (ESExp *sexp,
gint argc,
- struct _ESExpTerm **argv,
+ ESExpTerm **argv,
gpointer data)
{
- struct _ESExpResult *r, *r1;
+ ESExpResult *r, *r1;
GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal);
struct IterData lambdafoo;
gint type=-1;
@@ -276,20 +300,20 @@ term_eval_and (struct _ESExp *f,
r (printf ("( and\n"));
- r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ r = e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
oper = "AND";
- f->operators = g_slist_prepend (f->operators, (gpointer) oper);
+ sexp->priv->operators = g_slist_prepend (sexp->priv->operators, (gpointer) oper);
for (i = 0; bool && i < argc; i++) {
- r1 = e_sexp_term_eval (f, argv[i]);
+ r1 = e_sexp_term_eval (sexp, argv[i]);
if (type == -1)
type = r1->type;
if (type != r1->type) {
- e_sexp_result_free (f, r);
- e_sexp_result_free (f, r1);
+ e_sexp_result_free (sexp, r);
+ e_sexp_result_free (sexp, r1);
g_hash_table_destroy (ht);
- e_sexp_fatal_error (f, "Invalid types in AND");
+ e_sexp_fatal_error (sexp, "Invalid types in AND");
} else if (r1->type == ESEXP_RES_ARRAY_PTR) {
gchar **a1;
gint l1, j;
@@ -306,7 +330,7 @@ term_eval_and (struct _ESExp *f,
} else if (r1->type == ESEXP_RES_BOOL) {
bool = bool && r1->value.boolean;
}
- e_sexp_result_free (f, r1);
+ e_sexp_result_free (sexp, r1);
}
if (type == ESEXP_RES_ARRAY_PTR) {
@@ -321,18 +345,18 @@ term_eval_and (struct _ESExp *f,
}
g_hash_table_destroy (ht);
- f->operators = g_slist_remove (f->operators, oper);
+ sexp->priv->operators = g_slist_remove (sexp->priv->operators, oper);
return r;
}
static ESExpResult *
-term_eval_or (struct _ESExp *f,
+term_eval_or (ESExp *sexp,
gint argc,
- struct _ESExpTerm **argv,
+ ESExpTerm **argv,
gpointer data)
{
- struct _ESExpResult *r, *r1;
+ ESExpResult *r, *r1;
GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal);
struct IterData lambdafoo;
gint type = -1;
@@ -343,19 +367,19 @@ term_eval_or (struct _ESExp *f,
r (printf ("(or \n"));
oper = "OR";
- f->operators = g_slist_prepend (f->operators, (gpointer) oper);
+ sexp->priv->operators = g_slist_prepend (sexp->priv->operators, (gpointer) oper);
- r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ r = e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
for (i = 0; !bool && i < argc; i++) {
- r1 = e_sexp_term_eval (f, argv[i]);
+ r1 = e_sexp_term_eval (sexp, argv[i]);
if (type == -1)
type = r1->type;
if (r1->type != type) {
- e_sexp_result_free (f, r);
- e_sexp_result_free (f, r1);
+ e_sexp_result_free (sexp, r);
+ e_sexp_result_free (sexp, r1);
g_hash_table_destroy (ht);
- e_sexp_fatal_error (f, "Invalid types in OR");
+ e_sexp_fatal_error (sexp, "Invalid types in OR");
} else if (r1->type == ESEXP_RES_ARRAY_PTR) {
gchar **a1;
gint l1, j;
@@ -368,7 +392,7 @@ term_eval_or (struct _ESExp *f,
} else if (r1->type == ESEXP_RES_BOOL) {
bool |= r1->value.boolean;
}
- e_sexp_result_free (f, r1);
+ e_sexp_result_free (sexp, r1);
}
if (type == ESEXP_RES_ARRAY_PTR) {
@@ -383,14 +407,14 @@ term_eval_or (struct _ESExp *f,
}
g_hash_table_destroy (ht);
- f->operators = g_slist_remove (f->operators, oper);
+ sexp->priv->operators = g_slist_remove (sexp->priv->operators, oper);
return r;
}
static ESExpResult *
-term_eval_not (struct _ESExp *f,
+term_eval_not (ESExp *sexp,
gint argc,
- struct _ESExpResult **argv,
+ ESExpResult **argv,
gpointer data)
{
gint res = TRUE;
@@ -401,30 +425,30 @@ term_eval_not (struct _ESExp *f,
&& argv[0]->value.boolean)
res = FALSE;
}
- r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+ r = e_sexp_result_new (sexp, ESEXP_RES_BOOL);
r->value.boolean = res;
return r;
}
/* this should support all arguments ...? */
static ESExpResult *
-term_eval_lt (struct _ESExp *f,
+term_eval_lt (ESExp *sexp,
gint argc,
- struct _ESExpTerm **argv,
+ ESExpTerm **argv,
gpointer data)
{
- struct _ESExpResult *r, *r1, *r2;
+ ESExpResult *r, *r1, *r2;
- r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ r = e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
if (argc == 2) {
- r1 = e_sexp_term_eval (f, argv[0]);
- r2 = e_sexp_term_eval (f, argv[1]);
+ r1 = e_sexp_term_eval (sexp, argv[0]);
+ r2 = e_sexp_term_eval (sexp, argv[1]);
if (r1->type != r2->type) {
- e_sexp_result_free (f, r1);
- e_sexp_result_free (f, r2);
- e_sexp_result_free (f, r);
- e_sexp_fatal_error (f, "Incompatible types in compare <");
+ e_sexp_result_free (sexp, r1);
+ e_sexp_result_free (sexp, r2);
+ e_sexp_result_free (sexp, r);
+ e_sexp_fatal_error (sexp, "Incompatible types in compare <");
} else if (r1->type == ESEXP_RES_INT) {
r->type = ESEXP_RES_BOOL;
r->value.boolean = r1->value.number < r2->value.number;
@@ -435,31 +459,31 @@ term_eval_lt (struct _ESExp *f,
r->type = ESEXP_RES_BOOL;
r->value.boolean = strcmp (r1->value.string, r2->value.string) < 0;
}
- e_sexp_result_free (f, r1);
- e_sexp_result_free (f, r2);
+ e_sexp_result_free (sexp, r1);
+ e_sexp_result_free (sexp, r2);
}
return r;
}
/* this should support all arguments ...? */
static ESExpResult *
-term_eval_gt (struct _ESExp *f,
+term_eval_gt (ESExp *sexp,
gint argc,
- struct _ESExpTerm **argv,
+ ESExpTerm **argv,
gpointer data)
{
- struct _ESExpResult *r, *r1, *r2;
+ ESExpResult *r, *r1, *r2;
- r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ r = e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
if (argc == 2) {
- r1 = e_sexp_term_eval (f, argv[0]);
- r2 = e_sexp_term_eval (f, argv[1]);
+ r1 = e_sexp_term_eval (sexp, argv[0]);
+ r2 = e_sexp_term_eval (sexp, argv[1]);
if (r1->type != r2->type) {
- e_sexp_result_free (f, r1);
- e_sexp_result_free (f, r2);
- e_sexp_result_free (f, r);
- e_sexp_fatal_error (f, "Incompatible types in compare >");
+ e_sexp_result_free (sexp, r1);
+ e_sexp_result_free (sexp, r2);
+ e_sexp_result_free (sexp, r);
+ e_sexp_fatal_error (sexp, "Incompatible types in compare >");
} else if (r1->type == ESEXP_RES_INT) {
r->type = ESEXP_RES_BOOL;
r->value.boolean = r1->value.number > r2->value.number;
@@ -470,26 +494,26 @@ term_eval_gt (struct _ESExp *f,
r->type = ESEXP_RES_BOOL;
r->value.boolean = strcmp (r1->value.string, r2->value.string) > 0;
}
- e_sexp_result_free (f, r1);
- e_sexp_result_free (f, r2);
+ e_sexp_result_free (sexp, r1);
+ e_sexp_result_free (sexp, r2);
}
return r;
}
/* this should support all arguments ...? */
static ESExpResult *
-term_eval_eq (struct _ESExp *f,
+term_eval_eq (ESExp *sexp,
gint argc,
- struct _ESExpTerm **argv,
+ ESExpTerm **argv,
gpointer data)
{
- struct _ESExpResult *r, *r1, *r2;
+ ESExpResult *r, *r1, *r2;
- r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+ r = e_sexp_result_new (sexp, ESEXP_RES_BOOL);
if (argc == 2) {
- r1 = e_sexp_term_eval (f, argv[0]);
- r2 = e_sexp_term_eval (f, argv[1]);
+ r1 = e_sexp_term_eval (sexp, argv[0]);
+ r2 = e_sexp_term_eval (sexp, argv[1]);
if (r1->type != r2->type) {
r->value.boolean = FALSE;
} else if (r1->type == ESEXP_RES_INT) {
@@ -501,19 +525,19 @@ term_eval_eq (struct _ESExp *f,
} else if (r1->type == ESEXP_RES_STRING) {
r->value.boolean = strcmp (r1->value.string, r2->value.string) == 0;
}
- e_sexp_result_free (f, r1);
- e_sexp_result_free (f, r2);
+ e_sexp_result_free (sexp, r1);
+ e_sexp_result_free (sexp, r2);
}
return r;
}
static ESExpResult *
-term_eval_plus (struct _ESExp *f,
+term_eval_plus (ESExp *sexp,
gint argc,
- struct _ESExpResult **argv,
+ ESExpResult **argv,
gpointer data)
{
- struct _ESExpResult *r = NULL;
+ ESExpResult *r = NULL;
gint type;
gint i;
@@ -526,10 +550,10 @@ term_eval_plus (struct _ESExp *f,
total += argv[i]->value.number;
}
if (i < argc) {
- e_sexp_resultv_free (f, argc, argv);
- e_sexp_fatal_error (f, "Invalid types in (+ ints)");
+ e_sexp_resultv_free (sexp, argc, argv);
+ e_sexp_fatal_error (sexp, "Invalid types in (+ ints)");
}
- r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r = e_sexp_result_new (sexp, ESEXP_RES_INT);
r->value.number = total;
break; }
case ESEXP_RES_STRING: {
@@ -538,10 +562,10 @@ term_eval_plus (struct _ESExp *f,
g_string_append (s, argv[i]->value.string);
}
if (i < argc) {
- e_sexp_resultv_free (f, argc, argv);
- e_sexp_fatal_error (f, "Invalid types in (+ strings)");
+ e_sexp_resultv_free (sexp, argc, argv);
+ e_sexp_fatal_error (sexp, "Invalid types in (+ strings)");
}
- r = e_sexp_result_new (f, ESEXP_RES_STRING);
+ r = e_sexp_result_new (sexp, ESEXP_RES_STRING);
r->value.string = s->str;
g_string_free (s, FALSE);
break; }
@@ -554,30 +578,30 @@ term_eval_plus (struct _ESExp *f,
total += argv[i]->value.time;
if (i < argc) {
- e_sexp_resultv_free (f, argc, argv);
- e_sexp_fatal_error (f, "Invalid types in (+ time_t)");
+ e_sexp_resultv_free (sexp, argc, argv);
+ e_sexp_fatal_error (sexp, "Invalid types in (+ time_t)");
}
- r = e_sexp_result_new (f, ESEXP_RES_TIME);
+ r = e_sexp_result_new (sexp, ESEXP_RES_TIME);
r->value.time = total;
break; }
}
}
if (!r) {
- r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r = e_sexp_result_new (sexp, ESEXP_RES_INT);
r->value.number = 0;
}
return r;
}
static ESExpResult *
-term_eval_sub (struct _ESExp *f,
+term_eval_sub (ESExp *sexp,
gint argc,
- struct _ESExpResult **argv,
+ ESExpResult **argv,
gpointer data)
{
- struct _ESExpResult *r = NULL;
+ ESExpResult *r = NULL;
gint type;
gint i;
@@ -590,10 +614,10 @@ term_eval_sub (struct _ESExp *f,
total -= argv[i]->value.number;
}
if (i < argc) {
- e_sexp_resultv_free (f, argc, argv);
- e_sexp_fatal_error (f, "Invalid types in -");
+ e_sexp_resultv_free (sexp, argc, argv);
+ e_sexp_fatal_error (sexp, "Invalid types in -");
}
- r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r = e_sexp_result_new (sexp, ESEXP_RES_INT);
r->value.number = total;
break; }
case ESEXP_RES_TIME: {
@@ -605,18 +629,18 @@ term_eval_sub (struct _ESExp *f,
total -= argv[i]->value.time;
if (i < argc) {
- e_sexp_resultv_free (f, argc, argv);
- e_sexp_fatal_error (f, "Invalid types in (- time_t)");
+ e_sexp_resultv_free (sexp, argc, argv);
+ e_sexp_fatal_error (sexp, "Invalid types in (- time_t)");
}
- r = e_sexp_result_new (f, ESEXP_RES_TIME);
+ r = e_sexp_result_new (sexp, ESEXP_RES_TIME);
r->value.time = total;
break; }
}
}
if (!r) {
- r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r = e_sexp_result_new (sexp, ESEXP_RES_INT);
r->value.number = 0;
}
return r;
@@ -624,17 +648,17 @@ term_eval_sub (struct _ESExp *f,
/* cast to gint */
static ESExpResult *
-term_eval_castint (struct _ESExp *f,
+term_eval_castint (ESExp *sexp,
gint argc,
- struct _ESExpResult **argv,
+ ESExpResult **argv,
gpointer data)
{
- struct _ESExpResult *r;
+ ESExpResult *r;
if (argc != 1)
- e_sexp_fatal_error (f, "Incorrect argument count to (gint )");
+ e_sexp_fatal_error (sexp, "Incorrect argument count to (gint )");
- r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r = e_sexp_result_new (sexp, ESEXP_RES_INT);
switch (argv[0]->type) {
case ESEXP_RES_INT:
r->value.number = argv[0]->value.number;
@@ -646,8 +670,8 @@ term_eval_castint (struct _ESExp *f,
r->value.number = strtoul (argv[0]->value.string, NULL, 10);
break;
default:
- e_sexp_result_free (f, r);
- e_sexp_fatal_error (f, "Invalid type in (cast-int )");
+ e_sexp_result_free (sexp, r);
+ e_sexp_fatal_error (sexp, "Invalid type in (cast-int )");
}
return r;
@@ -655,17 +679,17 @@ term_eval_castint (struct _ESExp *f,
/* cast to string */
static ESExpResult *
-term_eval_caststring (struct _ESExp *f,
+term_eval_caststring (ESExp *sexp,
gint argc,
- struct _ESExpResult **argv,
+ ESExpResult **argv,
gpointer data)
{
- struct _ESExpResult *r;
+ ESExpResult *r;
if (argc != 1)
- e_sexp_fatal_error (f, "Incorrect argument count to (cast-string )");
+ e_sexp_fatal_error (sexp, "Incorrect argument count to (cast-string )");
- r = e_sexp_result_new (f, ESEXP_RES_STRING);
+ r = e_sexp_result_new (sexp, ESEXP_RES_STRING);
switch (argv[0]->type) {
case ESEXP_RES_INT:
r->value.string = g_strdup_printf ("%d", argv[0]->value.number);
@@ -677,8 +701,8 @@ term_eval_caststring (struct _ESExp *f,
r->value.string = g_strdup (argv[0]->value.string);
break;
default:
- e_sexp_result_free (f, r);
- e_sexp_fatal_error (f, "Invalid type in (gint )");
+ e_sexp_result_free (sexp, r);
+ e_sexp_fatal_error (sexp, "Invalid type in (gint )");
}
return r;
@@ -686,57 +710,58 @@ term_eval_caststring (struct _ESExp *f,
/* implements 'if' function */
static ESExpResult *
-term_eval_if (struct _ESExp *f,
+term_eval_if (ESExp *sexp,
gint argc,
- struct _ESExpTerm **argv,
+ ESExpTerm **argv,
gpointer data)
{
- struct _ESExpResult *r;
+ ESExpResult *r;
gint doit;
if (argc >=2 && argc <= 3) {
- r = e_sexp_term_eval (f, argv[0]);
+ r = e_sexp_term_eval (sexp, argv[0]);
doit = (r->type == ESEXP_RES_BOOL && r->value.boolean);
- e_sexp_result_free (f, r);
+ e_sexp_result_free (sexp, r);
if (doit) {
- return e_sexp_term_eval (f, argv[1]);
+ return e_sexp_term_eval (sexp, argv[1]);
} else if (argc > 2) {
- return e_sexp_term_eval (f, argv[2]);
+ return e_sexp_term_eval (sexp, argv[2]);
}
}
- return e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ return e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
}
/* implements 'begin' statement */
static ESExpResult *
-term_eval_begin (struct _ESExp *f,
+term_eval_begin (ESExp *sexp,
gint argc,
- struct _ESExpTerm **argv,
+ ESExpTerm **argv,
gpointer data)
{
- struct _ESExpResult *r = NULL;
+ ESExpResult *r = NULL;
gint i;
for (i = 0; i < argc; i++) {
if (r)
- e_sexp_result_free (f, r);
- r = e_sexp_term_eval (f, argv[i]);
+ e_sexp_result_free (sexp, r);
+ r = e_sexp_term_eval (sexp, argv[i]);
}
if (r)
return r;
else
- return e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ return e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
}
/* this must only be called from inside term evaluation callbacks! */
-struct _ESExpResult *
-e_sexp_term_eval (struct _ESExp *f,
- struct _ESExpTerm *t)
+ESExpResult *
+e_sexp_term_eval (ESExp *sexp,
+ ESExpTerm *t)
{
- struct _ESExpResult *r = NULL;
+ ESExpResult *r = NULL;
gint i;
- struct _ESExpResult **argv;
+ ESExpResult **argv;
+ g_return_val_if_fail (E_IS_SEXP (sexp), NULL);
g_return_val_if_fail (t != NULL, NULL);
r (printf ("eval term :\n"));
@@ -745,51 +770,51 @@ e_sexp_term_eval (struct _ESExp *f,
switch (t->type) {
case ESEXP_TERM_STRING:
r (printf (" (string \"%s\")\n", t->value.string));
- r = e_sexp_result_new (f, ESEXP_RES_STRING);
+ r = e_sexp_result_new (sexp, ESEXP_RES_STRING);
/* erk, this shoul;dn't need to strdup this ... */
r->value.string = g_strdup (t->value.string);
break;
case ESEXP_TERM_INT:
r (printf (" (gint %d)\n", t->value.number));
- r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r = e_sexp_result_new (sexp, ESEXP_RES_INT);
r->value.number = t->value.number;
break;
case ESEXP_TERM_BOOL:
r (printf (" (gint %d)\n", t->value.number));
- r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+ r = e_sexp_result_new (sexp, ESEXP_RES_BOOL);
r->value.boolean = t->value.boolean;
break;
case ESEXP_TERM_TIME:
r (printf (" (time_t %ld)\n", t->value.time));
- r = e_sexp_result_new (f, ESEXP_RES_TIME);
+ r = e_sexp_result_new (sexp, ESEXP_RES_TIME);
r->value.time = t->value.time;
break;
case ESEXP_TERM_IFUNC:
if (t->value.func.sym && t->value.func.sym->f.ifunc)
r = t->value.func.sym->f.ifunc (
- f, t->value.func.termcount,
+ sexp, t->value.func.termcount,
t->value.func.terms, t->value.func.sym->data);
break;
case ESEXP_TERM_FUNC:
/* first evaluate all arguments to result types */
argv = alloca (sizeof (argv[0]) * t->value.func.termcount);
for (i = 0; i < t->value.func.termcount; i++) {
- argv[i] = e_sexp_term_eval (f, t->value.func.terms[i]);
+ argv[i] = e_sexp_term_eval (sexp, t->value.func.terms[i]);
}
/* call the function */
if (t->value.func.sym->f.func)
r = t->value.func.sym->f.func (
- f, t->value.func.termcount,
+ sexp, t->value.func.termcount,
argv, t->value.func.sym->data);
- e_sexp_resultv_free (f, t->value.func.termcount, argv);
+ e_sexp_resultv_free (sexp, t->value.func.termcount, argv);
break;
default:
- e_sexp_fatal_error (f, "Unknown type in parse tree: %d", t->type);
+ e_sexp_fatal_error (sexp, "Unknown type in parse tree: %d", t->type);
}
if (r == NULL)
- r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ r = e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
return r;
}
@@ -820,7 +845,7 @@ eval_dump_result (ESExpResult *r,
printf ("string: '%s'\n", r->value.string);
break;
case ESEXP_RES_BOOL:
- printf ("bool: %c\n", r->value.boolean ? 't':'f');
+ printf ("bool: %c\n", r->value.boolean ? 't':'sexp');
break;
case ESEXP_RES_TIME:
printf ("time_t: %ld\n", (glong) r->value.time);
@@ -835,7 +860,7 @@ eval_dump_result (ESExpResult *r,
#ifdef TESTER
static void
-parse_dump_term (struct _ESExpTerm *t,
+parse_dump_term (ESExpTerm *t,
gint depth)
{
gint i;
@@ -856,7 +881,7 @@ parse_dump_term (struct _ESExpTerm *t,
printf (" %d", t->value.number);
break;
case ESEXP_TERM_BOOL:
- printf (" #%c", t->value.boolean ? 't':'f');
+ printf (" #%c", t->value.boolean ? 't':'sexp');
break;
case ESEXP_TERM_TIME:
printf (" %ld", (glong) t->value.time);
@@ -893,8 +918,8 @@ static const gchar *time_functions[] = {
static gboolean
occur_in_time_range_generator (gint argc,
- struct _ESExpResult **argv,
- struct _ESExpResult *r)
+ ESExpResult **argv,
+ ESExpResult *r)
{
g_return_val_if_fail (r != NULL, FALSE);
g_return_val_if_fail (argc == 2 || argc == 3, FALSE);
@@ -910,8 +935,8 @@ occur_in_time_range_generator (gint argc,
static gboolean
binary_generator (gint argc,
- struct _ESExpResult **argv,
- struct _ESExpResult *r)
+ ESExpResult **argv,
+ ESExpResult *r)
{
g_return_val_if_fail (r != NULL, FALSE);
g_return_val_if_fail (argc == 2, FALSE);
@@ -927,8 +952,8 @@ binary_generator (gint argc,
static gboolean
unary_generator (gint argc,
- struct _ESExpResult **argv,
- struct _ESExpResult *r)
+ ESExpResult **argv,
+ ESExpResult *r)
{
/* unary generator with end time */
g_return_val_if_fail (r != NULL, FALSE);
@@ -955,8 +980,8 @@ static const struct {
static gboolean
or_operator (gint argc,
- struct _ESExpResult **argv,
- struct _ESExpResult *r)
+ ESExpResult **argv,
+ ESExpResult *r)
{
gint ii;
@@ -992,8 +1017,8 @@ or_operator (gint argc,
static gboolean
and_operator (gint argc,
- struct _ESExpResult **argv,
- struct _ESExpResult *r)
+ ESExpResult **argv,
+ ESExpResult *r)
{
gint ii;
@@ -1078,15 +1103,15 @@ get_generator_function (const gchar *fname)
}
/* this must only be called from inside term evaluation callbacks! */
-static struct _ESExpResult *
-e_sexp_term_evaluate_occur_times (struct _ESExp *f,
- struct _ESExpTerm *t,
+static ESExpResult *
+e_sexp_term_evaluate_occur_times (ESExp *sexp,
+ ESExpTerm *t,
time_t *start,
time_t *end)
{
- struct _ESExpResult *r = NULL;
+ ESExpResult *r = NULL;
gint i, argc;
- struct _ESExpResult **argv;
+ ESExpResult **argv;
gboolean ok = TRUE;
g_return_val_if_fail (t != NULL, NULL);
@@ -1101,7 +1126,7 @@ e_sexp_term_evaluate_occur_times (struct _ESExp *f,
switch (t->type) {
case ESEXP_TERM_STRING:
r (printf (" (string \"%s\")\n", t->value.string));
- r = e_sexp_result_new (f, ESEXP_RES_STRING);
+ r = e_sexp_result_new (sexp, ESEXP_RES_STRING);
r->value.string = g_strdup (t->value.string);
break;
case ESEXP_TERM_IFUNC:
@@ -1112,19 +1137,19 @@ e_sexp_term_evaluate_occur_times (struct _ESExp *f,
r (printf (" (function \"%s\"\n", t->value.func.sym->name));
- r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ r = e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
argc = t->value.func.termcount;
argv = alloca (sizeof (argv[0]) * argc);
for (i = 0; i < t->value.func.termcount; i++) {
argv[i] = e_sexp_term_evaluate_occur_times (
- f, t->value.func.terms[i], start, end);
+ sexp, t->value.func.terms[i], start, end);
}
if (is_time_function (t->value.func.sym->name)) {
/* evaluate time */
if (t->value.func.sym->f.func)
- r = t->value.func.sym->f.func (f, t->value.func.termcount,
+ r = t->value.func.sym->f.func (sexp, t->value.func.termcount,
argv, t->value.func.sym->data);
} else if ((generator = get_generator_function (t->value.func.sym->name)) != NULL) {
/* evaluate generator function */
@@ -1138,7 +1163,7 @@ e_sexp_term_evaluate_occur_times (struct _ESExp *f,
r->time_generator = FALSE;
}
- e_sexp_resultv_free (f, t->value.func.termcount, argv);
+ e_sexp_resultv_free (sexp, t->value.func.termcount, argv);
break;
}
case ESEXP_TERM_INT:
@@ -1151,10 +1176,10 @@ e_sexp_term_evaluate_occur_times (struct _ESExp *f,
}
if (!ok)
- e_sexp_fatal_error (f, "Error in parse tree");
+ e_sexp_fatal_error (sexp, "Error in parse tree");
if (r == NULL)
- r = e_sexp_result_new (f, ESEXP_RES_UNDEFINED);
+ r = e_sexp_result_new (sexp, ESEXP_RES_UNDEFINED);
return r;
}
@@ -1163,18 +1188,18 @@ e_sexp_term_evaluate_occur_times (struct _ESExp *f,
PARSER
*/
-static struct _ESExpTerm *
-parse_term_new (struct _ESExp *f,
+static ESExpTerm *
+parse_term_new (ESExp *sexp,
gint type)
{
- struct _ESExpTerm *s = e_memchunk_alloc0 (f->term_chunks);
+ ESExpTerm *s = e_memchunk_alloc0 (sexp->priv->term_chunks);
s->type = type;
return s;
}
static void
-parse_term_free (struct _ESExp *f,
- struct _ESExpTerm *t)
+parse_term_free (ESExp *sexp,
+ ESExpTerm *t)
{
gint i;
@@ -1196,7 +1221,7 @@ parse_term_free (struct _ESExp *f,
case ESEXP_TERM_FUNC:
case ESEXP_TERM_IFUNC:
for (i = 0; i < t->value.func.termcount; i++) {
- parse_term_free (f, t->value.func.terms[i]);
+ parse_term_free (sexp, t->value.func.terms[i]);
}
g_free (t->value.func.terms);
break;
@@ -1204,24 +1229,24 @@ parse_term_free (struct _ESExp *f,
default:
printf ("parse_term_free: unknown type: %d\n", t->type);
}
- e_memchunk_free (f->term_chunks, t);
+ e_memchunk_free (sexp->priv->term_chunks, t);
}
-static struct _ESExpTerm **
-parse_values (ESExp *f,
+static ESExpTerm **
+parse_values (ESExp *sexp,
gint *len)
{
gint token;
- struct _ESExpTerm **terms;
+ ESExpTerm **terms;
gint i, size = 0;
- GScanner *gs = f->scanner;
+ GScanner *gs = sexp->priv->scanner;
GSList *list = NULL, *l;
p (printf ("parsing values\n"));
while ( (token = g_scanner_peek_next_token (gs)) != G_TOKEN_EOF
&& token != ')') {
- list = g_slist_prepend (list, parse_value (f));
+ list = g_slist_prepend (list, parse_value (sexp));
size++;
}
@@ -1249,18 +1274,20 @@ parse_values (ESExp *f,
* Since: 2.28
**/
ESExpTerm *
-e_sexp_parse_value (ESExp *f)
+e_sexp_parse_value (ESExp *sexp)
{
- return parse_value (f);
+ g_return_val_if_fail (E_IS_SEXP (sexp), NULL);
+
+ return parse_value (sexp);
}
-static struct _ESExpTerm *
-parse_value (ESExp *f)
+static ESExpTerm *
+parse_value (ESExp *sexp)
{
gint token, negative = FALSE;
- struct _ESExpTerm *t = NULL;
- GScanner *gs = f->scanner;
- struct _ESExpSymbol *s;
+ ESExpTerm *t = NULL;
+ GScanner *gs = sexp->priv->scanner;
+ ESExpSymbol *s;
p (printf ("parsing value\n"));
@@ -1270,12 +1297,12 @@ parse_value (ESExp *f)
break;
case G_TOKEN_LEFT_PAREN:
p (printf ("got brace, its a list!\n"));
- return parse_list (f, TRUE);
+ return parse_list (sexp, TRUE);
case G_TOKEN_STRING:
p (printf (
"got string '%s'\n",
g_scanner_cur_value (gs).v_string));
- t = parse_term_new (f, ESEXP_TERM_STRING);
+ t = parse_term_new (sexp, ESEXP_TERM_STRING);
t->value.string = g_strdup (g_scanner_cur_value (gs).v_string);
break;
case '-':
@@ -1283,14 +1310,14 @@ parse_value (ESExp *f)
token = g_scanner_get_next_token (gs);
if (token != G_TOKEN_INT) {
e_sexp_fatal_error (
- f, "Invalid format for a integer value");
+ sexp, "Invalid format for a integer value");
return NULL;
}
negative = TRUE;
/* fall through... */
case G_TOKEN_INT:
- t = parse_term_new (f, ESEXP_TERM_INT);
+ t = parse_term_new (sexp, ESEXP_TERM_INT);
t->value.number = g_scanner_cur_value (gs).v_int;
if (negative)
t->value.number = -t->value.number;
@@ -1303,7 +1330,7 @@ parse_value (ESExp *f)
token = g_scanner_get_next_token (gs);
if (token != G_TOKEN_IDENTIFIER) {
e_sexp_fatal_error (
- f, "Invalid format for a boolean value");
+ sexp, "Invalid format for a boolean value");
return NULL;
}
@@ -1312,11 +1339,11 @@ parse_value (ESExp *f)
g_return_val_if_fail (str != NULL, NULL);
if (!(strlen (str) == 1 && (str[0] == 't' || str[0] == 'f'))) {
e_sexp_fatal_error (
- f, "Invalid format for a boolean value");
+ sexp, "Invalid format for a boolean value");
return NULL;
}
- t = parse_term_new (f, ESEXP_TERM_BOOL);
+ t = parse_term_new (sexp, ESEXP_TERM_BOOL);
t->value.boolean = (str[0] == 't');
break; }
case G_TOKEN_SYMBOL:
@@ -1327,18 +1354,18 @@ parse_value (ESExp *f)
case ESEXP_TERM_IFUNC:
/* this is basically invalid, since we can't use
* function pointers, but let the runtime catch it */
- t = parse_term_new (f, s->type);
+ t = parse_term_new (sexp, s->type);
t->value.func.sym = s;
t->value.func.terms = parse_values (
- f, &t->value.func.termcount);
+ sexp, &t->value.func.termcount);
break;
case ESEXP_TERM_VAR:
- t = parse_term_new (f, s->type);
+ t = parse_term_new (sexp, s->type);
t->value.var = s;
break;
default:
e_sexp_fatal_error (
- f, "Invalid symbol type: %s: %d",
+ sexp, "Invalid symbol type: %s: %d",
s->name, s->type);
}
break;
@@ -1347,25 +1374,25 @@ parse_value (ESExp *f)
"got unknown identifider '%s'\n",
g_scanner_cur_value (gs).v_identifier));
e_sexp_fatal_error (
- f, "Unknown identifier: %s",
+ sexp, "Unknown identifier: %s",
g_scanner_cur_value (gs).v_identifier);
break;
default:
e_sexp_fatal_error (
- f, "Unexpected token encountered: %d", token);
+ sexp, "Unexpected token encountered: %d", token);
}
p (printf ("done parsing value\n"));
return t;
}
/* FIXME: this needs some robustification */
-static struct _ESExpTerm *
-parse_list (ESExp *f,
+static ESExpTerm *
+parse_list (ESExp *sexp,
gint gotbrace)
{
gint token;
- struct _ESExpTerm *t = NULL;
- GScanner *gs = f->scanner;
+ ESExpTerm *t = NULL;
+ GScanner *gs = sexp->priv->scanner;
p (printf ("parsing list\n"));
if (gotbrace)
@@ -1376,11 +1403,11 @@ parse_list (ESExp *f,
token = g_scanner_get_next_token (gs);
switch (token) {
case G_TOKEN_SYMBOL: {
- struct _ESExpSymbol *s;
+ ESExpSymbol *s;
s = g_scanner_cur_value (gs).v_symbol;
p (printf ("got funciton: %s\n", s->name));
- t = parse_term_new (f, s->type);
+ t = parse_term_new (sexp, s->type);
p (printf ("created new list %p\n", t));
/* if we have a variable, find out its base type */
while (s->type == ESEXP_TERM_VAR) {
@@ -1390,47 +1417,47 @@ parse_list (ESExp *f,
|| s->type == ESEXP_TERM_IFUNC) {
t->value.func.sym = s;
t->value.func.terms = parse_values (
- f, &t->value.func.termcount);
+ sexp, &t->value.func.termcount);
} else {
- parse_term_free (f, t);
+ parse_term_free (sexp, t);
e_sexp_fatal_error (
- f, "Trying to call variable "
+ sexp, "Trying to call variable "
"as function: %s", s->name);
}
break; }
case G_TOKEN_IDENTIFIER:
e_sexp_fatal_error (
- f, "Unknown identifier: %s",
+ sexp, "Unknown identifier: %s",
g_scanner_cur_value (gs).v_identifier);
break;
case G_TOKEN_LEFT_PAREN:
- return parse_list (f, TRUE);
+ return parse_list (sexp, TRUE);
default:
- e_sexp_fatal_error (f, "Unexpected token encountered: %d", token);
+ e_sexp_fatal_error (sexp, "Unexpected token encountered: %d", token);
}
token = g_scanner_get_next_token (gs);
if (token != ')') {
- e_sexp_fatal_error (f, "Missing ')'");
+ e_sexp_fatal_error (sexp, "Missing ')'");
}
} else {
- e_sexp_fatal_error (f, "Missing '('");
+ e_sexp_fatal_error (sexp, "Missing '('");
}
p (printf ("returning list %p\n", t));
return t;
}
-static void e_sexp_finalise (gpointer);
+static void e_sexp_finalise (GObject *object);
-#ifdef E_SEXP_IS_G_OBJECT
static void
e_sexp_class_init (ESExpClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ g_type_class_add_private (class, sizeof (ESExpPrivate));
+
object_class->finalize = e_sexp_finalise;
}
-#endif
/* 'builtin' functions */
static const struct {
@@ -1458,174 +1485,145 @@ free_symbol (gpointer key,
gpointer value,
gpointer data)
{
- struct _ESExpSymbol *s = value;
+ ESExpSymbol *s = value;
g_free (s->name);
g_free (s);
}
static void
-e_sexp_finalise (gpointer o)
+e_sexp_finalise (GObject *object)
{
- ESExp *s = (ESExp *) o;
+ ESExp *sexp = (ESExp *) object;
- if (s->tree) {
- parse_term_free (s, s->tree);
- s->tree = NULL;
+ if (sexp->priv->tree) {
+ parse_term_free (sexp, sexp->priv->tree);
+ sexp->priv->tree = NULL;
}
- g_free (s->error);
+ g_free (sexp->priv->error);
- e_memchunk_destroy (s->term_chunks);
- e_memchunk_destroy (s->result_chunks);
+ e_memchunk_destroy (sexp->priv->term_chunks);
+ e_memchunk_destroy (sexp->priv->result_chunks);
- g_scanner_scope_foreach_symbol (s->scanner, 0, free_symbol, NULL);
- g_scanner_destroy (s->scanner);
+ g_scanner_scope_foreach_symbol (sexp->priv->scanner, 0, free_symbol, NULL);
+ g_scanner_destroy (sexp->priv->scanner);
-#ifdef E_SEXP_IS_G_OBJECT
- G_OBJECT_CLASS (e_sexp_parent_class)->finalize (o);
-#endif
+ G_OBJECT_CLASS (e_sexp_parent_class)->finalize (object);
}
static void
-e_sexp_init (ESExp *s)
+e_sexp_init (ESExp *sexp)
{
gint i;
- s->scanner = g_scanner_new (&scanner_config);
- s->term_chunks = e_memchunk_new (16, sizeof (struct _ESExpTerm));
- s->result_chunks = e_memchunk_new (16, sizeof (struct _ESExpResult));
+ sexp->priv = G_TYPE_INSTANCE_GET_PRIVATE (sexp, E_TYPE_SEXP, ESExpPrivate);
+
+ sexp->priv->scanner = g_scanner_new (&scanner_config);
+ sexp->priv->term_chunks = e_memchunk_new (16, sizeof (ESExpTerm));
+ sexp->priv->result_chunks = e_memchunk_new (16, sizeof (ESExpResult));
/* load in builtin symbols? */
for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
if (symbols[i].type == 1) {
e_sexp_add_ifunction (
- s, 0,
+ sexp, 0,
symbols[i].name,
(ESExpIFunc *) symbols[i].func,
(gpointer) &symbols[i]);
} else {
e_sexp_add_function (
- s, 0,
+ sexp, 0,
symbols[i].name,
symbols[i].func,
(gpointer) &symbols[i]);
}
}
-
-#ifndef E_SEXP_IS_G_OBJECT
- s->refcount = 1;
-#endif
}
ESExp *
e_sexp_new (void)
{
-#ifdef E_SEXP_IS_G_OBJECT
- ESExp *f = (ESexp *) g_object_new (E_TYPE_SEXP, NULL);
-#else
- ESExp *f = g_malloc0 (sizeof (ESExp));
- e_sexp_init (f);
-#endif
-
- return f;
-}
-
-#ifndef E_SEXP_IS_G_OBJECT
-void
-e_sexp_ref (ESExp *f)
-{
- f->refcount++;
-}
-
-void
-e_sexp_unref (ESExp *f)
-{
- f->refcount--;
- if (f->refcount == 0) {
- e_sexp_finalise (f);
- g_free (f);
- }
+ return g_object_new (E_TYPE_SEXP, NULL);
}
-#endif
void
-e_sexp_add_function (ESExp *f,
+e_sexp_add_function (ESExp *sexp,
gint scope,
const gchar *name,
ESExpFunc *func,
gpointer data)
{
- struct _ESExpSymbol *s;
+ ESExpSymbol *s;
- g_return_if_fail (IS_E_SEXP (f));
+ g_return_if_fail (E_IS_SEXP (sexp));
g_return_if_fail (name != NULL);
- e_sexp_remove_symbol (f, scope, name);
+ e_sexp_remove_symbol (sexp, scope, name);
s = g_malloc0 (sizeof (*s));
s->name = g_strdup (name);
s->f.func = func;
s->type = ESEXP_TERM_FUNC;
s->data = data;
- g_scanner_scope_add_symbol (f->scanner, scope, s->name, s);
+ g_scanner_scope_add_symbol (sexp->priv->scanner, scope, s->name, s);
}
void
-e_sexp_add_ifunction (ESExp *f,
+e_sexp_add_ifunction (ESExp *sexp,
gint scope,
const gchar *name,
ESExpIFunc *ifunc,
gpointer data)
{
- struct _ESExpSymbol *s;
+ ESExpSymbol *s;
- g_return_if_fail (IS_E_SEXP (f));
+ g_return_if_fail (E_IS_SEXP (sexp));
g_return_if_fail (name != NULL);
- e_sexp_remove_symbol (f, scope, name);
+ e_sexp_remove_symbol (sexp, scope, name);
s = g_malloc0 (sizeof (*s));
s->name = g_strdup (name);
s->f.ifunc = ifunc;
s->type = ESEXP_TERM_IFUNC;
s->data = data;
- g_scanner_scope_add_symbol (f->scanner, scope, s->name, s);
+ g_scanner_scope_add_symbol (sexp->priv->scanner, scope, s->name, s);
}
void
-e_sexp_add_variable (ESExp *f,
+e_sexp_add_variable (ESExp *sexp,
gint scope,
gchar *name,
ESExpTerm *value)
{
- struct _ESExpSymbol *s;
+ ESExpSymbol *s;
- g_return_if_fail (IS_E_SEXP (f));
+ g_return_if_fail (E_IS_SEXP (sexp));
g_return_if_fail (name != NULL);
s = g_malloc0 (sizeof (*s));
s->name = g_strdup (name);
s->type = ESEXP_TERM_VAR;
s->data = value;
- g_scanner_scope_add_symbol (f->scanner, scope, s->name, s);
+ g_scanner_scope_add_symbol (sexp->priv->scanner, scope, s->name, s);
}
void
-e_sexp_remove_symbol (ESExp *f,
+e_sexp_remove_symbol (ESExp *sexp,
gint scope,
const gchar *name)
{
gint oldscope;
- struct _ESExpSymbol *s;
+ ESExpSymbol *s;
- g_return_if_fail (IS_E_SEXP (f));
+ g_return_if_fail (E_IS_SEXP (sexp));
g_return_if_fail (name != NULL);
- oldscope = g_scanner_set_scope (f->scanner, scope);
- s = g_scanner_lookup_symbol (f->scanner, name);
- g_scanner_scope_remove_symbol (f->scanner, scope, name);
- g_scanner_set_scope (f->scanner, oldscope);
+ oldscope = g_scanner_set_scope (sexp->priv->scanner, scope);
+ s = g_scanner_lookup_symbol (sexp->priv->scanner, name);
+ g_scanner_scope_remove_symbol (sexp->priv->scanner, scope, name);
+ g_scanner_set_scope (sexp->priv->scanner, oldscope);
if (s) {
g_free (s->name);
g_free (s);
@@ -1633,69 +1631,69 @@ e_sexp_remove_symbol (ESExp *f,
}
gint
-e_sexp_set_scope (ESExp *f,
+e_sexp_set_scope (ESExp *sexp,
gint scope)
{
- g_return_val_if_fail (IS_E_SEXP (f), 0);
+ g_return_val_if_fail (E_IS_SEXP (sexp), 0);
- return g_scanner_set_scope (f->scanner, scope);
+ return g_scanner_set_scope (sexp->priv->scanner, scope);
}
void
-e_sexp_input_text (ESExp *f,
+e_sexp_input_text (ESExp *sexp,
const gchar *text,
gint len)
{
- g_return_if_fail (IS_E_SEXP (f));
+ g_return_if_fail (E_IS_SEXP (sexp));
g_return_if_fail (text != NULL);
- g_scanner_input_text (f->scanner, text, len);
+ g_scanner_input_text (sexp->priv->scanner, text, len);
}
void
-e_sexp_input_file (ESExp *f,
+e_sexp_input_file (ESExp *sexp,
gint fd)
{
- g_return_if_fail (IS_E_SEXP (f));
+ g_return_if_fail (E_IS_SEXP (sexp));
- g_scanner_input_file (f->scanner, fd);
+ g_scanner_input_file (sexp->priv->scanner, fd);
}
/* returns -1 on error */
gint
-e_sexp_parse (ESExp *f)
+e_sexp_parse (ESExp *sexp)
{
- g_return_val_if_fail (IS_E_SEXP (f), -1);
+ g_return_val_if_fail (E_IS_SEXP (sexp), -1);
- if (setjmp (f->failenv))
+ if (setjmp (sexp->priv->failenv))
return -1;
- if (f->tree)
- parse_term_free (f, f->tree);
+ if (sexp->priv->tree)
+ parse_term_free (sexp, sexp->priv->tree);
- f->tree = parse_value (f);
+ sexp->priv->tree = parse_value (sexp);
return 0;
}
/* returns NULL on error */
-struct _ESExpResult *
-e_sexp_eval (ESExp *f)
+ESExpResult *
+e_sexp_eval (ESExp *sexp)
{
- g_return_val_if_fail (IS_E_SEXP (f), NULL);
- g_return_val_if_fail (f->tree != NULL, NULL);
+ g_return_val_if_fail (E_IS_SEXP (sexp), NULL);
+ g_return_val_if_fail (sexp->priv->tree != NULL, NULL);
- if (setjmp (f->failenv)) {
- g_warning ("Error in execution: %s", f->error);
+ if (setjmp (sexp->priv->failenv)) {
+ g_warning ("Error in execution: %s", sexp->priv->error);
return NULL;
}
- return e_sexp_term_eval (f, f->tree);
+ return e_sexp_term_eval (sexp, sexp->priv->tree);
}
/**
* e_cal_backend_sexp_evaluate_occur_times:
- * @f: An #ESExp object.
+ * @sexp: An #ESExp object.
* @start: Start of the time window will be stored here.
* @end: End of the time window will be stored here.
*
@@ -1704,25 +1702,26 @@ e_sexp_eval (ESExp *f)
* Since: 2.32
*/
gboolean
-e_sexp_evaluate_occur_times (ESExp *f,
+e_sexp_evaluate_occur_times (ESExp *sexp,
time_t *start,
time_t *end)
{
- struct _ESExpResult *r;
+ ESExpResult *r;
gboolean generator;
- g_return_val_if_fail (IS_E_SEXP (f), FALSE);
- g_return_val_if_fail (f->tree != NULL, FALSE);
+
+ g_return_val_if_fail (E_IS_SEXP (sexp), FALSE);
+ g_return_val_if_fail (sexp->priv->tree != NULL, FALSE);
g_return_val_if_fail (start != NULL, FALSE);
g_return_val_if_fail (end != NULL, FALSE);
*start = *end = -1;
- if (setjmp (f->failenv)) {
- g_warning ("Error in execution: %s", f->error);
+ if (setjmp (sexp->priv->failenv)) {
+ g_warning ("Error in execution: %s", sexp->priv->error);
return FALSE;
}
- r = e_sexp_term_evaluate_occur_times (f, f->tree, start, end);
+ r = e_sexp_term_evaluate_occur_times (sexp, sexp->priv->tree, start, end);
generator = r->time_generator;
if (generator) {
@@ -1730,7 +1729,7 @@ e_sexp_evaluate_occur_times (ESExp *f,
*end = r->occuring_end;
}
- e_sexp_result_free (f, r);
+ e_sexp_result_free (sexp, r);
return generator;
}
@@ -1747,6 +1746,8 @@ void
e_sexp_encode_bool (GString *s,
gboolean state)
{
+ g_return_if_fail (s != NULL);
+
if (state)
g_string_append (s, " #t");
else
@@ -1769,6 +1770,8 @@ e_sexp_encode_string (GString *s,
gchar c;
const gchar *p;
+ g_return_if_fail (s != NULL);
+
if (string == NULL)
p = "";
else
@@ -1785,25 +1788,25 @@ e_sexp_encode_string (GString *s,
#ifdef TESTER
gint main (gint argc, gchar **argv)
{
- ESExp *f;
+ ESExp *sexp;
gchar *t = "(+ \"foo\" \"\\\"\" \"bar\" \"\\\\ blah \\x \")";
ESExpResult *r;
- f = e_sexp_new ();
+ sexp = e_sexp_new ();
- e_sexp_add_variable (f, 0, "test", NULL);
+ e_sexp_add_variable (sexp, 0, "test", NULL);
if (argc < 2 || !argv[1])
return;
- e_sexp_input_text (f, t, t);
- e_sexp_parse (f);
+ e_sexp_input_text (sexp, t, t);
+ e_sexp_parse (sexp);
- if (f->tree) {
- parse_dump_term (f->tree, 0);
+ if (sexp->priv->tree) {
+ parse_dump_term (sexp->priv->tree, 0);
}
- r = e_sexp_eval (f);
+ r = e_sexp_eval (sexp);
if (r) {
eval_dump_result (r, 0);
} else {
diff --git a/libedataserver/e-sexp.h b/libedataserver/e-sexp.h
index a532e30..90f0a00 100644
--- a/libedataserver/e-sexp.h
+++ b/libedataserver/e-sexp.h
@@ -24,32 +24,20 @@
#include <time.h>
#include <glib.h>
-/* Don't define E_SEXP_IS_G_OBJECT as this object is now used by camel */
-
-#ifdef E_SEXP_IS_G_OBJECT
#include <glib-object.h>
-#endif
-#ifdef E_SEXP_IS_G_OBJECT
#define E_TYPE_SEXP (e_sexp_get_type ())
#define E_SEXP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SEXP, ESExp))
#define E_SEXP_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST ((cls), E_TYPE_SEXP, ESExpClass))
-#define IS_E_SEXP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SEXP))
-#define IS_E_SEXP_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE ((cls), E_TYPE_SEXP))
+#define E_IS_SEXP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SEXP))
+#define E_IS_SEXP_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE ((cls), E_TYPE_SEXP))
#define E_SEXP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_SEXP, ESExpClass))
-#else
-#define E_TYPE_SEXP (0)
-#define E_SEXP(obj) ((struct _ESExp *) (obj))
-#define E_SEXP_CLASS(cls) ((struct _ESExpClass *) (cls))
-#define IS_E_SEXP(obj) (1)
-#define IS_E_SEXP_CLASS(obj) (1)
-#define E_SEXP_GET_CLASS(obj) (NULL)
-#endif
G_BEGIN_DECLS
-typedef struct _ESExp ESExp;
-typedef struct _ESExpClass ESExpClass;
+typedef struct _ESExp ESExp;
+typedef struct _ESExpClass ESExpClass;
+typedef struct _ESExpPrivate ESExpPrivate;
typedef struct _ESExpSymbol ESExpSymbol;
typedef struct _ESExpResult ESExpResult;
@@ -123,76 +111,79 @@ struct _ESExpTerm {
};
struct _ESExp {
-#ifdef E_SEXP_IS_G_OBJECT
GObject parent_object;
-#else
- gint refcount;
-#endif
- GScanner *scanner; /* for parsing text version */
- ESExpTerm *tree; /* root of expression tree */
-
- /* private stuff */
- jmp_buf failenv;
- gchar *error;
- GSList *operators;
-
- /* TODO: may also need a pool allocator for term strings, so we dont lose them
- * in error conditions? */
- struct _EMemChunk *term_chunks;
- struct _EMemChunk *result_chunks;
+
+ ESExpPrivate *priv;
};
struct _ESExpClass {
-#ifdef E_SEXP_IS_G_OBJECT
GObjectClass parent_class;
-#else
- gint dummy;
-#endif
};
-#ifdef E_SEXP_IS_G_OBJECT
GType e_sexp_get_type (void);
-#endif
ESExp *e_sexp_new (void);
-#ifdef E_SEXP_IS_G_OBJECT
-#define e_sexp_ref(f) g_object_ref (f)
-#define e_sexp_unref(f) g_object_unref (f)
-#else
-void e_sexp_ref (ESExp *f);
-void e_sexp_unref (ESExp *f);
-#endif
-void e_sexp_add_function (ESExp *f, gint scope, const gchar *name, ESExpFunc *func, gpointer
data);
-void e_sexp_add_ifunction (ESExp *f, gint scope, const gchar *name, ESExpIFunc *func, gpointer
data);
-void e_sexp_add_variable (ESExp *f, gint scope, gchar *name, ESExpTerm *value);
-void e_sexp_remove_symbol (ESExp *f, gint scope, const gchar *name);
-gint e_sexp_set_scope (ESExp *f, gint scope);
-
-void e_sexp_input_text (ESExp *f, const gchar *text, gint len);
-void e_sexp_input_file (ESExp *f, gint fd);
-
-gint e_sexp_parse (ESExp *f);
-ESExpResult *e_sexp_eval (ESExp *f);
-
-ESExpResult *e_sexp_term_eval (struct _ESExp *f, struct _ESExpTerm *t);
-ESExpResult *e_sexp_result_new (struct _ESExp *f, gint type);
-void e_sexp_result_free (struct _ESExp *f, struct _ESExpResult *t);
+void e_sexp_add_function (ESExp *sexp,
+ gint scope,
+ const gchar *name,
+ ESExpFunc *func,
+ gpointer data);
+void e_sexp_add_ifunction (ESExp *sexp,
+ gint scope,
+ const gchar *name,
+ ESExpIFunc *func,
+ gpointer data);
+void e_sexp_add_variable (ESExp *sexp,
+ gint scope,
+ gchar *name,
+ ESExpTerm *value);
+void e_sexp_remove_symbol (ESExp *sexp,
+ gint scope,
+ const gchar *name);
+gint e_sexp_set_scope (ESExp *sexp,
+ gint scope);
+
+void e_sexp_input_text (ESExp *sexp,
+ const gchar *text,
+ gint len);
+void e_sexp_input_file (ESExp *sexp,
+ gint fd);
+
+gint e_sexp_parse (ESExp *sexp);
+ESExpResult *e_sexp_eval (ESExp *sexp);
+
+ESExpResult *e_sexp_term_eval (ESExp *sexp,
+ ESExpTerm *t);
+ESExpResult *e_sexp_result_new (ESExp *sexp,
+ gint type);
+void e_sexp_result_free (ESExp *sexp,
+ ESExpResult *t);
/* used in normal functions if they have to abort, to free their arguments */
-void e_sexp_resultv_free (struct _ESExp *f, gint argc, struct _ESExpResult **argv);
+void e_sexp_resultv_free (ESExp *sexp,
+ gint argc,
+ ESExpResult **argv);
/* utility functions for creating s-exp strings. */
-void e_sexp_encode_bool (GString *s, gboolean state);
-void e_sexp_encode_string (GString *s, const gchar *string);
+void e_sexp_encode_bool (GString *s,
+ gboolean state);
+void e_sexp_encode_string (GString *s,
+ const gchar *string);
/* only to be called from inside a callback to signal a fatal execution error */
-void e_sexp_fatal_error (struct _ESExp *f, const gchar *why, ...) G_GNUC_NORETURN;
+void e_sexp_fatal_error (ESExp *sexp,
+ const gchar *why,
+ ...) G_GNUC_NORETURN;
/* return the error string */
-const gchar *e_sexp_error (struct _ESExp *f);
+const gchar * e_sexp_get_error (ESExp *sexp);
+
+ESExpTerm * e_sexp_parse_value (ESExp *sexp);
-ESExpTerm * e_sexp_parse_value (ESExp *f);
+gboolean e_sexp_evaluate_occur_times
+ (ESExp *sexp,
+ time_t *start,
+ time_t *end);
-gboolean e_sexp_evaluate_occur_times (ESExp *f, time_t *start, time_t *end);
G_END_DECLS
#endif /* _E_SEXP_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]