From 4fe70ad0e6e1e48ed8486e6d32d6693e9726441d Mon Sep 17 00:00:00 2001 From: Cesare Tirabassi Date: Mon, 3 Aug 2009 11:49:26 +0200 Subject: [PATCH] weather: change hardcoded constant 5 to FORECAST_DAYS macro --- src/conky.c | 6 +++--- src/text_object.h | 4 +++- src/weather.c | 3 ++- src/weather.h | 17 +++++++++-------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/conky.c b/src/conky.c index b459a1f..df45fa6 100644 --- a/src/conky.c +++ b/src/conky.c @@ -3047,9 +3047,9 @@ static struct text_object *construct_text_object(const char *s, obj->data.weather_forecast.uri = uri; obj->data.weather_forecast.data_type = data_type; - /* Limit the day between 0 (today) and 4 */ - if (day > 4) { - day = 4; + /* Limit the day between 0 (today) and FORECAST_DAYS */ + if (day >= FORECAST_DAYS) { + day = FORECAST_DAYS-1; } obj->data.weather_forecast.day = day; diff --git a/src/text_object.h b/src/text_object.h index f916f18..519c318 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -385,8 +385,10 @@ enum text_object_type { #endif /* RSS */ #ifdef WEATHER OBJ_weather, - OBJ_weather_forecast, #endif /* WEATHER */ +#ifdef XOAP + OBJ_weather_forecast, +#endif /* XOAP */ #ifdef HAVE_LUA OBJ_lua, OBJ_lua_parse, diff --git a/src/weather.c b/src/weather.c index 86b91fa..671d526 100644 --- a/src/weather.c +++ b/src/weather.c @@ -141,7 +141,7 @@ static void parse_df(PWEATHER_FORECAST *res, xmlXPathContextPtr xpathCtx) res->hmid[k] = atoi(content); } xmlFree(content); - if (k++ == 4) break; + if (++k == FORECAST_DAYS) break; } } xmlXPathFreeObject(xpathObj); @@ -766,6 +766,7 @@ void load_xoap_keys(void) strcat(xoap_cc, key); strcat(xoap_cc, "&unit=m"); + /* TODO: Use FORECAST_DAYS instead of 5 */ strcpy(xoap_df, "?dayf=5&link=xoap&prod=xoap&par="); strcat(xoap_df, par); strcat(xoap_df, "&key="); diff --git a/src/weather.h b/src/weather.h index a677332..d70ec19 100644 --- a/src/weather.h +++ b/src/weather.h @@ -50,15 +50,16 @@ typedef struct PWEATHER_ { } PWEATHER; #ifdef XOAP +#define FORECAST_DAYS 5 typedef struct PWEATHER_FORECAST_ { - int hi[5]; - int low[5]; - char icon[5][3]; - char xoap_t[5][32]; - int wind_s[5]; - int wind_d[5]; - int hmid[5]; - int ppcp[5]; + int hi[FORECAST_DAYS]; + int low[FORECAST_DAYS]; + char icon[FORECAST_DAYS][3]; + char xoap_t[FORECAST_DAYS][32]; + int wind_s[FORECAST_DAYS]; + int wind_d[FORECAST_DAYS]; + int hmid[FORECAST_DAYS]; + int ppcp[FORECAST_DAYS]; } PWEATHER_FORECAST; #endif /* XOAP */ -- 1.7.9.5