dnl WEATHER
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([weather-metar],
+ AC_HELP_STRING([--enable-weather-metar], [enable if you want METAR weather support @<:@default=no@:>@]),
+ [want_metar="$enableval"], [want_metar=no])
-AC_ARG_ENABLE([xoap],
- AC_HELP_STRING([--enable-xoap], [enable if you want weather xoap support @<:@default=no@:>@]),
+AC_ARG_ENABLE([weather-xoap],
+ AC_HELP_STRING([--enable-weather-xoap], [enable if you want XOAP weather support (also enables METAR) @<:@default=no@:>@]),
[want_xoap="$enableval"], [want_xoap=no])
#
if test x$want_xoap = xyes; then
- want_weather=yes
+ want_metar=yes
fi
-AM_CONDITIONAL(BUILD_WEATHER, test x$want_weather = xyes)
+AM_CONDITIONAL(BUILD_WEATHER, test x$want_metar = xyes)
AM_CONDITIONAL(BUILD_XOAP, test x$want_xoap = xyes)
-if test x$want_weather = xyes; then
+if test x$want_metar = xyes; then
if test x$want_xoap = xyes; then
want_libxml2=yes
- AC_DEFINE(XOAP, 1, [Define if you want weather xoap support])
+ AC_DEFINE(XOAP, 1, [Define if you want XOAP weather support])
AC_DEFINE(XOAP_FILE, "$HOME/.xoaprc", [User xoap keys file])
fi
want_curl=yes
- AC_DEFINE(WEATHER, 1, [Define if you want weather support])
+ AC_DEFINE(WEATHER, 1, [Define if you want METAR weather support])
fi
dnl
RSS: $want_rss
Curl: $want_curl
Weather
- NOAA: $want_weather
+ METAR: $want_metar
XOAP: $want_xoap
wireless: $want_wlan
IBM: $want_ibm
" * RSS\n"
#endif /* RSS */
#ifdef WEATHER
- " * Weather (NOAA)\n"
+ " * Weather (METAR)\n"
#ifdef XOAP
" * Weather (XOAP)\n"
#endif /* XOAP */
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
char *append_file = NULL; FILE *append_fpointer = NULL;
-/* xoap suffix for weather from weather.com */
-#ifdef WEATHER
-static char *xoap = NULL;
-#endif /* WEATHER */
-
#ifdef X11
static int show_graph_scale;
END OBJ(curl, 0)
if (arg) {
int argc;
- float interval;
+ float interval = 0;
char *uri = (char *) malloc(128 * sizeof(char));
argc = sscanf(arg, "%127s %f", uri, &interval);
#ifdef RSS
END OBJ(rss, 0)
if (arg) {
- float interval;
+ float interval = 0;
int argc, act_par;
unsigned int nrspaces = 0;
char *uri = (char *) malloc(128 * sizeof(char));
END OBJ(weather, 0)
if (arg) {
int argc;
- float interval;
+ float interval = 0;
char *locID = (char *) malloc(9 * sizeof(char));
char *uri = (char *) malloc(128 * sizeof(char));
char *data_type = (char *) malloc(32 * sizeof(char));
- char *tmp_p;
argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
if (argc >= 3) {
- /* locID MUST BE upper-case */
- tmp_p = locID;
- while (*tmp_p) {
- *tmp_p = toupper(*tmp_p);
- tmp_p++;
- }
-
- /* Construct complete uri */
- if (strstr(uri, "xoap.weather.com")) {
- if(xoap != NULL) {
- strcat(uri, locID);
- strcat(uri, xoap);
- } else {
- free(uri);
- uri = NULL;
- }
- } else if (strstr(uri, "weather.noaa.gov")) {
- strcat(uri, locID);
- strcat(uri, ".TXT");
- } else if (!strstr(uri, "localhost") && !strstr(uri, "127.0.0.1")) {
+ if (process_weather_uri(uri, locID)) {
CRIT_ERR(obj, free_at_crash, \
"could not recognize the weather uri");
}
}
#endif /* X11 */
-#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
- * make the xoap keys file giveable as a command line option
- */
-static void load_xoap_keys(void)
-{
- FILE *fp;
- char *par = (char *) malloc(11 * sizeof(char));
- char *key = (char *) malloc(17 * sizeof(char));
-
- xoap = (char *) malloc(64 * sizeof(char));
- to_real_path(xoap, XOAP_FILE);
- fp = fopen(xoap, "r");
- if (fp != NULL) {
- if( fscanf(fp, "%10s %16s", par, key) == 2 ) {
- strcpy(xoap, "?cc=*&link=xoap&prod=xoap&par=");
- strcat(xoap, par);
- strcat(xoap, "&key=");
- strcat(xoap, key);
- strcat(xoap, "&unit=m");
- } else {
- free(xoap);
- xoap = NULL;
- }
- fclose(fp);
- } else {
- free(xoap);
- xoap = NULL;
- }
- free(par);
- free(key);
-}
-#endif /* WEATHER && XOAP */
-
static void print_help(const char *prog_name) {
printf("Usage: %s [OPTION]...\n"
PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
}
}
-#if defined(WEATHER) && defined(XOAP)
+#ifdef XOAP
/* Load xoap keys, if existing */
load_xoap_keys();
-#endif /* WEATHER && XOAP */
+#endif /* XOAP */
#ifdef HAVE_SYS_INOTIFY_H
inotify_fd = inotify_init();
#include "rss.h"
#endif /* RSS */
+#ifdef XOAP
+#ifndef WEATHER
+#error "WEATHER needs to be defined if XOAP is defined"
+#endif /* WEATHER */
+#endif /* XOAP */
+
#ifdef WEATHER
#include "weather.h"
#endif /* WEATHER */
timed_thread_unlock(curloc->p_timed_thread);
}
+#ifdef XOAP
+
+/* xoap suffix for weather from weather.com */
+static char *xoap = NULL;
+
+/*
+ * TODO: make the xoap keys file readable from the config file
+ * make the keys directly readable from the config file
+ * make the xoap keys file giveable as a command line option
+ */
+void load_xoap_keys(void)
+{
+ FILE *fp;
+ char *par = (char *) malloc(11 * sizeof(char));
+ char *key = (char *) malloc(17 * sizeof(char));
+
+ xoap = (char *) malloc(64 * sizeof(char));
+ to_real_path(xoap, XOAP_FILE);
+ fp = fopen(xoap, "r");
+ if (fp != NULL) {
+ if (fscanf(fp, "%10s %16s", par, key) == 2) {
+ strcpy(xoap, "?cc=*&link=xoap&prod=xoap&par=");
+ strcat(xoap, par);
+ strcat(xoap, "&key=");
+ strcat(xoap, key);
+ strcat(xoap, "&unit=m");
+ } else {
+ free(xoap);
+ xoap = NULL;
+ }
+ fclose(fp);
+ } else {
+ free(xoap);
+ xoap = NULL;
+ }
+ free(par);
+ free(key);
+}
+#endif /* XOAP */
+
+int process_weather_uri(char *uri, char *locID)
+{
+ /* locID MUST BE upper-case */
+ char *tmp_p = locID;
+ while (*tmp_p) {
+ *tmp_p = toupper(*tmp_p);
+ tmp_p++;
+ }
+
+ /* Construct complete uri */
+#ifdef XOAP
+ if (strstr(uri, "xoap.weather.com")) {
+ if (xoap != NULL) {
+ strcat(uri, locID);
+ strcat(uri, xoap);
+ } else {
+ free(uri);
+ uri = NULL;
+ }
+ } else
+#endif /* XOAP */
+ if (strstr(uri, "weather.noaa.gov")) {
+ strcat(uri, locID);
+ strcat(uri, ".TXT");
+ } else if (!strstr(uri, "localhost") && !strstr(uri, "127.0.0.1")) {
+ return -1;
+ }
+ return 0;
+}
+
#ifndef WEATHER_H_
#define WEATHER_H_
+#include "config.h"
+
/* WEATHER data */
typedef struct PWEATHER_ {
char lastupd[32];
/* Prototypes */
void weather_free_info(void);
void weather_process_info(char *p, int p_max_size, char *uri, char *data_type, int interval);
+int process_weather_uri(char *uri, char *locID);
+
+#ifdef XOAP
+void load_xoap_keys(void);
+#endif /* XOAP */
+
#endif /*WEATHER_H_*/