diff mbox

[FFmpeg-devel,1/2] configure: print_in_columns: Replace pr with awk

Message ID b78103f3f5f77abfa98d00e8b1172b3b9702aeb2.1556664245.git.eclipse7@gmx.net
State New
Headers show

Commit Message

Alexander Strasser May 1, 2019, 4:07 p.m. UTC
Get rid of pr dependency and write the columns strictly
alphabetical for the given rows.

Before pr would attempt to write pages, thus if a page
boundary was reached, the output looked confusing as one
couldn't see there was a new page and the alphabetical
order was disrupted when scanning down one of the columns.

Fixes output for sizes with width < column width, too.

Fixes part of ticket #5680

Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
---
 configure | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

--

Comments

Guo, Yejun May 5, 2019, 1:53 a.m. UTC | #1
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of

> Alexander Strasser

> Sent: Thursday, May 02, 2019 12:08 AM

> To: ffmpeg-devel@ffmpeg.org

> Subject: [FFmpeg-devel] [PATCH 1/2] configure: print_in_columns: Replace pr

> with awk

> 

> Get rid of pr dependency and write the columns strictly

> alphabetical for the given rows.

> 

> Before pr would attempt to write pages, thus if a page

> boundary was reached, the output looked confusing as one

> couldn't see there was a new page and the alphabetical

> order was disrupted when scanning down one of the columns.

> 

> Fixes output for sizes with width < column width, too.

> 

> Fixes part of ticket #5680

> 

> Signed-off-by: Alexander Strasser <eclipse7@gmx.net>

> ---

>  configure | 18 ++++++++++++++++--

>  1 file changed, 16 insertions(+), 2 deletions(-)

> 

> diff --git a/configure b/configure

> index b122b27268..81e3776060 100755

> --- a/configure

> +++ b/configure

> @@ -3831,8 +3831,22 @@ die_unknown(){

>  }

> 

>  print_in_columns() {

> -    cols=$(expr $ncols / 24)

> -    cat | tr ' ' '\n' | sort | pr -r "-$cols" -w $ncols -t

> +    tr ' ' '\n' | sort | tr '\r\n' '  ' | awk -v col_width=24 -v width="$ncols" '

> +    {

> +        num_cols = width > col_width ? int(width / col_width) : 1;

> +        num_rows = int((NF + num_cols-1) / num_cols);

> +        y = x = 1;

> +        for (y = 1; y <= num_rows; y++) {

> +            i = y;

> +            for (x = 1; x <= num_cols; x++) {

> +                if (i <= NF) {

> +                  line = sprintf("%s%-24s", line, $i);


not sure how to use col_width instead of the magic number 24.

> +                }

> +                i = i + num_rows;

> +            }

> +            print line; line = "";

> +        }

> +    }' | sed 's/ *$//'

>  }

> 

>  show_list() {

> --

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

> 

> To unsubscribe, visit link above, or email

> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Alexander Strasser May 5, 2019, 9:36 a.m. UTC | #2
Am 5. Mai 2019 03:53:20 MESZ schrieb "Guo, Yejun" <yejun.guo@intel.com>:
>
>
>> -----Original Message-----
>> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf
>Of
>> Alexander Strasser
>> Sent: Thursday, May 02, 2019 12:08 AM
>> To: ffmpeg-devel@ffmpeg.org
>> Subject: [FFmpeg-devel] [PATCH 1/2] configure: print_in_columns:
>Replace pr
>> with awk
>> 
>> Get rid of pr dependency and write the columns strictly
>> alphabetical for the given rows.
>> 
>> Before pr would attempt to write pages, thus if a page
>> boundary was reached, the output looked confusing as one
>> couldn't see there was a new page and the alphabetical
>> order was disrupted when scanning down one of the columns.
>> 
>> Fixes output for sizes with width < column width, too.
>> 
>> Fixes part of ticket #5680
>> 
>> Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
>> ---
>>  configure | 18 ++++++++++++++++--
>>  1 file changed, 16 insertions(+), 2 deletions(-)
>> 
>> diff --git a/configure b/configure
>> index b122b27268..81e3776060 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3831,8 +3831,22 @@ die_unknown(){
>>  }
>> 
>>  print_in_columns() {
>> -    cols=$(expr $ncols / 24)
>> -    cat | tr ' ' '\n' | sort | pr -r "-$cols" -w $ncols -t
>> +    tr ' ' '\n' | sort | tr '\r\n' '  ' | awk -v col_width=24 -v
>width="$ncols" '
>> +    {
>> +        num_cols = width > col_width ? int(width / col_width) : 1;
>> +        num_rows = int((NF + num_cols-1) / num_cols);
>> +        y = x = 1;
>> +        for (y = 1; y <= num_rows; y++) {
>> +            i = y;
>> +            for (x = 1; x <= num_cols; x++) {
>> +                if (i <= NF) {
>> +                  line = sprintf("%s%-24s", line, $i);
>
>not sure how to use col_width instead of the magic number 24.

Good catch! Fortunately it's easy to fix:

                      line = sprintf("%s%-" col_width "s", line, $i);

Will change it locally. Thanks.

  Alexander

>> +                }
>> +                i = i + num_rows;
>> +            }
>> +            print line; line = "";
>> +        }
>> +    }' | sed 's/ *$//'
>>  }
>> 
>>  show_list() {
>> --
Alexander Strasser June 24, 2019, 10:39 p.m. UTC | #3
On 2019-05-05 11:36 +0200, Alexander Strasser wrote:
>
>
> Am 5. Mai 2019 03:53:20 MESZ schrieb "Guo, Yejun" <yejun.guo@intel.com>:
> >
> >
> >> -----Original Message-----
> >> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf
> >Of
> >> Alexander Strasser
> >> Sent: Thursday, May 02, 2019 12:08 AM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: [FFmpeg-devel] [PATCH 1/2] configure: print_in_columns:
> >Replace pr
> >> with awk
> >>
> >> Get rid of pr dependency and write the columns strictly
> >> alphabetical for the given rows.
> >>
> >> Before pr would attempt to write pages, thus if a page
> >> boundary was reached, the output looked confusing as one
> >> couldn't see there was a new page and the alphabetical
> >> order was disrupted when scanning down one of the columns.
> >>
> >> Fixes output for sizes with width < column width, too.
> >>
> >> Fixes part of ticket #5680
> >>
> >> Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
> >> ---
> >>  configure | 18 ++++++++++++++++--
> >>  1 file changed, 16 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/configure b/configure
> >> index b122b27268..81e3776060 100755
> >> --- a/configure
> >> +++ b/configure
> >> @@ -3831,8 +3831,22 @@ die_unknown(){
> >>  }
> >>
> >>  print_in_columns() {
> >> -    cols=$(expr $ncols / 24)
> >> -    cat | tr ' ' '\n' | sort | pr -r "-$cols" -w $ncols -t
> >> +    tr ' ' '\n' | sort | tr '\r\n' '  ' | awk -v col_width=24 -v
> >width="$ncols" '
> >> +    {
> >> +        num_cols = width > col_width ? int(width / col_width) : 1;
> >> +        num_rows = int((NF + num_cols-1) / num_cols);
> >> +        y = x = 1;
> >> +        for (y = 1; y <= num_rows; y++) {
> >> +            i = y;
> >> +            for (x = 1; x <= num_cols; x++) {
> >> +                if (i <= NF) {
> >> +                  line = sprintf("%s%-24s", line, $i);
> >
> >not sure how to use col_width instead of the magic number 24.
>
> Good catch! Fortunately it's easy to fix:
>
>                       line = sprintf("%s%-" col_width "s", line, $i);
>
> Will change it locally. Thanks.

Pushed with this change and a more elaborate commit message.


  Alexander


> >> +                }
> >> +                i = i + num_rows;
> >> +            }
> >> +            print line; line = "";
> >> +        }
> >> +    }' | sed 's/ *$//'
> >>  }
> >>
> >>  show_list() {
> >> --
diff mbox

Patch

diff --git a/configure b/configure
index b122b27268..81e3776060 100755
--- a/configure
+++ b/configure
@@ -3831,8 +3831,22 @@  die_unknown(){
 }

 print_in_columns() {
-    cols=$(expr $ncols / 24)
-    cat | tr ' ' '\n' | sort | pr -r "-$cols" -w $ncols -t
+    tr ' ' '\n' | sort | tr '\r\n' '  ' | awk -v col_width=24 -v width="$ncols" '
+    {
+        num_cols = width > col_width ? int(width / col_width) : 1;
+        num_rows = int((NF + num_cols-1) / num_cols);
+        y = x = 1;
+        for (y = 1; y <= num_rows; y++) {
+            i = y;
+            for (x = 1; x <= num_cols; x++) {
+                if (i <= NF) {
+                  line = sprintf("%s%-24s", line, $i);
+                }
+                i = i + num_rows;
+            }
+            print line; line = "";
+        }
+    }' | sed 's/ *$//'
 }

 show_list() {