~ubuntu-branches/ubuntu/quantal/maildir-utils/quantal

« back to all changes in this revision

Viewing changes to find/mu-expr.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-01-19 20:12:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100119201243-d8qmzgxgexhy1bs0
Tags: 0.6~beta1-1
* new upstream release 0.6-beta
  - that merges the several different programs under one binary mu
  - no sqlite storage is used anymore
* debian packaging changes:
  - debian/patches
    . remove all patches
  - remove debian/HOWTO (upstream document) it is completely outdated
  - debian/control:
    . adjust build-dep for gmime-2.4
    . remove build-dep on quilt and sqlite
    . adjust the description to new reality
  - debian/rules:
    . do not try to install doc files that are not present anymore
    . disable quilt adaptions
  - add debian/NEWS that explains that the separate programs are gone

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
** Copyright (C) 2008 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
3
 
**
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.
8
 
**
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.
13
 
**
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.
17
 
**
18
 
*/
19
 
 
20
 
#include <glib.h>
21
 
#include <string.h>
22
 
 
23
 
#include "mu-expr.h"
24
 
 
25
 
struct _MuExpr {
26
 
        MuExprCrit *_crit; /* criteria, the part before the ':' */
27
 
        MuExprVal  *_val;  /* value, the part after the ':' */
28
 
};
29
 
 
30
 
MuExpr *
31
 
mu_expr_new (const char* str, GError **err)
32
 
{
33
 
        MuExpr *expr;
34
 
        MuExprVal *val;
35
 
        MuExprCrit *crit;
36
 
 
37
 
        char *colon;
38
 
        char *valstr, *critstr;
39
 
 
40
 
        g_return_val_if_fail (str, NULL);
41
 
 
42
 
        /* the first ':' separates crit and val */
43
 
 
44
 
        colon = strchr (str, ':');
45
 
        if (!colon) {
46
 
                g_set_error (err, 0,
47
 
                             MU_EXPR_ERROR_NO_COLON,
48
 
                             "expected: expression with colon, but got: %s",
49
 
                             str);
50
 
                return NULL;
51
 
        }
52
 
 
53
 
        if (colon == str) { /* expr starts with colon -- not good */
54
 
                g_set_error (err, 0,
55
 
                             MU_EXPR_ERROR_NO_CRITERIA,
56
 
                             "expected: expression with criteria, but got: %s",
57
 
                             str);
58
 
                return NULL;
59
 
        }
60
 
 
61
 
        if (colon[1] == '\0') { /* expr end with colon -- not good either */
62
 
                g_set_error (err, 0,
63
 
                             MU_EXPR_ERROR_NO_VALUE,
64
 
                             "expected: expression with value, but got: %s",
65
 
                             str);
66
 
                return NULL;
67
 
        }
68
 
 
69
 
        critstr = g_strndup (str, colon - str);
70
 
        crit = mu_expr_crit_new (critstr, err);
71
 
        g_free(critstr);
72
 
        if (!crit)
73
 
                return NULL;
74
 
 
75
 
        valstr  = g_strdup  (colon + 1);
76
 
 
77
 
        /* the first criterion determines the expression type */
78
 
        val = mu_expr_val_new (mu_expr_crit_types(crit)[0],valstr, err);
79
 
        
80
 
        g_free (valstr);
81
 
        if (!val)
82
 
                return NULL;
83
 
 
84
 
        expr = g_new0(MuExpr,1);
85
 
        expr->_crit = crit;
86
 
        expr->_val  = val;
87
 
 
88
 
        return expr;
89
 
}
90
 
 
91
 
 
92
 
void
93
 
mu_expr_destroy (MuExpr *expr)
94
 
{
95
 
        if (expr) {
96
 
                mu_expr_crit_destroy (expr->_crit);
97
 
                mu_expr_val_destroy  (expr->_val);
98
 
                g_free (expr);
99
 
        }
100
 
}
101
 
 
102
 
 
103
 
MuExprType
104
 
mu_expr_type (MuExpr *expr)
105
 
{
106
 
        g_return_val_if_fail (expr, -1);
107
 
 
108
 
        return mu_expr_crit_types(expr->_crit)[0];
109
 
 
110
 
}
111
 
 
112
 
MuExprVal*
113
 
mu_expr_get_val  (MuExpr *expr)
114
 
{
115
 
        g_return_val_if_fail (expr, NULL);
116
 
 
117
 
        return expr->_val;
118
 
 
119
 
}
120
 
 
121
 
 
122
 
MuExprCrit*
123
 
mu_expr_get_crit (MuExpr *expr)
124
 
{
125
 
        g_return_val_if_fail (expr, NULL);
126
 
 
127
 
        return expr->_crit;
128
 
}
129
 
 
130
 
 
131
 
MuExprList*
132
 
mu_expr_list_new (GSList *expr_strs, GError **err)
133
 
{
134
 
        GSList *lst, *cursor;
135
 
 
136
 
        if (!expr_strs)
137
 
                return NULL;
138
 
 
139
 
        cursor = expr_strs;
140
 
        for (cursor = expr_strs, lst=NULL; cursor; cursor=cursor->next) {
141
 
                MuExpr* expr;
142
 
                expr = mu_expr_new ((const char*)cursor->data, err);
143
 
                if (!expr) {
144
 
                        mu_expr_list_destroy (lst, FALSE);
145
 
                        return NULL;
146
 
                } else
147
 
                        lst = g_slist_append (lst, expr);
148
 
        }
149
 
 
150
 
        return lst;
151
 
}
152
 
 
153
 
 
154
 
 
155
 
void
156
 
mu_expr_list_destroy (MuExprList *exprs, gboolean shallow)
157
 
{
158
 
        if (exprs) {
159
 
                if (!shallow)
160
 
                        g_slist_foreach (exprs, (GFunc)mu_expr_destroy, NULL);
161
 
 
162
 
                g_slist_free (exprs);
163
 
        }
164
 
}