aboutsummaryrefslogtreecommitdiff
path: root/src/Keys.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-08-11 21:21:06 (GMT)
committerfluxgen <fluxgen>2002-08-11 21:21:06 (GMT)
commit18ddc4c28a7a80434ce3360c050c1fb3ce469950 (patch)
treecbf237509697641fd3a2ac471385bdaaf22dbff0 /src/Keys.cc
parent1e5883afb3fae62d7558c0e9726ec5206458b948 (diff)
downloadfluxbox-18ddc4c28a7a80434ce3360c050c1fb3ce469950.zip
fluxbox-18ddc4c28a7a80434ce3360c050c1fb3ce469950.tar.bz2
from char * to string getline
Diffstat (limited to 'src/Keys.cc')
-rw-r--r--src/Keys.cc72
1 files changed, 35 insertions, 37 deletions
diff --git a/src/Keys.cc b/src/Keys.cc
index 128ccf4..3dfc37f 100644
--- a/src/Keys.cc
+++ b/src/Keys.cc
@@ -19,32 +19,26 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22//$Id: Keys.cc,v 1.17 2002/07/27 18:03:39 fluxgen Exp $ 22//$Id: Keys.cc,v 1.18 2002/08/11 21:21:06 fluxgen Exp $
23 23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27 24
28#include "Keys.hh" 25#include "Keys.hh"
26
29#include "StringUtil.hh" 27#include "StringUtil.hh"
30 28
31#ifdef HAVE_STDIO_H 29#ifdef HAVE_CONFIG_H
32#include <stdio.h> 30#include "../config.h"
33#endif // HAVE_STDIO_H 31#endif // HAVE_CONFIG_H
32
34 33
35#ifdef HAVE_CTYPE_H 34#ifdef HAVE_CTYPE_H
36#include <ctype.h> 35#include <ctype.h>
37#endif // HAVE_CTYPE_H 36#endif // HAVE_CTYPE_H
38 37
39#ifdef STDC_HEADERS 38#include <cstdio>
40#include <stdlib.h> 39#include <cstdlib>
41#include <string.h> 40#include <cerrno>
42#include <errno.h> 41#include <cstring>
43#endif // STDC_HEADERS
44
45#if HAVE_STRINGS_H
46#include <strings.h>
47#endif
48 42
49#ifdef HAVE_SYS_TYPES_H 43#ifdef HAVE_SYS_TYPES_H
50#include <sys/types.h> 44#include <sys/types.h>
@@ -136,7 +130,7 @@ m_abortkey(0),
136m_display(display) 130m_display(display)
137{ 131{
138 assert(display); 132 assert(display);
139 if (filename) 133 if (filename != 0)
140 load(filename); 134 load(filename);
141} 135}
142 136
@@ -150,7 +144,7 @@ Keys::~Keys() {
150//-------------------------------- 144//--------------------------------
151void Keys::deleteTree() { 145void Keys::deleteTree() {
152 while (!m_keylist.empty()) { 146 while (!m_keylist.empty()) {
153 if (m_keylist.back()) 147 if (m_keylist.back() && m_keylist.back() != 0)
154 delete m_keylist.back(); 148 delete m_keylist.back();
155 m_keylist.pop_back(); 149 m_keylist.pop_back();
156 } 150 }
@@ -181,34 +175,34 @@ bool Keys::load(const char *filename) {
181 175
182 //ungrab all keys 176 //ungrab all keys
183 ungrabKeys(); 177 ungrabKeys();
178
184 //free memory of previous grabs 179 //free memory of previous grabs
185 deleteTree(); 180 deleteTree();
186 181
187 XSync(m_display, False); 182 XSync(m_display, False);
188 183
189 //open the file 184 //open the file
190 ifstream infile(filename); 185 ifstream infile(filename);
191 if (!infile) 186 if (!infile)
192 return false; 187 return false; // faild to open file
193 188
194
195 auto_ptr<char> linebuffer(new char[1024]);
196
197 int line=0;//current line, so we can tell the user where the fault is 189 int line=0;//current line, so we can tell the user where the fault is
198 190
199 while (!infile.eof()) { 191 while (!infile.eof()) {
200 192 string linebuffer;
201 infile.getline(linebuffer.get(), 1024); 193
194 getline(infile, linebuffer);
202 195
203 line++; 196 line++;
204 vector<string> val; 197 vector<string> val;
205 //Parse arguments 198 //Parse arguments
206 StringUtil::stringtok(val, linebuffer.get()); 199 StringUtil::stringtok(val, linebuffer.c_str());
200
207 //must have at least 1 argument 201 //must have at least 1 argument
208 if (val.size()<=0) 202 if (val.size() <= 0)
209 continue; 203 continue;
210 204
211 if (val[0][0]=='#') //the line is commented 205 if (val[0][0] == '#') //the line is commented
212 continue; 206 continue;
213 207
214 unsigned int key=0, mod=0; 208 unsigned int key=0, mod=0;
@@ -253,7 +247,7 @@ bool Keys::load(const char *filename) {
253 if (i < LASTKEYGRAB ) { 247 if (i < LASTKEYGRAB ) {
254 if (!current_key) { 248 if (!current_key) {
255 cerr<<"Error on line: "<<line<<endl; 249 cerr<<"Error on line: "<<line<<endl;
256 cerr<<linebuffer.get()<<endl; 250 cerr<<linebuffer<<endl;
257 delete current_key; 251 delete current_key;
258 current_key = 0; 252 current_key = 0;
259 last_key = 0; 253 last_key = 0;
@@ -280,7 +274,7 @@ bool Keys::load(const char *filename) {
280 case Keys::EXECUTE: 274 case Keys::EXECUTE:
281 last_key->execcommand = 275 last_key->execcommand =
282 const_cast<char *> 276 const_cast<char *>
283 (StringUtil::strcasestr(linebuffer.get(), 277 (StringUtil::strcasestr(linebuffer.c_str(),
284 getActionStr(Keys::EXECUTE))+ 278 getActionStr(Keys::EXECUTE))+
285 strlen(getActionStr(Keys::EXECUTE))); 279 strlen(getActionStr(Keys::EXECUTE)));
286 break; 280 break;
@@ -330,9 +324,9 @@ bool Keys::load(const char *filename) {
330 last_key = 0; 324 last_key = 0;
331 325
332 } else { //destroy list if no action is found 326 } else { //destroy list if no action is found
333 #ifdef DEBUG 327#ifdef DEBUG
334 cerr<<"Didnt find action="<<val[argc]<<endl; 328 cerr<<"Didnt find action="<<val[argc]<<endl;
335 #endif 329#endif // DEBUG
336 //destroy current_key ... this will also destroy the last_key 330 //destroy current_key ... this will also destroy the last_key
337 delete current_key; 331 delete current_key;
338 current_key = 0; 332 current_key = 0;
@@ -424,9 +418,10 @@ unsigned int Keys::getModifier(const char *modstr) {
424 {"MOD5", Mod5Mask}, 418 {"MOD5", Mod5Mask},
425 {0, 0} 419 {0, 0}
426 }; 420 };
427 421
422 // find mod mask string
428 for (unsigned int i=0; modlist[i].string!=0; i++) { 423 for (unsigned int i=0; modlist[i].string!=0; i++) {
429 if (modlist[i]==modstr) 424 if (modlist[i] == modstr)
430 return modlist[i].mask; 425 return modlist[i].mask;
431 } 426 }
432 427
@@ -552,6 +547,7 @@ void Keys::showKeyTree(t_key *key, unsigned int w) {
552 cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" ) {"<<getActionStr(key->action)<<"}"<<endl; 547 cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" ) {"<<getActionStr(key->action)<<"}"<<endl;
553} 548}
554#endif //DEBUG 549#endif //DEBUG
550
555//------------ mergeTree --------------- 551//------------ mergeTree ---------------
556// Merges two chains and binds new keys 552// Merges two chains and binds new keys
557// Returns true on success else false. 553// Returns true on success else false.
@@ -621,7 +617,9 @@ Keys::t_key::t_key(t_key *k) {
621Keys::t_key::~t_key() { 617Keys::t_key::~t_key() {
622 while (!keylist.empty()) { 618 while (!keylist.empty()) {
623 t_key *k = keylist.back(); 619 t_key *k = keylist.back();
624 delete k; 620 if (k != 0) { // make sure we don't have a bad key pointer
625 keylist.pop_back(); 621 delete k;
622 keylist.pop_back();
623 }
626 } 624 }
627} 625}