mirror of
https://git.zap.org.au/git/trader.git
synced 2024-09-01 17:14:15 -04:00
Rename intto_game_filename() to game_filename()
This commit is contained in:
parent
d9ff917835
commit
2a3e18460e
@ -67,5 +67,5 @@ int current_player;
|
|||||||
int number_players;
|
int number_players;
|
||||||
int first_player; // Who WAS the first player to go?
|
int first_player; // Who WAS the first player to go?
|
||||||
|
|
||||||
bool game_loaded; // True if game was loaded from disk
|
bool game_loaded = false; // True if game was loaded from disk
|
||||||
char *game_filename; // Game file filename
|
int game_num = 0; // Game number (1-9)
|
||||||
|
@ -138,7 +138,7 @@ extern int number_players;
|
|||||||
extern int first_player; // Who WAS the first player to go?
|
extern int first_player; // Who WAS the first player to go?
|
||||||
|
|
||||||
extern bool game_loaded; // True if game was loaded from disk
|
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 */
|
#endif /* included_GLOBALS_H */
|
||||||
|
@ -67,7 +67,7 @@ int main (int argc, char *argv[])
|
|||||||
printw("Program name: %s\n", program_name());
|
printw("Program name: %s\n", program_name());
|
||||||
printw("Home directory: %s\n", home_directory());
|
printw("Home directory: %s\n", home_directory());
|
||||||
printw("Data directory: %s\n", data_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("Cols x Lines: %d x %d\n", COLS, LINES);
|
||||||
printw("Colours, pairs: %d, %d\n", COLORS, COLOR_PAIRS);
|
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);
|
show_usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
game_filename = strto_game_filename(argv[optind]);
|
if ((strlen(argv[optind]) == 1) && isdigit(*argv[optind])) {
|
||||||
|
game_num = *argv[optind] - '0';
|
||||||
if (game_filename == NULL) {
|
} else {
|
||||||
fprintf(stderr, "%s: invalid game number `%s'\n",
|
fprintf(stderr, "%s: invalid game number `%s'\n",
|
||||||
program_name(), argv[optind]);
|
program_name(), argv[optind]);
|
||||||
show_usage(EXIT_FAILURE);
|
show_usage(EXIT_FAILURE);
|
||||||
|
33
src/utils.c
33
src/utils.c
@ -152,34 +152,9 @@ const char *data_directory (void)
|
|||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
Function: strto_game_filename - Convert a string to a game filename
|
Function: game_filename - Convert an integer to a game filename
|
||||||
Arguments: game_num - Game number (1-9) as a string
|
Arguments: game_num - Game number (1-9) as an integer
|
||||||
Returns: char * - Pointer to game filename 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
|
|
||||||
|
|
||||||
This function returns the full game filename as a malloc()ed 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
|
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.
|
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
|
char buf[GAME_FILENAME_BUFSIZE]; // Buffer for part of filename
|
||||||
const char *dd; // Data directory
|
const char *dd; // Data directory
|
||||||
|
@ -50,8 +50,7 @@ extern const char *program_name (void);
|
|||||||
extern const char *home_directory (void);
|
extern const char *home_directory (void);
|
||||||
extern const char *data_directory (void);
|
extern const char *data_directory (void);
|
||||||
|
|
||||||
extern char *strto_game_filename (const char *game_num);
|
extern char *game_filename (const int game_num);
|
||||||
extern char *intto_game_filename (const int game_num);
|
|
||||||
|
|
||||||
extern void err_exit (const char *format, ...)
|
extern void err_exit (const char *format, ...)
|
||||||
__attribute__((noreturn, format (printf, 1, 2)));
|
__attribute__((noreturn, format (printf, 1, 2)));
|
||||||
|
Loading…
Reference in New Issue
Block a user