added abstractions for using getpwuid()
[rocksndiamonds.git] / src / libgame / setup.c
index 599bff5d462d0ca5a833be648578530340fce06d..f1b87e170499063fbc93b0b01d6afd404e47a27c 100644 (file)
 
 #include "platform.h"
 
-#if !defined(PLATFORM_WIN32)
-#include <pwd.h>
-#include <sys/param.h>
-#endif
-
 #include "setup.h"
 #include "joystick.h"
 #include "text.h"
@@ -1361,19 +1356,19 @@ void dumpTreeInfo(TreeInfo *node, int depth)
 {
   int i;
 
-  printf("Dumping TreeInfo:\n");
+  Debug("tree", "Dumping TreeInfo:");
 
   while (node)
   {
     for (i = 0; i < (depth + 1) * 3; i++)
-      printf(" ");
+      DebugContinued("", " ");
 
-    printf("'%s' / '%s'\n", node->identifier, node->name);
+    DebugContinued("tree", "'%s' / '%s'\n", node->identifier, node->name);
 
     /*
     // use for dumping artwork info tree
-    printf("subdir == '%s' ['%s', '%s'] [%d])\n",
-          node->subdir, node->fullpath, node->basepath, node->in_user_dir);
+    Debug("tree", "subdir == '%s' ['%s', '%s'] [%d])",
+         node->subdir, node->fullpath, node->basepath, node->in_user_dir);
     */
 
     if (node->node_group != NULL)
@@ -1504,10 +1499,10 @@ char *getHomeDir(void)
   {
     if ((dir = getenv("HOME")) == NULL)
     {
-      struct passwd *pwd;
+      dir = getUnixHomeDir();
 
-      if ((pwd = getpwuid(getuid())) != NULL)
-       dir = getStringCopy(pwd->pw_dir);
+      if (dir != NULL)
+       dir = getStringCopy(dir);
       else
        dir = ".";
     }
@@ -1830,8 +1825,8 @@ static void printSetupFileList(SetupFileList *list)
   if (!list)
     return;
 
-  printf("token: '%s'\n", list->token);
-  printf("value: '%s'\n", list->value);
+  Debug("setup:printSetupFileList", "token: '%s'", list->token);
+  Debug("setup:printSetupFileList", "value: '%s'", list->value);
 
   printSetupFileList(list->next);
 }
@@ -1891,7 +1886,7 @@ SetupFileHash *newSetupFileHash(void)
     create_hashtable(16, 0.75, get_hash_from_key, keys_are_equal);
 
   if (new_hash == NULL)
-    Error(ERR_EXIT, "create_hashtable() failed -- out of memory");
+    Fail("create_hashtable() failed -- out of memory");
 
   return new_hash;
 }
@@ -1924,7 +1919,7 @@ void setHashEntry(SetupFileHash *hash, char *token, char *value)
   // change value; if it does not exist, insert it as new
   if (!change_hash_entry(hash, token, value_copy))
     if (!insert_hash_entry(hash, getStringCopy(token), value_copy))
-      Error(ERR_EXIT, "cannot insert into hash -- aborting");
+      Fail("cannot insert into hash -- aborting");
 }
 
 char *removeHashEntry(SetupFileHash *hash, char *token)
@@ -1941,8 +1936,8 @@ static void printSetupFileHash(SetupFileHash *hash)
 {
   BEGIN_HASH_ITERATION(hash, itr)
   {
-    printf("token: '%s'\n", HASH_ITERATION_TOKEN(itr));
-    printf("value: '%s'\n", HASH_ITERATION_VALUE(itr));
+    Debug("setup:printSetupFileHash", "token: '%s'", HASH_ITERATION_TOKEN(itr));
+    Debug("setup:printSetupFileHash", "value: '%s'", HASH_ITERATION_VALUE(itr));
   }
   END_HASH_ITERATION(hash, itr)
 }
@@ -3540,7 +3535,7 @@ void LoadLevelInfo(void)
   leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
 
   if (leveldir_first == NULL)
-    Error(ERR_EXIT, "cannot find any valid level series in any directory");
+    Fail("cannot find any valid level series in any directory");
 
   sortTreeInfo(&leveldir_first);
 
@@ -3830,9 +3825,12 @@ void LoadArtworkInfo(void)
   artwork.mus_current_identifier = artwork.mus_current->identifier;
 
 #if ENABLE_UNUSED_CODE
-  printf("graphics set == %s\n\n", artwork.gfx_current_identifier);
-  printf("sounds set == %s\n\n", artwork.snd_current_identifier);
-  printf("music set == %s\n\n", artwork.mus_current_identifier);
+  Debug("setup:LoadArtworkInfo", "graphics set == %s",
+       artwork.gfx_current_identifier);
+  Debug("setup:LoadArtworkInfo", "sounds set == %s",
+       artwork.snd_current_identifier);
+  Debug("setup:LoadArtworkInfo", "music set == %s",
+       artwork.mus_current_identifier);
 #endif
 
   sortTreeInfo(&artwork.gfx_first);
@@ -4050,7 +4048,7 @@ void AddTreeSetToTreeInfo(TreeInfo *tree_node, char *tree_dir,
                          char *tree_subdir_new, int type)
 {
   if (!AddTreeSetToTreeInfoExt(tree_node, tree_dir, tree_subdir_new, type))
-    Error(ERR_EXIT, "internal tree info structure corrupted -- aborting");
+    Fail("internal tree info structure corrupted -- aborting");
 }
 
 void AddUserLevelSetToLevelInfo(char *level_subdir_new)
@@ -4092,7 +4090,7 @@ TreeInfo *getArtworkTreeInfoForUserLevelSet(int type)
     ti = getTreeInfoFromIdentifier(artwork_first_node,
                                   ARTWORK_DEFAULT_SUBDIR(type));
     if (ti == NULL)
-      Error(ERR_EXIT, "cannot find default graphics -- should not happen");
+      Fail("cannot find default graphics -- should not happen");
   }
 
   return ti;