1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-07-07 15:54:14 -04:00

Rename intto_game_filename() to game_filename()

This commit is contained in:
John Zaitseff 2011-07-04 10:28:50 +10:00
parent d9ff917835
commit 2a3e18460e
5 changed files with 12 additions and 38 deletions

View File

@ -67,5 +67,5 @@ int current_player;
int number_players;
int first_player; // Who WAS the first player to go?
bool game_loaded; // True if game was loaded from disk
char *game_filename; // Game file filename
bool game_loaded = false; // True if game was loaded from disk
int game_num = 0; // Game number (1-9)

View File

@ -138,7 +138,7 @@ extern int number_players;
extern int first_player; // Who WAS the first player to go?
extern bool game_loaded; // True if game was loaded from disk
extern char *game_filename; // Game file filename
extern int game_num; // Game number (1-9)
#endif /* included_GLOBALS_H */

View File

@ -67,7 +67,7 @@ int main (int argc, char *argv[])
printw("Program name: %s\n", program_name());
printw("Home directory: %s\n", home_directory());
printw("Data directory: %s\n", data_directory());
printw("Game filename: %s\n", game_filename);
printw("Game filename: %s (%d)\n", game_filename(game_num), game_num);
printw("Cols x Lines: %d x %d\n", COLS, LINES);
printw("Colours, pairs: %d, %d\n", COLORS, COLOR_PAIRS);
@ -182,9 +182,9 @@ static void process_cmdline (int argc, char *argv[])
show_usage(EXIT_FAILURE);
}
game_filename = strto_game_filename(argv[optind]);
if (game_filename == NULL) {
if ((strlen(argv[optind]) == 1) && isdigit(*argv[optind])) {
game_num = *argv[optind] - '0';
} else {
fprintf(stderr, "%s: invalid game number `%s'\n",
program_name(), argv[optind]);
show_usage(EXIT_FAILURE);

View File

@ -152,34 +152,9 @@ const char *data_directory (void)
/*-----------------------------------------------------------------------
Function: strto_game_filename - Convert a string to a game filename
Arguments: game_num - Game number (1-9) as a string
Returns: char * - Pointer to game filename string
This function returns the full game filename as a malloc()ed string.
If game_num is a string between "1" and "9" inclusive, the string
returned is in the form data_directory() + "/" + GAME_FILENAME(game_num),
eg, "/home/test/.trader/game7". Otherwise, NULL is returned.
*/
char *strto_game_filename (const char *game_num)
{
if (game_num == NULL) {
return NULL;
}
if ((strlen(game_num) == 1) && isdigit(game_num[0])) {
return intto_game_filename(game_num[0] - '0');
} else {
return NULL;
}
}
/*-----------------------------------------------------------------------
Function: intto_game_filename - Convert an integer to a game filename
Arguments: game_num - Game number (1-9) as an integer
Returns: char * - Pointer to game filename string
Function: game_filename - Convert an integer to a game filename
Arguments: game_num - Game number (1-9) as an integer
Returns: char * - Pointer to game filename string
This function returns the full game filename as a malloc()ed string.
If game_num is between 1 and 9 inclusive, the string returned is in the
@ -187,7 +162,7 @@ char *strto_game_filename (const char *game_num)
any other integer, NULL is returned.
*/
char *intto_game_filename (const int game_num)
char *game_filename (const int game_num)
{
char buf[GAME_FILENAME_BUFSIZE]; // Buffer for part of filename
const char *dd; // Data directory

View File

@ -50,8 +50,7 @@ extern const char *program_name (void);
extern const char *home_directory (void);
extern const char *data_directory (void);
extern char *strto_game_filename (const char *game_num);
extern char *intto_game_filename (const int game_num);
extern char *game_filename (const int game_num);
extern void err_exit (const char *format, ...)
__attribute__((noreturn, format (printf, 1, 2)));