Put all player-related information in one place
Issue #20
resolved
Put all player-related information in one place, using a struct, including to record the file formats accepted by the players rather than hard-coding these formats in the common controls.
Comments (3)
-
reporter -
reporter static const char *hypothetical_findport(const char *); static player_id_t player_find(void); static bool player_supported(const char *); int main(void); int main(void) { if ((player = player_find()) == -1) { /* XXX No supported player found, report error */ exit(EXIT_FAILURE); } printf("Player ID: %d\n", player); printf("Player supports type: %d\n", (int)player_supported("mod")); /* XXX "mod" would normally be filename */ /* Examples of faster and cleaner if/case than with strcmp(3) */ if (player == P_DELITRACKER) printf("Player is Delitracker\n"); switch (player) { case P_DELITRACKER: printf("Indeed Delitracker\n"); break; case P_AMIGAAMP: /* FALLTHROUGH */ case P_EAGLEPLAYER: /* FALLTHROUGH */ case P_HIPPOPLAYER: /* FALLTHROUGH */ case P_MULTIPLAYER: /* FALLTHROUGH */ printf("Definitely something else\n"); break; } exit(EXIT_SUCCESS); } /* XXX Cheap test simulation :) */ static const char * hypothetical_findport(const char *port) { return (strcmp(port, "DELITRACKER") == 0 ? "DELITRACKER" : NULL); } /* Type support lookup example */ bool player_supported(const char *filename) { int i; unsigned int sup; assert(player != -1); sup = players[player].supported; for (i = 0; i < T_MAX; i++) { if ((sup & (1 << i)) != 0) { const char *str = type_str[i]; /* XXX if (str_startswith(filename, str) || str_endswith(filename, str)) return true; */ if (strcasecmp(filename, str) == 0) return true; } } return false; } /* Player lookup example */ static player_id_t player_find(void) { int i; for (i = 0; i < P_MAX; i++) { const struct player_info *p = &players[i]; if (hypothetical_findport(p->portname) != NULL) return p->id; } return -1; }
-
reporter - changed status to resolved
Finally done in v0.99995!
- Log in to comment
Use Matt's skeleton implementation that is very, very cool!