Skip to content

Commit

Permalink
Add support for 'unknown' as valid values for info,temp and info,wind…
Browse files Browse the repository at this point in the history
…speed
  • Loading branch information
tturocy committed Dec 30, 2023
1 parent 0733799 commit a411c70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
- In `cwgame`, warnings on empty values for attendance and timeofgame has been
removed. These are now output as 0 (instead of -1) to restore `BEVENT`
compatibility.
- In `cwgame`, "unknown" in now an accepted value for `info,temp`. When present
the temperature is output as 0 for `BEVENT` compatibility.
- In `cwgame`, "unknown" in now an accepted value for `info,temp` and `info,windspeed`.
"unknown" values are output as 0 for `BEVENT` compatibility.


# [0.10.0] - 2023-01-02
Expand Down
23 changes: 15 additions & 8 deletions src/cwtools/cwgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,14 @@ DECLARE_FIELDFUNC(cwgame_pitches)
/* Field 26 */
DECLARE_FIELDFUNC(cwgame_temperature)
{
char *tmp = cw_game_info_lookup(gameiter->game, "temp");
return sprintf(buffer, (ascii) ? "%d" : "%3d",
(tmp && strcmp(tmp, "") != 0 && strcmp(tmp, "unknown") != 0) ?
cw_atoi(tmp, "Warning: invalid value '%s' for info,temp\n") : 0);
char *value = cw_game_info_lookup(gameiter->game, "temp");
if (!value || !strcmp(value, "") || !strcmp(value, "unknown")) {
return sprintf(buffer, (ascii) ? "%d" : "%3d", 0);
}
else {
return sprintf(buffer, (ascii) ? "%d" : "%3d",
cw_atoi(value, "Warning: invalid value '%s' for info,temp\n"));
}
}

/* Field 27 */
Expand All @@ -472,10 +476,13 @@ DECLARE_FIELDFUNC(cwgame_wind_direction)
/* Field 28 */
DECLARE_FIELDFUNC(cwgame_wind_speed)
{
char *tmp;
return sprintf(buffer, "%d",
(tmp = cw_game_info_lookup(gameiter->game, "windspeed")) ?
cw_atoi(tmp, NULL) : 0);
char *value = cw_game_info_lookup(gameiter->game, "windspeed");
if (!value || !strcmp(value, "") || !strcmp(value, "unknown")) {
return sprintf(buffer, "%d", 0);
}
else {
return sprintf(buffer, "%d", cw_atoi(value, "Warning: invalid value '%s' for info,windspeed\n"));
}
}

/* Field 29 */
Expand Down

0 comments on commit a411c70

Please sign in to comment.