Enclosed please find a good patch for whatnowproc readine.

 > ...we can lose the debug tracing :-)

Yes, done.


 > I think you can drop all the signal handling here.

Yes, done.


 > >+    char *ans, **cpp;
 > >+
 > >+    for (;;) {
 > >+        ans = readline (prompt);
 > >+        if (ans[0] == '?' || ans[0] == 0 ) {
 > >+            printf ("Options are:\n");
 > >+            print_sw (ALL, ansp, "");
 > >+            free(ans);
 > >+       continue;
 > >+        }
 > >+   strcpy (ansbuf,ans); /* not sure why--but it makes brkstring() work */
 > >+        cpp = brkstring (ansbuf, " ", NULL);
 > 
 > ...so what happens if you don't strcpy but just pass ans to
 > brkstring()? I can't see anything in brkstring() that cares,
 > and it would be nice to avoid the fixed ansbuf[] buffer.

Sorry, my comment was still in "debug tracing" mode.  The problem isn't with
brkstring().  The problem is that readline() mallocs the char * it returns
and expects it to be free'ed.  I assume that not free'ing ans might lead to
a memory leak or something worse.

steve
--


--- configure.in.orig   2008-05-21 11:44:16.000000000 -0500
+++ configure.in        2010-12-20 08:49:09.000000000 -0600
@@ -43,6 +43,21 @@
 dnl CHECK COMMAND LINE OPTIONS
 dnl --------------------------
 
+dnl Do you want whatnow to use readline()?
+dnl (e.g. enable tab completion and editor support)
+AC_ARG_WITH([readline],
+  [AS_HELP_STRING([--with-readline],
+    [enable whatnow readline() (e.g. enable tab completion and editor 
support)])],
+  [],
+  [with_readline=no])
+LIBREADLINE=
+if test x"$with_readline" = x"yes"; then
+  AC_DEFINE(HAVE_LIBREADLINE, 1,
+    [Define if you have libreadline.])dnl
+  LIBREADLINE="-lreadline -lncurses"
+fi
+AC_SUBST(LIBREADLINE)dnl
+
 dnl Do you want client-side support for apop?
 AC_ARG_ENABLE(apop, AS_HELP_STRING([--enable-apop],
   [enable client-side support for POP3 and APOP]))
--- sbr/getans.c.orig   2007-04-29 17:34:04.000000000 -0500
+++ sbr/getans.c        2010-12-20 08:20:04.000000000 -0600
@@ -2,7 +2,7 @@
 /*
  * getans.c -- get an answer from the user and return a string array
  *
- * $Id: getans.c,v 1.3 2007/04/29 22:34:04 pm215 Exp $
+ * $Id: getans.c,v 1.2 2010/12/20 14:03:51 rader Exp rader $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -14,6 +14,11 @@
 #include <setjmp.h>
 #include <signal.h>
 
+#if HAVE_LIBREADLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+#endif
+
 static char ansbuf[BUFSIZ];
 static jmp_buf sigenv;
 
@@ -69,6 +74,39 @@
 }
 
 
+#if HAVE_LIBREADLINE
+char **
+getans_via_readline (char *prompt, struct swit *ansp)
+{
+    char *ans, **cpp;
+
+    for (;;) {
+        ans = readline (prompt);
+        if (ans[0] == '?' || ans[0] == 0 ) {
+            printf ("Options are:\n");
+            print_sw (ALL, ansp, "");
+            free(ans);
+           continue;
+        }
+       strcpy (ansbuf,ans); 
+        cpp = brkstring (ansbuf, " ", NULL);
+        switch (smatch (*cpp, ansp)) {
+            case AMBIGSW:
+                ambigsw (*cpp, ansp);
+                continue;
+            case UNKWNSW:
+                printf (" -%s unknown. Hit <CR> for help.\n", *cpp);
+                continue;
+            default:
+                free(ans);
+                return cpp;
+        }
+        free(ans);
+    }
+
+}
+#endif
+
 static RETSIGTYPE
 intrser (int i)
 {
--- uip/Makefile.in.orig        2005-12-24 11:17:38.000000000 -0600
+++ uip/Makefile.in     2010-12-20 08:35:24.000000000 -0600
@@ -30,6 +30,7 @@
 SASL_LIBS = @SASL_LIBS@
 HESIOD_LIBS = @HESIOD_LIBS@
 NDBM_LIBS = @NDBM_LIBS@
+READLINE_LIBS = @LIBREADLINE@
 LOCALLIBS = ../config/version.o ../config/config.o $(MTSLIB) ../sbr/libmh.a
 LINKLIBS = $(LOCALLIBS) $(KRB4_LIBS) $(SASL_LIBS) $(HESIOD_LIBS) $(LIBS)
 
@@ -114,14 +115,14 @@
 burst: burst.o $(LOCALLIBS)
        $(LINK) burst.o $(LINKLIBS)
 
-comp: comp.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LOCALLIBS)
-       $(LINK) comp.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LINKLIBS)
+comp: comp.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LOCALLIBS) 
+       $(LINK) comp.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LINKLIBS) $(READLINE_LIBS)
 
 conflict: conflict.o aliasbr.o $(LOCALLIBS)
        $(LINK) conflict.o aliasbr.o $(LINKLIBS)
 
 dist: dist.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LOCALLIBS)
-       $(LINK) dist.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LINKLIBS)
+       $(LINK) dist.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LINKLIBS) $(READLINE_LIBS)
 
 dp: dp.o termsbr.o $(LOCALLIBS)
        $(LINK) dp.o termsbr.o $(LINKLIBS) $(TERMLIB)
@@ -136,7 +137,7 @@
        $(LINK) folder.o $(LINKLIBS)
 
 forw: forw.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LOCALLIBS)
-       $(LINK) forw.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LINKLIBS)
+       $(LINK) forw.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LINKLIBS) $(READLINE_LIBS)
 
 inc: inc.o scansbr.o dropsbr.o termsbr.o $(POPLIB) $(LOCALLIBS)
        $(LINK) inc.o scansbr.o dropsbr.o termsbr.o $(POPLIB) $(LINKLIBS) 
$(TERMLIB)
@@ -211,7 +212,7 @@
        $(LINK) refile.o $(LINKLIBS)
 
 repl: repl.o replsbr.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o 
distsbr.o $(LOCALLIBS)
-       $(LINK) repl.o replsbr.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o 
distsbr.o $(LINKLIBS)
+       $(LINK) repl.o replsbr.o whatnowproc.o whatnowsbr.o sendsbr.o annosbr.o 
distsbr.o $(LINKLIBS) $(READLINE_LIBS)
 
 rmf: rmf.o $(LOCALLIBS)
        $(LINK) rmf.o $(LINKLIBS)
@@ -223,7 +224,7 @@
        $(LINK) scan.o scansbr.o termsbr.o $(LINKLIBS) $(TERMLIB)
 
 send: send.o sendsbr.o annosbr.o distsbr.o $(LOCALLIBS)
-       $(LINK) send.o sendsbr.o annosbr.o distsbr.o $(LINKLIBS)
+       $(LINK) send.o sendsbr.o annosbr.o distsbr.o $(LINKLIBS) 
$(READLINE_LIBS)
 
 show: show.o mhlsbr.o termsbr.o $(LOCALLIBS)
        $(LINK) show.o mhlsbr.o termsbr.o $(LINKLIBS) $(TERMLIB)
@@ -244,7 +245,7 @@
        $(LINK) vmh.o vmhsbr.o $(LINKLIBS) $(TERMLIB)
 
 whatnow: whatnow.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o $(LOCALLIBS)
-       $(LINK) whatnow.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o $(LINKLIBS)
+       $(LINK) whatnow.o whatnowsbr.o sendsbr.o annosbr.o distsbr.o 
$(LINKLIBS) $(READLINE_LIBS)
 
 whom: whom.o distsbr.o $(LOCALLIBS)
        $(LINK) whom.o distsbr.o $(LINKLIBS)
--- uip/whatnowsbr.c.orig       2008-05-22 05:42:10.000000000 -0500
+++ uip/whatnowsbr.c    2010-12-20 08:22:25.000000000 -0600
@@ -2,7 +2,7 @@
 /*
  * whatnowsbr.c -- the WhatNow shell
  *
- * $Id: whatnowsbr.c,v 1.9.2.1 2008/05/22 10:42:10 pm215 Exp $
+ * $Id: whatnowsbr.c,v 1.1 2010/12/20 14:22:25 rader Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -243,7 +243,11 @@
 
     snprintf (prompt, sizeof(prompt), myprompt, invo_name);
     for (;;) {
+#ifndef HAVE_LIBREADLINE
        if (!(argp = getans (prompt, aleqs))) {
+#else
+       if (!(argp = getans_via_readline (prompt, aleqs))) {
+#endif
            unlink (LINK);
            done (1);
        }
_______________________________________________
Nmh-workers mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/nmh-workers

Reply via email to