1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

Make weather.cc more c++-ish (and get rid of a leak in the process)

This commit is contained in:
Pavel Labath 2010-01-13 13:59:24 +01:00
parent c62266a5db
commit b7028cb9e5
2 changed files with 14 additions and 29 deletions

View File

@ -33,6 +33,7 @@
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
#include <mutex> #include <mutex>
#include <string>
#ifdef MATH #ifdef MATH
#include <math.h> #include <math.h>
#endif /* MATH */ #endif /* MATH */
@ -830,8 +831,10 @@ static void weather_process_info(char *p, int p_max_size, char *uri, char *data_
#ifdef BUILD_WEATHER_XOAP #ifdef BUILD_WEATHER_XOAP
/* xoap suffix for weather from weather.com */ /* xoap suffix for weather from weather.com */
static char *xoap_cc = NULL; namespace {
static char *xoap_df = NULL; std::string xoap_cc;
std::string xoap_df;
}
#endif /* BUILD_WEATHER_XOAP */ #endif /* BUILD_WEATHER_XOAP */
static int process_weather_uri(char *uri, char *locID, int dayf UNUSED_ATTR) static int process_weather_uri(char *uri, char *locID, int dayf UNUSED_ATTR)
@ -847,15 +850,14 @@ static int process_weather_uri(char *uri, char *locID, int dayf UNUSED_ATTR)
/* Construct complete uri */ /* Construct complete uri */
#ifdef BUILD_WEATHER_XOAP #ifdef BUILD_WEATHER_XOAP
if (strstr(uri, "xoap.weather.com")) { if (strstr(uri, "xoap.weather.com")) {
if ((dayf == 0) && (xoap_cc != NULL)) { if ((dayf == 0) && (xoap_cc.length() != 0)) {
strcat(uri, locID); strcat(uri, locID);
strcat(uri, xoap_cc); strcat(uri, xoap_cc.c_str());
} else if ((dayf == 1) && (xoap_df != NULL)) { } else if ((dayf == 1) && (xoap_df.length() != 0)) {
strcat(uri, locID); strcat(uri, locID);
strcat(uri, xoap_df); strcat(uri, xoap_df.c_str());
} else { } else {
free(uri); return 0;
uri = NULL;
} }
} else } else
#endif /* BUILD_WEATHER_XOAP */ #endif /* BUILD_WEATHER_XOAP */
@ -886,21 +888,12 @@ void load_xoap_keys(void)
fp = fopen(xoap, "r"); fp = fopen(xoap, "r");
if (fp != NULL) { if (fp != NULL) {
if (fscanf(fp, "%10s %16s", par, key) == 2) { if (fscanf(fp, "%10s %16s", par, key) == 2) {
xoap_cc = (char *) malloc(128 * sizeof(char)); xoap_cc = std::string("?cc=*&link=xoap&prod=xoap&par=")
xoap_df = (char *) malloc(128 * sizeof(char)); + par + "&key=" + key + "&unit=m";
strcpy(xoap_cc, "?cc=*&link=xoap&prod=xoap&par=");
strcat(xoap_cc, par);
strcat(xoap_cc, "&key=");
strcat(xoap_cc, key);
strcat(xoap_cc, "&unit=m");
/* TODO: Use FORECAST_DAYS instead of 5 */ /* TODO: Use FORECAST_DAYS instead of 5 */
strcpy(xoap_df, "?dayf=5&link=xoap&prod=xoap&par="); xoap_df = std::string("?dayf=5&link=xoap&prod=xoap&par=")
strcat(xoap_df, par); + par + "&key=" + key + "&unit=m";
strcat(xoap_df, "&key=");
strcat(xoap_df, key);
strcat(xoap_df, "&unit=m");
} }
fclose(fp); fclose(fp);
} }

View File

@ -31,10 +31,6 @@
#ifndef WEATHER_H_ #ifndef WEATHER_H_
#define WEATHER_H_ #define WEATHER_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Prototypes */ /* Prototypes */
void weather_free_info(void); void weather_free_info(void);
@ -48,8 +44,4 @@ void scan_weather_arg(struct text_object *, const char *, void *);
void print_weather(struct text_object *, char *, int); void print_weather(struct text_object *, char *, int);
void free_weather(struct text_object *); void free_weather(struct text_object *);
#ifdef __cplusplus
}
#endif
#endif /* WEATHER_H_ */ #endif /* WEATHER_H_ */