/***********************************************************
* Artsoft Retro-Game Library *
*----------------------------------------------------------*
-* (c) 1994-2001 Artsoft Entertainment *
+* (c) 1994-2002 Artsoft Entertainment *
* Holger Schemel *
* Detmolder Strasse 189 *
* 33604 Bielefeld *
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
-/*
-#include <sys/stat.h>
-*/
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
{
boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE);
+#if 0
#if defined(PLATFORM_MSDOS)
- /* don't use select() to perform waiting operations under DOS/Windows
+ /* don't use select() to perform waiting operations under DOS
environment; always use a busy loop for waiting instead */
do_busy_waiting = TRUE;
+#endif
#endif
if (do_busy_waiting)
{
#if defined(TARGET_SDL)
SDL_Delay(milliseconds_delay);
+#elif defined(TARGET_ALLEGRO)
+ rest(milliseconds_delay);
#else
struct timeval delay;
{
unsigned long actual_frame_counter = FrameCounter;
- if (actual_frame_counter < *frame_counter_var+frame_delay &&
+ if (actual_frame_counter < *frame_counter_var + frame_delay &&
actual_frame_counter >= *frame_counter_var)
- return(FALSE);
+ return FALSE;
*frame_counter_var = actual_frame_counter;
- return(TRUE);
+
+ return TRUE;
}
boolean DelayReached(unsigned long *counter_var,
if (actual_counter < *counter_var + delay &&
actual_counter >= *counter_var)
- return(FALSE);
+ return FALSE;
*counter_var = actual_counter;
- return(TRUE);
+
+ return TRUE;
}
void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
#if defined(PLATFORM_WIN32)
return ANONYMOUS_NAME;
#else
- struct passwd *pwd;
+ static char *login_name = NULL;
- if ((pwd = getpwuid(getuid())) == NULL)
- return ANONYMOUS_NAME;
- else
- return pwd->pw_name;
+ if (login_name == NULL)
+ {
+ struct passwd *pwd;
+
+ if ((pwd = getpwuid(getuid())) == NULL)
+ login_name = ANONYMOUS_NAME;
+ else
+ login_name = getStringCopy(pwd->pw_name);
+ }
+
+ return login_name;
#endif
}
#if defined(PLATFORM_UNIX)
static char *home_dir = NULL;
- if (!home_dir)
+ if (home_dir == NULL)
{
- if (!(home_dir = getenv("HOME")))
+ if ((home_dir = getenv("HOME")) == NULL)
{
struct passwd *pwd;
- if ((pwd = getpwuid(getuid())))
- home_dir = pwd->pw_dir;
- else
+ if ((pwd = getpwuid(getuid())) == NULL)
home_dir = ".";
+ else
+ home_dir = getStringCopy(pwd->pw_dir);
}
}
options.network = FALSE;
options.verbose = FALSE;
options.debug = FALSE;
+ options.debug_command = NULL;
while (*options_left)
{
Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
else if (strncmp(option, "-help", option_len) == 0)
{
- printf("Usage: %s [options] [server.name [port]]\n"
+ printf("Usage: %s [options] [<server host> [<server port>]]\n"
"Options:\n"
" -d, --display <host>[:<scr>] X server display\n"
" -b, --basepath <directory> alternative base directory\n"
" -l, --level <directory> alternative level directory\n"
" -g, --graphics <directory> alternative graphics directory\n"
- " -s, --sounds <directory> alternative graphics directory\n"
- " -m, --music <directory> alternative graphics directory\n"
+ " -s, --sounds <directory> alternative sounds directory\n"
+ " -m, --music <directory> alternative music directory\n"
" -n, --network network multiplayer game\n"
" --serveronly only start network server\n"
" -v, --verbose verbose mode\n"
" --debug display debugging information\n",
program.command_basename);
+
+ if (options.debug)
+ printf(" --debug-command <command> execute special command\n");
+
exit(0);
}
else if (strncmp(option, "-display", option_len) == 0)
{
options.debug = TRUE;
}
+ else if (strncmp(option, "-debug-command", option_len) == 0)
+ {
+ if (option_arg == NULL)
+ Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
+
+ options.debug_command = option_arg;
+ if (option_arg == next_option)
+ options_left++;
+ }
else if (*option == '-')
{
Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);
if (mode & ERR_WARN && !options.verbose)
return;
-#if !defined(PLATFORM_UNIX)
+#if defined(PLATFORM_MSDOS)
newline = "\r\n";
if ((error = openErrorFile()) == NULL)
}
}
+int getFileVersion(FILE *file)
+{
+ int version_major, version_minor, version_patch;
+
+ version_major = fgetc(file);
+ version_minor = fgetc(file);
+ version_patch = fgetc(file);
+ fgetc(file); /* not used */
+
+ return VERSION_IDENT(version_major, version_minor, version_patch);
+}
+
+void putFileVersion(FILE *file, int version)
+{
+ int version_major = VERSION_MAJOR(version);
+ int version_minor = VERSION_MINOR(version);
+ int version_patch = VERSION_PATCH(version);
+
+ fputc(version_major, file);
+ fputc(version_minor, file);
+ fputc(version_patch, file);
+ fputc(0, file); /* not used */
+}
+
void ReadUnusedBytesFromFile(FILE *file, unsigned long bytes)
{
- while (bytes--)
+ while (bytes-- && !feof(file))
fgetc(file);
}
fputc(0, file);
}
+
+/* ------------------------------------------------------------------------- */
+/* functions to translate key identifiers between different format */
+/* ------------------------------------------------------------------------- */
+
#define TRANSLATE_KEYSYM_TO_KEYNAME 0
#define TRANSLATE_KEYSYM_TO_X11KEYNAME 1
#define TRANSLATE_KEYNAME_TO_KEYSYM 2
sprintf(name_buffer, "%c", '0' + (char)(key - KSYM_0));
else if (key >= KSYM_KP_0 && key <= KSYM_KP_9)
sprintf(name_buffer, "keypad %c", '0' + (char)(key - KSYM_KP_0));
- else if (key >= KSYM_F1 && key <= KSYM_F24)
- sprintf(name_buffer, "function F%d", (int)(key - KSYM_F1 + 1));
+ else if (key >= KSYM_FKEY_FIRST && key <= KSYM_FKEY_LAST)
+ sprintf(name_buffer, "function F%d", (int)(key - KSYM_FKEY_FIRST + 1));
else if (key == KSYM_UNDEFINED)
strcpy(name_buffer, "(undefined)");
else
sprintf(name_buffer, "XK_%c", '0' + (char)(key - KSYM_0));
else if (key >= KSYM_KP_0 && key <= KSYM_KP_9)
sprintf(name_buffer, "XK_KP_%c", '0' + (char)(key - KSYM_KP_0));
- else if (key >= KSYM_F1 && key <= KSYM_F24)
- sprintf(name_buffer, "XK_F%d", (int)(key - KSYM_F1 + 1));
+ else if (key >= KSYM_FKEY_FIRST && key <= KSYM_FKEY_LAST)
+ sprintf(name_buffer, "XK_F%d", (int)(key - KSYM_FKEY_FIRST + 1));
else if (key == KSYM_UNDEFINED)
strcpy(name_buffer, "[undefined]");
else
((c2 >= '0' && c1 <= '9') || c2 == '\0'))
d = atoi(&name_ptr[4]);
- if (d >=1 && d <= 24)
+ if (d >= 1 && d <= KSYM_NUM_FKEYS)
key = KSYM_F1 + (Key)(d - 1);
}
else if (strncmp(name_ptr, "XK_", 3) == 0)
/* ========================================================================= */
-/* functions only needed for non-Unix (non-command-line) systems */
+/* functions for checking filenames */
/* ========================================================================= */
-#if !defined(PLATFORM_UNIX)
+boolean FileIsGraphic(char *filename)
+{
+ if (strlen(filename) > 4 &&
+ strcmp(&filename[strlen(filename) - 4], ".pcx") == 0)
+ return TRUE;
-#define ERROR_FILENAME "error.out"
+ return FALSE;
+}
-void initErrorFile()
+boolean FileIsSound(char *basename)
{
- char *filename;
+ if (strlen(basename) > 4 &&
+ strcmp(&basename[strlen(basename) - 4], ".wav") == 0)
+ return TRUE;
- InitUserDataDirectory();
+ return FALSE;
+}
- filename = getPath2(getUserDataDir(), ERROR_FILENAME);
- unlink(filename);
- free(filename);
+boolean FileIsMusic(char *basename)
+{
+ /* "music" can be a WAV (loop) file or (if compiled with SDL) a MOD file */
+
+ if (FileIsSound(basename))
+ return TRUE;
+
+#if defined(TARGET_SDL)
+ if (strlen(basename) > 4 &&
+ (strcmp(&basename[strlen(basename) - 4], ".mod") == 0 ||
+ strcmp(&basename[strlen(basename) - 4], ".MOD") == 0 ||
+ strncmp(basename, "mod.", 4) == 0 ||
+ strncmp(basename, "MOD.", 4) == 0))
+ return TRUE;
+#endif
+
+ return FALSE;
}
-FILE *openErrorFile()
+boolean FileIsArtworkType(char *basename, int type)
{
- char *filename;
- FILE *error_file;
+ if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(basename)) ||
+ (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(basename)) ||
+ (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(basename)))
+ return TRUE;
- filename = getPath2(getUserDataDir(), ERROR_FILENAME);
- error_file = fopen(filename, MODE_APPEND);
- free(filename);
+ return FALSE;
+}
+
+
+/* ========================================================================= */
+/* functions only needed for non-Unix (non-command-line) systems */
+/* (MS-DOS only; SDL/Windows creates files "stdout.txt" and "stderr.txt") */
+/* ========================================================================= */
+
+#if defined(PLATFORM_MSDOS)
+
+#define ERROR_FILENAME "stderr.txt"
- return error_file;
+void initErrorFile()
+{
+ unlink(ERROR_FILENAME);
}
-void dumpErrorFile()
+FILE *openErrorFile()
{
- char *filename;
- FILE *error_file;
+ return fopen(ERROR_FILENAME, MODE_APPEND);
+}
- filename = getPath2(getUserDataDir(), ERROR_FILENAME);
- error_file = fopen(filename, MODE_READ);
- free(filename);
+void dumpErrorFile()
+{
+ FILE *error_file = fopen(ERROR_FILENAME, MODE_READ);
if (error_file != NULL)
{