Hi,
Some patches for sandy:
1: fix mouse scroll down, also:
- add a comment in the README how to enable mouse scrolling. This is a
limitation in ncurses.
- read count can be 0 (not an error), this is reproducable if you scroll
down with the mouse with ncurses and --disable-mouse-ext.
2: minor cleanup
3: fix cast, wgetch() returns int ... so the check was always false.
4: fix possible out-of-bounds if size of fgcolors > bgcolors + the
color initialization was also wrong?
5: fix uninitialized variables
Also available at: http://www.codemadness.nl/downloads/patches/sandy/
Kind regards,
Hiltjo
From caeab9bd19a920f940dbcf0cfdc0350d86f4b7e6 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <[email protected]>
Date: Thu, 24 Jul 2014 16:40:06 +0000
Subject: [PATCH 1/5] fix mouse scroll down
- add a comment in the README how to enable mouse scrolling. This is a
limitation in ncurses.
- read count can be 0 (not an error), this is reproducable if you scroll
down with the mouse with ncurses and --disable-mouse-ext.
---
README | 4 ++++
config.def.h | 4 +++-
sandy.c | 3 ++-
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/README b/README
index 67967ba..1112f4c 100644
--- a/README
+++ b/README
@@ -40,3 +40,7 @@ Name
In case you are wondering, sandy was the smartest pet ferret. She died of
cancer though. We were sad and started coding this editor.
+
+Known issues
+------------
+Mouse scroll down works if ncurses is compiled with --enable-ext-mouse.
diff --git a/config.def.h b/config.def.h
index 9469130..fa80e52 100644
--- a/config.def.h
+++ b/config.def.h
@@ -266,7 +266,9 @@ static const Click clks[] = {
{BUTTON3_CLICKED, { TRUE , FALSE }, { t_sel, 0, 0 }, f_pipero, { .v = TOSEL } },
{BUTTON2_CLICKED, { FALSE, FALSE }, { t_rw, 0, 0 }, f_pipenull, { .v = FROMSEL } },
{BUTTON4_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_prevscr } },
-/*{BUTTON5_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_nextscr } },*/
+#ifdef BUTTON5_CLICKED
+{BUTTON5_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_nextscr } },
+#endif
/* ^^ NCurses is a sad old library.... it does not include button 5 nor
* cursor movement in its mouse declaration by default */
{BUTTON1_DOUBLE_CLICKED, { TRUE , TRUE }, { 0, 0, 0 }, f_extsel, { .i = ExtWord } },
diff --git a/sandy.c b/sandy.c
index ba4a39f..32acff5 100644
--- a/sandy.c
+++ b/sandy.c
@@ -1371,8 +1371,9 @@ i_pipetext(const char *cmd) {
}
if(FD_ISSET(perr[0], &fdI) && nerr > 0) {
/* Blatant TODO: take last line of stderr and copy as tmptitle */
+ ebuf[0] = '\0';
nerr = read(perr[0], ebuf, BUFSIZ);
- if(nerr != 0)
+ if(nerr == -1)
tmptitle = "WARNING! command reported an error!!!";
if(nerr < 0)
break;
--
2.0.2
From 4271b0f6c744fc41f68ba92140ce3741866ee8aa Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <[email protected]>
Date: Sun, 27 Jul 2014 13:45:10 +0000
Subject: [PATCH 2/5] minor cleanup
---
sandy.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/sandy.c b/sandy.c
index 32acff5..98f4b5d 100644
--- a/sandy.c
+++ b/sandy.c
@@ -582,7 +582,8 @@ f_select(const Arg * arg) {
/* Spawn (char **)arg->v */
void
f_spawn(const Arg * arg) {
- int pid = -1;
+ pid_t pid = -1;
+
reset_shell_mode();
if((pid = fork()) == 0) {
/* setsid() used to be called here, but it does not look as a good idea
@@ -1278,11 +1279,12 @@ i_multiply(void (*func)(const Arg * arg), const Arg arg) {
void
i_pipetext(const char *cmd) {
struct timeval tv;
- int pin[2], pout[2], perr[2], pid = -1, nr = 1, nerr = 1, nw, written;
+ int pin[2], pout[2], perr[2], nr = 1, nerr = 1, nw, written;
int iw = 0, closed = 0, exstatus;
char *buf = NULL, *ebuf = NULL, *s = NULL;
Filepos auxp;
fd_set fdI, fdO;
+ pid_t pid = -1;
if(!cmd || cmd[0] == '\0')
return;
@@ -1347,7 +1349,7 @@ i_pipetext(const char *cmd) {
FD_SET(perr[0], &fdI);
tv.tv_sec = 5;
tv.tv_usec = 0;
- nw = s ? strlen(s) : 0;
+ nw = strlen(s);
while(select(FD_SETSIZE, &fdI, &fdO, NULL, &tv) > 0 &&
(nw > 0 || nr > 0)) {
fflush(NULL);
@@ -1934,9 +1936,9 @@ i_update(void) {
setenv(envs[EnvOffset], buf, 1);
/* Update title */
- if(tmptitle)
+ if(tmptitle) {
snprintf(title, sizeof(title), "%s", tmptitle);
- else {
+ } else {
statusflags &= ~S_Warned; /* Reset warning */
snprintf(buf, 4, "%ld%%", (100 * ncur) / nlst);
snprintf(title, BUFSIZ, "%s%s [%s]%s%s%s%s %ld,%d %s",
--
2.0.2
From a8e31876767c751d1f21a07cf0e55239f1554bd7 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <[email protected]>
Date: Sun, 27 Jul 2014 13:45:49 +0000
Subject: [PATCH 3/5] fix cast, wgetch() returns int
... so the check was always false.
---
sandy.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/sandy.c b/sandy.c
index 98f4b5d..fbe7ad8 100644
--- a/sandy.c
+++ b/sandy.c
@@ -1014,7 +1014,7 @@ i_dokeys(const Key bindings[], unsigned int length_bindings) {
/* Main editing loop */
void
i_edit(void) {
- int i;
+ int i, tch;
fd_set fds;
Filepos oldsel, oldcur;
@@ -1073,9 +1073,12 @@ i_edit(void) {
if(c[0] == 0x1B || (isutf8 && !ISASCII(c[0]))) {
/* Multi-byte char or escape sequence */
wtimeout(textwin, 1);
- for(i = 1; i < (c[0] == 0x1B ? 6 : UTF8LEN(c[0])); i++)
- if((c[i] = wgetch(textwin)) == ERR)
+ for(i = 1; i < (c[0] == 0x1B ? 6 : UTF8LEN(c[0])); i++) {
+ tch = wgetch(textwin);
+ c[i] = (char)tch;
+ if(tch == ERR)
break;
+ }
for(; i < 7; i++)
c[i] = '\0';
wtimeout(textwin, 0);
--
2.0.2
From cca2b5575b295e19043d93e92dbead15c5935d71 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <[email protected]>
Date: Sun, 27 Jul 2014 13:47:58 +0000
Subject: [PATCH 4/5] fix possible out-of-bounds if size of fgcolors > bgcolors
+ the color initialization was also wrong?
---
sandy.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sandy.c b/sandy.c
index fbe7ad8..0efe201 100644
--- a/sandy.c
+++ b/sandy.c
@@ -1649,10 +1649,10 @@ i_setup(void) {
if(fgcolors[i] > 7)
init_color(fgcolors[i], fgcolors[i] >> 8,
(fgcolors[i] >> 4) & 0xF, fgcolors[i] & 0xFF);
- if(bgcolors[i] > 7)
- init_color(bgcolors[i], bgcolors[i] >> 8, (bgcolors[i] >> 4) & 0xF,
- bgcolors[i] & 0xFF);
+ if(bgcolors[j] > 7)
+ init_color(bgcolors[j], bgcolors[j] >> 8, (bgcolors[j] >> 4) & 0xF,
+ bgcolors[j] & 0xFF);
init_pair((i * LastBG) + j, fgcolors[i], bgcolors[j]);
textattrs[i][j] = COLOR_PAIR((i * LastBG) + j) | colorattrs[i];
}
--
2.0.2
From 8aac4b5d8b4f4ebee675d21efe0fdcbe6fe8a3cd Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <[email protected]>
Date: Sun, 27 Jul 2014 13:49:25 +0000
Subject: [PATCH 5/5] fix uninitialized variables
---
sandy.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sandy.c b/sandy.c
index 0efe201..d08b683 100644
--- a/sandy.c
+++ b/sandy.c
@@ -1755,10 +1755,10 @@ i_termwininit(void) {
void
i_update(void) {
int iline, irow, ixrow, ivchar, i, ifg, ibg, vlines;
- size_t ichar;
- int cursor_r, cursor_c;
+ int cursor_r = 0, cursor_c = 0;
int lines3; /* How many lines fit on screen */
- long int nscr, ncur, nlst; /* Line number for scrline, fcur.l and lstline */
+ long int nscr, ncur = 1, nlst = 1; /* Line number for scrline, fcur.l and lstline */
+ size_t ichar;
bool selection;
regmatch_t match[SYN_COLORS][1];
Line *l;
--
2.0.2