Simplify the code by removing logic around which file printer to call. Signed-off-by: Glenn Washburn <developm...@efficientek.com> --- grub-core/commands/ls.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 9e69b19371d5..43ee6aca085a 100644 --- a/grub-core/commands/ls.c +++ b/grub-core/commands/ls.c @@ -89,24 +89,12 @@ struct grub_ls_list_files_ctx char *dirname; int all; int human; + int longlist; }; /* Helper for grub_ls_list_files. */ static int -print_files (const char *filename, const struct grub_dirhook_info *info, - void *data) -{ - struct grub_ls_list_files_ctx *ctx = data; - - if (ctx->all || filename[0] != '.') - grub_printf ("%s%s ", filename, info->dir ? "/" : ""); - - return 0; -} - -/* Helper for grub_ls_list_files. */ -static int -print_files_long (const char *filename, const struct grub_dirhook_info *info, +print_file (const char *filename, const struct grub_dirhook_info *info, void *data) { struct grub_ls_list_files_ctx *ctx = data; @@ -114,6 +102,12 @@ print_files_long (const char *filename, const struct grub_dirhook_info *info, if ((! ctx->all) && (filename[0] == '.')) return 0; + if (! ctx->longlist) + { + grub_printf ("%s%s ", filename, info->dir ? "/" : ""); + return 0; + } + if (! info->dir) { grub_file_t file; @@ -217,13 +211,11 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) struct grub_ls_list_files_ctx ctx = { .dirname = dirname, .all = all, - .human = human + .human = human, + .longlist = longlist }; - if (longlist) - (fs->fs_dir) (dev, path, print_files_long, &ctx); - else - (fs->fs_dir) (dev, path, print_files, &ctx); + (fs->fs_dir) (dev, path, print_file, &ctx); if (grub_errno == GRUB_ERR_BAD_FILE_TYPE && path[grub_strlen (path) - 1] != '/') @@ -247,10 +239,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) goto fail; grub_memset (&info, 0, sizeof (info)); - if (longlist) - print_files_long (p, &info, &ctx); - else - print_files (p, &info, &ctx); + print_file (p, &info, &ctx); grub_free (ctx.dirname); } -- 2.34.1 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel