mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 09:38:38 +00:00
weather: changed ifs in parsing routine to switch/case and corrected TCU handling
This commit is contained in:
parent
1171ab38a5
commit
476296be5c
@ -37,9 +37,9 @@
|
|||||||
#define MAX_LOCATIONS 3
|
#define MAX_LOCATIONS 3
|
||||||
|
|
||||||
/* Possible sky conditions */
|
/* Possible sky conditions */
|
||||||
#define NUM_CC_CODES 7
|
#define NUM_CC_CODES 6
|
||||||
const char *CC_CODES[NUM_CC_CODES] =
|
const char *CC_CODES[NUM_CC_CODES] =
|
||||||
{"SKC", "CLR", "FEW", "SCT", "BKN", "OVC", "TCU"};
|
{"SKC", "CLR", "FEW", "SCT", "BKN", "OVC"};
|
||||||
|
|
||||||
/* Possible weather conditions */
|
/* Possible weather conditions */
|
||||||
#define NUM_WC_CODES 17
|
#define NUM_WC_CODES 17
|
||||||
@ -137,8 +137,10 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
int i;
|
int i;
|
||||||
char s_tmp[64];
|
char s_tmp[64];
|
||||||
|
|
||||||
|
switch (strlen(token)) {
|
||||||
|
|
||||||
//Check all tokens 2 chars long
|
//Check all tokens 2 chars long
|
||||||
if (strlen(token) == 2 ) {
|
case 2:
|
||||||
|
|
||||||
//Check if token is a weather condition
|
//Check if token is a weather condition
|
||||||
for (i=0; i<2; i++) {
|
for (i=0; i<2; i++) {
|
||||||
@ -160,10 +162,10 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
break;
|
||||||
|
|
||||||
//Check all tokens 3 chars long
|
//Check all tokens 3 chars long
|
||||||
if (strlen(token) == 3 ) {
|
case 3:
|
||||||
|
|
||||||
//Check if token is a modified weather condition
|
//Check if token is a modified weather condition
|
||||||
if ((token[0] == '+') || (token[0] == '-')) {
|
if ((token[0] == '+') || (token[0] == '-')) {
|
||||||
@ -181,16 +183,22 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for NCD
|
//Check for NCD or NCD
|
||||||
if (!strcmp(token, "NCD")) {
|
if ((!strcmp(token, "NCD")) || (!strcmp(token, "NSC"))) {
|
||||||
res->cc = 1;
|
res->cc = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Check for TCU
|
||||||
|
if (!strcmp(token, "TCU")) {
|
||||||
|
res->cc = 7;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
//Check all tokens 4 chars long
|
//Check all tokens 4 chars long
|
||||||
if (strlen(token) == 4 ) {
|
case 4:
|
||||||
|
|
||||||
//Check if token is an icao
|
//Check if token is an icao
|
||||||
for (i=0; i<4; i++) {
|
for (i=0; i<4; i++) {
|
||||||
@ -198,10 +206,10 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
}
|
}
|
||||||
if (i==4) return;
|
if (i==4) return;
|
||||||
|
|
||||||
}
|
break;
|
||||||
|
|
||||||
//Check all tokens 5 chars long
|
//Check all tokens 5 chars long
|
||||||
if (strlen(token) == 5 ) {
|
case 5:
|
||||||
|
|
||||||
//Check for CAVOK
|
//Check for CAVOK
|
||||||
if (!strcmp(token, "CAVOK")) {
|
if (!strcmp(token, "CAVOK")) {
|
||||||
@ -251,10 +259,11 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
break;
|
||||||
|
|
||||||
//Check all tokens 6 chars long
|
//Check all tokens 6 chars long
|
||||||
if (strlen(token) == 6 ) {
|
case 6:
|
||||||
|
|
||||||
//Check if token is the cloud cover
|
//Check if token is the cloud cover
|
||||||
for (i=0; i<3; i++) {
|
for (i=0; i<3; i++) {
|
||||||
@ -300,10 +309,11 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
break;
|
||||||
|
|
||||||
//Check all tokens 7 chars long
|
//Check all tokens 7 chars long
|
||||||
if (strlen(token) == 7 ) {
|
case 7:
|
||||||
|
|
||||||
//Check if token is the observation time
|
//Check if token is the observation time
|
||||||
for (i=0; i<6; i++) {
|
for (i=0; i<6; i++) {
|
||||||
@ -365,10 +375,10 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
if (i==7) return;
|
if (i==7) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
break;
|
||||||
|
|
||||||
//Check all tokens 8 chars long
|
//Check all tokens 8 chars long
|
||||||
if (strlen(token) == 8 ) {
|
case 8:
|
||||||
|
|
||||||
//Check if token is the wind speed/direction in m/s
|
//Check if token is the wind speed/direction in m/s
|
||||||
for (i=0; i<5; i++) {
|
for (i=0; i<5; i++) {
|
||||||
@ -386,9 +396,11 @@ static inline void parse_token(PWEATHER *res, char *token) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
default:
|
||||||
|
|
||||||
//printf("token : %s\n", token);
|
//printf("token : %s\n", token);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline PWEATHER *parse_weather(const char *data)
|
static inline PWEATHER *parse_weather(const char *data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user