From ac57c3dcca0820f1b915929bc5ea80faacf6b22d Mon Sep 17 00:00:00 2001 From: DogeyStamp Date: Wed, 22 Sep 2021 18:50:42 -0400 Subject: [PATCH] Improve documentation --- minrss.c | 4 ++++ net.c | 11 ++++++++++- xml.c | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/minrss.c b/minrss.c index 0ed0227..497be5e 100644 --- a/minrss.c +++ b/minrss.c @@ -11,6 +11,8 @@ void itemAction(itemStruct *item, const char *folder) { + // Receives a link list of articles to process. + itemStruct *cur = item; unsigned long long int newItems = 0; @@ -71,6 +73,8 @@ itemAction(itemStruct *item, const char *folder) void finish(char *url, long responseCode) { + // Executed after a download finishes + if (responseCode == 200) logMsg(4, "Finished downloading %s\n", url); else if (!responseCode) diff --git a/net.c b/net.c index 99657d3..b6dcf3b 100644 --- a/net.c +++ b/net.c @@ -12,6 +12,8 @@ static CURLM *multiHandle; int initCurl() { + // Initialise the curl handle. + curl_global_init(CURL_GLOBAL_ALL); multiHandle = curl_multi_init(); @@ -21,6 +23,8 @@ initCurl() static size_t writeCallback(void *ptr, size_t size, size_t nmemb, void *data) { + // Write blocks of data to the output. + size_t realsize = size * nmemb; outputStruct *mem = (outputStruct*) data; @@ -40,6 +44,8 @@ writeCallback(void *ptr, size_t size, size_t nmemb, void *data) int createRequest(const char* url, outputStruct *output) { + // Create the curl request for an URL. + CURL *requestHandle = curl_easy_init(); if (!requestHandle) @@ -75,6 +81,8 @@ createRequest(const char* url, outputStruct *output) int performRequests(void callback(char *, long)) { + // Perform all the curl requests. + int runningRequests; do { @@ -101,7 +109,8 @@ performRequests(void callback(char *, long)) curl_easy_cleanup(requestHandle); } } - // > 0 because curl puts negative numbers when there's broken requests + + // > 0 because curl puts negative numbers when there's broken requests } while (runningRequests > 0); curl_multi_cleanup(multiHandle); diff --git a/xml.c b/xml.c index 54c8368..ea56e99 100644 --- a/xml.c +++ b/xml.c @@ -14,6 +14,8 @@ void freeItem(itemStruct *item) { + // Free the memory used by an article. + char **mems[] = { &item->title, &item->link, @@ -42,6 +44,8 @@ parseXml(xmlDocPtr doc, const char *feedName, void itemAction(itemStruct *, const char *)) { + // Parse the XML in a single document. + if (!feedName || !feedName[0]) { logMsg(1, "Missing feed name, please set one.\n"); return 1; @@ -73,6 +77,7 @@ parseXml(xmlDocPtr doc, logMsg(1, "Invalid RSS syntax. Skipping...\n"); } + // Pointer to an article xml tag xmlNodePtr cur = channel->children; itemStruct *prev = NULL; @@ -84,6 +89,7 @@ parseXml(xmlDocPtr doc, if (TAGIS(cur, "item")) { itemStruct *item = ecalloc(1, sizeof(itemStruct)); + // Build a linked list of item structs to pass to itemAction() item->next = prev; prev = item; @@ -183,6 +189,8 @@ readDoc(char *content, const char *feedName, void itemAction(itemStruct *, const char *)) { + // Initialize the XML document, read it, then free it + xmlDocPtr doc; doc = xmlReadMemory(content, strlen(content), "noname.xml", NULL, 0);