* [libgpiod][PATCH] tools: replace alphasort() with versionsort()
@ 2023-04-03 14:28 Bartosz Golaszewski
2023-04-04 0:41 ` Kent Gibson
2023-04-04 7:23 ` Linus Walleij
0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2023-04-03 14:28 UTC (permalink / raw)
To: Kent Gibson, Linus Walleij, Andy Shevchenko, Viresh Kumar
Cc: linux-gpio, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
With a high enough number of chips, gpiodetect currently sorts them
like this:
gpiochip0
gpiochip1
gpiochip10
gpiochip11
gpiochip12
gpiochip13
gpiochip14
gpiochip15
gpiochip16
gpiochip17
gpiochip18
gpiochip19
gpiochip2
gpiochip20
gpiochip21
gpiochip22
gpiochip23
gpiochip24
gpiochip25
gpiochip26
gpiochip3
gpiochip4
gpiochip5
gpiochip6
gpiochip7
gpiochip8
gpiochip9
Switching to using versionsort() instead of alphasort() makes it look
better and the order is more logical:
gpiochip0
gpiochip1
gpiochip2
gpiochip3
gpiochip4
gpiochip5
gpiochip6
gpiochip7
gpiochip8
gpiochip9
gpiochip10
gpiochip11
gpiochip12
gpiochip13
gpiochip14
gpiochip15
gpiochip16
gpiochip17
gpiochip18
gpiochip19
gpiochip20
gpiochip21
gpiochip22
gpiochip23
gpiochip24
gpiochip25
gpiochip26
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
configure.ac | 2 +-
tools/tools-common.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 7d72c24..c1005a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,7 +119,7 @@ AS_IF([test "x$with_tools" = xtrue],
AC_CHECK_FUNC([daemon], [], [FUNC_NOT_FOUND_TOOLS([daemon])])
AC_CHECK_FUNC([asprintf], [], [FUNC_NOT_FOUND_LIB([asprintf])])
AC_CHECK_FUNC([scandir], [], [FUNC_NOT_FOUND_LIB([scandir])])
- AC_CHECK_FUNC([alphasort], [], [FUNC_NOT_FOUND_LIB([alphasort])])
+ AC_CHECK_FUNC([versionsort], [], [FUNC_NOT_FOUND_LIB([versionsort])])
AS_IF([test "x$with_gpioset_interactive" = xtrue],
[PKG_CHECK_MODULES([LIBEDIT], [libedit >= 3.1])])
])
diff --git a/tools/tools-common.c b/tools/tools-common.c
index e5f6fc1..64592d3 100644
--- a/tools/tools-common.c
+++ b/tools/tools-common.c
@@ -469,7 +469,7 @@ int all_chip_paths(char ***paths_ptr)
struct dirent **entries;
char **paths;
- num_chips = scandir("/dev/", &entries, chip_dir_filter, alphasort);
+ num_chips = scandir("/dev/", &entries, chip_dir_filter, versionsort);
if (num_chips < 0)
die_perror("unable to scan /dev");
--
2.37.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [libgpiod][PATCH] tools: replace alphasort() with versionsort()
2023-04-03 14:28 [libgpiod][PATCH] tools: replace alphasort() with versionsort() Bartosz Golaszewski
@ 2023-04-04 0:41 ` Kent Gibson
2023-04-04 7:23 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Kent Gibson @ 2023-04-04 0:41 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Andy Shevchenko, Viresh Kumar, linux-gpio,
Bartosz Golaszewski
On Mon, Apr 03, 2023 at 04:28:15PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> With a high enough number of chips, gpiodetect currently sorts them
> like this:
>
> gpiochip0
> gpiochip1
> gpiochip10
> gpiochip11
> gpiochip12
> gpiochip13
> gpiochip14
> gpiochip15
> gpiochip16
> gpiochip17
> gpiochip18
> gpiochip19
> gpiochip2
> gpiochip20
> gpiochip21
> gpiochip22
> gpiochip23
> gpiochip24
> gpiochip25
> gpiochip26
> gpiochip3
> gpiochip4
> gpiochip5
> gpiochip6
> gpiochip7
> gpiochip8
> gpiochip9
>
> Switching to using versionsort() instead of alphasort() makes it look
> better and the order is more logical:
>
> gpiochip0
> gpiochip1
> gpiochip2
> gpiochip3
> gpiochip4
> gpiochip5
> gpiochip6
> gpiochip7
> gpiochip8
> gpiochip9
> gpiochip10
> gpiochip11
> gpiochip12
> gpiochip13
> gpiochip14
> gpiochip15
> gpiochip16
> gpiochip17
> gpiochip18
> gpiochip19
> gpiochip20
> gpiochip21
> gpiochip22
> gpiochip23
> gpiochip24
> gpiochip25
> gpiochip26
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
The checkin comment is a bit excessive - perhaps just list an example
where it gets it wrong, like gpiochip10 < gpiochip2?
But otherwise it makes sense.
Reviewed-by: Kent Gibson <warthog618@gmail.com>
> ---
> configure.ac | 2 +-
> tools/tools-common.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 7d72c24..c1005a9 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -119,7 +119,7 @@ AS_IF([test "x$with_tools" = xtrue],
> AC_CHECK_FUNC([daemon], [], [FUNC_NOT_FOUND_TOOLS([daemon])])
> AC_CHECK_FUNC([asprintf], [], [FUNC_NOT_FOUND_LIB([asprintf])])
> AC_CHECK_FUNC([scandir], [], [FUNC_NOT_FOUND_LIB([scandir])])
> - AC_CHECK_FUNC([alphasort], [], [FUNC_NOT_FOUND_LIB([alphasort])])
> + AC_CHECK_FUNC([versionsort], [], [FUNC_NOT_FOUND_LIB([versionsort])])
> AS_IF([test "x$with_gpioset_interactive" = xtrue],
> [PKG_CHECK_MODULES([LIBEDIT], [libedit >= 3.1])])
> ])
> diff --git a/tools/tools-common.c b/tools/tools-common.c
> index e5f6fc1..64592d3 100644
> --- a/tools/tools-common.c
> +++ b/tools/tools-common.c
> @@ -469,7 +469,7 @@ int all_chip_paths(char ***paths_ptr)
> struct dirent **entries;
> char **paths;
>
> - num_chips = scandir("/dev/", &entries, chip_dir_filter, alphasort);
> + num_chips = scandir("/dev/", &entries, chip_dir_filter, versionsort);
> if (num_chips < 0)
> die_perror("unable to scan /dev");
>
> --
> 2.37.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [libgpiod][PATCH] tools: replace alphasort() with versionsort()
2023-04-03 14:28 [libgpiod][PATCH] tools: replace alphasort() with versionsort() Bartosz Golaszewski
2023-04-04 0:41 ` Kent Gibson
@ 2023-04-04 7:23 ` Linus Walleij
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2023-04-04 7:23 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Kent Gibson, Andy Shevchenko, Viresh Kumar, linux-gpio,
Bartosz Golaszewski
On Mon, Apr 3, 2023 at 4:28 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> With a high enough number of chips, gpiodetect currently sorts them
> like this:
(...)
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-04 7:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-03 14:28 [libgpiod][PATCH] tools: replace alphasort() with versionsort() Bartosz Golaszewski
2023-04-04 0:41 ` Kent Gibson
2023-04-04 7:23 ` Linus Walleij
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.