rnd-20030331-1-src
authorHolger Schemel <info@artsoft.org>
Mon, 31 Mar 2003 00:09:43 +0000 (02:09 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:40:47 +0000 (10:40 +0200)
15 files changed:
src/Makefile
src/conftime.h
src/files.c
src/init.c
src/libgame/macosx.h [new file with mode: 0644]
src/libgame/misc.c
src/libgame/misc.h
src/libgame/setup.c
src/libgame/setup.h
src/libgame/system.c
src/libgame/system.h
src/libgame/types.h
src/libgame/windows.h [new file with mode: 0644]
src/main.c
src/main.h

index fe9f33e07d3c794fbf079245a806f53640143d43..595f5996acb4a4770dcf80e888de840d08f2ee3d 100644 (file)
@@ -64,6 +64,7 @@ TARGET = allegro
 endif
 
 ifeq ($(PLATFORM),cross-win32)
+EXTRA_LDFLAGS = -lshfolder
 PROGNAME = ../$(PROGBASE).exe
 TARGET = sdl
 endif
index ed9b5fa231cec369ce2c12c5019136ef776089d1..896228b693ca5430dca701ca021e0967da69f5c2 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2003-03-27 00:55]"
+#define COMPILE_DATE_STRING "[2003-03-31 02:04]"
index 436decce8759e073aefceeb3d69aaa1fad2d8bfc..15264d2d4e3a6eeea4f12a875469f3496d01dc16 100644 (file)
@@ -1515,11 +1515,26 @@ static struct TokenInfo options_setup_tokens[] =
   { 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;
@@ -1660,6 +1675,8 @@ void LoadSetup()
 
   if (setup_file_list)
   {
+    char *player_name_new;
+
     checkSetupFileListIdentifier(setup_file_list, getCookie("SETUP"));
     decodeSetupFileList(setup_file_list);
 
@@ -1668,16 +1685,9 @@ void LoadSetup()
     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");
index 46f27d80a291445d1526f05172838d991cc3fdb1..80073129cc76208eb9d72c61abd0790f39b1e01d 100644 (file)
@@ -24,7 +24,6 @@
 #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 */
@@ -2770,12 +2769,6 @@ void OpenAll()
     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();
diff --git a/src/libgame/macosx.h b/src/libgame/macosx.h
new file mode 100644 (file)
index 0000000..7cccf57
--- /dev/null
@@ -0,0 +1,24 @@
+/***********************************************************
+* 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 */
index 2750b627f09d507494596ff02a83682c9a44d04f..cffa180b240647cf965a734315ffefb92efb3986 100644 (file)
@@ -332,13 +332,53 @@ unsigned int get_random_number(int nr, unsigned int max)
 /* 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;
@@ -348,70 +388,73 @@ char *getLoginName()
     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;
 }
 
 
index 6b05533ad7a30e80b94ef4fa2bb1488c70a0f6c2..2a727278931a41c64f3853a84c83812d8c960922 100644 (file)
 
 /* 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);
index dcf94aaa43d2961368a1e4c961f420bebd3ffe94..68dd7434d5d6e9553131300b8dc5bdb186595cb8 100644 (file)
@@ -170,7 +170,7 @@ static char *getTapeDir(char *level_subdir)
 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)
@@ -610,6 +610,7 @@ void InitTapeDirectory(char *level_subdir)
 
 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);
 }
@@ -885,15 +886,33 @@ char *getUserDataDir(void)
 {
   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()
index e5dc50d88ea7b4c873f64a185d9653730f8efe40..618e7cb0a2f343a521851c610156ac5f52be2c73 100644 (file)
@@ -195,6 +195,7 @@ void sortTreeInfo(TreeInfo **,
                  int (*compare_function)(const void *, const void *));
 
 char *getUserDataDir(void);
+char *getCommonDataDir(void);
 char *getSetupDir(void);
 void createDirectory(char *, char *, int);
 void InitUserDataDirectory(void);
index 0131c133e7543bb252a2fd76963ce794582b4984..1e628241f9eedb648019b17d71940aeb75ca3579 100644 (file)
@@ -66,10 +66,31 @@ int                 FrameCounter = 0;
 /* 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))
@@ -90,13 +111,6 @@ void InitPlatformDependantStuff(void)
 {
 #if defined(PLATFORM_MSDOS)
   _fmode = O_BINARY;
-#endif
-
-#if !defined(PLATFORM_UNIX)
-  program.userdata_directory = "userdata";
-#endif
-
-#if defined(PLATFORM_MSDOS)
   initErrorFile();
 #endif
 
@@ -113,34 +127,6 @@ void ClosePlatformDependantStuff(void)
 #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)
index bba4a30523e0358341819b04a5f250fe2247c8f7..2abb3cdda2cc7d64f4e0e27f42b1144b1c15acfc 100644 (file)
 #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"
@@ -632,14 +629,13 @@ extern int                        FrameCounter;
 
 /* 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);
index 1c527d09faed9d414877114d847be9e1a0eaa419..c8ab0efc85fac9471049ab5a6a15714fdd3e145c 100644 (file)
 #include <sys/types.h>
 
 typedef unsigned char boolean;
+
+#if !defined(PLATFORM_WIN32)
 typedef unsigned char byte;
+#endif
 
 #ifndef FALSE
 #define FALSE          0
diff --git a/src/libgame/windows.h b/src/libgame/windows.h
new file mode 100644 (file)
index 0000000..d96d4b7
--- /dev/null
@@ -0,0 +1,41 @@
+/***********************************************************
+* 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 */
index 4fd5ead512b0993598752a36ddd987c1c3240deb..bcd5dce7d742449b346de7d08f1e968a5650ae7d 100644 (file)
@@ -17,6 +17,7 @@
 #include "init.h"
 #include "game.h"
 #include "events.h"
+#include "config.h"
 
 #if 0
 GC                     tile_clip_gc;
@@ -3035,7 +3036,12 @@ struct FontInfo font_info[NUM_FONTS + 1] =
 
 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();
 
index b75fc447bfa4a5eb6371592522d8ef2a56508ac0..3922fb29bc760a9ee792a9d86e9589fa5e5ceb85 100644 (file)
 #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"