mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 14:35:04 +00:00
Reimplemented index_list_desc() by way of index_desc_first() and index_desc_next().
This commit is contained in:
parent
78f383f025
commit
5921ec57f6
2 changed files with 8 additions and 16 deletions
22
data.c
22
data.c
|
@ -651,26 +651,16 @@ xs_list *index_list_desc(const char *fn, int skip, int show)
|
|||
{
|
||||
xs_list *list = xs_list_new();
|
||||
FILE *f;
|
||||
int n = 0;
|
||||
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
flock(fileno(f), LOCK_SH);
|
||||
char md5[33];
|
||||
|
||||
char line[256];
|
||||
if (index_desc_first(f, md5, skip)) {
|
||||
int n = 1;
|
||||
|
||||
/* move to the end minus one entry (or more, if skipping entries) */
|
||||
if (!fseek(f, 0, SEEK_END) && !fseek(f, (skip + 1) * -33, SEEK_CUR)) {
|
||||
while (n < show && fgets(line, sizeof(line), f) != NULL) {
|
||||
if (line[0] != '-') {
|
||||
line[32] = '\0';
|
||||
list = xs_list_append(list, line);
|
||||
n++;
|
||||
}
|
||||
|
||||
/* move backwards 2 entries */
|
||||
if (fseek(f, -66, SEEK_CUR) == -1)
|
||||
break;
|
||||
}
|
||||
do {
|
||||
list = xs_list_append(list, md5);
|
||||
} while (n++ < show && index_desc_next(f, md5));
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
|
2
snac.h
2
snac.h
|
@ -101,6 +101,8 @@ int index_gc(const char *fn);
|
|||
int index_first(const char *fn, char *buf, int size);
|
||||
int index_len(const char *fn);
|
||||
xs_list *index_list(const char *fn, int max);
|
||||
int index_desc_next(FILE *f, char md5[33]);
|
||||
int index_desc_first(FILE *f, char md5[33], int skip);
|
||||
xs_list *index_list_desc(const char *fn, int skip, int show);
|
||||
|
||||
int object_add(const char *id, const xs_dict *obj);
|
||||
|
|
Loading…
Reference in a new issue