1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include <dos.h>
24 #include "wstdefs.h"
25 #include "wstglob.h"
26 #include "wstkill.h"
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 yank(line)
51 EDIT_LINE *line;
52 {
53 int line_chars_free;
54 int i, j;
55 int hi, lo;
56 int cnt;
57 int previous;
58
59
60 line_chars_free = MAX_LINE_SIZE - line->length;
61
62
63 if (kill_info.chars_free == KILL_BUFF_SIZE ||
64 (kill_info.current == kill_info.tail && !kill_info.head_of_killbuff)) {
65 beep();
66 return;
67 }
68
69
70 previous = (kill_info.current + KILL_BUFF_SIZE - kill_info.current_size) %
71 KILL_BUFF_SIZE;
72
73 i = previous;
74
75
76 lo = kill_info.kb[i];
77 i = (i+1)%KILL_BUFF_SIZE;
78 hi = kill_info.kb[i];
79 i = (i+1)%KILL_BUFF_SIZE;
80
81 cnt = (hi * MAX_7_BIT_VAL) + lo;
82
83
84 cnt -= TOTAL_SIZE_SPEC_BYTES;
85
86
87 if (line_chars_free < cnt) {
88 beep();
89 return;
90 }
91
92
93 for (j = line->length; j >= line->index; j--) {
94 line->line[j+cnt] = line->line[j];
95 line->size[j+cnt] = line->size[j];
96 }
97
98 line->length += cnt;
99 kill_info.yank_index = line->index;
100 kill_info.yank_size = cnt;
101
102
103 for (j = 0; j < cnt; j++) {
104 line->line[line->index+j] = kill_info.kb[i];
105 line->size[line->index+j] = (kb.echo) ? TRUE : FALSE;
106 i = (i+1)%KILL_BUFF_SIZE;
107 }
108
109
110 redisplay(line,line->index,&(line->max_row),&(line->max_col));
111 cursor_right(line,kill_info.yank_size);
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 yank_previous(line)
144 EDIT_LINE *line;
145 {
146 int i, j;
147 int hi, lo;
148 int cnt;
149 int previous;
150 int diff;
151
152
153 if (kill_info.yank_size < 1) {
154 beep();
155 return;
156 }
157
158
159 if (line->index != kill_info.yank_index+kill_info.yank_size) {
160 beep();
161 return;
162 }
163
164
165 if (kill_info.chars_free == KILL_BUFF_SIZE ||
166 (kill_info.current == kill_info.tail && !kill_info.head_of_killbuff)) {
167 beep();
168 return;
169 }
170
171
172 previous = (kill_info.current + KILL_BUFF_SIZE -
173 kill_info.current_size) % KILL_BUFF_SIZE;
174
175
176 if (previous == kill_info.tail)
177 previous = kill_info.head;
178
179
180 kill_info.current = previous;
181
182
183 if (previous != kill_info.tail) {
184
185
186 previous = (previous + KILL_BUFF_SIZE - N_SIZE_SPEC_BYTES) % KILL_BUFF_SIZE;
187 lo = kill_info.kb[previous];
188 previous = (previous+1) % KILL_BUFF_SIZE;
189 hi = kill_info.kb[previous];
190 kill_info.current_size = (hi * MAX_7_BIT_VAL)+lo;
191 }
192
193
194 kill_info.head_of_killbuff = FALSE;
195
196
197 previous = (kill_info.current + KILL_BUFF_SIZE -
198 kill_info.current_size) % KILL_BUFF_SIZE;
199
200
201 cursor_left(line,kill_info.yank_size);
202
203 i = previous;
204
205
206 lo = kill_info.kb[i];
207 i = (i+1)%KILL_BUFF_SIZE;
208 hi = kill_info.kb[i];
209 i = (i+1)%KILL_BUFF_SIZE;
210
211 cnt = (hi * MAX_7_BIT_VAL) + lo;
212 kill_info.current_size = cnt;
213
214 cnt -= TOTAL_SIZE_SPEC_BYTES;
215
216
217
218 if (cnt < kill_info.yank_size) {
219
220
221 diff = kill_info.yank_size - cnt;
222
223
224 for (j = kill_info.yank_index+cnt; j < line->length-diff; j++) {
225 line->line[j] = line->line[j+diff];
226 line->size[j] = line->size[j+diff];
227 }
228
229
230 line->length -= diff;
231 }
232
233 else if (kill_info.yank_size < cnt) {
234
235
236 diff = cnt - kill_info.yank_size;
237
238
239 if (line->length + diff >= MAX_LINE_SIZE) {
240 beep();
241 return;
242 }
243
244
245 for (j = line->length; j >= kill_info.yank_index; j--) {
246 line->line[j+diff] = line->line[j];
247 line->size[j+diff] = line->size[j];
248 }
249
250
251 line->length += diff;
252 }
253
254 kill_info.yank_index = line->index;
255 kill_info.yank_size = cnt;
256
257
258 for (j = 0; j < cnt; j++) {
259 line->line[line->index+j] = kill_info.kb[i];
260 line->size[line->index+j] = (kb.echo) ? TRUE : FALSE;
261 i = (i+1)%KILL_BUFF_SIZE;
262 }
263
264
265 redisplay(line,line->index,&(line->max_row),&(line->max_col));
266 cursor_right(line,kill_info.yank_size);
267
268
269
270 kill_info.head_of_killbuff = FALSE;
271 }
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299 save_to_killbuff(str,item_size)
300 char *str;
301 int item_size;
302 {
303 int i, j;
304 int lo_byte;
305 int hi_byte;
306 int first_chunk;
307 int buffer_empty;
308
309
310
311
312
313 if (item_size+TOTAL_SIZE_SPEC_BYTES > KILL_BUFF_SIZE)
314
315
316 item_size = KILL_BUFF_SIZE - TOTAL_SIZE_SPEC_BYTES;
317
318
319
320 while (kill_info.chars_free < item_size+TOTAL_SIZE_SPEC_BYTES) {
321
322 i = (kill_info.tail + kill_info.tail_item_size) % KILL_BUFF_SIZE;
323
324
325 if (i == kill_info.head && kill_info.chars_free == NONE) {
326
327
328 init_killbuff();
329 break;
330 }
331
332
333 kill_info.tail = i;
334 lo_byte = kill_info.kb[i];
335 i = (i+1)%KILL_BUFF_SIZE;
336 hi_byte = kill_info.kb[i];
337
338
339 kill_info.chars_free += kill_info.tail_item_size;
340 kill_info.tail_item_size = (hi_byte * MAX_7_BIT_VAL) + lo_byte;
341 }
342
343
344 if (kill_info.head == kill_info.tail && kill_info.chars_free == KILL_BUFF_SIZE)
345 buffer_empty = TRUE;
346 else
347 buffer_empty = FALSE;
348
349
350 kill_info.head_item_size = item_size+TOTAL_SIZE_SPEC_BYTES;
351 kill_info.chars_free -= kill_info.head_item_size;
352
353
354
355
356 lo_byte = kill_info.head_item_size % MAX_7_BIT_VAL;
357 hi_byte = kill_info.head_item_size / MAX_7_BIT_VAL;
358
359
360 i = kill_info.head;
361 kill_info.kb[i] = lo_byte;
362 i = (i+1)%KILL_BUFF_SIZE;
363 kill_info.kb[i] = hi_byte;
364 i = (i+1)%KILL_BUFF_SIZE;
365
366
367 if (i+item_size > KILL_BUFF_SIZE) {
368
369
370 first_chunk = KILL_BUFF_SIZE - i;
371
372
373
374 item_size -= first_chunk;
375
376
377 for (j = 0; j < first_chunk; j++)
378 kill_info.kb[i++] = str[j];
379 for (i = 0; i < item_size; i++)
380 kill_info.kb[i] = str[j++];
381
382 }
383
384
385 else {
386 for (j = 0; j < item_size; j++)
387 kill_info.kb[i++] = str[j];
388 }
389
390
391 i = i % KILL_BUFF_SIZE;
392 kill_info.kb[i] = lo_byte;
393 i = (i+1) % KILL_BUFF_SIZE;
394 kill_info.kb[i] = hi_byte;
395 i = (i+1) % KILL_BUFF_SIZE;
396
397
398 if (buffer_empty) {
399 kill_info.tail = kill_info.head;
400 kill_info.tail_item_size = kill_info.head_item_size;
401 }
402
403
404
405 kill_info.head = i;
406
407
408 kill_info.current = kill_info.head;
409
410
411 kill_info.current_size = kill_info.head_item_size;
412
413
414 kill_info.head_of_killbuff = TRUE;
415
416
417 kill_info.yank_index = ZERO_INDEX_VALUE;
418 kill_info.yank_size = ZERO_BYTES;
419
420 }
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439 init_killbuff()
440 {
441
442
443
444
445 kill_info.head = ZERO_INDEX_VALUE;
446 kill_info.head_item_size = ZERO_BYTES;
447 kill_info.tail = ZERO_INDEX_VALUE;
448 kill_info.tail_item_size = ZERO_BYTES;
449 kill_info.current = ZERO_INDEX_VALUE;
450 kill_info.current_size = ZERO_BYTES;
451 kill_info.chars_free = KILL_BUFF_SIZE;
452
453
454 kill_info.head_of_killbuff = TRUE;
455
456
457 kill_info.yank_index = ZERO_INDEX_VALUE;
458 kill_info.yank_size = ZERO_BYTES;
459 }
460