grub-devel
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]