[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 2/6] commands/ls: Merge print_files_long and print_files into
From: |
Glenn Washburn |
Subject: |
[PATCH v4 2/6] commands/ls: Merge print_files_long and print_files into print_file |
Date: |
Mon, 6 Jan 2025 01:02:40 -0600 |
Simplify the code by removing logic around which file printer to call.
Signed-off-by: Glenn Washburn <development@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
- [PATCH v4 0/6] More ls improvements, Glenn Washburn, 2025/01/06
- [PATCH v4 1/6] commands/ls: Return proper GRUB_ERR_* for functions returning type grub_err_t, Glenn Washburn, 2025/01/06
- [PATCH v4 3/6] commands/ls: Show modification time for file paths, Glenn Washburn, 2025/01/06
- [PATCH v4 2/6] commands/ls: Merge print_files_long and print_files into print_file,
Glenn Washburn <=
- [PATCH v4 4/6] commands/ls: Output path for single file arguments given with path, Glenn Washburn, 2025/01/06
- [PATCH v4 5/6] commands/ls: Print full paths for file args, Glenn Washburn, 2025/01/06
- [PATCH v4 6/6] commands/ls: Add directory header for dir args, Glenn Washburn, 2025/01/06