Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed 2/7] [gdb/testsuite] Factor out Term::_copy_line
Date: Wed, 14 Oct 2026 16:58:33 +0200	[thread overview]
Message-ID: <20261014145838.3560108-3-tdevries@suse.de> (raw)
In-Reply-To: <20261014145838.3560108-1-tdevries@suse.de>

Factor out Term::_copy_line and use it in 5 locations.
---
 gdb/testsuite/lib/tuiterm.exp | 40 +++++++++++++----------------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 3ca961a3f7d..62025857651 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -138,13 +138,21 @@ proc Term::_ctl_0x08 { {bw -1} } {
     }
 }
 
+# Helper function.  Copy line FROM to TO.
+proc Term::_copy_line { from to } {
+    variable _cols
+    variable _chars
+
+    for {set x 0} {$x < $_cols} {incr x} {
+	set _chars($x,$to) $_chars($x,$from)
+    }
+}
+
 # Linefeed.
 proc Term::_ctl_0x0a {} {
     _log_cur "Line feed" {
 	variable _cur_row
 	variable _rows
-	variable _cols
-	variable _chars
 
 	incr _cur_row 1
 	while {$_cur_row >= $_rows} {
@@ -156,9 +164,7 @@ proc Term::_ctl_0x0a {} {
 	    # side.
 	    for {set y 0} {$y < [expr $_rows - 1]} {incr y} {
 		set next_y [expr $y + 1]
-		for {set x 0} {$x < $_cols} {incr x} {
-		    set _chars($x,$y) $_chars($x,$next_y)
-		}
+		_copy_line $next_y $y
 	    }
 
 	    incr _cur_row -1
@@ -428,15 +434,11 @@ proc Term::_csi_L {args} {
     _log_cur "Insert Line ($arg)" {
 	variable _cur_row
 	variable _rows
-	variable _cols
-	variable _chars
 
 	set y [expr $_rows - 2]
 	set next_y [expr $y + $arg]
 	while {$y >= $_cur_row} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$next_y) $_chars($x,$y)
-	    }
+	    _copy_line $y $next_y
 	    incr y -1
 	    incr next_y -1
 	}
@@ -454,15 +456,11 @@ proc Term::_csi_M {args} {
     _log_cur "Delete line ($count)" {
 	variable _cur_row
 	variable _rows
-	variable _cols
-	variable _chars
 
 	set y $_cur_row
 	set next_y [expr {$y + $count}]
 	while {$next_y < $_rows} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$y) $_chars($x,$next_y)
-	    }
+	    _copy_line $next_y $y
 	    incr y
 	    incr next_y
 	}
@@ -504,9 +502,7 @@ proc Term::_csi_S {args} {
     set count [_default [lindex $args 0] 1]
 
     _log_cur "Pan Down ($count)" {
-	variable _cols
 	variable _rows
-	variable _chars
 
 	# The following code is written without consideration for
 	# the scroll margins.  At this time this comment was
@@ -518,9 +514,7 @@ proc Term::_csi_S {args} {
 	set y $count
 
 	while {$y < $_rows} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$dy) $_chars($x,$y)
-	    }
+	    _copy_line $y $dy
 	    incr y 1
 	    incr dy 1
 	}
@@ -536,9 +530,7 @@ proc Term::_csi_T {args} {
     set count [_default [lindex $args 0] 1]
 
     _log_cur "Pan Up ($count)" {
-	variable _cols
 	variable _rows
-	variable _chars
 
 	# The following code is written without consideration for
 	# the scroll margins.  At this time this comment was
@@ -550,9 +542,7 @@ proc Term::_csi_T {args} {
 	set dy $_rows
 
 	while {$dy >= $count} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$dy) $_chars($x,$y)
-	    }
+	    _copy_line $y $dy
 	    incr y -1
 	    incr dy -1
 	}
-- 
2.51.0


  parent reply	other threads:[~2026-10-14 14:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
2026-10-14 14:58 ` [pushed 1/7] [gdb/testsuite] Remove unused declarations in lib/tuiterm.exp Tom de Vries
2026-10-14 14:58 ` Tom de Vries [this message]
2026-10-14 14:58 ` [pushed 3/7] [gdb/testsuite] Factor out small_initial in gdb.tui/tuiterm.exp Tom de Vries
2026-10-14 14:58 ` [pushed 4/7] [gdb/testsuite] Add Term::check_size Tom de Vries
2026-10-14 14:58 ` [pushed 5/7] [gdb/testsuite] Work around namespace problem in tclint plugin Tom de Vries
2026-10-14 14:58 ` [pushed 6/7] [gdb/testsuite] Fix typo in tclint-plugin.py Tom de Vries
2026-10-14 14:58 ` [pushed 7/7] [gdb/testsuite] Fix test names in gdb.tui/tuiterm.exp Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014145838.3560108-3-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox