Jim Meyering wrote:
> Eric Blake wrote:
> > This repetition begs for a helper method in system.h.  It would look better
> > like:
> >
> > emit_blocksize (program_name);
> 
> I agree.
> Though please call it something like "emit_blocksize_note"
> so it's name doesn't imply it's printing a bare number.
> 
> > where emit_blocksize takes care of converting program_name to uppercase in 
> > its
> > spelling of %s_BLOCKSIZE.

Called emit_blocksize_note(), I don't think it is good to rely on
program_name variable and convert it internally to uppercased string -
as those envvars are not program_name dependent.
So I called emit_blocksize_note with constant string (uppercased).
Additionally I factored out duplicities about SIZE's - to same function
in system.h

Greetings,
         Ondřej Vašík
From abec47c101b23d138bc185e590e3be969fb666f2 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= <ova...@redhat.com>
Date: Wed, 9 Sep 2009 10:00:32 +0200
Subject: [PATCH] doc: du,df,ls - clarify default blocksize in usage

* src/du.c (usage): clarify default blocksize - requested by
  https://bugzilla.redhat.com/show_bug.cgi?id=511188
* src/ls.c (usage): likewise
* src/df.c (usage): likewise
* src/system.h: new function emit_blocksize_note to factor out
 duplicities from du/df/ls usage about blocksize/size
---
 src/df.c     |    5 +----
 src/du.c     |    5 +----
 src/ls.c     |    5 +----
 src/system.h |   14 ++++++++++++++
 4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/df.c b/src/df.c
index 86fd0e3..e89770e 100644
--- a/src/df.c
+++ b/src/df.c
@@ -833,10 +833,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
-      fputs (_("\n\
-SIZE may be (or may be an integer optionally followed by) one of following:\n\
-kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.\n\
-"), stdout);
+      emit_blocksize_note ("DF");
       emit_bug_reporting_address ();
     }
   exit (status);
diff --git a/src/du.c b/src/du.c
index 9da901a..7f1b93d 100644
--- a/src/du.c
+++ b/src/du.c
@@ -330,10 +330,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
-      fputs (_("\n\
-SIZE may be (or may be an integer optionally followed by) one of following:\n\
-kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.\n\
-"), stdout);
+      emit_blocksize_note ("DU");
       emit_bug_reporting_address ();
     }
   exit (status);
diff --git a/src/ls.c b/src/ls.c
index 553090d..2eb4038 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -4664,10 +4664,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
-      fputs (_("\n\
-SIZE may be (or may be an integer optionally followed by) one of following:\n\
-kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.\n\
-"), stdout);
+      emit_blocksize_note ("LS");
       fputs (_("\
 \n\
 By default, color is not used to distinguish types of files.  That is\n\
diff --git a/src/system.h b/src/system.h
index 3a05501..156402b 100644
--- a/src/system.h
+++ b/src/system.h
@@ -616,6 +616,20 @@ ptr_align (void const *ptr, size_t alignment)
     ? false : (((Accum) = (Accum) * 10 + (Digit_val)), true))		\
   )
 
+static inline void
+emit_blocksize_note (char const *program)
+{
+      printf (_("\n\
+If none of the environment variables BLOCKSIZE, BLOCK_SIZE or \n\
+%s_BLOCK_SIZE is specified, blocksize defaults to 1024 bytes.\n\
+(or 512 bytes when POSIXLY_CORRECT environment variable is set)\n\
+"), program);
+      fputs (_("\n\
+SIZE may be (or may be an integer optionally followed by) one of following:\n\
+kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.\n\
+"), stdout);
+}
+
 #include "hard-locale.h"
 static inline void
 emit_bug_reporting_address (void)
-- 
1.5.6.1.156.ge903b

Attachment: signature.asc
Description: Toto je digitálně podepsaná část zprávy

Reply via email to