From 18ddc4c28a7a80434ce3360c050c1fb3ce469950 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sun, 11 Aug 2002 21:21:06 +0000 Subject: from char * to string getline --- src/Keys.cc | 72 ++++++++++++++++++++++++++++++------------------------------- 1 file 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // 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 "StringUtil.hh" -#ifdef HAVE_STDIO_H -#include -#endif // HAVE_STDIO_H +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif // HAVE_CONFIG_H + #ifdef HAVE_CTYPE_H #include #endif // HAVE_CTYPE_H -#ifdef STDC_HEADERS -#include -#include -#include -#endif // STDC_HEADERS - -#if HAVE_STRINGS_H -#include -#endif +#include +#include +#include +#include #ifdef HAVE_SYS_TYPES_H #include @@ -136,7 +130,7 @@ m_abortkey(0), m_display(display) { assert(display); - if (filename) + if (filename != 0) load(filename); } @@ -150,7 +144,7 @@ Keys::~Keys() { //-------------------------------- void Keys::deleteTree() { while (!m_keylist.empty()) { - if (m_keylist.back()) + if (m_keylist.back() && m_keylist.back() != 0) delete m_keylist.back(); m_keylist.pop_back(); } @@ -181,34 +175,34 @@ bool Keys::load(const char *filename) { //ungrab all keys ungrabKeys(); + //free memory of previous grabs deleteTree(); - + XSync(m_display, False); //open the file ifstream infile(filename); if (!infile) - return false; - - - auto_ptr linebuffer(new char[1024]); - + return false; // faild to open file + int line=0;//current line, so we can tell the user where the fault is while (!infile.eof()) { - - infile.getline(linebuffer.get(), 1024); + string linebuffer; + + getline(infile, linebuffer); line++; vector val; //Parse arguments - StringUtil::stringtok(val, linebuffer.get()); + StringUtil::stringtok(val, linebuffer.c_str()); + //must have at least 1 argument - if (val.size()<=0) + if (val.size() <= 0) continue; - if (val[0][0]=='#') //the line is commented + if (val[0][0] == '#') //the line is commented continue; unsigned int key=0, mod=0; @@ -253,7 +247,7 @@ bool Keys::load(const char *filename) { if (i < LASTKEYGRAB ) { if (!current_key) { cerr<<"Error on line: "<execcommand = const_cast - (StringUtil::strcasestr(linebuffer.get(), + (StringUtil::strcasestr(linebuffer.c_str(), getActionStr(Keys::EXECUTE))+ strlen(getActionStr(Keys::EXECUTE))); break; @@ -330,9 +324,9 @@ bool Keys::load(const char *filename) { last_key = 0; } else { //destroy list if no action is found - #ifdef DEBUG +#ifdef DEBUG cerr<<"Didnt find action="<key<<" "<<(int)key->mod<<" ) {"<action)<<"}"<