1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-04 13:08:31 +00:00

rss: move init and print code into rss.c

This commit is contained in:
Phil Sutter 2009-10-04 19:04:08 +02:00
parent ddca4aac68
commit 6a2f58a25c
4 changed files with 36 additions and 25 deletions

View File

@ -1842,11 +1842,7 @@ static void generate_text_internal(char *p, int p_max_size,
#endif
#ifdef RSS
OBJ(rss) {
if (obj->data.rss.uri != NULL) {
rss_process_info(p, p_max_size, obj->data.rss.uri, obj->data.rss.action, obj->data.rss.act_par, obj->data.rss.interval, obj->data.rss.nrspaces);
} else {
NORM_ERR("error processing RSS data");
}
rss_print_info(obj, p, p_max_size);
}
#endif
#ifdef WEATHER

View File

@ -1463,23 +1463,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
#endif
#ifdef RSS
END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
float interval = 0;
int argc, act_par = 0;
unsigned int nrspaces = 0;
char *uri = (char *) malloc(128 * sizeof(char));
char *action = (char *) malloc(64 * sizeof(char));
argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
&act_par, &nrspaces);
if (argc >= 3) {
obj->data.rss.uri = uri;
obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
obj->data.rss.action = action;
obj->data.rss.act_par = act_par;
obj->data.rss.nrspaces = nrspaces;
} else {
NORM_ERR("wrong number of arguments for $rss");
}
rss_scan_arg(obj, arg);
#endif
#ifdef WEATHER
END OBJ_ARG(weather, 0, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]")

View File

@ -27,6 +27,7 @@
#include "conky.h"
#include "logging.h"
#include "prss.h"
#include "text_object.h"
#include "ccurl_thread.h"
#include <time.h>
#include <assert.h>
@ -44,7 +45,7 @@ void rss_free_info(void)
ccurl_free_locations(&locations_head);
}
void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
static void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
act_par, int interval, unsigned int nrspaces)
{
PRSS *data;
@ -147,3 +148,33 @@ void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
timed_thread_unlock(curloc->p_timed_thread);
}
void rss_scan_arg(struct text_object *obj, const char *arg)
{
float interval = 0;
int argc, act_par = 0;
unsigned int nrspaces = 0;
char *uri = (char *) malloc(128 * sizeof(char));
char *action = (char *) malloc(64 * sizeof(char));
argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
&act_par, &nrspaces);
if (argc < 3) {
NORM_ERR("wrong number of arguments for $rss");
return;
}
obj->data.rss.uri = uri;
obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
obj->data.rss.action = action;
obj->data.rss.act_par = act_par;
obj->data.rss.nrspaces = nrspaces;
}
void rss_print_info(struct text_object *obj, char *p, int p_max_size)
{
if (!obj->data.rss.uri) {
NORM_ERR("error processing RSS data");
return;
}
rss_process_info(p, p_max_size, obj->data.rss.uri, obj->data.rss.action,
obj->data.rss.act_par, obj->data.rss.interval, obj->data.rss.nrspaces);
}

View File

@ -5,8 +5,8 @@
#include "prss.h"
void rss_scan_arg(struct text_object *, const char *);
void rss_print_info(struct text_object *, char *, int);
void rss_free_info(void);
void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
act_par, int interval, unsigned int nrspaces);
#endif /*RSS_H_*/