* Terminal driving and line formatting routines.
* Basic motion optimizations are done here as well
* as formatting of lines (printing of control characters,
* line numbering and the like).
* Sync the position of the output cursor.
* Most work here is rounding for terminal boundaries getting the
* column position implied by wraparound or the lack thereof and
* rolling up the screen to get destline on the screen.
static int outcol
, outline
, destcol
, destline
, plodcnt
;
fprintf(outf
, "MVCUR: moving cursor from (%d,%d) to (%d,%d)\n", ly
, lx
, y
, x
);
if (destcol
> COLS
- 1) {
destline
+= destcol
/ COLS
;
if (outline
> LINES
- 1) {
destline
-= outline
- (LINES
- 1);
if (destline
> LINES
- 1) {
if (outline
< LINES
- 1) {
if (destline
< outline
&& !(CA
|| UP
!= NULL
))
cgp
= tgoto(CM
, destcol
, destline
);
if (plod(strlen(cgp
)) > 0)
fprintf(outf
, "_PUTCHAR(%s)\n", unctrl(c
));
reg
int soutcol
, soutline
;
i
= (destcol
/ HARDTABS
) + (destcol
% HARDTABS
);
j
= destcol
/ HARDTABS
- outcol
/ HARDTABS
;
if (outcol
- destcol
<= i
&& (BS
|| BC
))
i
= j
= outcol
- destcol
;
k
= (LINES
- 1) - destline
;
i
= destcol
% HARDTABS
+ destcol
/ HARDTABS
;
if (BT && outcol > destcol && (j = (((outcol+7) & ~7) - destcol - 1) >> 3)) {
if ((k += (destcol&7)) > 4)
* If we will later need a \n which will turn into a \r\n by
* the system or the terminal, then don't bother to try to \r.
if ((NONL
|| !pfast
) && outline
< destline
)
* If the terminal will do a \r\n and there isn't room for it,
* then we can't afford a \r.
if (NC
&& outline
>= destline
)
* If it will be cheaper, or if we can't back up, then send
* a return preliminarily.
if (j
> i
+ 1 || outcol
> destcol
&& !BS
&& !BC
) {
while (outline
< destline
) {
while (outcol
> destcol
) {
if (BT && outcol - destcol > 4+k) {
while (outline
> destline
) {
if (GT
&& destcol
- outcol
> 1) {
i
= (outcol
/ HARDTABS
+ 1) * HARDTABS
;
if (destcol
- outcol
> 4 && i
< COLS
&& (BC
|| BS
)) {
while (outcol
> destcol
) {
while (outcol
< destcol
) {
* Move (slowly) to destination.
* Hard thing here is using home cursor on really deficient terminals.
* Otherwise just use cursor motions, hacking use of tabs and overtabbing
fprintf(outf
, "PLODPUT(%s)\n", unctrl(c
));
fprintf(outf
, "PUTPAD: _puts(\"%s\")\n", cp
);