From: Glenn Washburn Date: Sun, 2 Mar 2025 05:15:33 +0000 (-0600) Subject: commands/ls: Merge print_files_long() and print_files() into print_file() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbfb031b145f89523aa47d5f493669d6e0349149;p=thirdparty%2Fgrub.git commands/ls: Merge print_files_long() and print_files() into print_file() Simplify the code by removing logic around which file printer to call. Signed-off-by: Glenn Washburn Reviewed-by: Daniel Kiper --- diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c index 65b17768b..2eaefaf90 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] != '/') @@ -251,10 +243,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); }