[Top][All Lists]
[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: |
Sun, 12 Aug 2007 00:29:54 +0530 |
Here (attached and inline) is a patch to fix this issue, and some
improvements for the non-readline scenario as well.
Preliminary testing over a day has not thrown any issues yet.
Comments?
Happy hacking,
Debarshi
diff -urNp inetutils/ftp/cmds.c inetutils-build/ftp/cmds.c
--- inetutils/ftp/cmds.c 2007-07-21 18:35:51.000000000 +0530
+++ inetutils-build/ftp/cmds.c 2007-08-12 05:51:35.000000000 +0530
@@ -134,22 +134,70 @@ int
another (pargc, pargv, prompt)
int *pargc;
char ***pargv;
- char *prompt;
+ const char *prompt;
{
int len = strlen (line), ret;
+#if HAVE_LIBREADLINE
+ char *arg;
+
+ arg = readline (prompt);
+ if (arg && *arg)
+ add_history (arg);
+ else if (!arg)
+ {
+ putchar ('\n');
+ return 0;
+ }
+ else
+ {
+ free (arg);
+ return 0;
+ }
+
+ line = realloc (line, len + strlen (arg) + 2);
+ if (!line)
+ {
+ free (arg);
+ intr ();
+ }
+
+ line[len++] = ' ';
+ strcpy (&line[len], arg);
+ free (arg);
+#else
+ char *status;
+ int num;
+
if (len >= sizeof (line) - 3)
{
- printf ("sorry, arguments too long\n");
+ printf ("Sorry, arguments too long.\n");
intr ();
}
- printf ("(%s) ", prompt);
+
+ printf ("%s", prompt);
line[len++] = ' ';
- if (fgets (&line[len], sizeof (line) - len, stdin) == NULL)
+ status = fgets (&line[len], sizeof (line) - len, stdin);
+ num = strlen (&line[len]);
+ if (num == 0)
+ {
+ putchar ('\n');
+ return 0;
+ }
+ else if (status == NULL)
intr ();
+
len += strlen (&line[len]);
- if (len > 0 && line[len - 1] == '\n')
- line[len - 1] = '\0';
+ if (line[--len] == '\n')
+ line[len] = '\0';
+ else if (len == sizeof (line) - 2)
+ {
+ printf ("Sorry, input line too long.\n");
+ while ((len = getchar ()) != '\n' && len != EOF)
+ /* void */ ;
+ intr ();
+ }
+#endif
makeargv ();
ret = margc > *pargc;
*pargc = margc;
@@ -178,7 +226,7 @@ setpeer (argc, argv)
return;
}
if (argc < 2)
- another (&argc, &argv, "to");
+ another (&argc, &argv, "(to) ");
if (argc < 2 || argc > 3)
{
printf ("usage: %s host-name [port]\n", argv[0]);
@@ -478,9 +526,9 @@ put (argc, argv)
argv[2] = argv[1];
loc++;
}
- if (argc < 2 && !another (&argc, &argv, "local-file"))
+ if (argc < 2 && !another (&argc, &argv, "(local-file) "))
goto usage;
- if (argc < 3 && !another (&argc, &argv, "remote-file"))
+ if (argc < 3 && !another (&argc, &argv, "(remote-file) "))
{
usage:
printf ("usage: %s local-file remote-file\n", argv[0]);
@@ -535,7 +583,7 @@ mput (argc, argv)
sig_t oldintr;
int ointer;
- if (argc < 2 && !another (&argc, &argv, "local-files"))
+ if (argc < 2 && !another (&argc, &argv, "(local-files) "))
{
printf ("usage: %s local-files\n", argv[0]);
code = -1;
@@ -727,9 +775,9 @@ getit (argc, argv, restartit, mode)
argv[2] = argv[1];
loc++;
}
- if (argc < 2 && !another (&argc, &argv, "remote-file"))
+ if (argc < 2 && !another (&argc, &argv, "(remote-file) "))
goto usage;
- if (argc < 3 && !another (&argc, &argv, "local-file"))
+ if (argc < 3 && !another (&argc, &argv, "(local-file) "))
{
usage:
printf ("usage: %s remote-file [ local-file ]\n", argv[0]);
@@ -862,7 +910,7 @@ mget (argc, argv)
int ch, ointer;
char *cp, *tp, *tp2;
- if (argc < 2 && !another (&argc, &argv, "remote-files"))
+ if (argc < 2 && !another (&argc, &argv, "(remote-files) "))
{
printf ("usage: %s remote-files\n", argv[0]);
code = -1;
@@ -1251,7 +1299,7 @@ cd (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "remote-directory"))
+ if (argc < 2 && !another (&argc, &argv, "(remote-directory) "))
{
printf ("usage: %s remote-directory\n", argv[0]);
code = -1;
@@ -1323,7 +1371,7 @@ delete (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "remote-file"))
+ if (argc < 2 && !another (&argc, &argv, "(remote-file) "))
{
printf ("usage: %s remote-file\n", argv[0]);
code = -1;
@@ -1344,7 +1392,7 @@ mdelete (argc, argv)
int ointer;
char *cp;
- if (argc < 2 && !another (&argc, &argv, "remote-files"))
+ if (argc < 2 && !another (&argc, &argv, "(remote-files) "))
{
printf ("usage: %s remote-files\n", argv[0]);
code = -1;
@@ -1390,9 +1438,9 @@ renamefile (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "from-name"))
+ if (argc < 2 && !another (&argc, &argv, "(from-name) "))
goto usage;
- if (argc < 3 && !another (&argc, &argv, "to-name"))
+ if (argc < 3 && !another (&argc, &argv, "(to-name) "))
{
usage:
printf ("%s from-name to-name\n", argv[0]);
@@ -1462,9 +1510,9 @@ mls (argc, argv)
int ointer, i;
char *cmd, mode[1], *dest;
- if (argc < 2 && !another (&argc, &argv, "remote-files"))
+ if (argc < 2 && !another (&argc, &argv, "(remote-files) "))
goto usage;
- if (argc < 3 && !another (&argc, &argv, "local-file"))
+ if (argc < 3 && !another (&argc, &argv, "(local-file) "))
{
usage:
printf ("usage: %s remote-files local-file\n", argv[0]);
@@ -1593,7 +1641,7 @@ user (argc, argv)
int n, aflag = 0;
if (argc < 2)
- another (&argc, &argv, "username");
+ another (&argc, &argv, "(username) ");
if (argc < 2 || argc > 4)
{
printf ("usage: %s username [password] [account]\n", argv[0]);
@@ -1663,7 +1711,7 @@ makedir (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "directory-name"))
+ if (argc < 2 && !another (&argc, &argv, "(directory-name) "))
{
printf ("usage: %s directory-name\n", argv[0]);
code = -1;
@@ -1686,7 +1734,7 @@ removedir (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "directory-name"))
+ if (argc < 2 && !another (&argc, &argv, "(directory-name) "))
{
printf ("usage: %s directory-name\n", argv[0]);
code = -1;
@@ -1709,7 +1757,7 @@ quote (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "command line to send"))
+ if (argc < 2 && !another (&argc, &argv, "(command line to send) "))
{
printf ("usage: %s line-to-send\n", argv[0]);
code = -1;
@@ -1729,7 +1777,7 @@ site (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "arguments to SITE command"))
+ if (argc < 2 && !another (&argc, &argv, "(arguments to SITE command) "))
{
printf ("usage: %s line-to-send\n", argv[0]);
code = -1;
@@ -1775,9 +1823,9 @@ do_chmod (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "mode"))
+ if (argc < 2 && !another (&argc, &argv, "(mode) "))
goto usage;
- if (argc < 3 && !another (&argc, &argv, "file-name"))
+ if (argc < 3 && !another (&argc, &argv, "(file-name) "))
{
usage:
printf ("usage: %s mode file-name\n", argv[0]);
@@ -1987,7 +2035,7 @@ doproxy (argc, argv)
struct cmd *c;
sig_t oldintr;
- if (argc < 2 && !another (&argc, &argv, "command"))
+ if (argc < 2 && !another (&argc, &argv, "(command) "))
{
printf ("usage: %s command\n", argv[0]);
code = -1;
@@ -2150,7 +2198,7 @@ setnmap (argc, argv)
code = mapflag;
return;
}
- if (argc < 3 && !another (&argc, &argv, "mapout"))
+ if (argc < 3 && !another (&argc, &argv, "(mapout) "))
{
printf ("Usage: %s [mapin mapout]\n", argv[0]);
code = -1;
@@ -2447,7 +2495,7 @@ macdef (argc, argv)
code = -1;
return;
}
- if (argc < 2 && !another (&argc, &argv, "macro name"))
+ if (argc < 2 && !another (&argc, &argv, "(macro name) "))
{
printf ("Usage: %s macro_name\n", argv[0]);
code = -1;
@@ -2515,7 +2563,7 @@ sizecmd (argc, argv)
char *argv[];
{
- if (argc < 2 && !another (&argc, &argv, "filename"))
+ if (argc < 2 && !another (&argc, &argv, "(filename) "))
{
printf ("usage: %s filename\n", argv[0]);
code = -1;
@@ -2534,7 +2582,7 @@ modtime (argc, argv)
{
int overbose;
- if (argc < 2 && !another (&argc, &argv, "filename"))
+ if (argc < 2 && !another (&argc, &argv, "(filename) "))
{
printf ("usage: %s filename\n", argv[0]);
code = -1;
diff -urNp inetutils/ftp/domacro.c inetutils-build/ftp/domacro.c
--- inetutils/ftp/domacro.c 2006-10-21 23:38:45.000000000 +0530
+++ inetutils-build/ftp/domacro.c 2007-08-11 16:30:15.000000000 +0530
@@ -45,7 +45,7 @@ domacro (int argc, char *argv[])
char *cp1, *cp2, line2[200];
struct cmd *c;
- if (argc < 2 && !another (&argc, &argv, "macro name"))
+ if (argc < 2 && !another (&argc, &argv, "(macro name) "))
{
printf ("Usage: %s macro_name.\n", argv[0]);
code = -1;
diff -urNp inetutils/ftp/extern.h inetutils-build/ftp/extern.h
--- inetutils/ftp/extern.h 2006-10-21 20:54:21.000000000 +0530
+++ inetutils-build/ftp/extern.h 2007-08-11 07:52:43.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/main.c inetutils-build/ftp/main.c
--- inetutils/ftp/main.c 2007-07-21 18:35:51.000000000 +0530
+++ inetutils-build/ftp/main.c 2007-08-11 07:51:03.000000000 +0530
@@ -287,7 +287,7 @@ cmdscanner (int top)
if (line)
{
free (line);
- line = 0;
+ line = NULL;
}
line = readline (prompt);
if (!line)
@@ -309,7 +309,7 @@ cmdscanner (int top)
fflush (stdout);
}
- if (fgets (line, sizeof line, stdin) == NULL)
+ if (fgets (line, sizeof (line), stdin) == NULL)
quit (0, 0);
l = strlen (line);
if (l == 0)
@@ -322,7 +322,7 @@ cmdscanner (int top)
}
else if (l == sizeof (line) - 2)
{
- printf ("sorry, input line too long\n");
+ printf ("Sorry, input line too long.\n");
while ((l = getchar ()) != '\n' && l != EOF)
/* void */ ;
break;
--
GPG key ID: 63D4A5A7
Key server: pgp.mit.edu
ftp-cmd.diff
Description: Text Data
- [bug-inetutils] ftp: command processing, Debarshi 'Rishi' Ray, 2007/08/08
- [bug-inetutils] Re: ftp: command processing,
Debarshi 'Rishi' Ray <=
- [bug-inetutils] Re: ftp: command processing, Debarshi 'Rishi' Ray, 2007/08/15
- [bug-inetutils] Re: ftp: command processing, Simon Josefsson, 2007/08/15
- [bug-inetutils] Re: ftp: command processing, Debarshi 'Rishi' Ray, 2007/08/15
- [bug-inetutils] Re: ftp: command processing, Simon Josefsson, 2007/08/15
- [bug-inetutils] Re: ftp: command processing, Debarshi 'Rishi' Ray, 2007/08/15
- [bug-inetutils] Re: ftp: command processing, Simon Josefsson, 2007/08/15
- [bug-inetutils] Re: ftp: command processing, Debarshi 'Rishi' Ray, 2007/08/15
- [bug-inetutils] Re: ftp: command processing, Debarshi 'Rishi' Ray, 2007/08/28
- [bug-inetutils] Re: ftp: command processing, Simon Josefsson, 2007/08/28
- [bug-inetutils] Re: ftp: command processing, Debarshi 'Rishi' Ray, 2007/08/28