Dear Team,

I worked on the pager issue in print.c and made the following updates:

   -

   Added a linecount() helper to correctly count all lines, including
   footers.
   -

   In IsPagerNeeded , replaced the old logic lines++ with lines +=
   linecount(f->data).

With this fix, the pager now triggers correctly for long outputs.
Please let me know if this way of fixing looks good, or if you have any
suggestions for improvement.

Best regards,
[lakshmi G]

On Wed, Oct 8, 2025 at 2:40 PM Erik Wienhold <[email protected]> wrote:

> On 2025-10-07 17:01 +0200, Tom Lane wrote:
> > Pushed, after a tiny bit more comment-burnishing.
>
> Thank you for the extensive rework.
>
> --
> Erik Wienhold
>
>
>
From f903ecc2aeb820f461d9caf06ac3c9731e81aff1 Mon Sep 17 00:00:00 2001
From: Lakshmi <[email protected]>
Date: Fri, 10 Oct 2025 11:57:05 +0530
Subject: [PATCH] Fix pager trigger in print.c by using linecount() helper for
 accurate line calculation

Signed-off-by: Lakshmi <[email protected]>
---
 src/fe_utils/print.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index 4af0f32f2f..43dcd3a87a 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -266,6 +266,25 @@ static const unicodeStyleFormat unicode_style = {
 
 /* Local functions */
 static int	strlen_max_width(unsigned char *str, int *target_width, int encoding);
+/* >>> INSERT helper function here <<< */
+static int
+linecount(const char *s)
+{
+    int count = 0;
+
+    if (s == NULL || *s == '\0')
+        return 0;
+
+    while (*s)
+    {
+        if (*s == '\n')
+            count++;
+        s++;
+    }
+    return count + 1;
+}
+
+
 static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded,
 						  FILE **fout, bool *is_pager);
 
@@ -3421,7 +3440,8 @@ IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded,
 			 * footers, not the number of lines in them.
 			 */
 			for (f = cont->footers; f; f = f->next)
-				lines++;
+				lines += linecount(f->data);
+
 		}
 
 		*fout = PageOutput(lines + extra_lines, cont->opt);
-- 
2.39.5

Reply via email to