pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src string_tokenizer.cxx,NONE,1.1 string_


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src string_tokenizer.cxx,NONE,1.1 string_tokenizer.hxx,NONE,1.1 Makefile.am,1.148,1.149 pingus_main.cxx,1.80,1.81
Date: 14 Apr 2003 17:56:38 -0000

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

Modified Files:
        Makefile.am pingus_main.cxx 
Added Files:
        string_tokenizer.cxx string_tokenizer.hxx 
Log Message:
- added some more voodo to find the correct data path under linux

--- NEW FILE: string_tokenizer.cxx ---
//  $Id: string_tokenizer.cxx,v 1.1 2003/04/14 17:56:36 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "string_tokenizer.hxx"

StringTokenizer::StringTokenizer(const std::string& str, char split_char)
{
  std::string::size_type start = 0;
  std::string::size_type end   = 0;

  while (start < str.size())
    {
      if ((end = str.find(split_char, start)) == std::string::npos)
        {
          tokens.push_back(str.substr(start));
          break;
        }

      const std::string& ret = str.substr(start, end - start);

      if (!ret.empty())
        tokens.push_back(ret);

      start = end + 1;
    }
}

#ifdef TEST_ME
#include <iostream>

int main()
{
  StringTokenizer tokenizer("Hello World:aoeu:aoeu:aeu:aeuaoeu::Aoeuaoe123::1", 
':');
  for(StringTokenizer::iterator i = tokenizer.begin(); i != tokenizer.end(); 
++i)
    std::cout << "Str: '" << *i << "'" << std::endl;
}
#endif

/* EOF */

--- NEW FILE: string_tokenizer.hxx ---
//  $Id: string_tokenizer.hxx,v 1.1 2003/04/14 17:56:36 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_STRING_TOKENIZER_HXX
#define HEADER_PINGUS_STRING_TOKENIZER_HXX

#include <string>
#include <vector>

/** */
class StringTokenizer
{
private:
  typedef std::vector<std::string> Token;
  Token tokens;
public:
  typedef Token::const_iterator iterator;

  /** Splits a string at \a split_char, empty tokens are ignored */
  StringTokenizer(const std::string& arg_str, char split_char);

  Token::const_iterator begin() const { return tokens.begin(); }
  Token::const_iterator end() const { return tokens.end(); }
private:
  StringTokenizer (const StringTokenizer&);
  StringTokenizer& operator= (const StringTokenizer&);
};

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/Makefile.am,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- Makefile.am 11 Apr 2003 16:51:15 -0000      1.148
+++ Makefile.am 14 Apr 2003 17:56:36 -0000      1.149
@@ -268,6 +268,8 @@
 story_screen.cxx \
 string_converter.cxx \
 string_converter.hxx \
+string_tokenizer.cxx \
+string_tokenizer.hxx \
 system.cxx \
 system.hxx \
 target_provider.cxx \

Index: pingus_main.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/pingus_main.cxx,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- pingus_main.cxx     13 Apr 2003 23:33:19 -0000      1.80
+++ pingus_main.cxx     14 Apr 2003 17:56:36 -0000      1.81
@@ -77,6 +77,7 @@
 #include "credits.hxx"
 #include "sound/sound.hxx"
 #include "worldmap/manager.hxx"
+#include "string_tokenizer.hxx"
 #include "story.hxx"
 #include "cheat.hxx"
 
@@ -582,6 +583,8 @@
   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("share/pingus/");  // started from base directory of 
the binary
+  path_manager.add_path("../share/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
@@ -592,12 +595,50 @@
       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
+      path_manager.add_path(real_path + "/share/pingus/");  // started from 
base directory of the binary
+      path_manager.add_path(real_path + "/../share/pingus/");  // started from 
base directory of the binary
     }
 
   // somebody added the real binary to PATH
-  //path_manager.add_path();
+  {
+    const char* path = getenv("PATH");
+    if (path)
+      {
+        StringTokenizer tokenizer(path, ':');
+        for (StringTokenizer::iterator i = tokenizer.begin(); i != 
tokenizer.end(); ++i)
+          {
+            std::string exe = *i + "/pingus";
+            if (System::exist(exe))
+              {
+                path_manager.add_path(*i + "/../data/");     // started from 
'src/'
+                path_manager.add_path(*i + "/data/");        // started from 
base directory with 'src/pingus'
+                path_manager.add_path(*i + "/share/games/pingus/");  // 
started from base directory of the binary
+                path_manager.add_path(*i + "/../share/games/pingus/");  // 
started from base directory of the binary
+                path_manager.add_path(*i + "/share/pingus/");  // started from 
base directory of the binary
+                path_manager.add_path(*i + "/../share/pingus/");  // started 
from base directory of the binary
+
+                // somebody added a symlink to the real binary to the PATH
+                if(System::is_symlink(*i + "/pingus"))
+                  {
+                    std::string real_path = 
System::dirname(System::readlink(exe));
+                    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/pingus/");
+                    path_manager.add_path(real_path + 
"/../share/games/pingus/");  // started from base directory of the binary
+                    path_manager.add_path(real_path + "/../share/pingus/");  
// started from base directory of the binary
+                  }
+
+                break;
+              }
+          }
+      }
+  }
 
   // As a last hope we try this:
+  path_manager.add_path ("/usr/local/share/games/pingus/");
+  path_manager.add_path ("/usr/share/games/pingus/");
+
   path_manager.add_path ("/usr/local/share/pingus/");
   path_manager.add_path ("/usr/share/pingus/");
 





reply via email to

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