weather: change hardcoded constant 5 to FORECAST_DAYS macro
authorCesare Tirabassi <norsetto@ubuntu.com>
Mon, 3 Aug 2009 09:49:26 +0000 (11:49 +0200)
committerCesare Tirabassi <norsetto@ubuntu.com>
Mon, 3 Aug 2009 09:49:26 +0000 (11:49 +0200)
src/conky.c
src/text_object.h
src/weather.c
src/weather.h

index b459a1f..df45fa6 100644 (file)
@@ -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;
 
index f916f18..519c318 100644 (file)
@@ -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,
index 86b91fa..671d526 100644 (file)
@@ -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=");
index a677332..d70ec19 100644 (file)
@@ -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 */