From ebdda2ed11cf8614f7de7651a19942735045cb20 Mon Sep 17 00:00:00 2001 From: Theodore Turocy Date: Sun, 31 Dec 2023 09:53:18 +0000 Subject: [PATCH] Treat null or blank values for batting and throwing side in rosters as question marks. --- ChangeLog.md | 2 ++ src/cwlib/roster.c | 4 ++-- src/cwtools/cwevent.c | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 2734819..5213876 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -16,6 +16,8 @@ "unknown" values are output as 0 for `BEVENT` compatibility. - In `cwevent`, the implementation of the batter/runner "fate" extended fields was entirely incorrect. This has been corrected. (#45) +- In handling rosters, treat blank or null values for batting or throwing side + as if they were explicit question marks. # [0.10.0] - 2023-01-02 diff --git a/src/cwlib/roster.c b/src/cwlib/roster.c index dcafc1a..99f4694 100644 --- a/src/cwlib/roster.c +++ b/src/cwlib/roster.c @@ -293,7 +293,7 @@ cw_roster_batting_hand(CWRoster *roster, char *player_id) for (player = roster->first_player; player; player = player->next) { if (!strcmp(player->player_id, player_id)) { - return player->bats; + return (player->bats != '\0' && player->bats != ' ') ? player->bats : '?'; } } @@ -311,7 +311,7 @@ cw_roster_throwing_hand(CWRoster *roster, char *player_id) for (player = roster->first_player; player; player = player->next) { if (!strcmp(player->player_id, player_id)) { - return player->throws; + return (player->throws != '\0' && player->throws != ' ') ? player->throws : '?'; } } diff --git a/src/cwtools/cwevent.c b/src/cwtools/cwevent.c index a2d9c1d..25534f2 100644 --- a/src/cwtools/cwevent.c +++ b/src/cwtools/cwevent.c @@ -218,9 +218,9 @@ DECLARE_FIELDFUNC(cwevent_batter_hand) { char batterHand, pitcherHand; if (gameiter->event->batter_hand == ' ') { - batterHand = cw_roster_batting_hand((gameiter->event->batting_team == 0) ? - visitors : home, - gameiter->event->batter); + batterHand = cw_roster_batting_hand((gameiter->event->batting_team == 0) ? + visitors : home, + gameiter->event->batter); } else { batterHand = gameiter->event->batter_hand; @@ -230,11 +230,11 @@ DECLARE_FIELDFUNC(cwevent_batter_hand) if (gameiter->state->pitcher_hand != ' ') { pitcherHand = gameiter->state->pitcher_hand; } - else{ + else { pitcherHand = - cw_roster_throwing_hand((gameiter->event->batting_team == 0) ? - home : visitors, - gameiter->state->fielders[1][1-gameiter->state->batting_team]); + cw_roster_throwing_hand((gameiter->event->batting_team == 0) ? + home : visitors, + gameiter->state->fielders[1][1 - gameiter->state->batting_team]); } if (pitcherHand == 'L') { batterHand = 'R';