From 737cd9d8f3c2c075474f18779e335fe7a02535a6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 14 Nov 2001 11:31:14 +0000 Subject: [PATCH] fix parsing of keyboard sequences git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3027 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 12 ++++++++++++ src/kbmap.C | 2 +- src/kbsequence.C | 18 +++++++++++++----- src/lyxrc.C | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8132e4a034..085c6d5616 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2001-11-14 Jean-Marc Lasgouttes + + * lyxrc.C (read): + * kbmap.C (bind): modify because return conventions of + kb_sequence::parse have changed. + + * kbsequence.C (parse): only ignore spaces and not any stupid + control character. This avoids tests like s[i] <= ' ', which are + guaranteed to fail with 8bit characters and signed chars. + Change return code to string::npos when there have been no error + (0 was a bad idea when error is at first character) + 2001-11-13 Jean-Marc Lasgouttes * text.C (selectNextWordToSpellcheck): do not test explicitely for diff --git a/src/kbmap.C b/src/kbmap.C index 67862d0bc6..8b528c49f1 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -82,7 +82,7 @@ string::size_type kb_keymap::bind(string const & seq, int action) kb_sequence k; string::size_type const res = k.parse(seq); - if (!res) { + if (res == string::npos) { defkey(&k, action); } else lyxerr[Debug::KBMAP] << "Parse error at position " << res diff --git a/src/kbsequence.C b/src/kbsequence.C index 89ce116ad6..7c661929c2 100644 --- a/src/kbsequence.C +++ b/src/kbsequence.C @@ -87,7 +87,7 @@ int kb_sequence::addkey(unsigned int key, Called by : [user] Purpose : parse a string that holds a key sequence and add the keys Parameters: s - string holding the key sequence - Returns : 0 - if ok, error pos if error + Returns : string::npos if ok, error pos if error Note : Keys must be separated with whitespace; Use the keysym names used by XStringToKeysym Prefixes are S-, C-, M- for shift, control, meta @@ -100,8 +100,10 @@ string::size_type kb_sequence::parse(string const & s) string::size_type i = 0; unsigned int mod = 0, nmod = 0; while (i < s.length()) { - if (s[i] && (s[i]) <= ' ') ++i; - if (i >= s.length()) break; + if (s[i] == ' ') + ++i; + if (i >= s.length()) + break; if (i + 1 < s.length() && s[i + 1] == '-') { switch (s[i]) { @@ -141,7 +143,7 @@ string::size_type kb_sequence::parse(string const & s) } else { string tbuf; string::size_type j = i; - for (; j < s.length() && s[j] > ' '; ++j) + for (; j < s.length() && s[j] != ' '; ++j) tbuf += s[j]; // (!!!check bounds :-) KeySym key = XStringToKeysym(tbuf.c_str()); @@ -158,7 +160,13 @@ string::size_type kb_sequence::parse(string const & s) nmod = 0; } } - return 0; + + // empty sequence? + if (!length) + return 0; + + // everything is fine + return string::npos; } diff --git a/src/lyxrc.C b/src/lyxrc.C index d8b811cfd2..c93b33729a 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -739,7 +739,7 @@ int LyXRC::read(string const & filename) << action << '\'' << endl; } res = toplevel_keymap->bind(seq, action); - if (res != 0 + if (res != string::npos && lyxerr.debugging(Debug::LYXRC)) { lexrc.printError( "RC_BIND: " -- 2.39.2