X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=blobdiff_plain;f=src%2Fttrss_model.c;h=57532566a7ea58a54a8782bdb7dbc67cb4cd3841;hp=2c80c9e73588a377082d8301e0ef5725eb52f732;hb=03759c1d9512afb87624c268481d5c9c499e8275;hpb=4e8c884a282bcf16f486d06164ee187faa8a2610 diff --git a/src/ttrss_model.c b/src/ttrss_model.c index 2c80c9e..5753256 100644 --- a/src/ttrss_model.c +++ b/src/ttrss_model.c @@ -18,44 +18,12 @@ */ #include +#include #include +#include "list.h" #include "ttrss_model.h" -static int list_length(void **list) -{ - int n; - - if (!list) - return 0; - - n = 0; - while (*list) { - n++; - list++; - } - - return n; -} - -static void **list_add(void **list, void *item) -{ - int n; - void **result; - - n = list_length(list); - - result = malloc((n + 1 + 1) * sizeof(void *)); - - if (list) - memcpy(result, list, n * sizeof(void *)); - - result[n] = item; - result[n + 1] = NULL; - - return result; -} - struct headline **headlines_add(struct headline **list, struct headline *h) { return (struct headline **)list_add((void **)list, (void *)h); @@ -103,7 +71,7 @@ struct headline *headline_new(int id, const char *url, const char *title) h->unread = -1; h->excerpt = NULL; h->content = NULL; - + return h; } @@ -161,3 +129,34 @@ void feeds_free(struct feed **feeds) free(feeds); } } + +struct feed *feeds_get_feed(struct feed **feeds, int id) +{ + struct feed **cur; + + if (feeds) + for (cur = feeds; *cur; cur++) + if ((*cur)->id == id) + return *cur; + + return NULL; +} + +struct headline *feeds_get_headline(struct feed **feeds, int id) +{ + struct headline *h; + + if (!feeds) + return NULL; + + while (*feeds) { + h = feed_get_headline(*feeds, id); + + if (h) + return h; + + feeds++; + } + + return NULL; +}