From 09e55bcc7e0aeead7a44898adf9e92ef39da89a3 Mon Sep 17 00:00:00 2001 From: Cesare Tirabassi Date: Tue, 7 Jul 2009 12:08:24 +0200 Subject: [PATCH] weather: add more weather modifiers --- src/weather.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/weather.c b/src/weather.c index f0cc24ce..dc5ab136 100644 --- a/src/weather.c +++ b/src/weather.c @@ -41,6 +41,11 @@ const char *CC_CODES[NUM_CC_CODES] = {"SKC", "CLR", "FEW", "SCT", "BKN", "OVC"}; +/* Possible weather modifiers */ +#define NUM_WM_CODES 9 +const char *WM_CODES[NUM_WM_CODES] = + {"VC", "MI", "BC", "PR", "TS", "BL", "SH", "DR", "FZ"}; + /* Possible weather conditions */ #define NUM_WC_CODES 17 const char *WC_CODES[NUM_WC_CODES] = @@ -200,11 +205,18 @@ static inline void parse_token(PWEATHER *res, char *token) { //Check all tokens 4 chars long case 4: - //Check if token is an icao - for (i=0; i<4; i++) { - if (!isalpha(token[i])) break; + //Check if token is a modified weather condition + for(i=0; iwc=i+1; + return; + } + } + break; + } } - if (i==4) return; break; @@ -260,6 +272,20 @@ static inline void parse_token(PWEATHER *res, char *token) { } } + //Check if token is a modified weather condition + if ((token[0] == '+') || (token[0] == '-')) { + for(i=0; iwc=i+1; + return; + } + } + break; + } + } + } break; //Check all tokens 6 chars long @@ -418,7 +444,11 @@ static inline PWEATHER *parse_weather(const char *data) char *p_tok = NULL; char *p_save = NULL; - if ((p_tok = strtok_r(s_tmp, delim, &p_save)) != NULL) { + if ((strtok_r(s_tmp, delim, &p_save)) != NULL) { + + //Jump first token, must be icao + p_tok = strtok_r(NULL, delim, &p_save); + do { parse_token(res, p_tok); @@ -426,7 +456,7 @@ static inline PWEATHER *parse_weather(const char *data) } while (p_tok != NULL); } - return res; + return res; } else { return NULL;