[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: patching dd
From: |
Olivier Delhomme |
Subject: |
Re: patching dd |
Date: |
Sat, 8 Nov 2003 21:29:11 +0100 |
Le Sat, 08 Nov 2003 09:50:13 +0100, Jim Meyering disait :
> Olivier Delhomme <address@hidden> wrote:
> > I send a patch on november 2 and i was wondering if
> > it was sent directly to /dev/null ?
>
> You sent it to the right place.
> But sometimes it takes a long time for me to handle feature additions.
>
> > Please let me know, where i am wrong with this patch
> > as it adds a feature requested in the TODO list :
> >
> > dd: consider adding an option to suppress `bytes/block read/written'
> > output to stderr. Suggested here:
> > http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=165045
> >
> > Learning is the best way to increase knowledge, please let me know !
>
> I looked at your patch.
> One of the first steps was to apply it to my working sources.
> That failed:
>
> $ patch < /tmp/k
> patching file dd.c
> patch: **** malformed patch at line 163: 234M)\n\+ si
> likewise, but uses powers of 1000 instead of
>
> because your mail client word-wrapped the message,
> making the diff nearly useless.
>
> Please resend the patch without mangling long lines.
>
Thank you for replying so quickly,
sorry for that mistake, i'm so confused. Here is the patch
against today's cvs sources :
--- coreutils/src/dd.c 2003-11-05 23:11:31.000000000 +0100
+++ coreutils-m/src/dd.c 2003-11-08 21:26:53.000000000 +0100
@@ -35,6 +35,7 @@
#include "quote.h"
#include "safe-read.h"
#include "xstrtol.h"
+#include "human.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "dd"
@@ -143,6 +144,15 @@
/* Index into current line, for `conv=block' and `conv=unblock'. */
static size_t col = 0;
+/* This is aimed to choose diplay type */
+static char const *display = "default";
+
+/* Human-readable options for output. */
+static int human_output_opts;
+
+/* The units to use when printing sizes. */
+static uintmax_t display_block_size = 0;
+
struct conversion
{
char *convname;
@@ -300,11 +310,24 @@
of=FILE write to FILE instead of stdout\n\
seek=BLOCKS skip BLOCKS obs-sized blocks at start of output\n\
skip=BLOCKS skip BLOCKS ibs-sized blocks at start of input\n\
+ display=MODE uses display mode according to MODE\n\
+ dbs=SIZE uses SIZE-byte blocks to display statistics\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
\n\
+MODE may be:\n\
+ quiet the statistics will not be displayed\n\
+ human they will be displayed in a human readable format\n\
+\n\
+SIZE may be:\n\
+ human prints all sizes in human readable format (e.g. 1K, 234M)\n\
+ si likewise, but uses powers of 1000 instead of 1024\n\
+ BYTES likewise, but use powers of BYTES\n\
+"),stdout);
+ fputs (_("\
+\n\
BLOCKS and BYTES may be followed by the following multiplicative suffixes:\n\
xM M, c 1, w 2, b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,\n\
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.\n\
@@ -366,21 +389,51 @@
}
static void
-print_stats (void)
+print_human_stats(void)
{
- char buf[2][INT_BUFSIZE_BOUND (uintmax_t)];
+ char display_buf[5][MAX (LONGEST_HUMAN_READABLE + 1, INT_BUFSIZE_BOUND
(uintmax_t))];
+
fprintf (stderr, _("%s+%s records in\n"),
- umaxtostr (r_full, buf[0]), umaxtostr (r_partial, buf[1]));
+ human_readable (r_full, display_buf[0], human_output_opts,
input_blocksize, display_block_size),
+ human_readable (r_partial, display_buf[1], human_output_opts,
input_blocksize, display_block_size));
+
fprintf (stderr, _("%s+%s records out\n"),
- umaxtostr (w_full, buf[0]), umaxtostr (w_partial, buf[1]));
+ human_readable (w_full, display_buf[2], human_output_opts,
output_blocksize , display_block_size),
+ human_readable (w_partial, display_buf[3], human_output_opts,
output_blocksize, display_block_size));
+
if (r_truncate > 0)
{
fprintf (stderr, "%s %s\n",
- umaxtostr (r_truncate, buf[0]),
- (r_truncate == 1
- ? _("truncated record")
+ human_readable (r_truncate, display_buf[5], human_output_opts,
output_blocksize, display_block_size),
+ (r_truncate == 1
? _("truncated record")
: _("truncated records")));
- }
+ }
+}
+
+static void
+print_stats (void)
+{
+ char buf[2][INT_BUFSIZE_BOUND (uintmax_t)];
+
+ if (STREQ (display,"human"))
+ { /* human readable format */
+ print_human_stats();
+ }
+ else if (!STREQ (display,"quiet"))
+ { /* in case dd should not be quiet */
+ fprintf (stderr, _("%s+%s records in\n"),
+ umaxtostr (r_full, buf[0]), umaxtostr (r_partial, buf[1]));
+ fprintf (stderr, _("%s+%s records out\n"),
+ umaxtostr (w_full, buf[0]), umaxtostr (w_partial, buf[1]));
+ if (r_truncate > 0)
+ {
+ fprintf (stderr, "%s %s\n",
+ umaxtostr (r_truncate, buf[0]),
+ (r_truncate == 1
+ ?_("truncated record")
+ : _("truncated records")));
+ }
+ }
}
static void
@@ -575,6 +628,10 @@
output_file = val;
else if (STREQ (name, "conv"))
parse_conversion (val);
+ else if (STREQ (name, "display")) // choose your display mode (quiet,
human, normal)
+ display = val;
+ else if (STREQ (name, "dbs")) // display block size
+ human_output_opts = human_options (val, true, &display_block_size);
else
{
int invalid = 0;
@@ -1163,6 +1220,9 @@
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION,
usage, AUTHORS, (char const *) NULL);
+ human_output_opts = human_options (getenv ("DD_DISPLAY_BLOCK_SIZE"), false,
+ &display_block_size);
+
/* Don't close stdout on exit from here on. */
closeout_func = NULL;
--
web site : http://olivier.delhomme.free.fr/
gpg public key : http://olivier.delhomme.free.fr/delhomme.gpg