Dear all,

lördag den  3 december 2011 klockan 22:34 skrev Mats Erik Andersson detta:
> fredag den  2 december 2011 klockan 12:44 skrev Simon Josefsson detta:
> > Thanks for analysis, I agree that it seems that we should try -ledit
> > too.  Could you take a look at am/readline.m4 and see if you can create
> > a solution?
> 
> This is hard work, guessing which mechanisms to use. The difference below
> applies to "gnulib/m4/readline.m4" and is sufficient to build our FTP
> client with line editing support for GNU/Linux Debian and NetBSD 5.1.
> The proper setting of LTLIBREADLINE should be added, though.

here comes a drafted patch that builds correctly on

  GNU/Linux, OpenBSD, GNU/OpenSolaris, and NetBSD.

For the latter all tests except "ftp-localhost" pass. On the other
hand I have manually used the FTP and TELNET clients from NetBSD 5.1
running inside Qemu (on OpenBSD) in order to connect to a GNU/Linux
host with full success. Similar tests were done from the other systems.

Since the patch below targets exactly "ftp", "telnet", and "telnetd",
which did not build on NetBSD 5.1 previously, the patch text holds
promise to be refineable! I have had to learn so many new things today
regarding Autoconf, taht I ask that you, Alfred and Simon, to take this
patch and polish it in order to later push it to our repository. It is
not ideal, not even with my scant knowledge, but it does work, and I have
not yet seen any disrupting side-effect.


Best regards,
  Mats


diff --git a/am/readline.m4 b/am/readline.m4
index b7ce9e4..354ab4d 100644
--- a/am/readline.m4
+++ b/am/readline.m4
@@ -53,6 +53,21 @@ AC_DEFUN([gl_FUNC_READLINE],
     LIBS="$am_save_LIBS"
   ])
 
+  dnl In case of failure, examine whether libedit can act
+  dnl as replacement. Small NetBSD systems use editline
+  dnl as wrapper for readline.
+  if test "$gl_cv_lib_readline" = no; then
+    am_save_LIBS="$LIBS"
+    LIBREADLINE=-ledit
+    LTLIBREADLINE=-ledit
+    LIBS="$am_save_LIBS $LIBREADLINE"
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
+#include <readline/readline.h>]],
+        [[readline((char*)0);]])],
+      [gl_cv_lib_readline="yes"])
+    LIBS="$am_save_LIBS"
+  fi
+
   if test "$gl_cv_lib_readline" != no; then
     AC_DEFINE([HAVE_READLINE], [1], [Define if you have the readline library.])
     extra_lib=`echo "$gl_cv_lib_readline" | sed -n -e 's/yes, requires //p'`
diff --git a/configure.ac b/configure.ac
index 5828951..984388e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -742,6 +742,38 @@ if test "$inetutils_cv_var_h_errno" = yes; then
   AC_CHECK_DECL(h_errno, , , [#include <netdb.h>])
 fi
 
+dnl Where is tgetent(3) declared?
+AC_MSG_CHECKING(tgetent in -lcurses)
+save_LIBS="$LIBS"
+LIBS="$save_LIBS -lcurses"
+AC_TRY_LINK([#include <curses.h>
+#include <term.h>],
+            [tgetent((void *)0, (void *)0)],
+            eval "ac_cv_lib_curses_tgetent=yes",
+            eval "ac_cv_lib_curses_tgetent=no")
+LIBS="$save_LIBS"
+AC_MSG_RESULT($ac_cv_lib_curses_tgetent)
+if test "$ac_cv_lib_curses_tgetent" = "yes"; then
+  AC_DEFINE([HAVE_TGETENT_CURSES], 1,
+            [FIXME: Access tgetent() using -lcurses])
+  LIBTERMCAP=-lcurses
+else
+  AC_MSG_CHECKING(tgetent in -ltermcap)
+  save_LIBS="$LIBS"
+  LIBS="$save_LIBS -ltermcap"
+  AC_TRY_LINK([#include <termcap.h>],
+              [tgetent((void *)0, (void *)0)],
+              eval "ac_cv_lib_termcap_tgetent=yes",
+              eval "ac_cv_lib_termcap_tgetent=no")
+  LIBS="$save_LIBS"
+  AC_MSG_RESULT($ac_cv_lib_termcap_tgetent)
+  if test "$ac_cv_lib_termcap_tgetent" = "yes"; then
+    AC_DEFINE([HAVE_TGETENT_TERMCAP], 1,
+              [FIXME: Access tgetent() using -ltermcap])
+    LIBTERMCAP=-ltermcap
+  fi
+fi
+
 ## Checks for CPP macros.
 dnl Look for the posix SEEK_ macros (for lseek), and if not found, try the
 dnl similar berkeley L_ macros; if neither can be found, use the classic unix
diff --git a/telnet/telnet.c b/telnet/telnet.c
index c5b4b19..ee81c28 100644
--- a/telnet/telnet.c
+++ b/telnet/telnet.c
@@ -73,9 +73,11 @@
 #include "types.h"
 #include "general.h"
 
-#ifdef HAVE_READLINE
+#if defined HAVE_TGETENT_CURSES
 # include <curses.h>
 # include <term.h>
+#elif defined HAVE_TGETENT_TERMCAP
+# include <termcap.h>
 #endif
 
 
@@ -729,7 +731,7 @@ int
 init_term (char *tname, int fd, int *errp)
 {
   int err = -1;
-#ifdef HAVE_READLINE
+#if defined HAVE_TGETENT_CURSES || defined HAVE_TGETENT_TERMCAP
   err = tgetent (termbuf, tname);
 #endif
   if (err == 1)
diff --git a/telnetd/utility.c b/telnetd/utility.c
index bb49298..ba1ef4a 100644
--- a/telnetd/utility.c
+++ b/telnetd/utility.c
@@ -37,9 +37,11 @@
 # define NET_ENCRYPT()
 #endif
 
-#ifdef HAVE_READLINE
+#if defined HAVE_TGETENT_CURSES
 # include <curses.h>
 # include <term.h>
+#elif defined HAVE_TGETENT_TERMCAP
+# include <termcap.h>
 #endif
 
 #if defined HAVE_STREAMSPTY && defined HAVE_GETMSG \
@@ -826,7 +828,7 @@ terminaltypeok (char *s)
   if (terminaltype == NULL)
     return 1;
 
-#ifdef HAVE_READLINE
+#if defined HAVE_TGETENT_CURSES || defined HAVE_TGETENT_TERMCAP
   if (tgetent (buf, s) == 0)
 #endif
     return 0;

Reply via email to