1
/*
2
 * Copyright 2008-2011 Various Authors
3
 * Copyright 2005 Timo Hirvonen
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as
7
 * published by the Free Software Foundation; either version 2 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
#ifndef EXPR_H
20
#define EXPR_H
21
22
#include "track_info.h"
23
#include "list.h"
24
25
enum { OP_LT, OP_LE, OP_EQ, OP_GE, OP_GT, OP_NE };
26
#define NR_OPS (OP_NE + 1)
27
28
enum expr_type {
29
	EXPR_AND,
30
	EXPR_OR,
31
32
	EXPR_NOT,
33
34
	EXPR_STR,
35
	EXPR_INT,
36
	EXPR_BOOL
37
};
38
#define NR_EXPRS (EXPR_BOOL + 1)
39
40
struct expr {
41
	struct expr *left, *right, *parent;
42
	enum expr_type type;
43
	char *key;
44
	union {
45
		struct {
46
			struct list_head glob_head;
47
			enum {
48
				SOP_EQ = OP_EQ,
49
				SOP_NE = OP_NE
50
			} op;
51
		} estr;
52
		struct {
53
			int val;
54
			enum {
55
				IOP_LT = OP_LT,
56
				IOP_LE = OP_LE,
57
				IOP_EQ = OP_EQ,
58
				IOP_GE = OP_GE,
59
				IOP_GT = OP_GT,
60
				IOP_NE = OP_NE
61
			} op;
62
		} eint;
63
	};
64
};
65
66
struct expr *expr_parse(const char *str);
67
int expr_check_leaves(struct expr **exprp, const char *(*get_filter)(const char *name));
68
int expr_eval(struct expr *expr, struct track_info *ti);
69
void expr_free(struct expr *expr);
70
const char *expr_error(void);
71
int expr_is_short(const char *str);
72
73
unsigned int expr_get_match_type(struct expr *expr);
74
/* "harmless" expressions will reduce filter results when adding characters at the beginning/end */
75
int expr_is_harmless(const struct expr *expr);
76
77
#endif