1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-30 05:59:07 +00:00

Merge branch 'master' of git.omp.am:/home/omp/git/conky

This commit is contained in:
Cesare Tirabassi 2009-07-21 00:05:13 +02:00
commit 7449c1afa9
5 changed files with 102 additions and 79 deletions

View File

@ -354,27 +354,27 @@ dnl
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
@ -944,7 +944,7 @@ $PACKAGE $VERSION configured successfully:
RSS: $want_rss
Curl: $want_curl
Weather
NOAA: $want_weather
METAR: $want_metar
XOAP: $want_xoap
wireless: $want_wlan
IBM: $want_ibm

View File

@ -216,7 +216,7 @@ static void print_version(void)
" * RSS\n"
#endif /* RSS */
#ifdef WEATHER
" * Weather (NOAA)\n"
" * Weather (METAR)\n"
#ifdef XOAP
" * Weather (XOAP)\n"
#endif /* XOAP */
@ -325,11 +325,6 @@ static int cpu_avg_samples, net_avg_samples, diskio_avg_samples;
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;
@ -2829,7 +2824,7 @@ static struct text_object *construct_text_object(const char *s,
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);
@ -2846,7 +2841,7 @@ static struct text_object *construct_text_object(const char *s,
#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));
@ -2872,35 +2867,15 @@ static struct text_object *construct_text_object(const char *s,
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");
}
@ -9008,42 +8983,6 @@ static void load_config_file_x11(const char *f)
}
#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"
@ -9428,10 +9367,10 @@ int main(int argc, char **argv)
}
}
#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();

View File

@ -95,6 +95,12 @@ char *strndup(const char *s, size_t n);
#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 */

View File

@ -583,3 +583,73 @@ void weather_process_info(char *p, int p_max_size, char *uri, char *data_type, i
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;
}

View File

@ -28,6 +28,8 @@
#ifndef WEATHER_H_
#define WEATHER_H_
#include "config.h"
/* WEATHER data */
typedef struct PWEATHER_ {
char lastupd[32];
@ -57,5 +59,11 @@ typedef struct PWEATHER_ {
/* 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_*/