terms.h 1.87 KB
Newer Older
Bernhard Link's avatar
Bernhard Link committed
1 2
#ifndef REPREPRO_TERMS_H
#define REPREPRO_TERMS_H
3 4 5

enum term_comparison { tc_none=0, tc_equal, tc_strictless, tc_strictmore,
				  tc_lessorequal, tc_moreorequal,
6
				  tc_notequal, tc_globmatch, tc_notglobmatch};
7

8 9
struct term_special;

10 11 12 13
typedef struct term_atom {
	/* global list to allow freeing them all */
	struct term_atom *next;
	/* the next atom to look at if this is true, resp. false,
14
	 * nextiftrue  == NULL means total result is true,
15
	 * nextiffalse == NULL means total result is false. */
16
	/*@dependent@*/struct term_atom *nextiftrue, *nextiffalse;
17
	bool negated, isspecial;
18
	/* architecture requirements */
19
	bool architectures_negated;
20
	struct strlist architectures;
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
	/* version/value requirement */
	enum term_comparison comparison;
	union {
		struct {
			/* package-name or key */
			char *key;
			/* version/value requirement */
			char *comparewith;
		} generic;
		struct {
			const struct term_special *type;
			struct compare_with {
				void *pointer;
				long number;
			} comparewith;
		} special;
	};
38 39
} term;

40 41 42
struct term_special {
	const char *name;
	retvalue (*parse)(enum term_comparison, const char *, size_t len, struct compare_with *);
43
	bool (*compare)(enum term_comparison, const struct compare_with *, void*, void*);
44 45 46
	void (*done)(enum term_comparison, struct compare_with *);
};

47 48 49 50 51 52 53 54 55 56 57 58
/* | is allowed in terms */
#define T_OR		0x01
/* () are allowed to build sub-expressions */
#define T_BRACKETS	0x02
/* expressions may be negated */
#define T_NEGATION	0x04
/* (<rel> <version>) is allowed */
#define T_VERSION 	0x10
/* [archlist] is allowed */
#define T_ARCHITECTURES 0x20
/* (!= value) is allowed */
#define T_NOTEQUAL	0x40
59 60
/* (% <globpattern>) and (!% globpattern) are allowed */
#define T_GLOBMATCH	0x80
61

62 63
retvalue term_compile(/*@out@*/term **, const char * /*formula*/, int /*options*/, /*@null@*/const struct term_special *specials);
void term_free(/*@null@*//*@only@*/term *);
64 65

#endif