from char * to string getline
This commit is contained in:
parent
1e5883afb3
commit
18ddc4c28a
1 changed files with 35 additions and 37 deletions
60
src/Keys.cc
60
src/Keys.cc
|
@ -19,32 +19,26 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
//$Id: Keys.cc,v 1.17 2002/07/27 18:03:39 fluxgen Exp $
|
//$Id: Keys.cc,v 1.18 2002/08/11 21:21:06 fluxgen Exp $
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Keys.hh"
|
#include "Keys.hh"
|
||||||
|
|
||||||
#include "StringUtil.hh"
|
#include "StringUtil.hh"
|
||||||
|
|
||||||
#ifdef HAVE_STDIO_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <stdio.h>
|
#include "../config.h"
|
||||||
#endif // HAVE_STDIO_H
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CTYPE_H
|
#ifdef HAVE_CTYPE_H
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#endif // HAVE_CTYPE_H
|
#endif // HAVE_CTYPE_H
|
||||||
|
|
||||||
#ifdef STDC_HEADERS
|
#include <cstdio>
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
#include <string.h>
|
#include <cerrno>
|
||||||
#include <errno.h>
|
#include <cstring>
|
||||||
#endif // STDC_HEADERS
|
|
||||||
|
|
||||||
#if HAVE_STRINGS_H
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -136,7 +130,7 @@ m_abortkey(0),
|
||||||
m_display(display)
|
m_display(display)
|
||||||
{
|
{
|
||||||
assert(display);
|
assert(display);
|
||||||
if (filename)
|
if (filename != 0)
|
||||||
load(filename);
|
load(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +144,7 @@ Keys::~Keys() {
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
void Keys::deleteTree() {
|
void Keys::deleteTree() {
|
||||||
while (!m_keylist.empty()) {
|
while (!m_keylist.empty()) {
|
||||||
if (m_keylist.back())
|
if (m_keylist.back() && m_keylist.back() != 0)
|
||||||
delete m_keylist.back();
|
delete m_keylist.back();
|
||||||
m_keylist.pop_back();
|
m_keylist.pop_back();
|
||||||
}
|
}
|
||||||
|
@ -181,6 +175,7 @@ bool Keys::load(const char *filename) {
|
||||||
|
|
||||||
//ungrab all keys
|
//ungrab all keys
|
||||||
ungrabKeys();
|
ungrabKeys();
|
||||||
|
|
||||||
//free memory of previous grabs
|
//free memory of previous grabs
|
||||||
deleteTree();
|
deleteTree();
|
||||||
|
|
||||||
|
@ -189,26 +184,25 @@ bool Keys::load(const char *filename) {
|
||||||
//open the file
|
//open the file
|
||||||
ifstream infile(filename);
|
ifstream infile(filename);
|
||||||
if (!infile)
|
if (!infile)
|
||||||
return false;
|
return false; // faild to open file
|
||||||
|
|
||||||
|
|
||||||
auto_ptr<char> linebuffer(new char[1024]);
|
|
||||||
|
|
||||||
int line=0;//current line, so we can tell the user where the fault is
|
int line=0;//current line, so we can tell the user where the fault is
|
||||||
|
|
||||||
while (!infile.eof()) {
|
while (!infile.eof()) {
|
||||||
|
string linebuffer;
|
||||||
|
|
||||||
infile.getline(linebuffer.get(), 1024);
|
getline(infile, linebuffer);
|
||||||
|
|
||||||
line++;
|
line++;
|
||||||
vector<string> val;
|
vector<string> val;
|
||||||
//Parse arguments
|
//Parse arguments
|
||||||
StringUtil::stringtok(val, linebuffer.get());
|
StringUtil::stringtok(val, linebuffer.c_str());
|
||||||
|
|
||||||
//must have at least 1 argument
|
//must have at least 1 argument
|
||||||
if (val.size()<=0)
|
if (val.size() <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (val[0][0]=='#') //the line is commented
|
if (val[0][0] == '#') //the line is commented
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
unsigned int key=0, mod=0;
|
unsigned int key=0, mod=0;
|
||||||
|
@ -253,7 +247,7 @@ bool Keys::load(const char *filename) {
|
||||||
if (i < LASTKEYGRAB ) {
|
if (i < LASTKEYGRAB ) {
|
||||||
if (!current_key) {
|
if (!current_key) {
|
||||||
cerr<<"Error on line: "<<line<<endl;
|
cerr<<"Error on line: "<<line<<endl;
|
||||||
cerr<<linebuffer.get()<<endl;
|
cerr<<linebuffer<<endl;
|
||||||
delete current_key;
|
delete current_key;
|
||||||
current_key = 0;
|
current_key = 0;
|
||||||
last_key = 0;
|
last_key = 0;
|
||||||
|
@ -280,7 +274,7 @@ bool Keys::load(const char *filename) {
|
||||||
case Keys::EXECUTE:
|
case Keys::EXECUTE:
|
||||||
last_key->execcommand =
|
last_key->execcommand =
|
||||||
const_cast<char *>
|
const_cast<char *>
|
||||||
(StringUtil::strcasestr(linebuffer.get(),
|
(StringUtil::strcasestr(linebuffer.c_str(),
|
||||||
getActionStr(Keys::EXECUTE))+
|
getActionStr(Keys::EXECUTE))+
|
||||||
strlen(getActionStr(Keys::EXECUTE)));
|
strlen(getActionStr(Keys::EXECUTE)));
|
||||||
break;
|
break;
|
||||||
|
@ -330,9 +324,9 @@ bool Keys::load(const char *filename) {
|
||||||
last_key = 0;
|
last_key = 0;
|
||||||
|
|
||||||
} else { //destroy list if no action is found
|
} else { //destroy list if no action is found
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cerr<<"Didnt find action="<<val[argc]<<endl;
|
cerr<<"Didnt find action="<<val[argc]<<endl;
|
||||||
#endif
|
#endif // DEBUG
|
||||||
//destroy current_key ... this will also destroy the last_key
|
//destroy current_key ... this will also destroy the last_key
|
||||||
delete current_key;
|
delete current_key;
|
||||||
current_key = 0;
|
current_key = 0;
|
||||||
|
@ -425,8 +419,9 @@ unsigned int Keys::getModifier(const char *modstr) {
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// find mod mask string
|
||||||
for (unsigned int i=0; modlist[i].string!=0; i++) {
|
for (unsigned int i=0; modlist[i].string!=0; i++) {
|
||||||
if (modlist[i]==modstr)
|
if (modlist[i] == modstr)
|
||||||
return modlist[i].mask;
|
return modlist[i].mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,6 +547,7 @@ void Keys::showKeyTree(t_key *key, unsigned int w) {
|
||||||
cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" ) {"<<getActionStr(key->action)<<"}"<<endl;
|
cerr<<"( "<<(int)key->key<<" "<<(int)key->mod<<" ) {"<<getActionStr(key->action)<<"}"<<endl;
|
||||||
}
|
}
|
||||||
#endif //DEBUG
|
#endif //DEBUG
|
||||||
|
|
||||||
//------------ mergeTree ---------------
|
//------------ mergeTree ---------------
|
||||||
// Merges two chains and binds new keys
|
// Merges two chains and binds new keys
|
||||||
// Returns true on success else false.
|
// Returns true on success else false.
|
||||||
|
@ -621,7 +617,9 @@ Keys::t_key::t_key(t_key *k) {
|
||||||
Keys::t_key::~t_key() {
|
Keys::t_key::~t_key() {
|
||||||
while (!keylist.empty()) {
|
while (!keylist.empty()) {
|
||||||
t_key *k = keylist.back();
|
t_key *k = keylist.back();
|
||||||
|
if (k != 0) { // make sure we don't have a bad key pointer
|
||||||
delete k;
|
delete k;
|
||||||
keylist.pop_back();
|
keylist.pop_back();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue