nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] (no subject)


From: David Lawrence Ramsey
Subject: Re: [Nano-devel] (no subject)
Date: Mon, 21 Mar 2005 03:03:41 -0500
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

Jim's Bugs wrote:

> Sorry for the delay.

No problem.  There've been a lot of delays on my end too.

> Finding the problem was, I'm afraid, mostly self-interest: our
> students keep killing our servers with hung nano processes.

Whatever your motivation to find it, doing so was definitely helpful.

> Anyway, finally getting back to this I see that nano 1.3.6 has been
> released with the input==ERR patch - I've tried it on both OpenBSD/vax
> 3.6 and Debian woody on an ultrasparc.  Nano dies gracefully on both
> when the parent shell is killed.

Good.

> Looking at the man pages on a couple of the OSes suggests ERR is the
> correct constant to test for - EOF was my foolish assumption (I saw -1
> in gdb).

Again, no problem.  -1 can mean a lot of different things.

> In any case, thanks very much for fixing the bug.

You're welcome.  By the way, I've finally been able to port the same fix
to nano 1.2.4.  It's in the attached patch if you need it.

diff -ur nano-1.2.4/files.c nano-1.2.4-fixed/files.c
--- nano-1.2.4/files.c  2004-06-25 20:23:40.000000000 -0400
+++ nano-1.2.4-fixed/files.c    2005-03-20 23:59:59.000000000 -0500
@@ -2822,7 +2822,7 @@
            }
        }
        wrefresh(edit);
-    } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY);
+    } while ((kbinput = blocking_wgetch(edit)) != NANO_EXIT_KEY);
     curs_set(1);
     blank_edit();
     titlebar(NULL);
diff -ur nano-1.2.4/nano.c nano-1.2.4-fixed/nano.c
--- nano-1.2.4/nano.c   2004-06-25 20:12:19.000000000 -0400
+++ nano-1.2.4-fixed/nano.c     2005-03-21 00:02:27.000000000 -0500
@@ -2619,13 +2619,13 @@
 #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
     /* If it was a mouse click, parse it with do_mouse() and it might
      * become the unjustify key.  Else give it back to the input stream. */
-    if ((i = wgetch(edit)) == KEY_MOUSE)
+    if ((i = blocking_wgetch(edit)) == KEY_MOUSE)
        do_mouse();
     else
        ungetch(i);
 #endif
 
-    if ((i = wgetch(edit)) != NANO_UNJUSTIFY_KEY) {
+    if ((i = blocking_wgetch(edit)) != NANO_UNJUSTIFY_KEY) {
        ungetch(i);
        /* Did we back up anything at all? */
        if (cutbuffer != cutbuffer_save)
@@ -3490,19 +3490,19 @@
        raw();
 #endif
 
-       kbinput = wgetch(edit);
+       kbinput = blocking_wgetch(edit);
 #ifdef DEBUG
        fprintf(stderr, "AHA!  %c (%d)\n", kbinput, kbinput);
 #endif
        if (kbinput == 27) {    /* Grab Alt-key stuff first */
-           kbinput = wgetch(edit);
+           kbinput = blocking_wgetch(edit);
            switch (kbinput) {
                /* Alt-O, suddenly very important ;) */
            case 'O':
-               kbinput = wgetch(edit);
+               kbinput = blocking_wgetch(edit);
                /* Shift or Ctrl + Arrows are Alt-O-[2,5,6]-[A,B,C,D] on some 
terms */
                if (kbinput == '2' || kbinput == '5' || kbinput == '6')
-                   kbinput = wgetch(edit);
+                   kbinput = blocking_wgetch(edit);
                if ((kbinput <= 'D' && kbinput >= 'A') ||
                        (kbinput <= 'd' && kbinput >= 'a'))
                    kbinput = abcd(kbinput);
@@ -3525,16 +3525,16 @@
                keyhandled = 1;
                break;
            case '[':
-               kbinput = wgetch(edit);
+               kbinput = blocking_wgetch(edit);
                switch (kbinput) {
                case '1':       /* Alt-[-1-[0-5,7-9] = F1-F8 in X at least */
-                   kbinput = wgetch(edit);
+                   kbinput = blocking_wgetch(edit);
                    if (kbinput >= '1' && kbinput <= '5') {
                        kbinput = KEY_F(kbinput - 48);
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                    } else if (kbinput >= '7' && kbinput <= '9') {
                        kbinput = KEY_F(kbinput - 49);
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                    } else if (kbinput == '~')
                        kbinput = KEY_HOME;
 #ifdef DEBUG
@@ -3546,23 +3546,23 @@
 #endif
                    break;
                case '2':       /* Alt-[-2-[0,1,3,4] = F9-F12 in many terms */
-                   kbinput = wgetch(edit);
+                   kbinput = blocking_wgetch(edit);
                    switch (kbinput) {
                    case '0':
                        kbinput = KEY_F(9);
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                        break;
                    case '1':
                        kbinput = KEY_F(10);
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                        break;
                    case '3':
                        kbinput = KEY_F(11);
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                        break;
                    case '4':
                        kbinput = KEY_F(12);
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                        break;
                    case '~':
                        kbinput = NANO_INSERTFILE_KEY;
@@ -3577,15 +3577,15 @@
                    break;
                case '3':       /* Alt-[-3 = Delete? */
                    kbinput = NANO_DELETE_KEY;
-                   wgetch(edit);
+                   blocking_wgetch(edit);
                    break;
                case '4':       /* Alt-[-4 = End? */
                    kbinput = NANO_END_KEY;
-                   wgetch(edit);
+                   blocking_wgetch(edit);
                    break;
                case '5':       /* Alt-[-5 = Page Up */
                    kbinput = KEY_PPAGE;
-                   wgetch(edit);
+                   blocking_wgetch(edit);
                    break;
                case 'V':       /* Alt-[-V = Page Up in Hurd Console */
                case 'I':       /* Alt-[-I = Page Up - FreeBSD Console */
@@ -3593,7 +3593,7 @@
                    break;
                case '6':       /* Alt-[-6 = Page Down */
                    kbinput = KEY_NPAGE;
-                   wgetch(edit);
+                   blocking_wgetch(edit);
                    break;
                case 'U':       /* Alt-[-U = Page Down in Hurd Console */
                case 'G':       /* Alt-[-G = Page Down - FreeBSD Console */
@@ -3601,11 +3601,11 @@
                    break;
                case '7':
                    kbinput = KEY_HOME;
-                   wgetch(edit);
+                   blocking_wgetch(edit);
                    break;
                case '8':
                    kbinput = KEY_END;
-                   wgetch(edit);
+                   blocking_wgetch(edit);
                    break;
                case '9':       /* Alt-[-9 = Delete in Hurd Console */
                    kbinput = KEY_DC;
@@ -3615,7 +3615,7 @@
                    kbinput = NANO_INSERTFILE_KEY;
                    break;
                case '[':       /* Alt-[-[-[A-E], F1-F5 in Linux console */
-                   kbinput = wgetch(edit);
+                   kbinput = blocking_wgetch(edit);
                    if (kbinput >= 'A' && kbinput <= 'E')
                        kbinput = KEY_F(kbinput - 64);
                    break;
diff -ur nano-1.2.4/proto.h nano-1.2.4-fixed/proto.h
--- nano-1.2.4/proto.h  2004-06-19 21:13:57.000000000 -0400
+++ nano-1.2.4-fixed/proto.h    2005-03-20 23:58:54.000000000 -0500
@@ -427,6 +427,7 @@
 #endif
 
 /* Public functions in winio.c */
+int blocking_wgetch(WINDOW *win);
 int do_first_line(void);
 int do_last_line(void);
 int xpt(const filestruct *fileptr, int index);
diff -ur nano-1.2.4/winio.c nano-1.2.4-fixed/winio.c
--- nano-1.2.4/winio.c  2003-09-16 22:36:56.000000000 -0400
+++ nano-1.2.4-fixed/winio.c    2005-03-21 00:07:16.000000000 -0500
@@ -34,6 +34,18 @@
                                   we call statusbar(), before we
                                   actually blank the statusbar */
 
+int blocking_wgetch(WINDOW *win)
+{
+    int retval = wgetch(win);
+
+    /* If we get ERR when using blocking input, it means that the input
+     * source that we were using is gone, so die gracefully. */
+    if (retval == ERR)
+       handle_hupterm(0);
+
+    return retval;
+}
+
 int do_first_line(void)
 {
     current = fileage;
@@ -247,7 +259,7 @@
        input */
     wrefresh(edit);
 
-    while ((kbinput = wgetch(bottomwin)) != 13) {
+    while ((kbinput = blocking_wgetch(bottomwin)) != 13) {
        for (t = s; t != NULL; t = t->next) {
 #ifdef DEBUG
            fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput);
@@ -455,9 +467,9 @@
        case KEY_DC:
            goto do_deletekey;
        case 27:
-           switch (kbinput = wgetch(edit)) {
+           switch (kbinput = blocking_wgetch(edit)) {
            case 'O':
-               switch (kbinput = wgetch(edit)) {
+               switch (kbinput = blocking_wgetch(edit)) {
                case 'F':
                    x = xend;
                    break;
@@ -467,7 +479,7 @@
                }
                break;
            case '[':
-               switch (kbinput = wgetch(edit)) {
+               switch (kbinput = blocking_wgetch(edit)) {
                case 'A':
 #ifndef NANO_SMALL
                    goto do_upkey;
@@ -1340,7 +1352,7 @@
     wrefresh(bottomwin);
 
     do {
-       int kbinput = wgetch(edit);
+       int kbinput = blocking_wgetch(edit);
 #if !defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)
        MEVENT mevent;
 #endif
@@ -1587,19 +1599,19 @@
            break;
 #endif
        case 27:
-           kbinput = wgetch(edit);
+           kbinput = blocking_wgetch(edit);
            switch(kbinput) {
            case '[':
-               kbinput = wgetch(edit);
+               kbinput = blocking_wgetch(edit);
                switch(kbinput) {
                    case '5':   /* Alt-[-5 = Page Up */
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                        goto do_pageupkey;
                    case 'V':   /* Alt-[-V = Page Up in Hurd Console */
                    case 'I':   /* Alt-[-I = Page Up - FreeBSD Console */
                        goto do_pageupkey;
                    case '6':   /* Alt-[-6 = Page Down */
-                       wgetch(edit);
+                       blocking_wgetch(edit);
                        goto do_pagedownkey;
                    case 'U':   /* Alt-[-U = Page Down in Hurd Console */
                    case 'G':   /* Alt-[-G = Page Down - FreeBSD Console */
@@ -1649,7 +1661,7 @@
            no_more = 1;
            continue;
        }
-    } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY &&
+    } while ((kbinput = blocking_wgetch(edit)) != NANO_EXIT_KEY &&
             kbinput != NANO_EXIT_FKEY);
 
     currshortcut = oldshortcut;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]