mirror of
https://git.zap.org.au/git/trader.git
synced 2024-10-13 18:03:39 -04:00
Add the functions init_program() and end_program()
This commit is contained in:
parent
4f62ef1b58
commit
4d5c5b70ca
@ -54,6 +54,8 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
135
src/trader.c
135
src/trader.c
@ -39,9 +39,13 @@
|
|||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
int main (int argc, char *argv[]);
|
int main (int argc, char *argv[]);
|
||||||
static void process_cmdline (int argc, char *argv[]);
|
|
||||||
static void show_version (void) __attribute__((noreturn));
|
void process_cmdline (int argc, char *argv[]);
|
||||||
static void show_usage (int status) __attribute__((noreturn));
|
void show_version (void) __attribute__((noreturn));
|
||||||
|
void show_usage (int status) __attribute__((noreturn));
|
||||||
|
|
||||||
|
void init_program (void);
|
||||||
|
void end_program (void);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@ -60,66 +64,25 @@ int main (int argc, char *argv[])
|
|||||||
// Process command line arguments
|
// Process command line arguments
|
||||||
process_cmdline(argc, argv);
|
process_cmdline(argc, argv);
|
||||||
|
|
||||||
|
// Set up the display, internal low-level routines, etc.
|
||||||
|
init_program();
|
||||||
|
|
||||||
// Testing...
|
// Play the actual game
|
||||||
init_screen();
|
|
||||||
|
|
||||||
wprintw(curwin, "Program name: %s\n", program_name());
|
/* @@@ to be completed
|
||||||
wprintw(curwin, "Home directory: %s\n", home_directory());
|
init_game();
|
||||||
wprintw(curwin, "Data directory: %s\n", data_directory());
|
while ((! quit_selected) && (turn_number <= max_turn)) {
|
||||||
wprintw(curwin, "Game filename: %s (%d)\n", game_filename(game_num), game_num);
|
select_moves();
|
||||||
|
get_move();
|
||||||
wprintw(curwin, "Cols x Lines: %d x %d\n", COLS, LINES);
|
process_move();
|
||||||
wprintw(curwin, "Colours, pairs: %d, %d\n", COLORS, COLOR_PAIRS);
|
exchange_stock();
|
||||||
|
next_player();
|
||||||
wrefresh(curwin);
|
|
||||||
|
|
||||||
curs_set(CURS_VERYVISIBLE);
|
|
||||||
|
|
||||||
newtxwin(WIN_LINES - 7, WIN_COLS, LINE_OFFSET + 7, COL_OFFSET + 0);
|
|
||||||
wbkgd(curwin, COLOR_PAIR(WHITE_ON_BLUE));
|
|
||||||
box(curwin, 0, 0);
|
|
||||||
wrefresh(curwin);
|
|
||||||
|
|
||||||
newtxwin(WIN_LINES - 9, WIN_COLS - 8, LINE_OFFSET + 8, COL_OFFSET + 4);
|
|
||||||
wbkgd(curwin, COLOR_PAIR(WHITE_ON_BLUE));
|
|
||||||
|
|
||||||
wattrset(curwin, has_colors() ? COLOR_PAIR(WHITE_ON_RED) | A_BOLD : A_REVERSE | A_BOLD);
|
|
||||||
center(curwin, true, "Type some keys (^C to exit):");
|
|
||||||
wattrset(curwin, A_NORMAL);
|
|
||||||
|
|
||||||
wrefresh(curwin);
|
|
||||||
|
|
||||||
scrollok(curwin, true);
|
|
||||||
keypad(curwin, true);
|
|
||||||
meta(curwin, true);
|
|
||||||
wtimeout(curwin, -1);
|
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
while ((c = wgetch(curwin)) != 3) {
|
|
||||||
if ((c >= 0) && (c < 32)) {
|
|
||||||
wprintw(curwin, "0%03o ^%c ", c, c + '@');
|
|
||||||
} else if ((c >= 32) && (c < 127)) {
|
|
||||||
wprintw(curwin, "0%03o %c ", c, c);
|
|
||||||
} else {
|
|
||||||
wprintw(curwin, "0%05o ", c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == 0x1C) {
|
|
||||||
err_exit("You pressed ^%c!", c + '@');
|
|
||||||
}
|
|
||||||
|
|
||||||
wrefresh(curwin);
|
|
||||||
}
|
}
|
||||||
|
end_game();
|
||||||
|
*/
|
||||||
|
|
||||||
deltxwin();
|
// Finish up...
|
||||||
txrefresh();
|
end_program();
|
||||||
|
|
||||||
mvwprintw(curwin, 1, 2, "All OK: ");
|
|
||||||
wgetch(curwin);
|
|
||||||
|
|
||||||
end_screen();
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +115,7 @@ static struct option const options_long[] = {
|
|||||||
and argv, setting global variables as appropriate.
|
and argv, setting global variables as appropriate.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void process_cmdline (int argc, char *argv[])
|
void process_cmdline (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@ -186,7 +149,8 @@ static void process_cmdline (int argc, char *argv[])
|
|||||||
show_usage(EXIT_FAILURE);
|
show_usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strlen(argv[optind]) == 1) && isdigit(*argv[optind])) {
|
if ((strlen(argv[optind]) == 1) &&
|
||||||
|
(*argv[optind] >= '1') && (*argv[optind] <= '9')) {
|
||||||
game_num = *argv[optind] - '0';
|
game_num = *argv[optind] - '0';
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: invalid game number `%s'\n",
|
fprintf(stderr, "%s: invalid game number `%s'\n",
|
||||||
@ -214,7 +178,7 @@ static void process_cmdline (int argc, char *argv[])
|
|||||||
terminates.
|
terminates.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void show_version (void)
|
void show_version (void)
|
||||||
{
|
{
|
||||||
printf("\
|
printf("\
|
||||||
" PACKAGE_NAME " (%s) %s\n\
|
" PACKAGE_NAME " (%s) %s\n\
|
||||||
@ -243,7 +207,7 @@ NO WARRANTY, to the extent permitted by law; see the License for details.\n\
|
|||||||
error, then terminates.
|
error, then terminates.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void show_usage (int status)
|
void show_usage (int status)
|
||||||
{
|
{
|
||||||
const char *pn = program_name();
|
const char *pn = program_name();
|
||||||
|
|
||||||
@ -280,3 +244,48 @@ playing that game. If GAME is not specified, start a new game.\n\n\
|
|||||||
|
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Initialisation and deinitialisation function definitions *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------
|
||||||
|
Function: init_program - Initialise program-wide functions
|
||||||
|
Arguments: (none)
|
||||||
|
Returns: (nothing)
|
||||||
|
|
||||||
|
This function initialises the terminal display, internal low-level
|
||||||
|
routines, etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void init_program (void)
|
||||||
|
{
|
||||||
|
time_t curtime = time(NULL); // NB: time_t may be larger than long int
|
||||||
|
|
||||||
|
|
||||||
|
// Initialise the random number generator
|
||||||
|
srand48((long int) curtime);
|
||||||
|
|
||||||
|
// Initialise the terminal display
|
||||||
|
init_screen();
|
||||||
|
|
||||||
|
// Initialise signal-handling functions
|
||||||
|
// @@@ to be completed
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------
|
||||||
|
Function: end_program - Deinitialise program-wide functions
|
||||||
|
Arguments: (none)
|
||||||
|
Returns: (nothing)
|
||||||
|
|
||||||
|
This function finalises the terminal display, internal low-level
|
||||||
|
routines, etc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void end_program (void)
|
||||||
|
{
|
||||||
|
end_screen();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user