pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src globals.hxx,1.14,1.15 path_manager.cx


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src globals.hxx,1.14,1.15 path_manager.cxx,1.4,1.5 pingus_main.cxx,1.79,1.80 system.cxx,1.16,1.17 system.hxx,1.8,1.9
Date: 13 Apr 2003 23:33:21 -0000

Update of /var/lib/cvs/Games/Pingus/src
In directory dark:/tmp/cvs-serv10100

Modified Files:
        globals.hxx path_manager.cxx pingus_main.cxx system.cxx 
        system.hxx 
Log Message:
- added some more path-finding magic
- some cleanup
- added Sytem:: stuff for symlink handling

Index: globals.hxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/globals.hxx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- globals.hxx 10 Apr 2003 19:38:51 -0000      1.14
+++ globals.hxx 13 Apr 2003 23:33:19 -0000      1.15
@@ -75,6 +75,7 @@
        PINGUS_DEBUG_GUI        = (1 << 9),
        PINGUS_DEBUG_INPUT      = (1 << 10),
        PINGUS_DEBUG_WORLDMAP   = (1 << 11),
+       PINGUS_DEBUG_PATHMGR    = (1 << 12),
        PINGUS_DEBUG_ALL        = (~0)
      };
 

Index: path_manager.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/path_manager.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- path_manager.cxx    29 Dec 2002 23:29:00 -0000      1.4
+++ path_manager.cxx    13 Apr 2003 23:33:19 -0000      1.5
@@ -36,6 +36,7 @@
 void 
 PathManager::add_path (const std::string& path)
 {
+  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: add_path: " << path << std::endl;
   path_list.push_back (path);
 }
 
@@ -43,7 +44,7 @@
 PathManager::complete (const std::string& relative_path)
 {
   std::string comp_path = base_path + "/" + relative_path;
-  pout(PINGUS_DEBUG_LOADING) << "PathManager: " << relative_path << " -> " << 
comp_path << std::endl;
+  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: " << relative_path << " -> " << 
comp_path << std::endl;
   
   return comp_path;
 }
@@ -64,13 +65,13 @@
          path_found = true;
          base_path = *i;
 
-         pout(PINGUS_DEBUG_LOADING) << "PathManager: Using base_path: " << 
base_path << std::endl;
+         pout(PINGUS_DEBUG_PATHMGR) << "PathManager: Using base_path: " << 
base_path << std::endl;
 
          return true;
        }
     }
 
-  pout(PINGUS_DEBUG_LOADING) << "PathManager: No base path found" << std::endl;
+  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: No base path found" << std::endl;
 
   return false;
 }
@@ -86,13 +87,13 @@
          path_found = true;
          base_path = *i;
 
-         pout(PINGUS_DEBUG_LOADING) << "PathManager: Using base_path: " << 
base_path << std::endl;
+         pout(PINGUS_DEBUG_PATHMGR) << "PathManager: Using base_path: " << 
base_path << std::endl;
 
          return true;
        }
     }
 
-  pout(PINGUS_DEBUG_LOADING) << "PathManager: No base path found" << std::endl;
+  pout(PINGUS_DEBUG_PATHMGR) << "PathManager: No base path found" << std::endl;
 
   return false;
 }

Index: pingus_main.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/pingus_main.cxx,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- pingus_main.cxx     13 Apr 2003 22:22:12 -0000      1.79
+++ pingus_main.cxx     13 Apr 2003 23:33:19 -0000      1.80
@@ -23,20 +23,12 @@
 //   along with this program; if not, write to the Free Software
 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+#include <config.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <signal.h>
-
 #include <locale.h>
-
-#ifndef WIN32
-#  include <config.h>
-#  include <getopt.h>
-#else /* !WIN32 */
-#  include <direct.h>
-#  include "win32/config.h"
-#  include "win32/getopt.h"
-#endif /* !WIN32 */
+#include <getopt.h>
 
 #include <ClanLib/Core/System/console_window.h>
 #include <ClanLib/Display/setupdisplay.h>
@@ -257,14 +249,17 @@
       break;
 
     switch(c) {
+
     case 'c': // -c, --enable-cursor
       cursor_enabled = true;
       if (verbose) std::cout << "PingusMain:check_args: Cursor enabled" << 
std::endl;
       break;
+
     case 'b': // -b, --print-fps
       print_fps = true;
       if (verbose) std::cout << "PingusMain:check_args: Printing fps enabled" 
<< std::endl;
       break;
+
     case 158: // --worldmap
       worldmapfile = optarg;
       break;
@@ -274,19 +269,13 @@
       break;
 
     case 'l': // -l, --level
-      {
-       // FIXME: Quick hack to get an absolute path
-       char cwd[1024];
-       levelfile = optarg;
-       if (getcwd (cwd, 1024))
-         levelfile = std::string(cwd) + "/" + levelfile;
-       if (verbose) 
-         std::cout << "PingusMain:check_args: Levelfile = " << levelfile << 
std::endl;
-      }
+      levelfile = optarg;
       break;
+
     case 't': // -t, --set-speed
       game_speed = atoi(optarg);
       break;
+
     case 'e':
       start_editor = true;
       //std::cout << "PingusMain: Starting Editor" << std::endl;
@@ -310,6 +299,10 @@
                       << "\"640x480\" or \"800x600\"" << std::endl;
             exit(EXIT_FAILURE);
           }
+        if (screen_width > 800 || screen_height > 600)
+          {
+            std::cout << _("Warning: Larger resolution than 800x600 will 
result in visual problems") << std::endl;
+          }
       }
       break;
     case 'S':
@@ -451,6 +444,10 @@
         {
           pingus_debug_flags |= PINGUS_DEBUG_WORLDMAP;
         }
+      else if (strcmp (optarg, "pathmgr") == 0)
+        {
+          pingus_debug_flags |= PINGUS_DEBUG_PATHMGR;
+        }
       else
        {
          std::cout << "PingusMain: Unhandled debug flag: " << optarg << 
std::endl;
@@ -517,7 +514,7 @@
         << "\n   --maintainer-mode        " << _("Enables some features, only 
interesting programmers")
         << "\n   --debug OPTION           " << _("Enable the output of 
debugging infos, possible")
         << "\n                            " << _("OPTION's are tiles, 
gametime, actions, sound, resources, gui,")
-        << "\n                            " << _("input")
+        << "\n                            " << _("input, pathmgr")
         << "\n   --min-frame-skip N       " << _("Skip at least N frames, 
larger values speed the game up")
         << "\n   --max-frame-skip N       " << _("Skip at most N frames")
         << "\n   --frame-skip N           " << _("Set both min and max 
frameskip to N")
@@ -580,15 +577,29 @@
     path_manager.add_path (pingus_datadir_env);
 
   /* Some magic for detecting the path */
-  path_manager.add_path (System::dirname(executable_name) + "/../data/");
-  path_manager.add_path ("../data/");     // started from 'src/'
-  path_manager.add_path ("data/");        // started from base directory with 
'src/pingus'
-  path_manager.add_path ("share/games/pingus/");  // started from base 
directory of the binary
-  path_manager.add_path ("../share/games/pingus/");  // started from base 
directory of the binary
-  path_manager.add_path (PINGUS_DATADIR); // started from $PATH
+  path_manager.add_path(System::dirname(executable_name) + "/../data/");
+  path_manager.add_path("../data/");     // started from 'src/'
+  path_manager.add_path("data/");        // started from base directory with 
'src/pingus'
+  path_manager.add_path("share/games/pingus/");  // started from base 
directory of the binary
+  path_manager.add_path("../share/games/pingus/");  // started from base 
directory of the binary
+  path_manager.add_path(PINGUS_DATADIR); // started from $PATH
+  
+  // somebody created a symlink in /usr/bin/ or so to the real binary elsewhere
+  if (System::is_symlink(executable_name))
+    {
+      std::string real_path = 
System::dirname(System::readlink(executable_name));
+      path_manager.add_path(real_path + "/../data/");     // started from 
'src/'
+      path_manager.add_path(real_path + "/data/");        // started from base 
directory with 'src/pingus'
+      path_manager.add_path(real_path + "/share/games/pingus/");  // started 
from base directory of the binary
+      path_manager.add_path(real_path + "/../share/games/pingus/");  // 
started from base directory of the binary
+    }
+
+  // somebody added the real binary to PATH
+  //path_manager.add_path();
+
   // As a last hope we try this:
-  path_manager.add_path ("/usr/share/pingus/");
   path_manager.add_path ("/usr/local/share/pingus/");
+  path_manager.add_path ("/usr/share/pingus/");
 
   std::list<std::string> file_list;
 
@@ -786,13 +797,23 @@
   executable_name = argv[0];
   
   // Register the segfault_handler
-  //signal(SIGSEGV, signal_handler);
+#ifndef WIN32
+  signal(SIGSEGV, signal_handler);
+#endif
   //signal(SIGINT,  signal_handler);
 
   // Redirect stdout to somewhere where it is readable
   //CL_ConsoleWindow cl_console(PACKAGE VERSION);
   //cl_console.redirect_stdio();
 
+  // Init error/warning/notice streams
+  pout.add (std::cout);
+  pout.add (console);
+  pwarn.add (std::cout);
+  pout.add (console);
+  perr.add (std::cout);
+  perr.add (console);
+
   try 
     {
       quick_check_args(argc, argv);
@@ -905,14 +926,6 @@
 void
 PingusMain::init_pingus()
 {
-  // Init error/warning/notice streams
-  pout.add (std::cout);
-  pout.add (console);
-  pwarn.add (std::cout);
-  pout.add (console);
-  perr.add (std::cout);
-  perr.add (console);
-
   SavegameManager::instance();
   StatManager::init();
  

Index: system.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/system.cxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- system.cxx  13 Apr 2003 12:30:10 -0000      1.16
+++ system.cxx  13 Apr 2003 23:33:19 -0000      1.17
@@ -457,5 +457,42 @@
 #endif
 }
 
+bool
+System::is_symlink(const std::string& filename)
+{
+#ifdef WIN32
+  return false;
+#else
+  struct stat buf;
+  if (lstat(filename.c_str(), &buf) == 0)
+    {
+      return S_ISLNK(buf.st_mode);
+    }
+  else
+    {
+      return false;
+    }
+#endif
+}
+
+std::string
+System::readlink(const std::string& filename)
+{
+#ifdef WIN32
+  return filename;
+#else
+  char path_buf[PATH_MAX + 1];
+  int ret = ::readlink(filename.c_str(), path_buf, PATH_MAX);
+  if (ret == -1)
+    {
+      return filename;
+    }
+  else
+    {
+      path_buf[ret] = '\0';
+      return path_buf;
+    }
+#endif
+}
 
 /* EOF */

Index: system.hxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/system.hxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- system.hxx  7 Mar 2003 18:49:20 -0000       1.8
+++ system.hxx  13 Apr 2003 23:33:19 -0000      1.9
@@ -133,7 +133,13 @@
    generation is very primitiv and should probably be replaced by CRC
    or md5. */
   static std::string checksum (std::string filename);
-  
+
+  /** @return true if \a filename is a symbolic link, false otherwise */
+  static bool is_symlink(const std::string& filename);
+
+  /** Return the value to which the symbolic link \a filename is
+      pointing to, on error \a filename is returned */
+  static std::string readlink(const std::string& filename);
 private:
   System (const System&);
   System& operator= (const System&);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]