The source code src/date.c is written mostly bottom-up, a style which does
not need forward declarations. Here's a patch to make it entirely bottom-up,
removing the last needed forward declarations.

NB: I'm not saying that bottom-up style is "better" or should be _generally_
preferred to the top-down style. Each has its own benefits. Only that
having an 80% bottom-up style with a helper function at the end (20%
top-down style) makes the code hard to understand.


>From b6c38b0ca3f493188d9f284f8eea98a20767c826 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 31 Jul 2025 18:45:45 +0200
Subject: [PATCH] date: Refactor

* src/date.c (show_date_helper): Move function. Remove forward
declaration.
---
 src/date.c | 48 +++++++++++++++++++++++-------------------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/date.c b/src/date.c
index 4a8dabc2e..42e66e25d 100644
--- a/src/date.c
+++ b/src/date.c
@@ -38,8 +38,6 @@
 
 #define AUTHORS proper_name ("David MacKenzie")
 
-static bool show_date_helper (char const *, bool, struct timespec, timezone_t);
-
 enum Time_spec
 {
   /* Display only the date.  */
@@ -373,6 +371,29 @@ set_LC_TIME (char const *locale)
   return ret;
 }
 
+static bool
+show_date_helper (char const *format, bool use_c_locale,
+                  struct timespec when, timezone_t tz)
+{
+  if (parse_datetime_flags & PARSE_DATETIME_DEBUG)
+    error (0, 0, _("output format: %s"), quote (format));
+
+  bool ok;
+  if (use_c_locale)
+    {
+      char *old_locale_category = set_LC_TIME ("C");
+      ok = show_date (format, when, tz);
+      char *new_locale_category = set_LC_TIME (old_locale_category);
+      free (new_locale_category);
+      free (old_locale_category);
+    }
+  else
+    ok = show_date (format, when, tz);
+
+  putchar ('\n');
+  return ok;
+}
+
 /* Parse each line in INPUT_FILENAME as with --date and display each
    resulting time and date.  If the file cannot be opened, tell why
    then exit.  Issue a diagnostic for any lines that cannot be parsed.
@@ -697,26 +718,3 @@ main (int argc, char **argv)
 
   main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-
-static bool
-show_date_helper (char const *format, bool use_c_locale,
-                  struct timespec when, timezone_t tz)
-{
-  if (parse_datetime_flags & PARSE_DATETIME_DEBUG)
-    error (0, 0, _("output format: %s"), quote (format));
-
-  bool ok;
-  if (use_c_locale)
-    {
-      char *old_locale_category = set_LC_TIME ("C");
-      ok = show_date (format, when, tz);
-      char *new_locale_category = set_LC_TIME (old_locale_category);
-      free (new_locale_category);
-      free (old_locale_category);
-    }
-  else
-    ok = show_date (format, when, tz);
-
-  putchar ('\n');
-  return ok;
-}
-- 
2.50.1

Reply via email to