diff options
Diffstat (limited to 'src/FbMenuParser.cc')
-rw-r--r-- | src/FbMenuParser.cc | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/src/FbMenuParser.cc b/src/FbMenuParser.cc deleted file mode 100644 index 716ced2..0000000 --- a/src/FbMenuParser.cc +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | // FbMenuParser.cc for Fluxbox | ||
2 | // Copyright (c) 2004 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // and Simon Bowden (rathnor at users.sourceforge.net) | ||
4 | // | ||
5 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
6 | // copy of this software and associated documentation files (the "Software"), | ||
7 | // to deal in the Software without restriction, including without limitation | ||
8 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
9 | // and/or sell copies of the Software, and to permit persons to whom the | ||
10 | // Software is furnished to do so, subject to the following conditions: | ||
11 | // | ||
12 | // The above copyright notice and this permission notice shall be included in | ||
13 | // all copies or substantial portions of the Software. | ||
14 | // | ||
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
21 | // DEALINGS IN THE SOFTWARE. | ||
22 | |||
23 | #include "FbMenuParser.hh" | ||
24 | |||
25 | #include "FbTk/StringUtil.hh" | ||
26 | |||
27 | bool FbMenuParser::open(const std::string &filename) { | ||
28 | m_file.open(filename.c_str()); | ||
29 | m_curr_pos = 0; | ||
30 | m_row = 0; | ||
31 | m_curr_token = DONE; | ||
32 | return isLoaded(); | ||
33 | } | ||
34 | |||
35 | FbTk::Parser &FbMenuParser::operator >> (FbTk::Parser::Item &out) { | ||
36 | if (eof()) { | ||
37 | out = FbTk::Parser::s_empty_item; | ||
38 | return *this; | ||
39 | } | ||
40 | |||
41 | if (m_curr_line.empty()) | ||
42 | m_curr_token = DONE; // try next line | ||
43 | |||
44 | char first = '['; | ||
45 | char second = ']'; | ||
46 | |||
47 | switch (m_curr_token) { | ||
48 | case TYPE: | ||
49 | first = '['; | ||
50 | second = ']'; | ||
51 | break; | ||
52 | case NAME: | ||
53 | first = '('; | ||
54 | second = ')'; | ||
55 | break; | ||
56 | case ARGUMENT: | ||
57 | first = '{'; | ||
58 | second = '}'; | ||
59 | break; | ||
60 | case ICON: | ||
61 | first = '<'; | ||
62 | second = '>'; | ||
63 | break; | ||
64 | case DONE: // get new line and call this again | ||
65 | if (!nextLine()) { | ||
66 | out = FbTk::Parser::s_empty_item; | ||
67 | return *this; | ||
68 | } | ||
69 | return (*this)>>out; | ||
70 | break; | ||
71 | } | ||
72 | |||
73 | std::string key; | ||
74 | int err = FbTk::StringUtil:: | ||
75 | getStringBetween(key, m_curr_line.c_str() + m_curr_pos, | ||
76 | first, second); | ||
77 | if (err <= 0) { | ||
78 | if (m_curr_token == TYPE) | ||
79 | m_curr_token = NAME; | ||
80 | else if (m_curr_token == NAME) | ||
81 | m_curr_token = ARGUMENT; | ||
82 | else if (m_curr_token == ARGUMENT) | ||
83 | m_curr_token = ICON; | ||
84 | else if (m_curr_token == ICON) | ||
85 | m_curr_token = DONE; | ||
86 | |||
87 | out = FbTk::Parser::s_empty_item; | ||
88 | return *this; | ||
89 | } | ||
90 | |||
91 | m_curr_pos += err; // update current position in current line | ||
92 | |||
93 | // set value | ||
94 | out.second = key; | ||
95 | |||
96 | // set type and next token to be read | ||
97 | switch (m_curr_token) { | ||
98 | case TYPE: | ||
99 | out.first = "TYPE"; | ||
100 | m_curr_token = NAME; | ||
101 | break; | ||
102 | case NAME: | ||
103 | out.first = "NAME"; | ||
104 | m_curr_token = ARGUMENT; | ||
105 | break; | ||
106 | case ARGUMENT: | ||
107 | out.first = "ARGUMENT"; | ||
108 | m_curr_token = ICON; | ||
109 | break; | ||
110 | case ICON: | ||
111 | out.first = "ICON"; | ||
112 | m_curr_token = DONE; | ||
113 | break; | ||
114 | case DONE: | ||
115 | break; | ||
116 | } | ||
117 | return *this; | ||
118 | } | ||
119 | |||
120 | FbTk::Parser::Item FbMenuParser::nextItem() { | ||
121 | FbTk::Parser::Item item; | ||
122 | (*this)>>item; | ||
123 | return item; | ||
124 | } | ||
125 | |||
126 | bool FbMenuParser::nextLine() { | ||
127 | if (!std::getline(m_file, m_curr_line)) | ||
128 | return false; | ||
129 | |||
130 | m_row++; | ||
131 | m_curr_pos = 0; | ||
132 | m_curr_token = TYPE; | ||
133 | |||
134 | return true; | ||
135 | } | ||