From 5eef83d90a38e4bd225bf56115de0f3445ce120d Mon Sep 17 00:00:00 2001 From: Cesare Tirabassi Date: Sat, 18 Jul 2009 21:29:27 +0200 Subject: [PATCH] add compilation switch --enable-xoap to be able to use www.weather.com as a source of weather data --- ChangeLog | 6 ++++++ configure.ac.in | 18 ++++++++++++++---- src/conky.c | 10 +++++----- src/weather.c | 34 ++++++++++++++++++++++------------ src/weather.h | 18 ++++++++++-------- 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8827a7c..f458f9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ 2009-07-18 + * add compilation switch --enable-xoap to be able to use + www.weather.com as a source of weather data (this avoids adding + libxml2 as a required dependency for users that wish to use noaa + and not weather.com) + +2009-07-18 * www.weather.com can now be used as well as a source of weather data 2009-07-11 diff --git a/configure.ac.in b/configure.ac.in index 9c9facd..697e670 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -353,13 +353,24 @@ dnl AC_ARG_ENABLE([weather], AC_HELP_STRING([--enable-weather], [enable if you want weather support @<:@default=no@:>@]), [want_weather="$enableval"], [want_weather=no]) + +AC_ARG_ENABLE([xoap], + AC_HELP_STRING([--enable-xoap], [enable if you want weather xoap support @<:@default=no@:>@]), + [want_xoap="$enableval"], [want_xoap=no]) # AM_CONDITIONAL(BUILD_WEATHER, test x$want_weather = xyes) if test x$want_weather = xyes; then - PKG_CHECK_MODULES([libxml2], libxml-2.0) + AM_CONDITIONAL(BUILD_XOAP, test x$want_xoap = xyes) + if test x$want_xoap = xyes; then + PKG_CHECK_MODULES([libxml2], libxml-2.0) + conky_CFLAGS="$conky_CFLAGS $libxml2_CFLAGS" + conky_LIBS="$conky_LIBS $libxml2_LIBS" + AC_DEFINE(XOAP, 1, [Define if you want weather xoap support]) + AC_DEFINE(XOAP_FILE, "$HOME/.xoaprc", [User xoap keys file]) + fi PKG_CHECK_MODULES([libcurl], libcurl) - conky_CFLAGS="$conky_CFLAGS $libxml2_CFLAGS $libcurl_CFLAGS" - conky_LIBS="$conky_LIBS $libxml2_LIBS $libcurl_LIBS" + conky_CFLAGS="$conky_CFLAGS $libcurl_CFLAGS" + conky_LIBS="$conky_LIBS $libcurl_LIBS" AC_DEFINE(WEATHER, 1, [Define if you want weather support]) fi @@ -707,7 +718,6 @@ dnl AC_DEFINE(DEFAULTNETDEV, "eth0", [Default networkdevice]) AC_DEFINE(CONFIG_FILE, "$HOME/.conkyrc", [Configfile of the user]) -AC_DEFINE(XOAP_FILE, "$HOME/.xoaprc", [User xoap keys file]) AC_DEFINE(MAX_SPECIALS_DEFAULT, 512, [Default maximum number of special things, e.g. fonts, offsets, aligns, etc.]) AC_DEFINE(MAX_USER_TEXT_DEFAULT, 16384, [Default maximum size of config TEXT buffer, i.e. below TEXT line.]) AC_DEFINE(DEFAULT_TEXT_BUFFER_SIZE, 256, [Default size used for temporary, static text buffers]) diff --git a/src/conky.c b/src/conky.c index 84edfb3..2bf028c 100644 --- a/src/conky.c +++ b/src/conky.c @@ -4673,7 +4673,7 @@ static void generate_text_internal(char *p, int p_max_size, if( obj->data.weather.uri != NULL ) { process_weather_info(p, p_max_size, obj->data.weather.uri, obj->data.weather.data_type, obj->data.weather.interval); } else { - strncpy(p, "invalid xoap keys file", p_max_size); + strncpy(p, "either invalid xoap keys file or compiled without xoap support", p_max_size); } } #endif @@ -8912,7 +8912,7 @@ static void load_config_file_x11(const char *f) } #endif /* X11 */ -#ifdef WEATHER +#if defined(WEATHER) && defined(XOAP) /* * TODO: make the xoap keys file readable from the config file * make the keys directly readable from the config file @@ -8946,7 +8946,7 @@ static void load_xoap_keys(void) free(par); free(key); } -#endif /* WEATHER */ +#endif /* WEATHER && XOAP */ static void print_help(const char *prog_name) { printf("Usage: %s [OPTION]...\n" @@ -9332,10 +9332,10 @@ int main(int argc, char **argv) } } -#ifdef WEATHER +#if defined(WEATHER) && defined(XOAP) /* Load xoap keys, if existing */ load_xoap_keys(); -#endif /* WEATHER */ +#endif /* WEATHER && XOAP */ #ifdef HAVE_SYS_INOTIFY_H inotify_fd = inotify_init(); diff --git a/src/weather.c b/src/weather.c index 6d29027..737c33c 100644 --- a/src/weather.c +++ b/src/weather.c @@ -38,7 +38,9 @@ #include #include #include +#ifdef XOAP #include +#endif /* XOAP */ /* Possible sky conditions */ #define NUM_CC_CODES 6 @@ -58,7 +60,7 @@ const char *WM_CODES[NUM_WM_CODES] = { const char *WC_CODES[NUM_WC_CODES] = { "DZ", "RA", "GR", "GS", "SN", "SG", "FG", "HZ", "FU", "BR", "DU", "SA", - "FC", "PO", "SQ", "SS", "DS", + "FC", "PO", "SQ", "SS", "DS" }; typedef struct location_ { @@ -126,6 +128,7 @@ int rel_humidity(int dew_point, int air) { #endif /* MATH */ } +#ifdef XOAP //TODO: Lets get rid of the recursion static void parse_cc(PWEATHER *res, xmlNodePtr cc) { @@ -194,6 +197,7 @@ static void parse_weather_xml(PWEATHER *res, const char *data) xmlFreeDoc(doc); return ; } +#endif /* XOAP */ /* * Horrible hack to avoid using regexes @@ -490,16 +494,19 @@ static void parse_weather(PWEATHER *res, const char *data) //Reset results memset(res, 0, sizeof(PWEATHER)); +#ifdef XOAP //Check if it is an xml file if ( strncmp(data, "lastupd, s_tmp) == 2) { + //Divide time stamp and metar data + if (sscanf(data, "%[^'\n']\n%[^'\n']", res->lastupd, s_tmp) == 2) { //Process all tokens char *p_tok = NULL; @@ -518,11 +525,11 @@ static void parse_weather(PWEATHER *res, const char *data) } while (p_tok != NULL); } return; + } + else { + return; + } } - else { - return; - } - } } void fetch_weather_info(location *curloc) @@ -596,9 +603,12 @@ void process_weather_info(char *p, int p_max_size, char *uri, char *data_type, i } else if (strcmp(data_type, "temperature") == EQUAL) { temp_print(p, p_max_size, curloc->data.temp, TEMP_CELSIUS); } else if (strcmp(data_type, "cloud_cover") == EQUAL) { +#ifdef XOAP if (curloc->data.xoap_t[0] != '\0') { strncpy(p, curloc->data.xoap_t, p_max_size); - } else if (curloc->data.cc == 0) { + } else +#endif /* XOAP */ + if (curloc->data.cc == 0) { strncpy(p, "", p_max_size); } else if (curloc->data.cc < 3) { strncpy(p, "clear", p_max_size); diff --git a/src/weather.h b/src/weather.h index 3c9b9d4..70dd4e9 100644 --- a/src/weather.h +++ b/src/weather.h @@ -31,15 +31,8 @@ /* WEATHER data */ typedef struct PWEATHER_ { char lastupd[32]; +#ifdef XOAP char xoap_t[32]; - int temp; - int dew; - int cc; - int bar; - int wind_s; - int wind_d; - int hmid; - int wc; /* * TODO: * Is it worth investigating about using icons from weather.com? @@ -50,6 +43,15 @@ typedef struct PWEATHER_ { char icon[3]; */ +#endif /* XOAP */ + int temp; + int dew; + int cc; + int bar; + int wind_s; + int wind_d; + int hmid; + int wc; } PWEATHER; /* Prototypes */ -- 1.7.9.5