#include "sound.h"
#include "random.h"
#include "joystick.h"
-
+#include "files.h"
#ifdef MSDOS
volatile unsigned long counter = 0;
char *option_arg = NULL;
int option_len = strlen(option);
+ if (option_len >= MAX_OPTION_LEN)
+ Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
+
strcpy(option_str, option); /* copy argument into buffer */
option = option_str;
if (strcmp(option, "--") == 0) /* stop scanning arguments */
break;
- if (option_len >= MAX_OPTION_LEN)
- Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
-
if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */
option++;
options.display_name = option_arg;
if (option_arg == next_option)
options_left++;
-
- printf("--display == '%s'\n", options.display_name);
}
else if (strncmp(option, "-basepath", option_len) == 0)
{
if (option_arg == next_option)
options_left++;
- printf("--basepath == '%s'\n", options.base_directory);
-
/* adjust path for level directory accordingly */
options.level_directory =
getPath2(options.base_directory, LEVELS_DIRECTORY);
options.level_directory = option_arg;
if (option_arg == next_option)
options_left++;
-
- printf("--levels == '%s'\n", options.level_directory);
}
else if (strncmp(option, "-network", option_len) == 0)
{
- printf("--network\n");
-
options.network = TRUE;
}
else if (strncmp(option, "-serveronly", option_len) == 0)
{
- printf("--serveronly\n");
-
options.serveronly = TRUE;
}
else if (strncmp(option, "-verbose", option_len) == 0)
{
- printf("--verbose\n");
-
options.verbose = TRUE;
}
else if (*option == '-')
+ {
Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);
+ }
else if (options.server_host == NULL)
{
options.server_host = *options_left;
-
- printf("server.name == '%s'\n", options.server_host);
}
else if (options.server_port == 0)
{
options.server_port = atoi(*options_left);
if (options.server_port < 1024)
Error(ERR_EXIT_HELP, "bad port number '%d'", options.server_port);
-
- printf("port == %d\n", options.server_port);
}
else
Error(ERR_EXIT_HELP, "too many arguments");
void Error(int mode, char *format, ...)
{
char *process_name = "";
+ FILE *error = stderr;
+
+ /* display warnings only when running in verbose mode */
+ if (mode & ERR_WARN && !options.verbose)
+ return;
+
+#ifdef MSDOS
+ if ((error = openErrorFile()) == NULL)
+ {
+ printf("Cannot write to error output file!\n");
+ CloseAllAndExit(1);
+ }
+#endif
if (mode & ERR_SOUND_SERVER)
process_name = " sound server";
{
va_list ap;
- fprintf(stderr, "%s%s: ", program_name, process_name);
+ fprintf(error, "%s%s: ", program_name, process_name);
if (mode & ERR_WARN)
- fprintf(stderr, "warning: ");
+ fprintf(error, "warning: ");
va_start(ap, format);
- vfprintf(stderr, format, ap);
+ vfprintf(error, format, ap);
va_end(ap);
- fprintf(stderr, "\n");
+ fprintf(error, "\n");
}
if (mode & ERR_HELP)
- fprintf(stderr, "%s: Try option '--help' for more information.\n",
+ fprintf(error, "%s: Try option '--help' for more information.\n",
program_name);
if (mode & ERR_EXIT)
- {
- fprintf(stderr, "%s%s: aborting\n", program_name, process_name);
+ fprintf(error, "%s%s: aborting\n", program_name, process_name);
+ if (error != stderr)
+ fclose(error);
+
+ if (mode & ERR_EXIT)
+ {
if (mode & ERR_FROM_SERVER)
exit(1); /* child process: normal exit */
else
{ XK_apostrophe, "XK_apostrophe", "'" },
{ XK_plus, "XK_plus", "+" },
{ XK_minus, "XK_minus", "-" },
+ { XK_equal, "XK_equal", "equal" },
{ XK_comma, "XK_comma", "," },
{ XK_period, "XK_period", "." },
+ { XK_colon, "XK_colon", ";" },
+ { XK_slash, "XK_slash", "/" },
{ XK_numbersign, "XK_numbersign", "#" },
+ { XK_backslash, "XK_backslash", "backslash" },
+ { XK_braceleft, "XK_braceleft", "brace left" },
+ { XK_braceright, "XK_braceright", "brace right" },
{ XK_less, "XK_less", "less" },
{ XK_greater, "XK_greater", "greater" },
{ XK_asciicircum, "XK_asciicircum", "circumflex" },
return joysymbol;
}
+int getJoystickNrFromDeviceName(char *device_name)
+{
+ char c;
+ int joystick_nr = 0;
+
+ if (device_name == NULL || device_name[0] == '\0')
+ return 0;
+
+ c = device_name[strlen(device_name) - 1];
+
+ if (c >= '0' && c <= '9')
+ joystick_nr = (int)(c - '0');
+
+ if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS)
+ joystick_nr = 0;
+
+ return joystick_nr;
+}
+
+/* ----------------------------------------------------------------- */
/* the following is only for debugging purpose and normally not used */
+/* ----------------------------------------------------------------- */
+
#define DEBUG_NUM_TIMESTAMPS 3
void debug_print_timestamp(int counter_nr, char *message)
counter[counter_nr][1] = Counter();
}
-
-void print_debug(char *s)
-{
- FILE *f;
-
- if (!s)
- {
- if ((f = fopen("debug.asc", "w")) == NULL)
- {
- printf("Cannot write to debug file!\n");
- exit(1);
- }
- fclose(f);
- return;
- }
-
- if ((f = fopen("debug.asc", "a")) == NULL)
- {
- printf("Cannot append to debug file!\n");
- exit(1);
- }
-
- fprintf(f, "%s\r\n", s);
- fclose(f);
-}