Re: [PATCH 1/2] wget: add -o flag

2019-01-04 Thread Denys Vlasenko
On Wed, Dec 26, 2018 at 4:28 PM Martin Lewis  wrote:
>
> Signed-off-by: Martin Lewis 
> ---
>  networking/wget.c | 28 +---
>  1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/networking/wget.c b/networking/wget.c
> index 58a51d9..8da0ce8 100644
> --- a/networking/wget.c
> +++ b/networking/wget.c
> @@ -128,9 +128,10 @@
>  /* //usage:"   [--no-check-certificate] [--no-cache] [--passive-ftp] 
> [-t TRIES]" */
>  /* //usage:"   [-nv] [-nc] [-nH] [-np]" */
>  //usage:   "   [-S|--server-response] [-U|--user-agent AGENT]" 
> IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
> +//usage:   "   [-o|--output-file]\n"
>  //usage:   )

Rather bad --help (it does not show FILE param, and it exceeds 80 columns).
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH 1/2] wget: add -o flag

2019-01-04 Thread Denys Vlasenko
On Wed, Dec 26, 2018 at 4:28 PM Martin Lewis  wrote:
> Signed-off-by: Martin Lewis 
> ---
>  networking/wget.c | 28 +---
>  1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/networking/wget.c b/networking/wget.c
> index 58a51d9..8da0ce8 100644
> --- a/networking/wget.c
> +++ b/networking/wget.c
> @@ -128,9 +128,10 @@
>  /* //usage:"   [--no-check-certificate] [--no-cache] [--passive-ftp] 
> [-t TRIES]" */
>  /* //usage:"   [-nv] [-nc] [-nH] [-np]" */
>  //usage:   "   [-S|--server-response] [-U|--user-agent AGENT]" 
> IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
> +//usage:   "   [-o|--output-file]\n"
>  //usage:   )
>  //usage:   IF_NOT_FEATURE_WGET_LONG_OPTIONS(
> -//usage:   "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]"
> +//usage:   "[-cq] [-O FILE] [-o FILE] [-Y on/off] [-P DIR] [-S] [-U 
> AGENT]"
>  //usage:   IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
>  //usage:   )
>  //usage:#define wget_full_usage "\n\n"
> @@ -147,6 +148,7 @@
>  //usage: "\n   -T SEC  Network read timeout is SEC seconds"
>  //usage:   )
>  //usage: "\n   -O FILE Save to FILE ('-' for stdout)"
> +//usage: "\n   -o FILE Save output to FILE ('-' for stdout)"
>  //usage: "\n   -U STR  Use STR for User-Agent header"
>  //usage: "\n   -Y on/off   Use proxy"
>
> @@ -231,9 +233,11 @@ struct globals {
> unsigned char user_headers; /* Headers mentioned by the user */
>  #endif
> char *fname_out;/* where to direct output (-O) */
> +   char *fname_log;/* where to direct log (-o) */
> const char *proxy_flag; /* Use proxies if env vars are set */
> const char *user_agent; /* "User-Agent" header field */
> int output_fd;
> +   int log_fd;
> int o_flags;
>  #if ENABLE_FEATURE_WGET_TIMEOUT
> unsigned timeout_seconds;
> @@ -287,6 +291,10 @@ static void progress_meter(int flag)
> if (option_mask32 & WGET_OPT_QUIET)
> return;
>
> +   /* Don't save progress to log file */
> +   if (G.log_fd >= 0)
> +   return;
> +
> if (flag == PROGRESS_START)
> bb_progress_init(&G.pmt, G.curfile);
>
> @@ -1401,6 +1409,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
> "quiet\0"No_argument   "q"
> "server-response\0"  No_argument   "S"
> "output-document\0"  Required_argument "O"
> +   "output-file\0"  Required_argument "o"
> "directory-prefix\0" Required_argument "P"
> "proxy\0"Required_argument "Y"
> "user-agent\0"   Required_argument "U"
> @@ -1444,7 +1453,7 @@ IF_DESKTOP(   "no-parent\0"No_argument  
>  "\xf0")
>  #if ENABLE_FEATURE_WGET_LONG_OPTIONS
>  #endif
> GETOPT32(argv, "^"
> -   "cqSO:P:Y:U:T:+"
> +   "cqSO:o:P:Y:U:T:+"


You forgot to update WGET_OPT_xyz constants.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH 1/2] wget: add -o flag

2018-12-26 Thread Kang-Che Sung
On Wednesday, December 26, 2018, Martin Lewis 
wrote:
> [...]
> @@ -147,6 +148,7 @@
>  //usage: "\n   -T SEC  Network read timeout is SEC
seconds"
>  //usage:   )
>  //usage: "\n   -O FILE Save to FILE ('-' for stdout)"
> +//usage: "\n   -o FILE Save output to FILE ('-' for
stdout)"

Am I the only one who think "output" is confusing for the "-o" option?

GNU wget manual already changed the name to "logfile" for what you are
implementing.

Speaking of, would you mind also change the "-O" help text to clarify it
refer to the "downloaded data"? Since both can be technically considered
wget "output" it helps to distinguish between the two.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH 1/2] wget: add -o flag

2018-12-26 Thread Martin Lewis
Signed-off-by: Martin Lewis 
---
 networking/wget.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/networking/wget.c b/networking/wget.c
index 58a51d9..8da0ce8 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -128,9 +128,10 @@
 /* //usage:"   [--no-check-certificate] [--no-cache] [--passive-ftp] 
[-t TRIES]" */
 /* //usage:"   [-nv] [-nc] [-nH] [-np]" */
 //usage:   "   [-S|--server-response] [-U|--user-agent AGENT]" 
IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
+//usage:   "   [-o|--output-file]\n"
 //usage:   )
 //usage:   IF_NOT_FEATURE_WGET_LONG_OPTIONS(
-//usage:   "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]"
+//usage:   "[-cq] [-O FILE] [-o FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]"
 //usage:   IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
 //usage:   )
 //usage:#define wget_full_usage "\n\n"
@@ -147,6 +148,7 @@
 //usage: "\n   -T SEC  Network read timeout is SEC seconds"
 //usage:   )
 //usage: "\n   -O FILE Save to FILE ('-' for stdout)"
+//usage: "\n   -o FILE Save output to FILE ('-' for stdout)"
 //usage: "\n   -U STR  Use STR for User-Agent header"
 //usage: "\n   -Y on/off   Use proxy"
 
@@ -231,9 +233,11 @@ struct globals {
unsigned char user_headers; /* Headers mentioned by the user */
 #endif
char *fname_out;/* where to direct output (-O) */
+   char *fname_log;/* where to direct log (-o) */
const char *proxy_flag; /* Use proxies if env vars are set */
const char *user_agent; /* "User-Agent" header field */
int output_fd;
+   int log_fd;
int o_flags;
 #if ENABLE_FEATURE_WGET_TIMEOUT
unsigned timeout_seconds;
@@ -287,6 +291,10 @@ static void progress_meter(int flag)
if (option_mask32 & WGET_OPT_QUIET)
return;
 
+   /* Don't save progress to log file */
+   if (G.log_fd >= 0)
+   return;
+
if (flag == PROGRESS_START)
bb_progress_init(&G.pmt, G.curfile);
 
@@ -1401,6 +1409,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
"quiet\0"No_argument   "q"
"server-response\0"  No_argument   "S"
"output-document\0"  Required_argument "O"
+   "output-file\0"  Required_argument "o"
"directory-prefix\0" Required_argument "P"
"proxy\0"Required_argument "Y"
"user-agent\0"   Required_argument "U"
@@ -1444,7 +1453,7 @@ IF_DESKTOP(   "no-parent\0"No_argument   
"\xf0")
 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
 #endif
GETOPT32(argv, "^"
-   "cqSO:P:Y:U:T:+"
+   "cqSO:o:P:Y:U:T:+"
/*ignored:*/ "t:"
/*ignored:*/ "n::"
/* wget has exactly four -n opts, all of which we can 
ignore:
@@ -1459,7 +1468,7 @@ IF_DESKTOP(   "no-parent\0"No_argument   
"\xf0")
"-1" /* at least one URL */
IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */
LONGOPTS
-   , &G.fname_out, &G.dir_prefix,
+   , &G.fname_out, &G.fname_log, &G.dir_prefix,
&G.proxy_flag, &G.user_agent,
IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) 
IF_NOT_FEATURE_WGET_TIMEOUT(NULL),
NULL, /* -t RETRIES */
@@ -1521,12 +1530,25 @@ IF_DESKTOP( "no-parent\0"No_argument   
"\xf0")
G.o_flags = O_WRONLY | O_CREAT | O_TRUNC;
}
 
+   G.log_fd = -1;
+   if (G.fname_log) { /* -o FILE ? */
+   if (!LONE_DASH(G.fname_log)) { /* not -o - ? */
+   /* compat with wget: -o FILE can overwrite */
+   G.log_fd = xopen(G.fname_log, O_WRONLY | O_CREAT | 
O_TRUNC);
+   /* Redirect only stderr to log file, so -O - will work 
*/
+   xdup2(G.log_fd, STDERR_FILENO);
+   }
+   }
+
while (*argv)
download_one_url(*argv++);
 
if (G.output_fd >= 0)
xclose(G.output_fd);
 
+   if (G.log_fd >= 0)
+   xclose(G.log_fd);
+
 #if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS
free(G.extra_headers);
 #endif
-- 
1.9.1

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox