summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-23 11:46:35 +0200
committerErich Eckner <git@eckner.net>2018-10-23 11:46:35 +0200
commit8bb5c8d45bd83dccd4fba224ccd347e6cdd74cf0 (patch)
tree20746c7fd61e966983376b9852a29c7b2e985545
parent1fed55d023562d9aa54e1f08919df4cc764cc201 (diff)
downloadanzeige-8bb5c8d45bd83dccd4fba224ccd347e6cdd74cf0.tar.xz
input_gadgets.c: Datum/Urzeit zur Temperatur mit ausgeben
-rw-r--r--input_gadgets.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/input_gadgets.c b/input_gadgets.c
index 00a2d36..cf6e3d6 100644
--- a/input_gadgets.c
+++ b/input_gadgets.c
@@ -5,7 +5,7 @@
#include "input_gadgets.h"
-#define temperatur_regex ">Temperatur</td>\\s*\n\\s*<td [^>]*><strong>([^<]*)</strong>"
+#define temperatur_regex "<strong>\\s*\n\\s*Wetterdaten vom ([0-9.]{10}) um ([0-9:]{5}) MEZ</strong>(.|\n)*>Temperatur</td>\\s*\n\\s*<td [^>]*><strong>([^<]*)</strong>"
static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
@@ -60,14 +60,14 @@ int gadgets_retrieve_temperature(unsigned char *output, int max_len)
}
regex_t re;
- regmatch_t rm[2];
+ regmatch_t rm[5];
if (regcomp(&re, temperatur_regex, REG_EXTENDED|REG_NEWLINE) != 0)
{
fprintf(stderr, "Failed to compile regex '%s'\n", temperatur_regex);
free(chunk.memory);
return EXIT_FAILURE;
}
- if (ret_val = regexec(&re, chunk.memory, 2, rm, 0))
+ if (ret_val = regexec(&re, chunk.memory, 5, rm, 0))
{
char *reg_err;
reg_err = malloc(1024);
@@ -78,11 +78,15 @@ int gadgets_retrieve_temperature(unsigned char *output, int max_len)
return EXIT_FAILURE;
}
regfree(&re);
- if ((int)(rm[1].rm_eo - rm[1].rm_so) < max_len - 1)
- max_len = (int)(rm[1].rm_eo - rm[1].rm_so) + 1;
- memmove(output, chunk.memory + rm[1].rm_so, max_len - 1);
- output[max_len - 1] = '\0';
- for (int i=0; i<max_len; i++)
+ int i = snprintf(output, max_len, "%.*s (%.*s %.*s)",
+ (int)(rm[4].rm_eo - rm[4].rm_so), (char*)(chunk.memory + rm[4].rm_so),
+ (int)(rm[2].rm_eo - rm[2].rm_so), (char*)(chunk.memory + rm[2].rm_so),
+ (int)(rm[1].rm_eo - rm[1].rm_so), (char*)(chunk.memory + rm[1].rm_so)
+ );
+ for (; i>=0; i--)
+ if (output[i] == '(')
+ break;
+ for (; i>=0; i--)
if (output[i] == '.')
output[i] = ',';
free(chunk.memory);