Moved path helper to separate file

This commit is contained in:
Ingo Ruhnke 2011-04-13 19:40:15 +02:00
parent fd806996dc
commit 2c39e7e9d5
7 changed files with 99 additions and 43 deletions

View file

@ -24,7 +24,7 @@
#include "evdev_helper.hpp"
#include "log.hpp"
#include "helper.hpp"
#include "path.hpp"
#include "uinput.hpp"
#include "buttonevent/abs_button_event_handler.hpp"
@ -103,7 +103,7 @@ ButtonEvent::from_string(const std::string& str, const std::string& directory)
}
else if (token == "macro")
{
return ButtonEvent::create(MacroButtonEventHandler::from_string(path_join(directory, rest)));
return ButtonEvent::create(MacroButtonEventHandler::from_string(path::join(directory, rest)));
}
else
{

View file

@ -28,8 +28,9 @@
#include "helper.hpp"
#include "ini_parser.hpp"
#include "ini_schema_builder.hpp"
#include "raise_exception.hpp"
#include "options.hpp"
#include "path.hpp"
#include "raise_exception.hpp"
#include "ui_event.hpp"
#include "axisfilter/relative_axis_filter.hpp"
@ -1298,7 +1299,7 @@ CommandLineParser::read_config_file(const std::string& filename)
}
else
{
m_directory_context.push_back(dirname(filename));
m_directory_context.push_back(path::dirname(filename));
INISchemaBuilder builder(m_ini);
INIParser parser(in, builder, filename);

View file

@ -210,36 +210,4 @@ pid_t spawn_exe(const std::vector<std::string>& args)
return pid;
}
std::string dirname(const std::string& filename)
{
std::string::size_type p = filename.rfind('/');
if (p == std::string::npos)
{
return "./";
}
else
{
return filename.substr(0, p+1);
}
}
std::string path_join(const std::string& lhs, const std::string& rhs)
{
if (lhs.empty())
{
return rhs;
}
else
{
if (lhs[lhs.size()-1] == '/')
{
return lhs + rhs;
}
else
{
return lhs + '/' + rhs;
}
}
}
/* EOF */

View file

@ -39,11 +39,6 @@ void split_string_at(const std::string& str, char c, std::string* lhs, std::stri
which case it is handled as (range * int(str)) */
int to_number(int range, const std::string& str);
uint32_t get_time();
/** Returns the directory component of a filename, trailing '/' is included */
std::string dirname(const std::string& filename);
std::string path_join(const std::string& lhs, const std::string& rhs);
namespace Math {
template<class T>

57
src/path.cpp Normal file
View file

@ -0,0 +1,57 @@
/*
** Xbox360 USB Gamepad Userspace Driver
** Copyright (C) 2011 Ingo Ruhnke <grumbel@gmx.de>
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "path.hpp"
namespace path {
std::string dirname(const std::string& filename)
{
std::string::size_type p = filename.rfind('/');
if (p == std::string::npos)
{
return "./";
}
else
{
return filename.substr(0, p+1);
}
}
std::string join(const std::string& lhs, const std::string& rhs)
{
if (lhs.empty())
{
return rhs;
}
else
{
if (lhs[lhs.size()-1] == '/')
{
return lhs + rhs;
}
else
{
return lhs + '/' + rhs;
}
}
}
} // namespace path
/* EOF */

35
src/path.hpp Normal file
View file

@ -0,0 +1,35 @@
/*
** Xbox360 USB Gamepad Userspace Driver
** Copyright (C) 2011 Ingo Ruhnke <grumbel@gmx.de>
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef HEADER_XBOXDRV_PATH_HPP
#define HEADER_XBOXDRV_PATH_HPP
#include <string>
namespace path {
/** Returns the directory component of a filename, trailing '/' is included */
std::string dirname(const std::string& filename);
std::string join(const std::string& lhs, const std::string& rhs);
} // namespace path
#endif
/* EOF */

View file

@ -18,14 +18,14 @@
#include <iostream>
#include "helper.hpp"
#include "path.hpp"
int main(int argc, char** argv)
{
for(int i = 1; i < argc; ++i)
{
std::cout << '"' << argv[i] << '"' << std::endl;
std::cout << '"' << dirname(argv[i]) << '"' << std::endl;
std::cout << '"' << path::dirname(argv[i]) << '"' << std::endl;
std::cout << std::endl;
}
return 0;