-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagdb_util.lc
100 lines (88 loc) · 2.17 KB
/
tagdb_util.lc
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
92
93
94
95
96
97
98
99
100
#include <assert.h>
#include "log.h"
#include "tag.h"
#include "tagdb.h"
#include "set_ops.h"
#include "tagdb.h"
#include "tagdb_util.h"
#include "util.h"
GList *_tag_intersection(TagDB *db, tagdb_key_t key);
GList *get_tags_list (TagDB *db, tagdb_key_t key)
{
%(log);
if (key_is_empty(key))
{
return tagdb_tags(db);
}
GList *tags = _tag_intersection(db, key);
GList *res = NULL;
LL(tags, it)
{
Tag *t = retrieve_tag(db, TO_S(it->data));
assert(t != NULL);
res = g_list_prepend(res, t);
} LL_END;
g_list_free(tags);
return res;
}
GList *_tag_intersection(TagDB *db, tagdb_key_t key)
{
int skip = 1;
GList *res = NULL;
KL(key, i)
{
file_id_t tid = key_ref(key, i);
GList *this_drawer = file_cabinet_get_drawer_tags(db->files, tid);
this_drawer = g_list_sort(this_drawer, (GCompareFunc) long_cmp);
GList *tmp = NULL;
if (skip)
{
tmp = g_list_copy(this_drawer);
}
else
{
tmp = g_list_intersection(res, this_drawer, (GCompareFunc) long_cmp);
}
g_list_free(this_drawer);
g_list_free(res);
res = tmp;
skip = 0;
} KL_END;
return res;
}
/* Gets all of the files with the given tags
as well as all of the tags below this one
in the tree */
GList *get_files_list (TagDB *db, tagdb_key_t key)
{
GList *res = NULL;
int skip = 1;
if (key_is_empty(key))
{
debug("Getting untagged files");
res = tagdb_untagged_items(db);
}
else
{
KL(key, i)
{
GList *tmp = NULL;
GList *files = NULL;
files = file_cabinet_get_drawer_l(db->files, key_ref(key, i));
files = g_list_sort(files, (GCompareFunc) file_id_cmp);
if (skip)
{
tmp = g_list_copy(files);
}
else
{
tmp = g_list_intersection(res, files, (GCompareFunc) file_id_cmp);
}
g_list_free(res);
g_list_free(files);
res = tmp;
skip = 0;
} KL_END;
}
return res;
}