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