[net.bugs.usg] System V.2 Curses Bug #2

laman@sdcsvax.UUCP (Mike Laman) (08/11/84)

A call from "mvcur()" to "_loc_down()" can generate incorrect cursor motion
under the following circumstances:

	1. ONLCR is set in the user's terminal modes,
	2. "cursor_down=^J" in the terminfo information, and
	3. "cursor_down" is the "optimal" move chosen by "mvcur()"
	   (easily accomplished with a simple terminfo entry with NO absolute
	   cursor addressing).

If "mvcur()" is called and it is desired to move the cursor such that
"_loc_down(2, 3, 1, 0)" is called (I'm sure other situations can be generated
so restriction #3 won't be needed, but that's beside the point.),
"cursor_down", namely '^J' is outputted.  Since ONLCR is set, a newline and
form feed are echoed just as the tty driver should do.  "_loc_down()" properly
figures out that we are not at the beginning of the line (i.e. we are now at
column number 0).  That's fine, but "mvcur()" doesn't know the column number
has been changed!  More specifically, "oldcol" in "mvcur()" is still 3.
So in the "local motions are cheapest" section near the end of "mvcur()",
"_loc_left()" is called, and the cursor gets moved back a few spaces in its
attempt to get the cursor to column #0 (but this ends up walking back a few
columns on the end of the previous line on my terminal since my terminal has
"auto_left_margin" (i.e. bw)).  This extra backing up of the cursor is caused
by the intelligent cursor movement by "_loc_down()" not being communicated
back up to "mvcur()".

There seem to be two plausible solutions of "mvcur()" not knowing about
"_loc_down()"'s possible changing of the cursor's actual column number, namely:

	1. Let "mvcur()" know about it.  [ This is the route I chose. ]

		Since "_loc_down()" already has the logic, we might as well
		use it.  Have  "mvcur()" pass the address of "oldcol" as
		another argument to "_loc_down()", and have "_loc_down()"
		change it when the situation occurs.  [ Now the call to
		"_loc_left()" will immediately return seeing that we are
		already on the desired column, namely column #0. ]
		[ Sorry, but the sources are not on this system, so I can't
		  include any diffs here. ]

	2. Don't allow "_loc_down()" to make any changes that would affect
	   the cursor's column number.

		Drop "col" as an argument to "_loc_down()", its references
		in "_loc_down()", and the argument on all "_loc_down()" calls.

		Mike Laman, NCR @ Torrey Pines
		UUCP: {ucbvax,philabs,sdcsla}!sdcsvax!laman