bug-inetutils
[Top][All Lists]
Advanced

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

Re: [bug-inetutils] Re: ftp: command processing


From: Debarshi 'Rishi' Ray
Subject: Re: [bug-inetutils] Re: ftp: command processing
Date: Sat, 1 Sep 2007 12:59:35 +0530

Here (http://rishi.fedorapeople.org/gnu/ftp-cmd.diff and inline) is the patch.

* I did not remove the check for readline in configure, since we still
need to pass -lreadline in LDADD if GNU Readline is present. Or is
there some other way to handle this?

* libhistory is checked for add_history, only if it is not present
there and the system has GNU Readline do we repeat the check in
readline.

* I plan to address the issue of turning on warning and mentioning the
headers in a subsequent patch.

Comments?

Happy hacking,
Debarshi

diff -urNp inetutils/ftp/Makefile.am inetutils-build/ftp/Makefile.am
--- inetutils/ftp/Makefile.am   2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/ftp/Makefile.am     2007-09-01 14:55:11.000000000 +0530
@@ -31,7 +31,7 @@ man_MANS = ftp.1
 INCLUDES = -I$(top_srcdir)/lib -I../lib -I$(top_srcdir)/libinetutils
 AM_CPPFLAGS = $(PATHDEF_TMP) $(PATHDEF_BSHELL)

address@hidden@ @LIBTERMCAP@
address@hidden@ @LIBTERMCAP@ @LIBHISTORY@
 LDADD = -L../libinetutils -linetutils -L../lib -lgnu $(LIBGLOB) $(READLINE)

 EXTRA_DIST = $(man_MANS)
diff -urNp inetutils/ftp/cmds.c inetutils-build/ftp/cmds.c
--- inetutils/ftp/cmds.c        2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/ftp/cmds.c  2007-09-01 14:48:50.000000000 +0530
@@ -134,22 +134,45 @@ int
 another (pargc, pargv, prompt)
      int *pargc;
      char ***pargv;
-     char *prompt;
+     const char *prompt;
 {
+  char *arg;
+  char *buffer;
   int len = strlen (line), ret;

-  if (len >= sizeof (line) - 3)
+  buffer = (char *) malloc (sizeof (char) * (strlen (prompt) + 4));
+  if (!buffer)
+    intr ();
+
+  sprintf (buffer, "(%s) ", prompt);
+
+  arg = readline (buffer);
+  free (buffer);
+
+#if HAVE_LIBHISTORY
+  if (arg && *arg)
+    add_history (arg);
+#endif
+
+  if (!arg)
+    intr ();
+  else if (!*arg)
     {
-      printf ("sorry, arguments too long\n");
+      free (arg);
+      return 0;
+    }
+
+  line = realloc (line, sizeof (char) * (len + strlen (arg) + 2));
+  if (!line)
+    {
+      free (arg);
       intr ();
     }
-  printf ("(%s) ", prompt);
+
   line[len++] = ' ';
-  if (fgets (&line[len], sizeof (line) - len, stdin) == NULL)
-    intr ();
-  len += strlen (&line[len]);
-  if (len > 0 && line[len - 1] == '\n')
-    line[len - 1] = '\0';
+  strcpy (&line[len], arg);
+  free (arg);
+
   makeargv ();
   ret = margc > *pargc;
   *pargc = margc;
diff -urNp inetutils/ftp/extern.h inetutils-build/ftp/extern.h
--- inetutils/ftp/extern.h      2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/ftp/extern.h        2007-08-31 14:18:10.000000000 +0530
@@ -37,7 +37,7 @@ void abortpt ();
 void abortrecv ();
 void abortsend ();
 void account (int, char **);
-int another (int *, char ***, char *);
+int another (int *, char ***, const char *);
 void blkfree (char **);
 void cd (int, char **);
 void cdup (int, char **);
diff -urNp inetutils/ftp/ftp.c inetutils-build/ftp/ftp.c
--- inetutils/ftp/ftp.c 2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/ftp/ftp.c   2007-08-31 14:18:10.000000000 +0530
@@ -308,13 +308,12 @@ login (host)
     {
       if (!strcmp ("init", macros[n].mac_name))
        {
-#if HAVE_LIBREADLINE
          if (line)
            free (line);
          line = calloc (200, sizeof (*line));
          if (!line)
            quit (0, 0);
-#endif
+
          strcpy (line, "$init");
          makeargv ();
          domacro (margc, margv);
diff -urNp inetutils/ftp/ftp_var.h inetutils-build/ftp/ftp_var.h
--- inetutils/ftp/ftp_var.h     2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/ftp/ftp_var.h       2007-08-31 14:18:10.000000000 +0530
@@ -93,11 +93,7 @@ FTP_EXTERN struct servent *sp;       /* servic

 FTP_EXTERN jmp_buf toplevel;   /* non-local goto stuff for cmd scanner */

-#if HAVE_LIBREADLINE
 FTP_EXTERN char *line;
-#else
-FTP_EXTERN char line[MAXLINE]; /* input line buffer */
-#endif

 FTP_EXTERN char *stringbase;   /* current scan point in line buffer */
 FTP_EXTERN char argbuf[MAXLINE];       /* argument storage buffer */
diff -urNp inetutils/ftp/main.c inetutils-build/ftp/main.c
--- inetutils/ftp/main.c        2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/ftp/main.c  2007-09-01 17:26:46.000000000 +0530
@@ -46,6 +46,7 @@
 #include <error.h>
 #include <netdb.h>
 #include <pwd.h>
+#include <readline.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -57,10 +58,6 @@
 #include "ftp_var.h"

 #include "libinetutils.h"
-
-#if HAVE_READLINE_READLINE_H
-# include <readline/readline.h>
-#endif
 

 #define DEFAULT_PROMPT "ftp> "
@@ -282,12 +279,10 @@ cmdscanner (int top)
     putchar ('\n');
   for (;;)
     {
-
-#if HAVE_LIBREADLINE
       if (line)
        {
          free (line);
-         line = 0;
+         line = NULL;
        }
       line = readline (prompt);
       if (!line)
@@ -298,36 +293,15 @@ cmdscanner (int top)
          printf ("Line too long.\n");
          break;
        }
+
+#if HAVE_LIBHISTORY
       if (line && *line)
        add_history (line);
-      if (l == 0)
-       break;
-#else
-      if (prompt)
-       {
-         printf ("%s", prompt);
-         fflush (stdout);
-       }
+#endif

-      if (fgets (line, sizeof line, stdin) == NULL)
-       quit (0, 0);
-      l = strlen (line);
       if (l == 0)
        break;
-      if (line[--l] == '\n')
-       {
-         if (l == 0)
-           break;
-         line[l] = '\0';
-       }
-      else if (l == sizeof (line) - 2)
-       {
-         printf ("sorry, input line too long\n");
-         while ((l = getchar ()) != '\n' && l != EOF)
-           /* void */ ;
-         break;
-       }                       /* else it was a line without a newline */
-#endif
+
       makeargv ();
       if (margc == 0)
        continue;
diff -urNp inetutils/ChangeLog inetutils-build/ChangeLog
--- inetutils/ChangeLog 2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/ChangeLog   2007-09-01 17:54:16.000000000 +0530
@@ -1,3 +1,28 @@
+2007-08-28  Debarshi Ray <address@hidden>
+
+       * bootstrap.conf (gnulib_modules): Added `readline'.
+
+       * configure.ac: Added libhistory check. Added check for add_history in
+       libreadline if it is not present in libhistory.
+
+       * ftp/Makefile.am (READLINE): 'Added @LIBHISTORY@'.
+
+       * ftp/cmds.c (another): Changed to 'int another (int *pargc,
+       char ***pargv, const char *prompt)'. Added new variables BUFFER and
+       ARG. Use readline for input. Use add_history only when
+       HAVE_LIBREADLINE is defined. Fix error-checking.
+
+       * ftp/extern.h (another) [notdef]: Changed to 'int another (int
+       *pargc, char ***pargv, const char *prompt)'.
+
+       * ftp/ftp.c (login): Removed HAVE_LIBREADLINE.
+
+       * ftp/ftp_var.h: Removed HAVE_LIBREADLINE and LINE is always char*.
+
+       * ftp/main.c: #include <readline.h>
+       (cmdscanner): Use readline uniformly. Use add_history only when
+       HAVE_LIBREADLINE is defined. Replaced 0 with NULL.
+
 2007-07-26  Debarshi Ray <address@hidden>

        * ping/ping_echo.c (ping_echo): Free PING->ping_hostname.
diff -urNp inetutils/bootstrap.conf inetutils-build/bootstrap.conf
--- inetutils/bootstrap.conf    2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/bootstrap.conf      2007-08-31 14:18:10.000000000 +0530
@@ -51,6 +51,7 @@ memset
 minmax
 obstack
 poll
+readline
 readutmp
 realloc
 regex
diff -urNp inetutils/configure.ac inetutils-build/configure.ac
--- inetutils/configure.ac      2007-08-12 07:17:48.000000000 +0530
+++ inetutils-build/configure.ac        2007-09-01 15:20:41.000000000 +0530
@@ -157,6 +157,22 @@ AC_CHECK_LIB(readline, rl_bind_key,
 AC_SUBST(LIBREADLINE)
 AC_SUBST(LIBTERMCAP)

+AC_CHECK_LIB(history, add_history,
+             [LIBHISTORY=-lhistory
+              AC_DEFINE(HAVE_LIBHISTORY, 1,
+                  [Define to one if you have -lhistory])],
+             [LIBHISTORY=])
+AC_SUBST(LIBHISTORY)
+
+# If libhistory does not provide add_history check if libreadline has it.
+if test -z "$LIBHISTORY" && test -n "$LIBREADLINE"; then
+  AC_CHECK_LIB(readline, add_history,
+               [LIBHISTORY=-lreadline
+                AC_DEFINE(HAVE_LIBHISTORY, 1,
+                     [Define to one if you have -lhistory])],
+               [LIBHISTORY=])
+fi
+
 dnl See if there's a separate libcrypt (many systems put crypt there)
 AC_CHECK_LIB(crypt, crypt, LIBCRYPT=-lcrypt)
 AC_SUBST(LIBCRYPT)

-- 
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu




reply via email to

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