]> Dogcows Code - chaz/openbox/blob - util/epist/parser.cc
fix std:: namespace problems
[chaz/openbox] / util / epist / parser.cc
1 extern "C" {
2 #include <stdio.h>
3 }
4
5 #include "parser.hh"
6
7 #include <string>
8
9 using std::string;
10
11
12 parser::parser(keytree *kt)
13 : _kt(kt), _mask(0), _action(Action::noaction), _key(""), _arg("")
14 {
15 }
16
17 parser::~parser()
18 {
19 // nothing to see here. move along.
20 }
21
22 void parser::parse(string rc_file)
23 {
24 extern int yyparse(void *);
25 extern FILE *yyin;
26
27 yyin = fopen(rc_file.c_str(), "r");
28
29 yyparse(this);
30
31 fclose(yyin);
32 _kt->reset();
33 }
34
35 void parser::setAction(string act)
36 {
37 struct {
38 string str;
39 Action::ActionType act;
40 }
41 actions[] = {
42 { "noaction", Action::noaction },
43 { "execute", Action::execute },
44 { "iconify", Action::iconify },
45 { "raise", Action::raise },
46 { "lower", Action::lower },
47 { "close", Action::close },
48 { "toggleshade", Action::toggleshade },
49 { "toggleomnipresent", Action::toggleomnipresent },
50 { "moveWindowUp", Action::moveWindowUp },
51 { "moveWindowDown", Action::moveWindowDown },
52 { "moveWindowLeft", Action::moveWindowLeft },
53 { "moveWindowRight", Action::moveWindowRight },
54 { "resizeWindowWidth", Action::resizeWindowWidth },
55 { "resizeWindowHeight", Action::resizeWindowHeight },
56 { "toggleMaximizeFull", Action::toggleMaximizeFull },
57 { "toggleMaximizeVertical", Action::toggleMaximizeVertical },
58 { "toggleMaximizeHorizontal", Action::toggleMaximizeHorizontal },
59 { "sendToWorkspace", Action::sendToWorkspace },
60 { "nextWindow", Action::nextWindow },
61 { "prevWindow", Action::prevWindow },
62 { "nextWindowOnAllWorkspaces", Action::nextWindowOnAllWorkspaces },
63 { "prevWindowOnAllWorkspaces", Action::prevWindowOnAllWorkspaces },
64 { "nextWindowOnAllScreens", Action::nextWindowOnAllScreens },
65 { "prevWindowOnAllScreens", Action::prevWindowOnAllScreens },
66 { "nextWindowOfClass", Action::nextWindowOfClass },
67 { "prevWindowOfClass", Action::prevWindowOfClass },
68 { "nextWindowOfClassOnAllWorkspaces", Action::nextWindowOfClassOnAllWorkspaces },
69 { "prevWindowOfClassOnAllWorkspaces", Action::prevWindowOfClassOnAllWorkspaces },
70 { "changeWorkspace", Action::changeWorkspace },
71 { "nextWorkspace", Action::nextWorkspace },
72 { "prevWorkspace", Action::prevWorkspace },
73 { "nextScreen", Action::nextScreen },
74 { "prevScreen", Action::prevScreen },
75 { "showRootMenu", Action::showRootMenu },
76 { "showWorkspaceMenu", Action::showWorkspaceMenu },
77 { "stringChain", Action::stringChain },
78 { "keyChain", Action::keyChain },
79 { "numberChain", Action::numberChain },
80 { "cancel", Action::cancel },
81 { "", Action::noaction }
82 };
83
84 bool found = false;
85
86 for (int i = 0; actions[i].str != ""; ++i) {
87 if (actions[i].str == act) {
88 _action = actions[i].act;
89 found = true;
90 }
91 }
92
93 if (!found)
94 _action = Action::noaction;
95 }
96
97 void parser::addModifier(string mod)
98 {
99 struct {
100 string str;
101 unsigned int mask;
102 }
103 modifiers[] = {
104 { "Mod1", Mod1Mask },
105 { "Mod2", Mod2Mask },
106 { "Mod3", Mod3Mask },
107 { "Control", ControlMask },
108 { "Shift", ShiftMask },
109 { "", 0 }
110 };
111
112 for (int i = 0; modifiers[i].str != ""; ++i) {
113 if (modifiers[i].str == mod)
114 _mask |= modifiers[i].mask;
115 }
116 }
117
118 void parser::endAction()
119 {
120 _kt->addAction(_action, _mask, _key, _arg);
121 reset();
122 }
123
124 void parser::startChain()
125 {
126 _kt->advanceOnNewNode();
127 setChainBinding();
128 reset();
129 }
130
131 void parser::endChain()
132 {
133 _kt->retract();
134 reset();
135 }
136
137 void parser::setChainBinding()
138 {
139 if (_mask != 0 && _key != "") {
140 _kt->setCurrentNodeProps(Action::noaction, _mask, _key, "");
141 reset();
142 }
143 }
144
145 void parser::reset()
146 {
147 _mask = 0;
148 _action = Action::noaction;
149 _key = "";
150 _arg = "";
151 }
This page took 0.044673 seconds and 5 git commands to generate.