2011-06-14 04:19:01 -04:00
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Star Traders: A Game of Interstellar Trading *
|
|
|
|
* Copyright (C) 1990-2011, John Zaitseff *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2011-06-14 09:01:15 -04:00
|
|
|
Author: John Zaitseff <J.Zaitseff@zap.org.au>
|
2011-06-14 04:19:01 -04:00
|
|
|
$Id$
|
|
|
|
|
|
|
|
Star Traders is a simple game of interstellar trading, where the object
|
|
|
|
of the game is to create companies, buy and sell shares, borrow and
|
|
|
|
repay money, in order to become the wealthiest player (the winner).
|
|
|
|
|
2011-06-14 07:59:48 -04:00
|
|
|
This file, trader.c, contains the main program for Star Traders.
|
2011-06-14 04:19:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
2011-06-14 09:02:16 -04:00
|
|
|
|
|
|
|
|
2011-06-14 09:19:58 -04:00
|
|
|
#include "trader.h"
|
|
|
|
|
|
|
|
|
2011-06-28 23:15:26 -04:00
|
|
|
/************************************************************************
|
|
|
|
* Internal function declarations *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
int main (int argc, char *argv[]);
|
|
|
|
static void process_cmdline (int argc, char *argv[]);
|
2011-06-30 02:09:13 -04:00
|
|
|
static void __attribute__((noreturn)) show_version (void);
|
|
|
|
static void __attribute__((noreturn)) show_usage (int status);
|
2011-06-28 23:15:26 -04:00
|
|
|
|
|
|
|
|
2011-06-14 09:02:16 -04:00
|
|
|
/************************************************************************
|
|
|
|
* Main program *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2011-06-15 08:34:28 -04:00
|
|
|
init_program_name(argv);
|
|
|
|
|
2011-06-30 06:31:19 -04:00
|
|
|
// Initialise the locale (and ignore any errors)
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2011-06-28 23:15:26 -04:00
|
|
|
// Process command line arguments
|
|
|
|
process_cmdline(argc, argv);
|
|
|
|
|
|
|
|
|
2011-06-15 08:34:28 -04:00
|
|
|
// Testing...
|
2011-06-30 06:31:19 -04:00
|
|
|
initscr();
|
|
|
|
noecho();
|
|
|
|
timeout(-1);
|
2011-06-30 07:11:36 -04:00
|
|
|
keypad(stdscr, true);
|
2011-06-30 06:31:19 -04:00
|
|
|
raw();
|
|
|
|
|
|
|
|
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(_("Cols x Lines: %d x %d\n"), COLS, LINES);
|
|
|
|
printw(_("Colours, pairs: %d, %d\n"), COLORS, COLOR_PAIRS);
|
|
|
|
|
|
|
|
printw(_("Type some keys (^C to exit):\n\n"));
|
|
|
|
|
|
|
|
int c = 0;
|
|
|
|
while ((c = getch()) != 3) {
|
|
|
|
if ((c >= 0) && (c < 32)) {
|
|
|
|
printw("0%03o ^%c ", c, c + '@');
|
|
|
|
} else if ((c >= 32) && (c <= 127)) {
|
|
|
|
printw("0%03o %c ", c, c);
|
|
|
|
} else {
|
|
|
|
printw("0%05o ", c);
|
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
endwin();
|
2011-06-15 08:34:28 -04:00
|
|
|
|
2011-06-14 09:02:16 -04:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2011-06-28 23:15:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Command line processing *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/* Constants for command line options */
|
|
|
|
|
2011-06-30 01:25:30 -04:00
|
|
|
static const char options_short[] = "hV";
|
|
|
|
/* -h --help
|
|
|
|
-V --version
|
2011-06-28 23:15:26 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static struct option const options_long[] = {
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
Function: process_cmdline - Process command line arguments
|
|
|
|
Arguments: argc - Same as passed to main()
|
|
|
|
argv - Same as passed to main()
|
|
|
|
Returns: (nothing)
|
|
|
|
|
|
|
|
This function processes the command line arguments passed through argc
|
|
|
|
and argv, setting global variables as appropriate.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void process_cmdline (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
// Process arguments starting with "-" or "--"
|
2011-06-30 07:11:36 -04:00
|
|
|
opterr = true;
|
|
|
|
while (true) {
|
2011-06-28 23:15:26 -04:00
|
|
|
c = getopt_long(argc, argv, options_short, options_long, NULL);
|
|
|
|
if (c == EOF)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
2011-06-30 01:25:30 -04:00
|
|
|
/* -h, --help: show help */
|
2011-06-28 23:15:26 -04:00
|
|
|
show_usage(EXIT_SUCCESS);
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
/* -V, --version: show version information */
|
|
|
|
show_version();
|
|
|
|
|
|
|
|
default:
|
|
|
|
show_usage(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process remaining arguments
|
|
|
|
|
|
|
|
if ((optind < argc) && (argv[optind] != NULL)) {
|
2011-06-30 01:25:30 -04:00
|
|
|
if (argv[optind][0] == '-') {
|
|
|
|
fprintf(stderr, _("%s: invalid operand `%s'\n"), program_name(),
|
|
|
|
argv[optind]);
|
|
|
|
show_usage(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
game_filename = strto_game_filename(argv[optind]);
|
|
|
|
optind++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((optind < argc) && (argv[optind] != NULL)) {
|
|
|
|
fprintf(stderr, _("%s: extra operand `%s'\n"), program_name(),
|
|
|
|
argv[optind]);
|
|
|
|
show_usage(EXIT_FAILURE);
|
2011-06-28 23:15:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
Function: show_version - Show program version information
|
|
|
|
Arguments: (none)
|
|
|
|
Returns: (nothing)
|
|
|
|
|
|
|
|
This function displays version information about this program, then
|
|
|
|
terminates.
|
|
|
|
*/
|
|
|
|
|
2011-06-30 02:09:13 -04:00
|
|
|
static void __attribute__((noreturn)) show_version (void)
|
2011-06-28 23:15:26 -04:00
|
|
|
{
|
|
|
|
printf(_("\
|
|
|
|
" PACKAGE_NAME " (%s) %s\n\
|
|
|
|
Copyright (C) %s, John Zaitseff.\n\
|
|
|
|
\n\
|
|
|
|
Star Traders is a simple game of interstellar trading, where the object\n\
|
|
|
|
of the game is to create companies, buy and sell shares, borrow and repay\n\
|
|
|
|
money, in order to become the wealthiest player (the winner).\n\
|
|
|
|
\n\
|
|
|
|
This program is free software that is distributed under the terms of the\n\
|
|
|
|
GNU General Public License, version 3 or later. You are welcome to\n\
|
|
|
|
modify and/or distribute it under certain conditions. This program has\n\
|
|
|
|
NO WARRANTY, to the extent permitted by law; see the License for details.\n\
|
|
|
|
"), program_name(), PACKAGE_VERSION, "1990-2011");
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
Function: show_usage - Show command line usage information
|
|
|
|
Arguments: status - Exit status
|
|
|
|
Returns: (nothing)
|
|
|
|
|
|
|
|
This function displays usage information to standard output or standard
|
|
|
|
error, then terminates.
|
|
|
|
*/
|
|
|
|
|
2011-06-30 02:09:13 -04:00
|
|
|
static void __attribute__((noreturn)) show_usage (int status)
|
2011-06-28 23:15:26 -04:00
|
|
|
{
|
|
|
|
if (status != EXIT_SUCCESS) {
|
2011-06-30 01:25:30 -04:00
|
|
|
fprintf(stderr, _("%s: Try `%s --help' for more information.\n"),
|
|
|
|
program_name(), program_name());
|
2011-06-28 23:15:26 -04:00
|
|
|
} else {
|
|
|
|
printf(_("Usage: %s [OPTION ...] [GAME]\n"), program_name());
|
|
|
|
printf(_("\
|
|
|
|
Play Star Traders, a simple game of interstellar trading.\n\n\
|
|
|
|
"));
|
|
|
|
printf(_("\
|
|
|
|
Options:\n\
|
|
|
|
-V, --version output version information and exit\n\
|
|
|
|
-h, --help display this help and exit\n\n\
|
|
|
|
"));
|
|
|
|
printf(_("\
|
|
|
|
If GAME is specified as a number between 1 and 9, load and continue\n\
|
|
|
|
playing that game. If GAME is not specified, start a new game.\n\n\
|
|
|
|
"));
|
|
|
|
|
|
|
|
#ifdef PACKAGE_AUTHOR
|
|
|
|
printf(_("Report bugs to %s <%s>.\n"), PACKAGE_AUTHOR, PACKAGE_BUGREPORT);
|
|
|
|
#else
|
|
|
|
printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
|
|
|
|
#endif
|
|
|
|
#ifdef PACKAGE_PACKAGER_BUG_REPORTS
|
|
|
|
printf(_("Report %s bugs to <%s>.\n"), PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
|
|
|
|
#endif
|
|
|
|
#ifdef PACKAGE_URL
|
|
|
|
printf(_("Star Traders home page: <%s>.\n"), PACKAGE_URL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(status);
|
|
|
|
}
|