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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
include "display/curses.h"
include "screen.h"
define MAXSCR 10
define MIN_HEIGHT 4
# COUNT_WINDOW -- Return number of windows
int procedure count_window ()
#--
include "window.com"
begin
return (nscreens)
end
# FOCUS_WINDOW -- Move the cursor to its current position in a window
procedure focus_window (win)
pointer win # i: window descriptor
#--
int row, col
int winstat()
begin
row = winstat (win, W_CURROW)
col = winstat (win, W_CURCOL)
call wmove (win, row, col)
end
# GET_WINDOW -- Get a window from the list of screens
int procedure get_window (iscr, scr)
int iscr # i: index into list of screens
pointer scr # o: screen descriptor
#--
include "window.com"
begin
# Return EOF if this is the last screen on the list
if (iscr > nscreens) {
scr = scrlist[1]
return (EOF)
} else {
scr = scrlist[iscr]
return (OK)
}
end
# INIT_WINDOW -- Create the initial set of windows
procedure init_window (scr)
pointer scr # o: initial screen
#--
include "window.com"
int nrows, ncols
int newwin()
begin
# Get size of terminal screen
call wdimen (STDSCR, nrows, ncols)
# Create the initial screen
call malloc (scr, TED_SCRLEN, TY_STRUCT)
TED_WINDOW(scr) = newwin (nrows-2, ncols, 1, 1)
TED_TABLE(scr) = NULL
# Create the prompt window
wprompt = newwin (2, ncols, nrows-1, 1)
# Initialze the global variables
nscreens = 1
scrlist[1] = scr
end
# JOIN_WINDOW -- Join screen window with the adjacent window
procedure join_window (scr)
pointer scr # i: screen descriptor
#--
include "window.com"
int win1, win2
int iscr, jscr, top, left, row1, col1, row2, col2
pointer scr2
string notnull "join_window: table was not closed"
string notfound "join_window: could not find screen"
int winstat(), newwin()
begin
# Cannot join single screen or screen that is still open
if (nscreens == 1 || TED_TABLE(scr) != NULL)
call err1_prompt (notnull)
# Find the screen and its adjacent screen
# Pay attention to which screen is on top
jscr = 0
do iscr = 1, nscreens {
if (scrlist[iscr] == scr) {
jscr = iscr
if (jscr == 1) {
win1 = TED_WINDOW(scrlist[1])
win2 = TED_WINDOW(scrlist[2])
scr2 = scrlist[2]
} else {
win1 = TED_WINDOW(scrlist[jscr-1])
win2 = TED_WINDOW(scrlist[jscr])
scr2 = scrlist[jscr-1]
}
break
}
}
if (jscr == 0) {
call err1_prompt (notfound)
} else {
# Get dimensions of windows, delete them
top = winstat (win1, W_TOP)
left = winstat (win1, W_LEFT)
call wdimen (win1, row1, col1)
call delwin (win1)
call wdimen (win2, row2, col2)
call delwin (win2)
# Create new window, assign to adjacent screen
TED_WINDOW(scr2) = newwin (row1+row2, col2, top, left)
# Delete screen and remove from list of screens
call mfree (scr, TY_STRUCT)
nscreens = nscreens - 1
do iscr= jscr, nscreens
scrlist[iscr] = scrlist[iscr+1]
}
end
# PROMPT_WINDOW -- Return the prompt window
int procedure prompt_window ()
#--
include "window.com"
begin
return (wprompt)
end
# SPLIT_WINDOW -- Split window into two windows
procedure split_window (scr1, scr2)
pointer scr1 # u: current screen
pointer scr2 # o: new screen (or NULL)
#--
include "window.com"
int win1
int iscr, jscr, top, left, row1, col1, row2, col2
string noroom "Screen is too small to split"
string notfound "split_window: could not find screen"
int winstat(), newwin()
begin
# Find screen in list of screens
jscr = 0
do iscr = 1, nscreens {
if (scr1 == scrlist[iscr]) {
jscr = iscr
break
}
}
if (jscr == 0) {
call err1_prompt (notfound)
} else {
# Get dimensions of current window
win1 = TED_WINDOW(scr1)
top = winstat (win1, W_TOP)
left = winstat (win1, W_LEFT)
call wdimen (win1, row1, col1)
row2 = row1 / 2
col2 = col1
row1 = row1 - row2
# Don't split window if it is too small
if (row2 <= MIN_HEIGHT) {
call warn1_prompt (scr1, noroom)
scr2 = NULL
} else {
# Delete current window and create new half-size window
call delwin (win1)
TED_WINDOW(scr1) = newwin (row1, col1, top, left)
# Create new screen and its window
call malloc (scr2, TED_SCRLEN, TY_STRUCT)
TED_WINDOW(scr2) = newwin (row2, col2, top+row1, left)
TED_TABLE(scr2) = NULL
# Add to list of screens
do iscr = jscr+1, nscreens
scrlist[iscr+1] = scrlist[iscr]
scrlist[jscr+1] = scr2
nscreens = nscreens + 1
}
}
end
|