bug-inetutils
[Top][All Lists]
Advanced

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

[bug-inetutils] Re: ftp: command processing


From: Debarshi 'Rishi' Ray
Subject: [bug-inetutils] Re: ftp: command processing
Date: Mon, 3 Sep 2007 00:59:46 +0530

Here (http://rishi.fedorapeople.org/gnu/ChangeLog and inline) is the
ChangeLog entry:

2007-09-02  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 type of PROMPT to const char *.
        Added new variables BUFFER and ARG.  Use readline for input.  Use
        add_history only when HAVE_LIBHISTORY is defined.  Fix error-checking.

        * ftp/extern.h (another) [notdef]: Changed type of PROMPT to
        const char *.

        * ftp/ftp.c (login): Removed HAVE_LIBREADLINE.

        * ftp/ftp_var.h: Removed HAVE_LIBREADLINE and LINE is always char*.

        * ftp/main.c [!HAVE_LIBREADLINE]: #include "readline.h"
        (cmdscanner): Use readline uniformly.  Use add_history only when
        HAVE_LIBHISTORY is defined.  Replaced 0 with NULL.

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

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 18:15:40.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-02 18:31:18.000000000 +0530
@@ -58,8 +58,10 @@

 #include "libinetutils.h"

-#if HAVE_READLINE_READLINE_H
-# include <readline/readline.h>
+#if HAVE_LIBREADLINE
+#  include <readline/readline.h>
+#else
+#  include "readline.h"
 #endif
 

@@ -282,12 +284,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 +298,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/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 18:15:27.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)

Comments?

Happy hacking,
Debarshi
-- 
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu




reply via email to

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