mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-24 22:15:04 +00:00
New function index_len().
This commit is contained in:
parent
6fd5d14428
commit
83a68d635d
2 changed files with 43 additions and 8 deletions
47
data.c
47
data.c
|
@ -333,6 +333,19 @@ int index_first(const char *fn, char *line, int size)
|
|||
}
|
||||
|
||||
|
||||
int index_len(const char *fn)
|
||||
/* returns the number of elements in an index */
|
||||
{
|
||||
struct stat st;
|
||||
int len = 0;
|
||||
|
||||
if (stat(fn, &st) != -1)
|
||||
len = st.st_size / 33;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
d_char *index_list(const char *fn, int max)
|
||||
/* returns an index as a list */
|
||||
{
|
||||
|
@ -588,31 +601,49 @@ int object_del_if_unref(const char *id)
|
|||
}
|
||||
|
||||
|
||||
d_char *_object_metadata(const char *id, const char *idxsfx)
|
||||
/* returns the content of a metadata index */
|
||||
d_char *_object_index_fn(const char *id, const char *idxsfx)
|
||||
/* returns the filename of an object's index */
|
||||
{
|
||||
xs *fn = _object_fn(id);
|
||||
fn = xs_replace_i(fn, ".json", idxsfx);
|
||||
return index_list(fn, XS_ALL);
|
||||
d_char *fn = _object_fn(id);
|
||||
return xs_replace_i(fn, ".json", idxsfx);
|
||||
}
|
||||
|
||||
|
||||
int object_likes_len(const char *id)
|
||||
/* returns the number of likes (without reading the index) */
|
||||
{
|
||||
xs *fn = _object_index_fn(id, "_l.idx");
|
||||
return index_len(fn);
|
||||
}
|
||||
|
||||
|
||||
int object_announces_len(const char *id)
|
||||
/* returns the number of announces (without reading the index) */
|
||||
{
|
||||
xs *fn = _object_index_fn(id, "_a.idx");
|
||||
return index_len(fn);
|
||||
}
|
||||
|
||||
|
||||
d_char *object_children(const char *id)
|
||||
/* returns the list of an object's children */
|
||||
{
|
||||
return _object_metadata(id, "_c.idx");
|
||||
xs *fn = _object_index_fn(id, "_c.idx");
|
||||
return index_list(fn, XS_ALL);
|
||||
}
|
||||
|
||||
|
||||
d_char *object_likes(const char *id)
|
||||
{
|
||||
return _object_metadata(id, "_l.idx");
|
||||
xs *fn = _object_index_fn(id, "_l.idx");
|
||||
return index_list(fn, XS_ALL);
|
||||
}
|
||||
|
||||
|
||||
d_char *object_announces(const char *id)
|
||||
{
|
||||
return _object_metadata(id, "_a.idx");
|
||||
xs *fn = _object_index_fn(id, "_a.idx");
|
||||
return index_list(fn, XS_ALL);
|
||||
}
|
||||
|
||||
|
||||
|
|
4
snac.h
4
snac.h
|
@ -57,6 +57,7 @@ double mtime_nl(const char *fn, int *n_link);
|
|||
int index_add(const char *fn, const char *md5);
|
||||
int index_del(const char *fn, const char *md5);
|
||||
int index_first(const char *fn, char *buf, int size);
|
||||
int index_len(const char *fn);
|
||||
d_char *index_list(const char *fn, int max);
|
||||
d_char *index_list_desc(const char *fn, int skip, int show);
|
||||
|
||||
|
@ -70,6 +71,9 @@ int object_del(const char *id);
|
|||
int object_del_if_unref(const char *id);
|
||||
int object_admire(const char *id, const char *actor, int like);
|
||||
|
||||
int object_likes_len(const char *id);
|
||||
int object_announces_len(const char *id);
|
||||
|
||||
d_char *object_children(const char *id);
|
||||
d_char *object_likes(const char *id);
|
||||
d_char *object_announces(const char *id);
|
||||
|
|
Loading…
Reference in a new issue