openbox/util/epist/parser.cc

152 lines
4 KiB
C++
Raw Normal View History

extern "C" {
#include <stdio.h>
#include <string.h>
}
2002-08-07 01:34:34 +00:00
#include "parser.hh"
2002-08-07 01:34:34 +00:00
#include <string>
using std::string;
parser::parser(keytree *kt)
2002-08-07 01:34:34 +00:00
: _kt(kt), _mask(0), _action(Action::noaction), _key(""), _arg("")
{
}
parser::~parser()
{
// nothing to see here. move along.
}
void parser::parse(string rc_file)
{
extern int yyparse(void *);
extern FILE *yyin;
yyin = fopen(rc_file.c_str(), "r");
yyparse(this);
fclose(yyin);
_kt->reset();
}
void parser::setAction(string act)
{
struct {
const char* str;
Action::ActionType act;
}
actions[] = {
{ "noaction", Action::noaction },
{ "execute", Action::execute },
{ "iconify", Action::iconify },
{ "raise", Action::raise },
{ "lower", Action::lower },
{ "close", Action::close },
{ "toggleshade", Action::toggleshade },
{ "toggleomnipresent", Action::toggleomnipresent },
{ "movewindowup", Action::moveWindowUp },
{ "movewindowdown", Action::moveWindowDown },
{ "movewindowleft", Action::moveWindowLeft },
{ "movewindowright", Action::moveWindowRight },
{ "resizewindowwidth", Action::resizeWindowWidth },
{ "resizewindowheight", Action::resizeWindowHeight },
{ "togglemaximizefull", Action::toggleMaximizeFull },
{ "togglemaximizevertical", Action::toggleMaximizeVertical },
{ "togglemaximizehorizontal", Action::toggleMaximizeHorizontal },
{ "sendtoworkspace", Action::sendToWorkspace },
{ "nextwindow", Action::nextWindow },
{ "prevwindow", Action::prevWindow },
{ "nextwindowonallworkspaces", Action::nextWindowOnAllWorkspaces },
{ "prevwindowonallworkspaces", Action::prevWindowOnAllWorkspaces },
{ "nextwindowonallscreens", Action::nextWindowOnAllScreens },
{ "prevwindowonallscreens", Action::prevWindowOnAllScreens },
{ "nextwindowofclass", Action::nextWindowOfClass },
{ "prevwindowofclass", Action::prevWindowOfClass },
{ "nextwindowofclassonallworkspaces", Action::nextWindowOfClassOnAllWorkspaces },
{ "prevwindowofclassonallworkspaces", Action::prevWindowOfClassOnAllWorkspaces },
{ "changeworkspace", Action::changeWorkspace },
{ "nextworkspace", Action::nextWorkspace },
{ "prevworkspace", Action::prevWorkspace },
{ "nextscreen", Action::nextScreen },
{ "prevscreen", Action::prevScreen },
{ "showrootmenu", Action::showRootMenu },
{ "showworkspacemenu", Action::showWorkspaceMenu },
{ "stringchain", Action::stringChain },
{ "keychain", Action::keyChain },
{ "numberchain", Action::numberChain },
{ "cancel", Action::cancel },
{ "", Action::noaction }
};
bool found = false;
for (int i = 0; actions[i].str != ""; ++i) {
if ( strcasecmp(actions[i].str, act.c_str()) == 0 ) {
_action = actions[i].act;
found = true;
}
}
if (!found)
_action = Action::noaction;
}
void parser::addModifier(string mod)
{
struct {
string str;
unsigned int mask;
}
modifiers[] = {
{ "Mod1", Mod1Mask },
{ "Mod2", Mod2Mask },
{ "Mod3", Mod3Mask },
{ "Mod4", Mod4Mask },
{ "Control", ControlMask },
{ "Shift", ShiftMask },
{ "", 0 }
};
for (int i = 0; modifiers[i].str != ""; ++i) {
if (modifiers[i].str == mod)
_mask |= modifiers[i].mask;
}
}
void parser::endAction()
{
_kt->addAction(_action, _mask, _key, _arg);
reset();
}
void parser::startChain()
{
_kt->advanceOnNewNode();
setChainBinding();
reset();
}
void parser::endChain()
{
_kt->retract();
reset();
}
void parser::setChainBinding()
{
if (_mask != 0 && _key != "") {
_kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
reset();
}
}
void parser::reset()
{
_mask = 0;
_action = Action::noaction;
_key = "";
_arg = "";
}