aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/tedit/display/screen/pswrtcells.x
blob: 0e080121644abb88cb73f81570993bf9e54c86a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
include	<ctype.h>
include	"../curses.h"

# PS_WRTCELLS -- Write a vector of cells
#
# B.Simon	19-Jan-89	Original
# B.Simon	26-Sep-90	Updated to use screen buffer

procedure ps_wrtcells (row, col, vector, ncols)

int	row		# i: Starting row
int	col		# i: Starting column
char	vector[ARB]	# i: Vector to write
int	ncols		# i: Number of columns to write
#--
include	"screen.com"

char	blank, att, ch
int	colstart, colend, idxstart, idxend, idx
pointer	scr

data	blank	/ ' ' /

bool	ttygetb()
pointer	ps_screen()

begin
	# Don't try to print if vector is entirely off the screen

	if (row < 1 || row > lines || col > cols)
	    return

	# Compute the portion of the vector that is on the screen

	colstart = max (col, 1)
	colend = min (ncols + col - 1, cols)

	if (colend == cols && row == lines) {
	    if (ttygetb (term, "am"))
		colend = colend - 1
	}

	idxstart = colstart - col + 1
	idxend = colend - col + 1

	# Adjust string start and end so that portions that
	# duplicate the current screen contents are not printed

	scr = ps_screen (row, colend)
	while (idxend >= idxstart) {
	    if (vector[idxend] != Memc[scr])
		break

	    colend = colend - 1
	    idxend = idxend - 1
	    scr = scr - 1
	}

	scr = ps_screen (row, colstart)
	while (idxstart <= idxend) {
	    if (vector[idxstart] != Memc[scr])
		break

	    colstart = colstart + 1
	    idxstart = idxstart + 1
	    scr = scr + 1
	}

	if (colend < colstart)
	    return

	# Move the cursor to the position of the first printed character

	call ps_setcur (row, colstart)

	# Print the vector

	att = 0
	do idx = idxstart, idxend {

	    # Set the proper attribute

	    if (vector[idx] < A_STANDOUT) {
		ch = vector[idx]
		if (att != 0) {
		    att = 0
		    call ps_sendcap ("se", 1)
		}
	    } else {
		ch = vector[idx] - A_STANDOUT
		if (att == 0) {
		    att = vector[idx] - ch
		    call ps_sendcap ("so", 1)
		}
	    }

	    # Print non-printing character as blank

	    if (IS_PRINT(ch)) {
		call putc (ttyout, ch)
		Memc[scr] = ch + att
	    } else {
		call putc (ttyout, blank)
		Memc[scr] = blank + att
	    }
	    scr = scr + 1
	}

	if (att != 0)
	    call ps_sendcap ("se", 1)

	call ps_updcur (row, colend + 1)

end