sandy

text editor
git clone git://git.suckless.org/sandy
Log | Files | Refs | README | LICENSE

commit 4b2fd17c08ed33cd3160fc85abb9706c3097c8b2
parent 6d727eb2194b8acbbb63d365c977fe5aaa1ec9be
Author: Rafael Garcia <rafael.garcia.gallego@gmail.com>
Date:   Thu,  4 Aug 2011 16:20:45 +0200

Fixes a bug present in 64bit computers.
Diffstat:
config.def.h | 40++++++++++++++++++++--------------------
sandy.c | 11+++++++----
2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -52,26 +52,26 @@ static const char nlstr[1] = { 0 }; #define CONTROL(ch) {(ch ^ 0x40)} #define META(ch) {0x1B, ch} -static const Key curskeys[] = { /* Don't use CONTROL or META here */ -/* keyv, tests, func, arg */ -{ {KEY_BACKSPACE}, { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevchar } }, -{ {KEY_DC}, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } }, -{ {KEY_DC}, { t_rw, 0, 0, 0 }, f_delete, { .m = m_nextchar } }, -{ {KEY_IC}, { t_sel, 0, 0, 0 }, f_pipero, TOCLIP }, -{ {KEY_SDC}, { t_sel, t_rw, 0, 0 }, f_pipe, TOCLIP }, -{ {KEY_SIC}, { t_rw, 0, 0, 0 }, f_pipe, FROMCLIP }, -{ {KEY_HOME}, { 0, 0, 0, 0 }, f_moveb, { .m = m_bol } }, -{ {KEY_END}, { 0, 0, 0, 0 }, f_moveb, { .m = m_eol } }, -{ {KEY_SHOME}, { 0, 0, 0, 0 }, f_moveb, { .m = m_bof } }, -{ {KEY_SEND}, { 0, 0, 0, 0 }, f_moveb, { .m = m_eof } }, -{ {KEY_PPAGE}, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevscr } }, -{ {KEY_NPAGE}, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextscr } }, -{ {KEY_UP}, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevline } }, -{ {KEY_DOWN}, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextline } }, -{ {KEY_LEFT}, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevchar } }, -{ {KEY_RIGHT}, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextchar } }, -{ {KEY_SLEFT}, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevword } }, -{ {KEY_SRIGHT}, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextword } }, +static const NCKey curskeys[] = { /* Plain keys here, no CONTROL or META */ +/* keyv, tests, func, arg */ +{ KEY_BACKSPACE, { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevchar } }, +{ KEY_DC, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } }, +{ KEY_DC, { t_rw, 0, 0, 0 }, f_delete, { .m = m_nextchar } }, +{ KEY_IC, { t_sel, 0, 0, 0 }, f_pipero, TOCLIP }, +{ KEY_SDC, { t_sel, t_rw, 0, 0 }, f_pipe, TOCLIP }, +{ KEY_SIC, { t_rw, 0, 0, 0 }, f_pipe, FROMCLIP }, +{ KEY_HOME, { 0, 0, 0, 0 }, f_moveb, { .m = m_bol } }, +{ KEY_END, { 0, 0, 0, 0 }, f_moveb, { .m = m_eol } }, +{ KEY_SHOME, { 0, 0, 0, 0 }, f_moveb, { .m = m_bof } }, +{ KEY_SEND, { 0, 0, 0, 0 }, f_moveb, { .m = m_eof } }, +{ KEY_PPAGE, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevscr } }, +{ KEY_NPAGE, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextscr } }, +{ KEY_UP, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevline } }, +{ KEY_DOWN, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextline } }, +{ KEY_LEFT, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevchar } }, +{ KEY_RIGHT, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextchar } }, +{ KEY_SLEFT, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevword } }, +{ KEY_SRIGHT, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextword } }, }; static const Key stdkeys[] = { diff --git a/sandy.c b/sandy.c @@ -70,7 +70,10 @@ typedef union { /** An argument to a f_* function, generic */ } Arg; typedef struct { /** A keybinding */ - int keyv[6]; /* Keyv to press */ + union { + char c[6]; /* Standard chars */ + int i; /* NCurses code */ + } keyv; bool (*test[4])(void); /* Conditions to match */ void (*func)(const Arg *arg); /* Function to perform */ const Arg arg; /* Argument to func() */ @@ -727,7 +730,7 @@ i_dotests(bool (*const a[])(void)) { void /* Main editing loop */ i_edit(void) { int ch, i; - int c[7]; + char c[7]; fd_set fds; Filepos oldsel, oldcur; @@ -769,7 +772,7 @@ i_edit(void) { if(ch==KEY_MOUSE) { i_mouse(); } else for(i=0; i<LENGTH(curskeys); i++) { - if(memcmp(&ch, curskeys[i].keyv, sizeof ch) == 0 && i_dotests(curskeys[i].test) ) { + if(ch == curskeys[i].keyv.i && i_dotests(curskeys[i].test) ) { if(curskeys[i].func != f_insert) statusflags&=~(S_GroupUndo); curskeys[i].func(&(curskeys[i].arg)); break; @@ -793,7 +796,7 @@ i_edit(void) { if(!(statusflags&S_InsEsc) && ISCTRL(c[0])) { for(i=0; i<LENGTH(stdkeys); i++) { - if(memcmp(c, stdkeys[i].keyv, sizeof stdkeys[i].keyv) == 0 && i_dotests(stdkeys[i].test) ) { + if(memcmp(c, stdkeys[i].keyv.c, sizeof stdkeys[i].keyv.c) == 0 && i_dotests(stdkeys[i].test) ) { if(stdkeys[i].func != f_insert) statusflags&=~(S_GroupUndo); stdkeys[i].func(&(stdkeys[i].arg)); break;