endif
ifeq ($(PLATFORM),cross-win32)
+EXTRA_LDFLAGS = -lshfolder
PROGNAME = ../$(PROGBASE).exe
TARGET = sdl
endif
-#define COMPILE_DATE_STRING "[2003-03-27 00:55]"
+#define COMPILE_DATE_STRING "[2003-03-31 02:04]"
{ TYPE_BOOLEAN, &soi.verbose, "options.verbose" }
};
+static char *get_corrected_login_name(char *login_name)
+{
+ /* needed because player name must be a fixed length string */
+ char *login_name_new = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
+
+ strncpy(login_name_new, login_name, MAX_PLAYER_NAME_LEN);
+ login_name_new[MAX_PLAYER_NAME_LEN] = '\0';
+
+ if (strlen(login_name) > MAX_PLAYER_NAME_LEN) /* name has been cut */
+ if (strchr(login_name_new, ' '))
+ *strchr(login_name_new, ' ') = '\0';
+
+ return login_name_new;
+}
+
static void setSetupInfoToDefaults(struct SetupInfo *si)
{
int i;
- si->player_name = getStringCopy(getLoginName());
+ si->player_name = get_corrected_login_name(getLoginName());
si->sound = TRUE;
si->sound_loops = TRUE;
if (setup_file_list)
{
+ char *player_name_new;
+
checkSetupFileListIdentifier(setup_file_list, getCookie("SETUP"));
decodeSetupFileList(setup_file_list);
freeSetupFileList(setup_file_list);
/* needed to work around problems with fixed length strings */
- if (strlen(setup.player_name) > MAX_PLAYER_NAME_LEN)
- setup.player_name[MAX_PLAYER_NAME_LEN] = '\0';
- else if (strlen(setup.player_name) < MAX_PLAYER_NAME_LEN)
- {
- char *new_name = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
-
- strcpy(new_name, setup.player_name);
- free(setup.player_name);
- setup.player_name = new_name;
- }
+ player_name_new = get_corrected_login_name(setup.player_name);
+ free(setup.player_name);
+ setup.player_name = player_name_new;
}
else
Error(ERR_WARN, "using default setup values");
#include "network.h"
#include "netserv.h"
#include "cartoons.h"
-#include "config.h"
#include "conf_e2g.c" /* include auto-generated data structure definitions */
#include "conf_esg.c" /* include auto-generated data structure definitions */
exit(0); /* never reached */
}
- InitProgramInfo(UNIX_USERDATA_DIRECTORY,
- PROGRAM_TITLE_STRING, getWindowTitleString(),
- ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
- MSDOS_POINTER_FILENAME,
- COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
-
InitSetup();
InitPlayerInfo();
--- /dev/null
+/***********************************************************
+* Artsoft Retro-Game Library *
+*----------------------------------------------------------*
+* (c) 1994-2003 Artsoft Entertainment *
+* Holger Schemel *
+* Detmolder Strasse 189 *
+* 33604 Bielefeld *
+* Germany *
+* e-mail: info@artsoft.org *
+*----------------------------------------------------------*
+* macosx.h *
+***********************************************************/
+
+#ifndef MACOSX_H
+#define MACOSX_H
+
+
+/* some symbols are already defined on Mac OS X */
+#define Delay Delay_internal
+#define DrawLine DrawLine_internal
+#define DrawText DrawText_internal
+#define GetPixel GetPixel_internal
+
+#endif /* MACOSX_H */
/* system info functions */
/* ------------------------------------------------------------------------- */
+static char *get_corrected_real_name(char *real_name)
+{
+ char *real_name_new = checked_malloc(MAX_USERNAME_LEN + 1);
+ char *from_ptr = real_name;
+ char *to_ptr = real_name_new;
+
+ if (strchr(real_name, 'ß') == NULL) /* name does not contain 'ß' */
+ {
+ strncpy(real_name_new, real_name, MAX_USERNAME_LEN);
+ real_name_new[MAX_USERNAME_LEN] = '\0';
+
+ return real_name_new;
+ }
+
+ /* the user's real name may contain a 'ß' character (german sharp s),
+ which has no equivalent in upper case letters (which our fonts use) */
+ while (*from_ptr && (long)(to_ptr - real_name_new) < MAX_USERNAME_LEN - 1)
+ {
+ if (*from_ptr != 'ß')
+ *to_ptr++ = *from_ptr++;
+ else
+ {
+ from_ptr++;
+ *to_ptr++ = 's';
+ *to_ptr++ = 's';
+ }
+ }
+
+ *to_ptr = '\0';
+
+ return real_name_new;
+}
+
char *getLoginName()
{
-#if defined(PLATFORM_WIN32)
- return ANONYMOUS_NAME;
-#else
static char *login_name = NULL;
+#if defined(PLATFORM_WIN32)
+ if (login_name == NULL)
+ {
+ unsigned long buffer_size = MAX_USERNAME_LEN + 1;
+ login_name = checked_malloc(buffer_size);
+
+ if (GetUserName(login_name, &buffer_size) == 0)
+ strcpy(login_name, ANONYMOUS_NAME);
+ }
+#else
if (login_name == NULL)
{
struct passwd *pwd;
else
login_name = getStringCopy(pwd->pw_name);
}
+#endif
return login_name;
-#endif
}
char *getRealName()
{
-#if defined(PLATFORM_UNIX)
- struct passwd *pwd;
+ static char *real_name = NULL;
- if ((pwd = getpwuid(getuid())) == NULL || strlen(pwd->pw_gecos) == 0)
- return ANONYMOUS_NAME;
- else
+#if defined(PLATFORM_WIN32)
+ if (real_name == NULL)
{
- static char real_name[1024];
- char *from_ptr = pwd->pw_gecos, *to_ptr = real_name;
-
- if (strchr(pwd->pw_gecos, 'ß') == NULL)
- return pwd->pw_gecos;
+ static char buffer[MAX_USERNAME_LEN + 1];
+ unsigned long buffer_size = MAX_USERNAME_LEN + 1;
- /* the user's real name contains a 'ß' character (german sharp s),
- which has no equivalent in upper case letters (which our fonts use) */
- while (*from_ptr != '\0' && (long)(to_ptr - real_name) < 1024 - 2)
- {
- if (*from_ptr != 'ß')
- *to_ptr++ = *from_ptr++;
- else
- {
- from_ptr++;
- *to_ptr++ = 's';
- *to_ptr++ = 's';
- }
- }
- *to_ptr = '\0';
+ if (GetUserName(buffer, &buffer_size) != 0)
+ real_name = get_corrected_real_name(buffer);
+ else
+ real_name = ANONYMOUS_NAME;
+ }
+#elif defined(PLATFORM_UNIX)
+ if (real_name == NULL)
+ {
+ struct passwd *pwd;
- return real_name;
+ if ((pwd = getpwuid(getuid())) != NULL && strlen(pwd->pw_gecos) != 0)
+ real_name = get_corrected_real_name(pwd->pw_gecos);
+ else
+ real_name = ANONYMOUS_NAME;
}
-#else /* !PLATFORM_UNIX */
- return ANONYMOUS_NAME;
+#else
+ real_name = ANONYMOUS_NAME;
#endif
+
+ return real_name;
}
char *getHomeDir()
{
-#if defined(PLATFORM_UNIX)
- static char *home_dir = NULL;
+ static char *dir = NULL;
- if (home_dir == NULL)
+#if defined(PLATFORM_WIN32)
+ if (dir == NULL)
+ {
+ dir = checked_malloc(MAX_PATH + 1);
+
+ if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, dir)))
+ strcpy(dir, ".");
+ }
+#elif defined(PLATFORM_UNIX)
+ if (dir == NULL)
{
- if ((home_dir = getenv("HOME")) == NULL)
+ if ((dir = getenv("HOME")) == NULL)
{
struct passwd *pwd;
- if ((pwd = getpwuid(getuid())) == NULL)
- home_dir = ".";
+ if ((pwd = getpwuid(getuid())) != NULL)
+ dir = getStringCopy(pwd->pw_dir);
else
- home_dir = getStringCopy(pwd->pw_dir);
+ dir = ".";
}
}
-
- return home_dir;
#else
- return ".";
+ dir = ".";
#endif
+
+ return dir;
}
/* values for general file handling stuff */
#define MAX_FILENAME_LEN 256
-#define MAX_LINE_LEN 1000
+#define MAX_LINE_LEN 1024
+
+/* values for general username handling stuff */
+#define MAX_USERNAME_LEN 1024
+
void fprintf_line(FILE *, char *, int);
void printf_line(char *, int);
static char *getScoreDir(char *level_subdir)
{
static char *score_dir = NULL;
- char *data_dir = options.rw_base_directory;
+ char *data_dir = getCommonDataDir();
char *score_subdir = SCORES_DIRECTORY;
if (score_dir)
void InitScoreDirectory(char *level_subdir)
{
+ createDirectory(getCommonDataDir(), "common data", PERMS_PUBLIC);
createDirectory(getScoreDir(NULL), "main score", PERMS_PUBLIC);
createDirectory(getScoreDir(level_subdir), "level score", PERMS_PUBLIC);
}
{
static char *userdata_dir = NULL;
- if (!userdata_dir)
+ if (userdata_dir == NULL)
+ userdata_dir = getPath2(getHomeDir(), program.userdata_directory);
+
+ return userdata_dir;
+}
+
+char *getCommonDataDir(void)
+{
+ static char *common_data_dir = NULL;
+
+#if defined(PLATFORM_WIN32)
+ if (common_data_dir == NULL)
{
- char *home_dir = getHomeDir();
- char *data_dir = program.userdata_directory;
+ char *dir = checked_malloc(MAX_PATH + 1);
- userdata_dir = getPath2(home_dir, data_dir);
+ if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, dir))
+ && strcmp(dir, "") != 0) /* empty for Windows 95/98 */
+ common_data_dir = getPath2(dir, program.userdata_directory);
+ else
+ common_data_dir = options.rw_base_directory;
}
+#else
+ if (common_data_dir == NULL)
+ common_data_dir = options.rw_base_directory;
+#endif
- return userdata_dir;
+ return common_data_dir;
}
char *getSetupDir()
int (*compare_function)(const void *, const void *));
char *getUserDataDir(void);
+char *getCommonDataDir(void);
char *getSetupDir(void);
void createDirectory(char *, char *, int);
void InitUserDataDirectory(void);
/* init/close functions */
/* ========================================================================= */
-void InitCommandName(char *argv0)
+void InitProgramInfo(char *argv0,
+ char *userdata_directory, char *program_title,
+ char *window_title, char *icon_title,
+ char *x11_icon_filename, char *x11_iconmask_filename,
+ char *msdos_pointer_filename,
+ char *cookie_prefix, char *filename_prefix,
+ int program_version)
{
program.command_basename =
(strrchr(argv0, '/') ? strrchr(argv0, '/') + 1 : argv0);
+
+ program.userdata_directory = userdata_directory;
+ program.program_title = program_title;
+ program.window_title = window_title;
+ program.icon_title = icon_title;
+ program.x11_icon_filename = x11_icon_filename;
+ program.x11_iconmask_filename = x11_iconmask_filename;
+ program.msdos_pointer_filename = msdos_pointer_filename;
+
+ program.cookie_prefix = cookie_prefix;
+ program.filename_prefix = filename_prefix;
+
+ program.version_major = VERSION_MAJOR(program_version);
+ program.version_minor = VERSION_MINOR(program_version);
+ program.version_patch = VERSION_PATCH(program_version);
}
void InitExitFunction(void (*exit_function)(int))
{
#if defined(PLATFORM_MSDOS)
_fmode = O_BINARY;
-#endif
-
-#if !defined(PLATFORM_UNIX)
- program.userdata_directory = "userdata";
-#endif
-
-#if defined(PLATFORM_MSDOS)
initErrorFile();
#endif
#endif
}
-void InitProgramInfo(char *unix_userdata_directory, char *program_title,
- char *window_title, char *icon_title,
- char *x11_icon_filename, char *x11_iconmask_filename,
- char *msdos_pointer_filename,
- char *cookie_prefix, char *filename_prefix,
- int program_version)
-{
-#if defined(PLATFORM_UNIX)
- program.userdata_directory = unix_userdata_directory;
-#else
- program.userdata_directory = "userdata";
-#endif
-
- program.program_title = program_title;
- program.window_title = window_title;
- program.icon_title = icon_title;
- program.x11_icon_filename = x11_icon_filename;
- program.x11_iconmask_filename = x11_iconmask_filename;
- program.msdos_pointer_filename = msdos_pointer_filename;
-
- program.cookie_prefix = cookie_prefix;
- program.filename_prefix = filename_prefix;
-
- program.version_major = VERSION_MAJOR(program_version);
- program.version_minor = VERSION_MINOR(program_version);
- program.version_patch = VERSION_PATCH(program_version);
-}
-
void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
int real_sx, int real_sy,
int full_sxsize, int full_sysize)
#include "platform.h"
#include "types.h"
-#if defined(PLATFORM_MSDOS)
+
+#if defined(PLATFORM_MACOSX)
+#include "macosx.h"
+#elif defined(PLATFORM_WIN32)
+#include "windows.h"
+#elif defined(PLATFORM_MSDOS)
#include "msdos.h"
#endif
#include "x11.h"
#endif
-#if defined(PLATFORM_MACOSX)
-/* some symbols are already defined on Mac OS X */
-#define Delay Delay_internal
-#define DrawLine DrawLine_internal
-#define DrawText DrawText_internal
-#define GetPixel GetPixel_internal
-#endif
-
/* the additional 'b' is needed for Win32 to open files in binary mode */
#define MODE_READ "rb"
/* function definitions */
-void InitCommandName(char *);
+void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
+ char *, char *, char *, int);
+
void InitExitFunction(void (*exit_function)(int));
void InitPlatformDependantStuff(void);
void ClosePlatformDependantStuff(void);
-void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
- char *, char *, int);
-
void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
void InitGfxDoor1Info(int, int, int, int);
void InitGfxDoor2Info(int, int, int, int);
#include <sys/types.h>
typedef unsigned char boolean;
+
+#if !defined(PLATFORM_WIN32)
typedef unsigned char byte;
+#endif
#ifndef FALSE
#define FALSE 0
--- /dev/null
+/***********************************************************
+* Artsoft Retro-Game Library *
+*----------------------------------------------------------*
+* (c) 1994-2003 Artsoft Entertainment *
+* Holger Schemel *
+* Detmolder Strasse 189 *
+* 33604 Bielefeld *
+* Germany *
+* e-mail: info@artsoft.org *
+*----------------------------------------------------------*
+* windows.h *
+***********************************************************/
+
+#ifndef WINDOWS_H
+#define WINDOWS_H
+
+#include <shlobj.h>
+
+
+/* some symbols are already defined on Windows */
+#define CreateBitmap CreateBitmap_internal
+#define GetPixel GetPixel_internal
+#define CloseWindow CloseWindow_internal
+#define FloodFill FloodFill_internal
+
+#ifdef LoadImage
+#undef LoadImage
+#define LoadImage LoadImage_internal
+#endif
+
+#ifdef PlaySound
+#undef PlaySound
+#define PlaySound PlaySound_internal
+#endif
+
+#ifdef DrawText
+#undef DrawText
+#define DrawText DrawText_internal
+#endif
+
+#endif /* WINDOWS_H */
#include "init.h"
#include "game.h"
#include "events.h"
+#include "config.h"
#if 0
GC tile_clip_gc;
int main(int argc, char *argv[])
{
- InitCommandName(argv[0]);
+ InitProgramInfo(argv[0], USERDATA_DIRECTORY,
+ PROGRAM_TITLE_STRING, getWindowTitleString(),
+ ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
+ MSDOS_POINTER_FILENAME,
+ COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
+
InitExitFunction(CloseAllAndExit);
InitPlatformDependantStuff();
#define WINDOW_TITLE_STRING PROGRAM_TITLE_STRING " " PROGRAM_IDENT_STRING
#define WINDOW_SUBTITLE_STRING PROGRAM_RIGHTS_STRING " " PROGRAM_AUTHOR_STRING
#define ICON_TITLE_STRING PROGRAM_TITLE_STRING
-#define UNIX_USERDATA_DIRECTORY ".rocksndiamonds"
#define COOKIE_PREFIX "ROCKSNDIAMONDS"
#define FILENAME_PREFIX "Rocks"
+#define USERDATA_DIR_STRING "Userdata"
+#if defined(PLATFORM_UNIX)
+#define USERDATA_DIRECTORY ".rocksndiamonds"
+#elif defined(PLATFORM_WIN32)
+#define USERDATA_DIRECTORY PROGRAM_TITLE_STRING " " USERDATA_DIR_STRING
+#else
+#define USERDATA_DIRECTORY USERDATA_DIR_STRING
+#endif
+
#define X11_ICON_FILENAME "rocks_icon.xbm"
#define X11_ICONMASK_FILENAME "rocks_iconmask.xbm"
#define MSDOS_POINTER_FILENAME "mouse.pcx"