mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
Code formatting.
This commit is contained in:
parent
6f1c578e70
commit
4139ec096f
190
src/weather.c
190
src/weather.c
@ -133,69 +133,69 @@ int rel_humidity(int dew_point, int air) {
|
|||||||
static void parse_cc(PWEATHER *res, xmlNodePtr cc)
|
static void parse_cc(PWEATHER *res, xmlNodePtr cc)
|
||||||
{
|
{
|
||||||
|
|
||||||
xmlNodePtr cur = NULL;
|
xmlNodePtr cur = NULL;
|
||||||
|
|
||||||
for (cur = cc; cur; cur = cur->next) {
|
for (cur = cc; cur; cur = cur->next) {
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
if (!xmlStrcmp(cur->name, (const xmlChar *) "lsup")) {
|
if (!xmlStrcmp(cur->name, (const xmlChar *) "lsup")) {
|
||||||
strncpy(res->lastupd, (char *)cur->children->content, 31);
|
strncpy(res->lastupd, (char *)cur->children->content, 31);
|
||||||
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "tmp")) {
|
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "tmp")) {
|
||||||
res->temp = atoi((char *)cur->children->content);
|
res->temp = atoi((char *)cur->children->content);
|
||||||
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "t")) {
|
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "t")) {
|
||||||
if(res->xoap_t[0] == '\0') {
|
if(res->xoap_t[0] == '\0') {
|
||||||
strncpy(res->xoap_t, (char *)cur->children->content, 31);
|
strncpy(res->xoap_t, (char *)cur->children->content, 31);
|
||||||
|
}
|
||||||
|
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "r")) {
|
||||||
|
res->bar = atoi((char *)cur->children->content);
|
||||||
|
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "s")) {
|
||||||
|
res->wind_s = atoi((char *)cur->children->content);
|
||||||
|
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "d")) {
|
||||||
|
if (isdigit((char)cur->children->content[0])) {
|
||||||
|
res->wind_d = atoi((char *)cur->children->content);
|
||||||
|
}
|
||||||
|
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "hmid")) {
|
||||||
|
res->hmid = atoi((char *)cur->children->content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parse_cc(res, cur->children);
|
||||||
}
|
}
|
||||||
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "r")) {
|
return;
|
||||||
res->bar = atoi((char *)cur->children->content);
|
|
||||||
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "s")) {
|
|
||||||
res->wind_s = atoi((char *)cur->children->content);
|
|
||||||
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "d")) {
|
|
||||||
if (isdigit((char)cur->children->content[0])) {
|
|
||||||
res->wind_d = atoi((char *)cur->children->content);
|
|
||||||
}
|
|
||||||
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "hmid")) {
|
|
||||||
res->hmid = atoi((char *)cur->children->content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parse_cc(res, cur->children);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_weather_xml(PWEATHER *res, const char *data)
|
static void parse_weather_xml(PWEATHER *res, const char *data)
|
||||||
{
|
{
|
||||||
xmlDocPtr doc;
|
xmlDocPtr doc;
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
|
|
||||||
if (!(doc = xmlReadMemory(data, strlen(data), "", NULL, 0))) {
|
if (!(doc = xmlReadMemory(data, strlen(data), "", NULL, 0))) {
|
||||||
ERR("weather: can't read xml data");
|
ERR("weather: can't read xml data");
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
cur = xmlDocGetRootElement(doc);
|
|
||||||
|
|
||||||
while(cur) {
|
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
|
||||||
if (!xmlStrcmp(cur->name, (const xmlChar *) "weather")) {
|
|
||||||
cur = cur->children;
|
|
||||||
while (cur != NULL) {
|
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
|
||||||
if (!xmlStrcmp(cur->name, (const xmlChar *) "cc")) {
|
|
||||||
parse_cc(res, cur->children);
|
|
||||||
xmlFreeDoc(doc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
ERR("weather: incorrect xml data");
|
cur = xmlDocGetRootElement(doc);
|
||||||
xmlFreeDoc(doc);
|
|
||||||
return ;
|
while(cur) {
|
||||||
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
|
if (!xmlStrcmp(cur->name, (const xmlChar *) "weather")) {
|
||||||
|
cur = cur->children;
|
||||||
|
while (cur != NULL) {
|
||||||
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
|
if (!xmlStrcmp(cur->name, (const xmlChar *) "cc")) {
|
||||||
|
parse_cc(res, cur->children);
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
ERR("weather: incorrect xml data");
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
#endif /* XOAP */
|
#endif /* XOAP */
|
||||||
|
|
||||||
@ -491,45 +491,45 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
|
|
||||||
static void parse_weather(PWEATHER *res, const char *data)
|
static void parse_weather(PWEATHER *res, const char *data)
|
||||||
{
|
{
|
||||||
//Reset results
|
//Reset results
|
||||||
memset(res, 0, sizeof(PWEATHER));
|
memset(res, 0, sizeof(PWEATHER));
|
||||||
|
|
||||||
#ifdef XOAP
|
#ifdef XOAP
|
||||||
//Check if it is an xml file
|
//Check if it is an xml file
|
||||||
if ( strncmp(data, "<?xml ", 6) == 0 ) {
|
if ( strncmp(data, "<?xml ", 6) == 0 ) {
|
||||||
parse_weather_xml(res, data);
|
parse_weather_xml(res, data);
|
||||||
} else
|
} else
|
||||||
#endif /* XOAP */
|
#endif /* XOAP */
|
||||||
{
|
{
|
||||||
//We assume its a text file
|
//We assume its a text file
|
||||||
char s_tmp[256];
|
char s_tmp[256];
|
||||||
const char delim[] = " ";
|
const char delim[] = " ";
|
||||||
|
|
||||||
//Divide time stamp and metar data
|
//Divide time stamp and metar data
|
||||||
if (sscanf(data, "%[^'\n']\n%[^'\n']", res->lastupd, s_tmp) == 2) {
|
if (sscanf(data, "%[^'\n']\n%[^'\n']", res->lastupd, s_tmp) == 2) {
|
||||||
|
|
||||||
//Process all tokens
|
//Process all tokens
|
||||||
char *p_tok = NULL;
|
char *p_tok = NULL;
|
||||||
char *p_save = NULL;
|
char *p_save = NULL;
|
||||||
|
|
||||||
if ((strtok_r(s_tmp, delim, &p_save)) != NULL) {
|
if ((strtok_r(s_tmp, delim, &p_save)) != NULL) {
|
||||||
|
|
||||||
//Jump first token, must be icao
|
//Jump first token, must be icao
|
||||||
p_tok = strtok_r(NULL, delim, &p_save);
|
p_tok = strtok_r(NULL, delim, &p_save);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
parse_token(res, p_tok);
|
parse_token(res, p_tok);
|
||||||
p_tok = strtok_r(NULL, delim, &p_save);
|
p_tok = strtok_r(NULL, delim, &p_save);
|
||||||
|
|
||||||
} while (p_tok != NULL);
|
} while (p_tok != NULL);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fetch_weather_info(location *curloc)
|
void fetch_weather_info(location *curloc)
|
||||||
@ -604,25 +604,25 @@ void process_weather_info(char *p, int p_max_size, char *uri, char *data_type, i
|
|||||||
temp_print(p, p_max_size, curloc->data.temp, TEMP_CELSIUS);
|
temp_print(p, p_max_size, curloc->data.temp, TEMP_CELSIUS);
|
||||||
} else if (strcmp(data_type, "cloud_cover") == EQUAL) {
|
} else if (strcmp(data_type, "cloud_cover") == EQUAL) {
|
||||||
#ifdef XOAP
|
#ifdef XOAP
|
||||||
if (curloc->data.xoap_t[0] != '\0') {
|
if (curloc->data.xoap_t[0] != '\0') {
|
||||||
strncpy(p, curloc->data.xoap_t, p_max_size);
|
strncpy(p, curloc->data.xoap_t, p_max_size);
|
||||||
} else
|
} else
|
||||||
#endif /* XOAP */
|
#endif /* XOAP */
|
||||||
if (curloc->data.cc == 0) {
|
if (curloc->data.cc == 0) {
|
||||||
strncpy(p, "", p_max_size);
|
strncpy(p, "", p_max_size);
|
||||||
} else if (curloc->data.cc < 3) {
|
} else if (curloc->data.cc < 3) {
|
||||||
strncpy(p, "clear", p_max_size);
|
strncpy(p, "clear", p_max_size);
|
||||||
} else if (curloc->data.cc < 5) {
|
} else if (curloc->data.cc < 5) {
|
||||||
strncpy(p, "partly cloudy", p_max_size);
|
strncpy(p, "partly cloudy", p_max_size);
|
||||||
} else if (curloc->data.cc == 5) {
|
} else if (curloc->data.cc == 5) {
|
||||||
strncpy(p, "cloudy", p_max_size);
|
strncpy(p, "cloudy", p_max_size);
|
||||||
} else if (curloc->data.cc == 6) {
|
} else if (curloc->data.cc == 6) {
|
||||||
strncpy(p, "overcast", p_max_size);
|
strncpy(p, "overcast", p_max_size);
|
||||||
} else if (curloc->data.cc == 7) {
|
} else if (curloc->data.cc == 7) {
|
||||||
strncpy(p, "towering cumulus", p_max_size);
|
strncpy(p, "towering cumulus", p_max_size);
|
||||||
} else {
|
} else {
|
||||||
strncpy(p, "cumulonimbus", p_max_size);
|
strncpy(p, "cumulonimbus", p_max_size);
|
||||||
}
|
}
|
||||||
} else if (strcmp(data_type, "pressure") == EQUAL) {
|
} else if (strcmp(data_type, "pressure") == EQUAL) {
|
||||||
snprintf(p, p_max_size, "%d", curloc->data.bar);
|
snprintf(p, p_max_size, "%d", curloc->data.bar);
|
||||||
} else if (strcmp(data_type, "wind_speed") == EQUAL) {
|
} else if (strcmp(data_type, "wind_speed") == EQUAL) {
|
||||||
|
@ -30,28 +30,28 @@
|
|||||||
|
|
||||||
/* WEATHER data */
|
/* WEATHER data */
|
||||||
typedef struct PWEATHER_ {
|
typedef struct PWEATHER_ {
|
||||||
char lastupd[32];
|
char lastupd[32];
|
||||||
#ifdef XOAP
|
#ifdef XOAP
|
||||||
char xoap_t[32];
|
char xoap_t[32];
|
||||||
/*
|
/*
|
||||||
* TODO:
|
* TODO:
|
||||||
* Is it worth investigating about using icons from weather.com?
|
* Is it worth investigating about using icons from weather.com?
|
||||||
* We could use them for data from noaa as well.
|
* We could use them for data from noaa as well.
|
||||||
* They can display nicely with cimlib_add_image (with appropriate
|
* They can display nicely with cimlib_add_image (with appropriate
|
||||||
* #ifdefs on imlib2 and x11), and an additional input argoment for position.
|
* #ifdefs on imlib2 and x11), and an additional input argoment for position.
|
||||||
|
|
||||||
char icon[3];
|
char icon[3];
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#endif /* XOAP */
|
#endif /* XOAP */
|
||||||
int temp;
|
int temp;
|
||||||
int dew;
|
int dew;
|
||||||
int cc;
|
int cc;
|
||||||
int bar;
|
int bar;
|
||||||
int wind_s;
|
int wind_s;
|
||||||
int wind_d;
|
int wind_d;
|
||||||
int hmid;
|
int hmid;
|
||||||
int wc;
|
int wc;
|
||||||
} PWEATHER;
|
} PWEATHER;
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
|
Loading…
Reference in New Issue
Block a user