Added support Macro filenames relative to their parent config files

This commit is contained in:
Ingo Ruhnke 2011-04-12 18:54:12 +02:00
parent a6d577c8a4
commit fd806996dc
8 changed files with 108 additions and 11 deletions

View file

@ -11,16 +11,16 @@
# joysticktype = 2axis
[xboxdrv]
ui-clear=true
extra-events=false
ui-clear=true # start with a completely clear config
extra-events=false
[modifier]
square-axis=X1:Y1
square-axis=X1:Y1 # flightsims like full [-1,1] range
dpad-restrictor=fourway # dpad is used as buttons, so we don't need diagonals
[ui-axismap]
X1^dead:5000 = ABS_X # regular steering
Y1^dead:5000 = ABS_Y
X1^dead:5000 = ABS_X # regular steering left/right
Y1^dead:5000 = ABS_Y # regular steering up/down
X2 = KEY_BACKSLASH:KEY_ENTER:24000 # full throttle/match throttle
Y2 = KEY_EQUAL:KEY_MINUS:10000 # throttle plus/minus
@ -42,11 +42,13 @@ RT = JS_0 # wire weapons
START = KEY_LEFTSHIFT+KEY_F9 # shield to laser
BACK = KEY_LEFTSHIFT+KEY_F10 # laser to shield
GUIDE = KEY_P:KEY_ESC:500
GUIDE = KEY_P:KEY_ESC:500 # a click for pause, hold getting the menu
LB+GUIDE = KEY_H # hyperspace
RB+GUIDE = KEY_LEFTALT+KEY_E # eject
RB+BACK = KEY_LEFTALT+KEY_T # toggle time wrap
# Energy Management
DU = KEY_F8 # energy to ray
DD = KEY_S # toggle shield front/back/center
@ -68,6 +70,7 @@ RB+DR = KEY_LEFTSHIFT+KEY_COMMA # prev component
TR = KEY_BACKSPACE # full throttle
TL = KEY_DOT # cockpit on/off
LB+TR = KEY_A # target nearest attacker of current target
LB+TL = macro:calibrate.macro
RB+TL = KEY_F4 # view release
RB+TR = KEY_F3 # external view

View file

@ -24,6 +24,7 @@
#include "evdev_helper.hpp"
#include "log.hpp"
#include "helper.hpp"
#include "uinput.hpp"
#include "buttonevent/abs_button_event_handler.hpp"
@ -75,7 +76,7 @@ ButtonEvent::create_rel(int code)
}
ButtonEventPtr
ButtonEvent::from_string(const std::string& str)
ButtonEvent::from_string(const std::string& str, const std::string& directory)
{
std::string::size_type p = str.find(':');
const std::string& token = str.substr(0, p);
@ -102,7 +103,7 @@ ButtonEvent::from_string(const std::string& str)
}
else if (token == "macro")
{
return ButtonEvent::create(MacroButtonEventHandler::from_string(rest));
return ButtonEvent::create(MacroButtonEventHandler::from_string(path_join(directory, rest)));
}
else
{

View file

@ -41,7 +41,7 @@ public:
static ButtonEventPtr create_key();
static ButtonEventPtr create_abs(int code);
static ButtonEventPtr create_rel(int code);
static ButtonEventPtr from_string(const std::string& str);
static ButtonEventPtr from_string(const std::string& str, const std::string& directory);
protected:
ButtonEvent(ButtonEventHandler* handler);

View file

@ -136,7 +136,8 @@ enum {
CommandLineParser::CommandLineParser() :
m_argp(),
m_ini(),
m_options()
m_options(),
m_directory_context()
{
init_argp();
}
@ -1060,7 +1061,7 @@ CommandLineParser::set_ui_buttonmap(ButtonMap& btn_map, const std::string& name,
}
else
{
event = ButtonEvent::from_string(value);
event = ButtonEvent::from_string(value, get_directory_context());
if (event)
{
btn_map.bind(shift, btn, event);
@ -1297,9 +1298,13 @@ CommandLineParser::read_config_file(const std::string& filename)
}
else
{
m_directory_context.push_back(dirname(filename));
INISchemaBuilder builder(m_ini);
INIParser parser(in, builder, filename);
parser.run();
m_directory_context.pop_back();
}
}
@ -1381,4 +1386,17 @@ CommandLineParser::mouse()
sizeof(xboxdrv_vfs::examples_mouse_xboxdrv));
}
std::string
CommandLineParser::get_directory_context() const
{
if (m_directory_context.empty())
{
return std::string();
}
else
{
return m_directory_context.back();
}
}
/* EOF */

View file

@ -19,6 +19,8 @@
#ifndef HEADER_COMMAND_LINE_OPTIONS_HPP
#define HEADER_COMMAND_LINE_OPTIONS_HPP
#include <vector>
#include "arg_parser.hpp"
#include "ini_schema.hpp"
#include "uinput.hpp"
@ -34,6 +36,7 @@ public:
ArgParser m_argp;
INISchema m_ini;
Options* m_options;
std::vector<std::string> m_directory_context;
public:
CommandLineParser();
@ -96,6 +99,7 @@ private:
private:
void init_argp();
void init_ini(Options* opts);
std::string get_directory_context() const;
private:
CommandLineParser(const CommandLineParser&);

View file

@ -210,4 +210,36 @@ 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,6 +39,11 @@ 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>

34
test/dirname_test.cpp Normal file
View file

@ -0,0 +1,34 @@
/*
** 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 <iostream>
#include "helper.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 << std::endl;
}
return 0;
}
/* EOF */