diff mbox

[FFmpeg-devel,V5,1/2] configure: sort decoder/encoder/filter/... names in alphabet order

Message ID 1556111573-3100-1-git-send-email-yejun.guo@intel.com
State New
Headers show

Commit Message

Guo, Yejun April 24, 2019, 1:12 p.m. UTC
take decoder names an example, with the default page length, shell command
'pr' needs two pages for all the decoder names. The names are firstly printed
in the first page, then in the second page. So, as a whole, the names are
sorted neither in column order nor in row order. It's a little confused.

One method is to calculate the proper page length, so all the names are printed
in one page by 'pr -l', and so strictly in alphabet order, column by column.

Another method is to use command printf instead of pr, because buybox doesn't
have pr. This patch refines print_in_columns to print the names with printf
in alphabet order, very similar with 'pr -l', except the case when the last
column is not fully filled with names.

contributor: Alexander Strasser <eclipse7@gmx.net>
contributor: avih <avihpit@yahoo.com>
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
---
 configure | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

Comments

avih April 24, 2019, 1:22 p.m. UTC | #1
>  print_in_columns() {
> -    cols=$(expr $ncols / 24)
> -    cat | tr ' ' '\n' | sort | pr -r "-$cols" -w $ncols -t
> +    # the input should not contain chars such as '*',
> +    # otherwise, '*' will be expanded to be all files in the current
> +    # working directory which don't begin with a dot (`.`)
> +    set -- $(tr ' ' '\n' | sort)
> +    col_width=24
> +    if [ $ncols -lt $col_width ]; then
> +        col_width=$ncols
> +    fi
> +    cols=$(($ncols / $col_width))
> +    rows=$(($(($# + $cols - 1)) / $cols))
> +    cols_seq=$(seq $cols)
> +    rows_seq=$(seq $rows)
> +    for row in $rows_seq; do
> +        print_index=$row
> +        print_line=""
> +        for col in $cols_seq; do
> +            if [ $print_index -le $# ]; then
> +                eval print_line='"$print_line "${'$print_index'}'
> +            fi
> +            print_index=$(($print_index + $rows))
> +        done
> +        printf "%-${col_width}s" $print_line
> +        printf "\n"
> +    done | sed 's/ *$//'
> }

Looks good to me. No further comments (but I don't push).

Next time, know that you can use e.g. `$((x + y))` instead of `$(($x + $y))`,
though in this case it doesn't matter and not worth another version.
Guo, Yejun April 24, 2019, 1:36 p.m. UTC | #2
> 

> From: avih [mailto:avihpit@yahoo.com]

> Sent: Wednesday, April 24, 2019 9:22 PM

> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>

> Cc: Guo, Yejun <yejun.guo@intel.com>

> Subject: Re: [FFmpeg-devel] [PATCH V5 1/2] configure: sort

> decoder/encoder/filter/... names in alphabet order

> 

> >  print_in_columns() {

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

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

> > +    # the input should not contain chars such as '*',

> > +    # otherwise, '*' will be expanded to be all files in the current

> > +    # working directory which don't begin with a dot (`.`)

> > +    set -- $(tr ' ' '\n' | sort)

> > +    col_width=24

> > +    if [ $ncols -lt $col_width ]; then

> > +        col_width=$ncols

> > +    fi

> > +    cols=$(($ncols / $col_width))

> > +    rows=$(($(($# + $cols - 1)) / $cols))

> > +    cols_seq=$(seq $cols)

> > +    rows_seq=$(seq $rows)

> > +    for row in $rows_seq; do

> > +        print_index=$row

> > +        print_line=""

> > +        for col in $cols_seq; do

> > +            if [ $print_index -le $# ]; then

> > +                eval print_line='"$print_line "${'$print_index'}'

> > +            fi

> > +            print_index=$(($print_index + $rows))

> > +        done

> > +        printf "%-${col_width}s" $print_line

> > +        printf "\n"

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

> > }

> 

> Looks good to me. No further comments (but I don't push).

> 

> Next time, know that you can use e.g. `$((x + y))` instead of `$(($x + $y))`,

> though in this case it doesn't matter and not worth another version.


got it, thanks.
diff mbox

Patch

diff --git a/configure b/configure
index 3b11ffe..ad1b183 100755
--- a/configure
+++ b/configure
@@ -3832,8 +3832,30 @@  die_unknown(){
 }
 
 print_in_columns() {
-    cols=$(expr $ncols / 24)
-    cat | tr ' ' '\n' | sort | pr -r "-$cols" -w $ncols -t
+    # the input should not contain chars such as '*',
+    # otherwise, '*' will be expanded to be all files in the current
+    # working directory which don't begin with a dot (`.`)
+    set -- $(tr ' ' '\n' | sort)
+    col_width=24
+    if [ $ncols -lt $col_width ]; then
+        col_width=$ncols
+    fi
+    cols=$(($ncols / $col_width))
+    rows=$(($(($# + $cols - 1)) / $cols))
+    cols_seq=$(seq $cols)
+    rows_seq=$(seq $rows)
+    for row in $rows_seq; do
+        print_index=$row
+        print_line=""
+        for col in $cols_seq; do
+            if [ $print_index -le $# ]; then
+                eval print_line='"$print_line "${'$print_index'}'
+            fi
+            print_index=$(($print_index + $rows))
+        done
+        printf "%-${col_width}s" $print_line
+        printf "\n"
+    done | sed 's/ *$//'
 }
 
 show_list() {