2
** Copyright (C) 2008 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
4
** This program is free software; you can redistribute it and/or modify
5
** it under the terms of the GNU General Public License as published by
6
** the Free Software Foundation; either version 3 of the License, or
7
** (at your option) any later version.
9
** This program is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
** GNU General Public License for more details.
14
** You should have received a copy of the GNU General Public License
15
** along with this program; if not, write to the Free Software Foundation,
16
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
MuExprCrit *_crit; /* criteria, the part before the ':' */
27
MuExprVal *_val; /* value, the part after the ':' */
31
mu_expr_new (const char* str, GError **err)
38
char *valstr, *critstr;
40
g_return_val_if_fail (str, NULL);
42
/* the first ':' separates crit and val */
44
colon = strchr (str, ':');
47
MU_EXPR_ERROR_NO_COLON,
48
"expected: expression with colon, but got: %s",
53
if (colon == str) { /* expr starts with colon -- not good */
55
MU_EXPR_ERROR_NO_CRITERIA,
56
"expected: expression with criteria, but got: %s",
61
if (colon[1] == '\0') { /* expr end with colon -- not good either */
63
MU_EXPR_ERROR_NO_VALUE,
64
"expected: expression with value, but got: %s",
69
critstr = g_strndup (str, colon - str);
70
crit = mu_expr_crit_new (critstr, err);
75
valstr = g_strdup (colon + 1);
77
/* the first criterion determines the expression type */
78
val = mu_expr_val_new (mu_expr_crit_types(crit)[0],valstr, err);
84
expr = g_new0(MuExpr,1);
93
mu_expr_destroy (MuExpr *expr)
96
mu_expr_crit_destroy (expr->_crit);
97
mu_expr_val_destroy (expr->_val);
104
mu_expr_type (MuExpr *expr)
106
g_return_val_if_fail (expr, -1);
108
return mu_expr_crit_types(expr->_crit)[0];
113
mu_expr_get_val (MuExpr *expr)
115
g_return_val_if_fail (expr, NULL);
123
mu_expr_get_crit (MuExpr *expr)
125
g_return_val_if_fail (expr, NULL);
132
mu_expr_list_new (GSList *expr_strs, GError **err)
134
GSList *lst, *cursor;
140
for (cursor = expr_strs, lst=NULL; cursor; cursor=cursor->next) {
142
expr = mu_expr_new ((const char*)cursor->data, err);
144
mu_expr_list_destroy (lst, FALSE);
147
lst = g_slist_append (lst, expr);
156
mu_expr_list_destroy (MuExprList *exprs, gboolean shallow)
160
g_slist_foreach (exprs, (GFunc)mu_expr_destroy, NULL);
162
g_slist_free (exprs);