Rebuild autotool system
[construo.git] / path_manager.cxx
blobac48b14dd1c6b3d1acb2cb6cd108dbbb1b20560a
1 // $Id: path_manager.cxx,v 1.1 2003/07/25 11:07:44 grumbel Exp $
2 //
3 // Pingus - A free Lemmings clone
4 // Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <iostream>
21 #include <unistd.h>
22 #include "globals.hxx"
23 #include "path_manager.hxx"
25 PathManager path_manager;
27 PathManager::PathManager ()
28 : path_found (false)
32 PathManager::~PathManager ()
36 void
37 PathManager::add_path (const std::string& path)
39 path_list.push_back (path);
42 std::string
43 PathManager::complete (const std::string& relative_path)
45 std::string comp_path = base_path + "/" + relative_path;
47 return comp_path;
50 bool
51 PathManager::find_path (const std::list<std::string>& file_list)
53 for (PathIter i = path_list.begin (); !path_found && i != path_list.end (); ++i)
55 bool found_file = true;
56 for (PathIter f = file_list.begin (); found_file && f != file_list.end (); ++f)
58 if (!(access((*i + "/" + *f).c_str(), R_OK) == 0))
59 found_file = false;
61 if (found_file)
63 path_found = true;
64 base_path = *i;
66 std::cout << "PathManager: Using base_path: " << base_path << std::endl;
68 return true;
72 std::cout << "PathManager: No base path found" << std::endl;
74 return false;
77 /** Search for a path which contains the file 'file' */
78 bool
79 PathManager::find_path (const std::string& file)
81 for (PathIter i = path_list.begin (); !path_found && i != path_list.end (); ++i)
83 if ((access((*i + "/" + file).c_str(), R_OK) == 0))
85 path_found = true;
86 base_path = *i;
88 std::cout << "PathManager: Using base_path: " << base_path << std::endl;
90 return true;
94 std::cout << "PathManager: No base path found" << std::endl;
96 return false;
99 void
100 PathManager::set_path (const std::string& path)
102 base_path = path;
105 /* EOF */