bug-coreutils
[Top][All Lists]
Advanced

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

Re: Fw: pr and indentation -- proposed patch


From: Jim Meyering
Subject: Re: Fw: pr and indentation -- proposed patch
Date: Sat, 07 Mar 2009 15:44:23 +0100

hggdh wrote:
> I sent the email below sometime ago; since there was no response, I
> decided to propose a patch in order to have the title line also indented
> by --indent.
>
> Regards,
>
> ..hggdh..
>
> diff --git a/src/pr.c b/src/pr.c
> index 308a025..331762f 100644
> --- a/src/pr.c
> +++ b/src/pr.c
> @@ -2399,13 +2399,13 @@ print_header (void)
>       "Page %"PRIuMAX does not generate more than (sizeof page_text - 1)
>       bytes.  */
>    sprintf (page_text, _("Page %"PRIuMAX), page_number++);
> -  available_width = header_width_available - mbswidth (page_text, 0);
> +  available_width = header_width_available - (chars_per_margin + mbswidth 
> (page_text, 0));
>    available_width = MAX (0, available_width);
>    lhs_spaces = available_width >> 1;
>    rhs_spaces = available_width - lhs_spaces;
>
> -  printf ("\n\n%s%*s%s%*s%s\n\n\n",
> -         date_text, lhs_spaces, " ", file_text, rhs_spaces, " ", page_text);
> +  printf ("\n\n%*s%s%*s%s%*s%s\n\n\n",
> +         chars_per_margin, " ", date_text, lhs_spaces, " ", file_text, 
> rhs_spaces, " ", page_text);
>
>    print_a_header = false;
>    output_position = 0;

Thank you for the bug report and patch.
We would have gotten to it eventually, but
sending a patch tends to accelerate the process ;-)

For reference, that patch did not apply for me.
Please send git format-patch output in the future.

  http://git.sv.gnu.org/cgit/coreutils.git/plain/HACKING

I had to make a small correction: use %*.*s, rather than just %*s.
Otherwise, there'd always be at least one space of indentation.
Compare:

    $ printf 'x%*sy\n' 0 -
    x-y
    $ printf 'x%*.*sy\n' 0 0 -
    xy

Also, I dropped the first hunk of your change, because we don't
want to narrow the usable width to accommodate indentation.
POSIX appears to specify that, and the result is then consistent
with what Solaris' /usr/bin/pr does.

Also, I had to adjust numerous expected output files
to match the new output when invoked with -o.

The only missing piece is an indication of what you'd
like to appear in the commit log and in THANKS.
i.e., Real Name <address@hidden> is customary.

Modulo your name, here's what I expect to push.



>From ebbbb1f4536cd5b9eb56d3af44bdbbe1720afa1b Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 6 Mar 2009 20:03:26 +0100
Subject: [PATCH] pr: fix a bug whereby --indent=N (-o) did not indent header 
lines

* src/pr.c (print_header): Honor chars_per_margin also for the header.
Based on a patch by hggdh.
* NEWS (Bug fixes): Mention it.
* tests/pr/o3Jml24f-lm-lo: Adjust for new expected output.
* tests/pr/o3a3Sl24f-tn: Likewise.
* tests/pr/o3a3Snl24f-tn: Likewise.
* tests/pr/o3a3l24f-tn: Likewise.
* tests/pr/o3b3Sl24f-tn: Likewise.
* tests/pr/o3b3Snl24f-tn: Likewise.
* tests/pr/o3b3l24f-tn: Likewise.
* tests/pr/o3mSl24f-bl-tn: Likewise.
* tests/pr/o3mSnl24fbltn: Likewise.
* tests/pr/o3ml24f-bl-tn: Likewise.
---
 NEWS                    |    3 +++
 THANKS                  |    1 +
 src/pr.c                |    6 ++++--
 tests/pr/W20l24f-ll     |   18 +++++++++---------
 tests/pr/o3Jml24f-lm-lo |   18 +++++++++---------
 tests/pr/o3a3Sl24f-tn   |    4 ++--
 tests/pr/o3a3Snl24f-tn  |    4 ++--
 tests/pr/o3a3l24f-tn    |    4 ++--
 tests/pr/o3b3Sl24f-tn   |    4 ++--
 tests/pr/o3b3Snl24f-tn  |    4 ++--
 tests/pr/o3b3l24f-tn    |    4 ++--
 tests/pr/o3mSl24f-bl-tn |   20 ++++++++++----------
 tests/pr/o3mSnl24fbltn  |   20 ++++++++++----------
 tests/pr/o3ml24f-bl-tn  |   20 ++++++++++----------
 14 files changed, 68 insertions(+), 62 deletions(-)

diff --git a/NEWS b/NEWS
index 87589c4..0f6e853 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   The bug strikes only with both --recursive (-r, -R) and --link (-l).
   [bug introduced in coreutils-7.1]

+  pr: fix the bug whereby --indent=N (-o) did not indent header lines
+  [bug introduced in coreutils-6.9.90]
+
   sort now handles specified key ends correctly.
   Previously -k1,1b would have caused leading space from field 2 to be
   included in the sort while -k2,3.0 would have not included field 3.
diff --git a/THANKS b/THANKS
index c4e900b..3509da1 100644
--- a/THANKS
+++ b/THANKS
@@ -225,6 +225,7 @@ Harvey Eneman                       address@hidden
 Heiko Marr                          address@hidden
 Helen Faulkner                      address@hidden
 Herbert Xu                          address@hidden
+hggdh                               address@hidden
 Holger Berger                       address@hidden
 Hon-Yin Kok                         address@hidden
 Hugh Daniel                         address@hidden
diff --git a/src/pr.c b/src/pr.c
index 0c02430..3b6e801 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -2402,8 +2402,10 @@ print_header (void)
   lhs_spaces = available_width >> 1;
   rhs_spaces = available_width - lhs_spaces;

-  printf ("\n\n%s%*s%s%*s%s\n\n\n",
-         date_text, lhs_spaces, " ", file_text, rhs_spaces, " ", page_text);
+  printf ("\n\n%*.*s%s%*.*s%s%*.*s%s\n\n\n",
+          chars_per_margin, chars_per_margin, " ",
+          date_text, lhs_spaces, lhs_spaces, " ",
+          file_text, rhs_spaces, rhs_spaces, " ", page_text);

   print_a_header = false;
   output_position = 0;
diff --git a/tests/pr/W20l24f-ll b/tests/pr/W20l24f-ll
index ecc9a7a..92d08af 100644
--- a/tests/pr/W20l24f-ll
+++ b/tests/pr/W20l24f-ll
@@ -1,6 +1,6 @@


--- Date/Time -- x Page 1
+-- Date/Time --xPage 1


 1<<<  -Test: FF's in
@@ -19,13 +19,13 @@
 14<<<  123456789 123
 

--- Date/Time -- x Page 2
+-- Date/Time --xPage 2



 

--- Date/Time -- x Page 3
+-- Date/Time --xPage 3


 15<<<  xyzxyzxyz XYZ
@@ -44,13 +44,13 @@
 28<<<  trunc
 

--- Date/Time -- x Page 4
+-- Date/Time --xPage 4



 

--- Date/Time -- x Page 5
+-- Date/Time --xPage 5


 29<<<xyzxyzxyz XYZXY
@@ -69,19 +69,19 @@
 42<<<  123456789 abc
 

--- Date/Time -- x Page 6
+-- Date/Time --xPage 6



 

--- Date/Time -- x Page 7
+-- Date/Time --xPage 7



 

--- Date/Time -- x Page 8
+-- Date/Time --xPage 8


 43<<<  xyzxyzxyz XYZ
@@ -100,7 +100,7 @@
 56<<<  123456789 abc
 

--- Date/Time -- x Page 9
+-- Date/Time --xPage 9


 57<<<  xyzxyzxyz XYZ
diff --git a/tests/pr/o3Jml24f-lm-lo b/tests/pr/o3Jml24f-lm-lo
index a141835..e0aa4a4 100644
--- a/tests/pr/o3Jml24f-lm-lo
+++ b/tests/pr/o3Jml24f-lm-lo
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


    1<<<         -Test: FF's in Text                    >>>     1:::  
Test-INPUT: "Without FF set by Hand"        :::
@@ -19,7 +19,7 @@
    14<<<  123456789 123456789 123456789         >>>    14:::  89 123456789 
123456789 123456789 123456789 123456789 123456789 1234567890  :::
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


        15:::  xyzxyzxyz XYZXYZXYZ abcabcab      :::
@@ -38,7 +38,7 @@
        28:::  89 123456789 123456789 123456789 123456789 123456789 123456789 
1234567890  :::
    

--- Date/Time --                         x                         Page 3
+   -- Date/Time --                         x                         Page 3


    15<<<  xyzxyzxyz XYZXYZXYZ abcabcab >>>     29:::  xyzxyzxyz XYZXYZXYZ 
abcabcab      :::
@@ -57,7 +57,7 @@
    28<<<  trunc        42:::  89 123456789 123456789 123456789 123456789 
123456789 123456789 1234567890  :::
    

--- Date/Time --                         x                         Page 4
+   -- Date/Time --                         x                         Page 4


        43:::  xyzxyzxyz XYZXYZXYZ abcabcab      :::
@@ -76,7 +76,7 @@
        56:::  89 123456789 123456789 123456789 123456789 123456789 123456789 
1234567890  :::
    

--- Date/Time --                         x                         Page 5
+   -- Date/Time --                         x                         Page 5


    29<<<xyzxyzxyz XYZXYZXYZ abcabcab  >>>      57:::    xyzxyzxyz XYZXYZXYZ 
abcabcab  :::
@@ -95,19 +95,19 @@
    42<<<  123456789 abcdefghi ABCDEDFHI         >>>
    

--- Date/Time --                         x                         Page 6
+   -- Date/Time --                         x                         Page 6



    

--- Date/Time --                         x                         Page 7
+   -- Date/Time --                         x                         Page 7



    

--- Date/Time --                         x                         Page 8
+   -- Date/Time --                         x                         Page 8


    43<<<  xyzxyzxyz XYZXYZXYZ abcabcab >>>     
@@ -126,7 +126,7 @@
    56<<<  123456789 abcdefghi ABCDEDFHI         >>>
    

--- Date/Time --                         x                         Page 9
+   -- Date/Time --                         x                         Page 9


    57<<<  xyzxyzxyz XYZXYZXYZ abcabcab >>>     
diff --git a/tests/pr/o3a3Sl24f-tn b/tests/pr/o3a3Sl24f-tn
index 8986aea..0064f2f 100644
--- a/tests/pr/o3a3Sl24f-tn
+++ b/tests/pr/o3a3Sl24f-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


    1   Test-INPUT: "With:--:2  Options -b -3 [+2:--:3   Options -a -3 [+2
@@ -19,7 +19,7 @@
    40 DEFGHI 123456789 :--:41 yzxyzxyz XYZXYZXYZ:--:42 456789 123456789 a
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


    43 xyzxyzxyz XYZXYZXY:--:44 456789 123456789 x:--:5
diff --git a/tests/pr/o3a3Snl24f-tn b/tests/pr/o3a3Snl24f-tn
index 2560cec..5a8f263 100644
--- a/tests/pr/o3a3Snl24f-tn
+++ b/tests/pr/o3a3Snl24f-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


        1.1   Test-INPUT::--:   2.2   Options -b :--:    3.3   Options -a
@@ -19,7 +19,7 @@
       40.40 DEFGHI 12345:--:   41.41 yzxyzxyz XYZ:--:  42.42 456789 12345
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


       43.43 xyzxyzxyz XY:--:   44.44 456789 12345:--:  45.5
diff --git a/tests/pr/o3a3l24f-tn b/tests/pr/o3a3l24f-tn
index b2d8a42..9adbe67 100644
--- a/tests/pr/o3a3l24f-tn
+++ b/tests/pr/o3a3l24f-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


    1   Test-INPUT: "Withou 2   Options -b -3 [+2|+ 3   Options -a -3 [+2|+
@@ -19,7 +19,7 @@
    40 DEFGHI 123456789    41 yzxyzxyz XYZXYZXYZ a 42 456789 123456789 abc
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


    43 xyzxyzxyz XYZXYZXYZ  44 456789 123456789 xyz 5
diff --git a/tests/pr/o3b3Sl24f-tn b/tests/pr/o3b3Sl24f-tn
index 6294d91..2e11983 100644
--- a/tests/pr/o3b3Sl24f-tn
+++ b/tests/pr/o3b3Sl24f-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


    1   Test-INPUT: "With:--:15 xyzxyzxyz XYZXYZXY:--:29 xyzxyzxyz XYZXYZXY
@@ -19,7 +19,7 @@
    14 456789 123456789 1:--:28 no trunc                 :--:42 456789 
123456789 a
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


    43 xyzxyzxyz XYZXYZXY:--:50                  :--:57 xyzxyzxyz XYZXYZXY
diff --git a/tests/pr/o3b3Snl24f-tn b/tests/pr/o3b3Snl24f-tn
index 200b780..1b945fe 100644
--- a/tests/pr/o3b3Snl24f-tn
+++ b/tests/pr/o3b3Snl24f-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


        1.1   Test-INPUT::--:   15.15 xyzxyzxyz XY:--:  29.29 xyzxyzxyz XY
@@ -19,7 +19,7 @@
       14.14 456789 12345:--:   28.28 no trunc   :--:   42.42 456789 12345
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


       43.43 xyzxyzxyz XY:--:   50.50            :--:   57.57 xyzxyzxyz XY
diff --git a/tests/pr/o3b3l24f-tn b/tests/pr/o3b3l24f-tn
index 73309b6..0d237bb 100644
--- a/tests/pr/o3b3l24f-tn
+++ b/tests/pr/o3b3l24f-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


    1   Test-INPUT: "Withou 15 xyzxyzxyz XYZXYZXYZ  29 xyzxyzxyz XYZXYZXYZ
@@ -19,7 +19,7 @@
    14 456789 123456789 123 28 no trunc            42 456789 123456789 abc
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


    43 xyzxyzxyz XYZXYZXYZ  50                     57 xyzxyzxyz XYZXYZXYZ
diff --git a/tests/pr/o3mSl24f-bl-tn b/tests/pr/o3mSl24f-bl-tn
index adac88e..c90a2b4 100644
--- a/tests/pr/o3mSl24f-bl-tn
+++ b/tests/pr/o3mSl24f-bl-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


    1   FF-Test: FF's in Text        :--:1   Test-INPUT: "Without FF set by
@@ -19,7 +19,7 @@
    14 456789 123456789 123456789 1234:--:14 456789 123456789 123456789 1234
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


                                     :--:15 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -38,7 +38,7 @@
                                     :--:28 no trunc
    

--- Date/Time --                         x                         Page 3
+   -- Date/Time --                         x                         Page 3


    15 xyzxyzxyz XYZXYZXYZ abcabcab   :--:29 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -57,7 +57,7 @@
                                     :--:42 456789 123456789 abcdefghi ABCD
    

--- Date/Time --                         x                         Page 4
+   -- Date/Time --                         x                         Page 4


                                     :--:43 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -76,7 +76,7 @@
                                     :--:56 456789 123456789 abcdefghi ABCD
    

--- Date/Time --                         x                         Page 5
+   -- Date/Time --                         x                         Page 5


    29 xyzxyzxyz XYZXYZXYZ abcabcab   :--:57 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -95,19 +95,19 @@
    42 456789 123456789 abcdefghi ABCD
    

--- Date/Time --                         x                         Page 6
+   -- Date/Time --                         x                         Page 6



    

--- Date/Time --                         x                         Page 7
+   -- Date/Time --                         x                         Page 7



    

--- Date/Time --                         x                         Page 8
+   -- Date/Time --                         x                         Page 8


    43 xyzxyzxyz XYZXYZXYZ abcabcab   :--:
@@ -126,7 +126,7 @@
    56 456789 123456789 abcdefghi ABCD
    

--- Date/Time --                         x                         Page 9
+   -- Date/Time --                         x                         Page 9


                                     :--:
@@ -145,7 +145,7 @@
    70  456789 123456789 abcdefghi ABC:--:
    

--- Date/Time --                        x                         Page 10
+   -- Date/Time --                        x                         Page 10


    1                                :--:
diff --git a/tests/pr/o3mSnl24fbltn b/tests/pr/o3mSnl24fbltn
index 7243641..655b56f 100644
--- a/tests/pr/o3mSnl24fbltn
+++ b/tests/pr/o3mSnl24fbltn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


        1.1   FF-Test: FF's in Text     :--:1   Test-INPUT: "Without FF set
@@ -19,7 +19,7 @@
       14.14 456789 123456789 123456789 1:--:14 456789 123456789 123456789 1
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


       15.                              :--:15 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -38,7 +38,7 @@
       28.                              :--:28 no trunc
    

--- Date/Time --                         x                         Page 3
+   -- Date/Time --                         x                         Page 3


       29.15 xyzxyzxyz XYZXYZXYZ abcabcab:--:29 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -57,7 +57,7 @@
       42.                              :--:42 456789 123456789 abcdefghi A
    

--- Date/Time --                         x                         Page 4
+   -- Date/Time --                         x                         Page 4


       43.                              :--:43 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -76,7 +76,7 @@
       56.                              :--:56 456789 123456789 abcdefghi A
    

--- Date/Time --                         x                         Page 5
+   -- Date/Time --                         x                         Page 5


       57.29 xyzxyzxyz XYZXYZXYZ abcabcab:--:57 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -95,19 +95,19 @@
       70.42 456789 123456789 abcdefghi A
    

--- Date/Time --                         x                         Page 6
+   -- Date/Time --                         x                         Page 6



    

--- Date/Time --                         x                         Page 7
+   -- Date/Time --                         x                         Page 7



    

--- Date/Time --                         x                         Page 8
+   -- Date/Time --                         x                         Page 8


       71.43 xyzxyzxyz XYZXYZXYZ abcabcab:--:
@@ -126,7 +126,7 @@
       84.56 456789 123456789 abcdefghi A
    

--- Date/Time --                         x                         Page 9
+   -- Date/Time --                         x                         Page 9


       85.                              :--:
@@ -145,7 +145,7 @@
       98.70  456789 123456789 abcdefghi :--:
    

--- Date/Time --                        x                         Page 10
+   -- Date/Time --                        x                         Page 10


       99.1                             :--:
diff --git a/tests/pr/o3ml24f-bl-tn b/tests/pr/o3ml24f-bl-tn
index a2b7be5..5109be0 100644
--- a/tests/pr/o3ml24f-bl-tn
+++ b/tests/pr/o3ml24f-bl-tn
@@ -1,6 +1,6 @@
    

--- Date/Time --                         x                         Page 1
+   -- Date/Time --                         x                         Page 1


    1   FF-Test: FF's in Text          1   Test-INPUT: "Without FF set by
@@ -19,7 +19,7 @@
    14 456789 123456789 123456789 12345 14 456789 123456789 123456789 12345
    

--- Date/Time --                         x                         Page 2
+   -- Date/Time --                         x                         Page 2


                                       15 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -38,7 +38,7 @@
                                       28 no trunc
    

--- Date/Time --                         x                         Page 3
+   -- Date/Time --                         x                         Page 3


    15 xyzxyzxyz XYZXYZXYZ abcabcab     29 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -57,7 +57,7 @@
                                       42 456789 123456789 abcdefghi ABCDE
    

--- Date/Time --                         x                         Page 4
+   -- Date/Time --                         x                         Page 4


                                       43 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -76,7 +76,7 @@
                                       56 456789 123456789 abcdefghi ABCDE
    

--- Date/Time --                         x                         Page 5
+   -- Date/Time --                         x                         Page 5


    29 xyzxyzxyz XYZXYZXYZ abcabcab     57 xyzxyzxyz XYZXYZXYZ abcabcab
@@ -95,19 +95,19 @@
    42 456789 123456789 abcdefghi ABCDE
    

--- Date/Time --                         x                         Page 6
+   -- Date/Time --                         x                         Page 6



    

--- Date/Time --                         x                         Page 7
+   -- Date/Time --                         x                         Page 7



    

--- Date/Time --                         x                         Page 8
+   -- Date/Time --                         x                         Page 8


    43 xyzxyzxyz XYZXYZXYZ abcabcab     
@@ -126,7 +126,7 @@
    56 456789 123456789 abcdefghi ABCDE
    

--- Date/Time --                         x                         Page 9
+   -- Date/Time --                         x                         Page 9


                                       
@@ -145,7 +145,7 @@
    70  456789 123456789 abcdefghi ABCD 
    

--- Date/Time --                        x                         Page 10
+   -- Date/Time --                        x                         Page 10


    1                                  
-- 
1.6.2.rc1.285.gc5f54




reply via email to

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