Subversion Repositories Kolibri OS

Rev

Rev 814 | Rev 1035 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
814 diamond 1
virtual at 0
2
editor_data:
3
	.hPlugin	dd	?
4
	.hFile		dd	?
5
if (.hPlugin <> viewer_data.hPlugin) | (.hFile <> viewer_data.hFile)
6
error in viewer_IsHandleUsed/editor_IsHandleUsed
7
end if
8
	.memsize	dd	?
9
	.encoding	db	?
10
	.flags		db	?	; & 0x80: modified
11
					; & 0x40: file is locked
12
					; & 0x20: next key as a symbol
13
					; & 0x10: replace mode (vs insert)
14
	.eol		db	?
15
			rb	1
16
	.first_block	dd	?
17
	.last_block	dd	?
18
	.numfree	dd	?
19
	.freeblocks	dd	?
20
	.numlines	dd	?
21
	.curline	dd	?
22
	.curcol		dd	?
23
	;.curpos_block	dd	?
24
	;.curpos_offs	dd	?
25
	.cur_block	dd	?
26
	.cur_offs	dd	?
27
	.cur_delta	dd	?
28
	.cursor_x	dd	?
29
	.cursor_y	dd	?
30
	align 200h
31
	.filename	rb	1024
32
	.hostname	rb	1024
33
if (.filename <> viewer_data.filename) | (.hostname <> viewer_data.hostname)
34
error in viewer_getname/editor_getname
35
end if
36
	.buf		rb	16384	; all I/O operations use this buffer
37
	.basesize = $
38
	.linedata_start:
39
end virtual
40
 
41
virtual at 0
42
editor_line:
43
	.block		dd	?
44
	.offs		dw	?
45
	;.length		dd	?
46
	.plugdata:
47
end virtual
48
 
49
; when a file is loaded into the editor, this file is fragmented to blocks
50
; each block has RESERVE_IN_BLOCK empty bytes to allow quick inserting
51
; must be dword-aligned!
52
edit.RESERVE_IN_BLOCK = 16
53
edit.eol_dos = 1	; DOS/Win EOLn style (0D 0A)
54
edit.eol_unix = 2	; Unix EOLn style (0A)
55
edit.eol_mac = 3	; MacOS EOLn style (0D)
56
 
57
virtual at 0
58
edit_block_header:
59
	.next		dd	?
60
	.prev		dd	?
61
	.limit		dd	?
62
	.size = $	; must be dword-aligned
63
end virtual
64
 
65
edit_file:
66
	mov	eax, [ebp + panel1_files - panel1_data]
67
	mov	ecx, [eax+ecx*4]
68
	test	byte [ecx], 10h
69
	jz	.file
70
	ret
71
.file:
72
; calculate required memory size
73
	cmp	dword [ecx+36], 0
74
	jnz	.nomemory
75
; block size = 4096
76
; block header: edit_block_header.size bytes
77
; some plugin-specific data can follow
78
; reserve RESERVE_IN_BLOCK free bytes in the end of block
79
	mov	ebx, 4096
80
	mov	eax, [EditPlugInfo]
81
	add	eax, edit_block_header.size
82
	mov	[EditBlockStart], eax
83
	sub	ebx, eax
84
	sub	ebx, edit.RESERVE_IN_BLOCK
85
	mov	[EditBlockSize], ebx
86
; now ebx = size of file data in each block
87
	mov	eax, [ecx+32]
88
; if eax == 0, set eax = 1
89
	sub	eax, 1
90
	adc	eax, 1
91
	xor	edx, edx
92
	div	ebx
93
	sub	edx, 1
94
	sbb	eax, -1
95
	add	eax, [EditDataSize]
96
; eax = number of blocks + memory for editor_data structure
97
	cmp	eax, 0x80000000 shr 12
98
	jb	.memok
99
.nomemory:
100
	push	aEditNoMemory
101
	mov	eax, esp
102
	push	ContinueBtn
103
	push	1
104
	push	eax
105
	push	1
106
	call	SayErr
107
	pop	eax
108
	ret
109
.memok:
110
	lea	esi, [ebp + panel1_dir - panel1_data]
111
	push	eax
112
	push	ecx
113
	mov	ecx, eax
114
	shl	ecx, 12
115
	mov	edx, editor_vtable
116
	call	new_screen
117
	pop	ecx
118
	pop	ebx
119
	test	eax, eax
120
	jnz	@f
121
	ret
122
@@:
123
	mov	[ebp + editor_data.memsize], ebx
124
	mov	al, [EditEOLStyle]
125
	mov	[ebp + editor_data.eol], al
997 diamond 126
	mov	eax, dword [esi + panel1_hPlugin - panel1_dir]
814 diamond 127
	mov	[ebp + editor_data.hPlugin], eax
128
	test	eax, eax
129
	jz	.nocopyhostname
130
	lea	edi, [ebp + editor_data.hostname]
131
	push	esi
132
	mov	eax, dword [esi + panel1_parents - panel1_dir]
133
	mov	esi, dword [esi + panel1_parents_sz - panel1_dir]
134
	add	esi, eax
135
@@:
136
	dec	esi
137
	cmp	byte [esi-1], 0
138
	jz	@f
139
	cmp	byte [esi-1], '/'
140
	jnz	@b
141
@@:
142
	lodsb
143
	stosb
144
	test	al, al
145
	jnz	@b
146
	pop	esi
147
.nocopyhostname:
148
	mov	eax, dword [esi + panel1_hFile - panel1_dir]
149
	mov	[ebp + editor_data.hFile], eax
150
	mov	[ebp + editor_data.encoding], encodings.cp866
151
	xor	eax, eax
152
	mov	[ebp + editor_data.flags], al
153
	inc	eax
154
	mov	[ebp + editor_data.numlines], eax
155
	lea	edi, [ebp + editor_data.filename]
156
	mov	ebx, readinfo
157
	mov	[ebx+21], edi
158
@@:
159
	lodsb
160
	test	al, al
161
	jz	@f
162
	stosb
163
	jmp	@b
164
@@:
165
	lea	esi, [ecx+40]
166
	mov	al, '/'
167
	cmp	byte [edi-1], al
168
	jz	@f
169
	stosb
170
@@:
171
	lodsb
172
	stosb
173
	test	al, al
174
	jnz	@b
175
; load file into memory
176
	mov	esi, [ebp + editor_data.memsize]
177
	mov	edi, [EditDataSize]
178
	sub	esi, edi	; esi = number of blocks
179
	shl	edi, 12
180
	;mov	[ebp + editor_data.curpos_block], edi
181
	mov	[ebp + editor_data.first_block], edi
182
	mov	[ebp + editor_data.cur_block], edi
183
	add	edi, ebp	; edi -> first block
184
	mov	[ebp + editor_data.linedata_start + editor_line.block], edi
185
	xor	eax, eax
186
	mov	[ebx+4], eax
187
	mov	[ebx+8], eax
188
	mov	dword [ebx+12], 16384
189
	lea	eax, [ebp + editor_data.buf]
190
	mov	[ebx+16], eax
191
	mov	edx, [ebp + editor_data.hPlugin]
192
	test	edx, edx
193
	jz	@f
194
	pushad
195
	push	O_READ
196
	push	dword [ebx+21]
197
	push	[ebp + editor_data.hFile]
198
	call	[edx + PluginInfo.open]
997 diamond 199
	mov	[esp+1Ch], eax
814 diamond 200
	popad
201
	test	eax, eax
202
	jz	..openerr_in_screen
203
	mov	ebx, eax
204
@@:
205
.readloop:
206
	mov	edx, [ebp + editor_data.hPlugin]
207
	test	edx, edx
208
	jz	.readnative
209
	pushad
210
	push	16384
211
	push	[readinfo.data]
212
	push	ebx
213
	call	[edx + PluginInfo.read]
997 diamond 214
	mov	[esp+1Ch], eax
814 diamond 215
	popad
216
	cmp	eax, -1
217
	jnz	.readok
218
; let us hope that plugin says error itself
219
	push	ebp
220
	push	ebx
221
	call	[edx + PluginInfo.close]
222
	pop	ebp
223
	jmp	.readfailed
224
.readnative:
225
	push	ebx
226
	push	70
227
	pop	eax
228
	int	40h
229
	mov	edx, ebx
230
	xchg	eax, edx
231
	pop	ebx
232
	add	dword [ebx+4], eax
233
	adc	dword [ebx+8], 0
234
	test	edx, edx
235
	jz	.readok
236
	cmp	edx, 6
237
	jz	.readok
238
	push	dword [ebx+21]
239
	push	aCannotReadFile
240
	xchg	eax, edx
241
	call	get_error_msg
242
	push	eax
243
	mov	eax, esp
244
	push	RetryOrCancelBtn
245
	push	2
246
	push	eax
247
	push	3
248
	call	SayErr
249
	add	esp, 3*4
250
	test	eax, eax
251
	jz	.readnative
252
.readfailed:
253
	jmp	delete_active_screen
254
.readok:
255
; eax = number of bytes read
256
	test	eax, eax
257
	jnz	@f
258
	mov	ecx, edi
259
	sub	ecx, ebp
260
	cmp	ecx, [ebp + editor_data.first_block]
261
	jnz	.readdone
262
@@:
263
	push	eax ebx
997 diamond 264
	mov	ebx, [readinfo.data]
814 diamond 265
.loadloop:
266
	mov	ecx, [EditBlockSize]
267
	cmp	eax, ecx
268
	ja	@f
269
	mov	ecx, eax
270
@@:
271
	sub	eax, ecx
272
	push	eax
273
	dec	esi
274
	jns	.hasblock
275
	push	ecx
276
	add	[ebp + editor_data.memsize], 8
277
	add	esi, 8
278
	mov	ecx, [ebp + editor_data.memsize]
279
	cmp	ecx, 80000000h shr 12
280
	jb	@f
281
.nomemory2:
282
	pop	ecx eax ebx eax
283
	call	.nomemory
284
	jmp	.readfailed
285
@@:
286
	sub	edi, ebp
287
	shl	ecx, 12
288
	mov	edx, ebp
289
	call	xpgrealloc
290
	test	eax, eax
291
	jz	.nomemory2
292
	mov	ebp, eax
293
	add	edi, eax
294
	pop	ecx
295
.hasblock:
296
	lea	eax, [edi + 0x1000]
297
	push	eax
298
	sub	eax, ebp
299
	stosd	; edit_block_header.next
300
	sub	eax, 0x2000
301
	stosd	; edit_block_header.prev
302
	mov	eax, [EditBlockStart]
303
	add	eax, ecx
304
	stosd	; edit_block_header.limit
305
	push	ecx
306
	mov	ecx, [EditPlugInfo]
307
	inc	ecx
308
	jz	@f
309
	dec	ecx
310
@@:
311
	xor	eax, eax
312
	rep	stosb	; info for plugins: zeroed
313
	pop	ecx
314
	push	esi edi ecx
315
	mov	esi, ebx
316
	add	ecx, 3
317
	shr	ecx, 2
318
	rep	movsd
319
	mov	ebx, esi
320
	pop	ecx edi
321
; calculate number of lines in this block
322
	mov	esi, edi
323
	xor	edx, edx
324
	test	ecx, ecx
325
	jz	.4
326
.1:
327
	lodsb
328
	cmp	al, 13
329
	jz	@f
330
	cmp	al, 10
331
	jz	@f
332
	mov	dl, 0
333
	jmp	.3
334
@@:
335
	cmp	al, dl
336
	mov	dl, 0
337
	jz	.3
338
	inc	[ebp + editor_data.numlines]
339
	cmp	al, 10
340
	jz	.3
341
	mov	dl, 10
342
.3:
343
	loop	.1
344
.4:
345
	pop	esi
346
	pop	edi
347
	pop	eax
348
	test	eax, eax
349
	jnz	.loadloop
350
	pop	ebx eax
351
	cmp	eax, 16384
352
	jz	.readloop
353
.readdone:
354
	xor	eax, eax
355
	mov	ecx, edi
356
	sub	ecx, ebp
357
	mov	edx, ecx
358
	shr	ecx, 12
359
	sub	ecx, [ebp + editor_data.memsize]
360
	neg	ecx
361
	mov	[ebp + editor_data.numfree], ecx
362
	jz	.nofree
363
	mov	[ebp + editor_data.freeblocks], edx
364
	push	edi
365
.addfree:
366
	add	edx, 1000h
367
	mov	[edi], edx
368
	add	edi, 1000h
369
	loop	.addfree
370
	mov	[edi-1000h], eax
371
	pop	edi
372
.nofree:
373
	sub	edi, 1000h
374
	mov	[edi + edit_block_header.next], eax
375
	sub	edi, ebp
376
	mov	[ebp + editor_data.last_block], edi
377
	mov	ecx, [EditDataSize]
378
	shl	ecx, 12
379
	mov	[ecx + ebp + edit_block_header.prev], eax
380
	mov	[ebp + editor_data.curline], eax
381
	mov	[ebp + editor_data.curcol], eax
382
	mov	[ebp + editor_data.cursor_x], eax
383
	inc	eax
384
	mov	[ebp + editor_data.cursor_y], eax
385
	mov	eax, [EditBlockStart]
386
	;mov	[ebp + editor_data.curpos_offs], eax
387
	mov	[ebp + editor_data.linedata_start + editor_line.offs], ax
388
	mov	[ebp + editor_data.cur_offs], eax
389
	mov	ecx, [ebp + editor_data.first_block]
390
	cmp	[ecx + edit_block_header.limit], eax
391
	setz	cl
392
	movzx	ecx, cl
393
	dec	ecx
394
	mov	[ebp + editor_data.cur_delta], ecx
395
	call	editor_init_lines
396
editor_OnRedraw:
397
	mov	eax, [ebp + editor_data.cursor_x]
398
	mov	[cursor_x], eax
399
	mov	eax, [ebp + editor_data.cursor_y]
400
	mov	[cursor_y], eax
401
	test	[ebp + editor_data.flags], 10h
402
	jz	@f
403
	mov	[cursor_size], cursor_big_size
404
@@:
405
	call	editor_test_cursor_x
406
	call	editor_test_cursor_y
407
	call	editor_set_keybar
408
	call	editor_draw_text
409
	ret
410
 
411
editor_save:
412
	cmp	[ebp + editor_data.hPlugin], 0
413
	jz	.native
414
	push	aCannotSaveToPlugin
415
	mov	eax, esp
416
	push	ContinueBtn
417
	push	1
418
	push	eax
419
	push	1
420
	call	SayErr
421
	pop	eax
422
	ret
423
.native:
424
	call	editor_calc_filesize
425
	mov	ebx, writeinfo
426
	mov	[ebx+4], eax
427
	xor	eax, eax
428
	mov	[ebx+8], eax
429
	mov	[ebx+12], eax
430
	mov	[ebx+16], eax
431
	lea	eax, [ebp + editor_data.filename]
432
	mov	[ebx+21], eax
433
.setsize_retry:
434
	mov	byte [ebx], 4
435
	push	70
436
	pop	eax
437
	push	ebx
438
	int	0x40
439
	pop	ebx
440
	mov	byte [ebx], 3
441
	test	eax, eax
442
	jz	.sizeok
443
	push	dword [ebx+21]
444
	push	aCannotWriteFile
445
	call	get_error_msg
446
	push	eax
447
	mov	eax, esp
448
	push	RetryOrCancelBtn
449
	push	2
450
	push	eax
451
	push	3
452
	call	SayErr
453
	add	esp, 12
454
	test	eax, eax
455
	jz	.setsize_retry
456
.ret:
457
	ret
458
.sizeok:
459
	and	dword [ebx+4], 0
460
	mov	esi, [ebp + editor_data.first_block]
461
	add	esi, ebp
462
	mov	ebx, [EditBlockStart]
463
	call	editor_normalize_offs
464
	jnc	.writeok
465
	lea	edi, [ebp + editor_data.buf]
466
.loop:
467
	mov	ecx, 16384
468
	call	editor_get_data
469
	test	eax, eax
470
	jz	.done
471
	push	ebx
472
	mov	ebx, writeinfo
473
	mov	[ebx+12], eax
474
	mov	[ebx+16], edi
475
.write_retry:
476
	push	70
477
	pop	eax
478
	push	ebx
479
	int	0x40
480
	pop	ebx
481
	test	eax, eax
482
	jz	.writeok
483
	push	dword [ebx+21]
484
	push	aCannotWriteFile
485
	call	get_error_msg
486
	push	eax
487
	mov	eax, esp
488
	push	RetryOrCancelBtn
489
	push	2
490
	push	eax
491
	push	3
492
	call	SayErr
493
	add	esp, 12
494
	test	eax, eax
495
	jz	.write_retry
496
	ret
497
.writeok:
498
	mov	eax, [ebx+12]
499
	add	[ebx+4], eax
500
	adc	dword [ebx+8], 0
501
	pop	ebx
502
	jmp	.loop
503
.done:
504
	and	[ebp + editor_data.flags], not 0x80
505
	ret
506
 
507
editor_calc_filesize:
508
	xor	eax, eax
509
	push	esi
510
	mov	esi, [ebp + editor_data.first_block]
511
@@:
512
	add	esi, ebp
513
	add	eax, [esi + edit_block_header.limit]
514
	sub	eax, [EditBlockStart]
515
	mov	esi, [esi + edit_block_header.next]
516
	test	esi, esi
517
	jnz	@b
518
	pop	ebx
519
	ret
520
 
521
editor_get_data:
522
	push	edi
523
	test	esi, esi
524
	jz	.ret
525
.loop:
526
	mov	edx, [esi + edit_block_header.limit]
527
	sub	edx, ebx
528
	push	ecx
529
	cmp	ecx, edx
530
	jb	@f
531
	mov	ecx, edx
532
@@:
533
	push	esi
534
	add	esi, ebx
535
	add	ebx, ecx
536
	add	eax, ecx
537
	rep	movsb
538
	pop	esi
539
	pop	ecx
540
	sub	ecx, edx
541
	jb	.ret
542
	mov	esi, [esi + edit_block_header.next]
543
	mov	ebx, [EditBlockStart]
544
	test	esi, esi
545
	jz	.ret
546
	add	esi, ebp
547
	jmp	.loop
548
.ret:
549
	mov	eax, edi
550
	pop	edi
551
	sub	eax, edi
552
	ret
553
 
554
editor_get_pos:
555
	;mov	esi, [ebp + editor_data.curpos_block]
556
	;mov	ebx, [ebp + editor_data.curpos_offs]
557
	mov	esi, [ebp + editor_data.linedata_start + editor_line.block]
558
	sub	esi, ebp
559
	movzx	ebx, [ebp + editor_data.linedata_start + editor_line.offs]
560
@@:
561
	test	esi, esi
562
	jz	@f
563
	add	esi, ebp
564
	cmp	ebx, [esi + edit_block_header.limit]
565
	jb	@f
566
	mov	esi, [esi + edit_block_header.next]
567
	mov	ebx, [EditBlockStart]
568
	jmp	@b
569
@@:
570
	ret
571
 
572
editor_curline_start:
573
	mov	edx, [EditPlugInfo]
574
	add	edx, editor_line.plugdata
575
	mov	eax, [ebp + editor_data.cursor_y]
576
	dec	eax
577
	imul	eax, edx
578
	lea	edi, [ebp + eax + editor_data.linedata_start]
579
	mov	esi, [edi + editor_line.block]
580
	movzx	ebx, [edi + editor_line.offs]
581
	ret
582
 
583
editor_step_forward:
584
; in: esi = block (must be nonzero), ebx = offset in block
585
; out: esi = block (zero iff EOF reached), ebx = offset in block
586
; out: CF=1 iff EOF NOT reached
587
	inc	ebx
588
editor_normalize_offs:
589
	cmp	ebx, [esi + edit_block_header.limit]
590
	jb	@f
591
	mov	esi, [esi + edit_block_header.next]
592
	mov	ebx, [EditBlockStart]
593
	test	esi, esi
594
	jz	@f
595
	add	esi, ebp
596
	stc
597
@@:
598
	ret
599
 
600
editor_step_backward:
601
; in: esi = block (must be nonzero), ebx = offset in block
602
; out: esi = block (zero iff input was at the beginning), ebx = offset in block
603
; out: CF=1 iff start of file reached
604
	dec	ebx
605
	cmp	ebx, [EditBlockStart]
606
	jae	@f
607
	mov	esi, [esi + edit_block_header.prev]
608
	test	esi, esi
609
	stc
610
	jz	@f
611
	add	esi, ebp
612
	mov	ebx, [esi + edit_block_header.limit]
613
	dec	ebx
614
@@:
615
	ret
616
 
617
editor_get_string:
618
; read string up to the end of line
619
; in: esi = block, ebx = offset in block
620
; in: edi = destination, ecx = maximum number of bytes to copy, edx = number of bytes to skip
621
; out: esi = block, ebx = offset in block
622
; out: ecx = number of rest bytes (ecx_in - ecx_out = number of copied characters)
623
	mov	ah, [edit_normal_color]
624
	cmp	ebx, [esi + edit_block_header.limit]
625
	jz	.retnp
626
	push	0	; current position in line
627
.loop:
628
	test	ecx, ecx
629
	jz	.ret
630
	mov	al, [esi + ebx]
631
	cmp	al, 13
632
	jz	.ret
633
	cmp	al, 10
634
	jz	.ret
635
	cmp	al, 9
636
	jz	.tab
637
	inc	dword [esp]
638
	dec	edx
639
	jns	.4
640
	xor	edx, edx
641
	stosw
642
	dec	ecx
643
.4:
644
	call	editor_step_forward
645
	jc	.loop
646
.ret:
647
	pop	edx
648
.retnp:
649
	ret
650
.tab:
651
	push	eax edx
652
	mov	eax, [esp+8]
653
	xor	edx, edx
654
	div	[editor_tabsize]
655
	sub	edx, [editor_tabsize]
656
	neg	edx
657
	add	[esp+8], edx
658
	sub	[esp], edx
659
	pop	edx eax
660
	jns	.4
661
	mov	al, ' '
662
@@:
663
	stosw
664
	dec	ecx
665
	jz	.ret
666
	inc	edx
667
	jnz	@b
668
	jmp	.4
669
 
670
editor_find_newline:
671
; in: esi = block, ebx = offset in block
672
; out: esi = block, ebx = offset in block, ecx = line length
673
	xor	ecx, ecx
674
	test	esi, esi
675
	jz	.ret0
676
	cmp	ebx, [esi + edit_block_header.limit]
677
	jb	.1
678
	xor	esi, esi
679
.ret0:
680
	ret
681
.1:
682
	mov	al, [esi + ebx]
683
	inc	ecx
684
	call	editor_step_forward
685
	cmp	al, 13
686
	jz	.2
687
	cmp	al, 10
688
	jz	.2
689
	test	esi, esi
690
	jnz	.1
691
.ret1:
692
	mov	esi, [ebp + editor_data.last_block]
693
	add	esi, ebp
694
	mov	ebx, [esi + edit_block_header.limit]
695
	ret
696
.2:
697
	dec	ecx
698
	test	esi, esi
699
	jz	.ret1
700
	cmp	al, 13
701
	jnz	.ret
702
	cmp	byte [esi + ebx], 10
703
	jnz	.ret
704
	call	editor_step_forward
705
	jnc	.ret1
706
.ret:
707
	ret
708
 
709
editor_prev_newline:
710
	xor	ecx, ecx
711
	test	esi, esi
712
	jnz	@f
713
	mov	esi, [ebp + editor_data.last_block]
714
	add	esi, ebp
715
	mov	ebx, [esi + edit_block_header.limit]
716
@@:
717
	call	editor_step_backward
718
	jc	.ret
719
	mov	al, [esi + ebx]
720
	call	editor_step_backward
721
	jc	.ret
722
	cmp	al, 10
723
	jnz	.1
724
	cmp	byte [esi + ebx], 13
725
	jnz	.1
726
@@:
727
	call	editor_step_backward
728
	jc	.ret
729
.1:
730
	inc	ecx
731
	mov	al, [esi + ebx]
732
	cmp	al, 13
733
	jz	@f
734
	cmp	al, 10
735
	jnz	@b
736
@@:
737
	dec	ecx
738
	inc	ebx
739
	cmp	ebx, [esi + edit_block_header.limit]
740
	jb	.ret
741
	mov	esi, [esi + edit_block_header.next]
742
	mov	ebx, [EditBlockStart]
743
	test	esi, esi
744
	jz	.ret
745
	add	esi, ebp
746
.ret:
747
	test	esi, esi
748
	jnz	@f
749
	mov	esi, [ebp + editor_data.first_block]
750
	mov	ebx, [EditBlockStart]
751
	add	esi, ebp
752
@@:
753
	ret
754
 
755
editor_init_lines:
756
	call	editor_get_pos
757
	test	esi, esi
758
	jnz	@f
759
	mov	esi, [ebp + editor_data.last_block]
760
	add	esi, ebp
761
	mov	ebx, [esi + edit_block_header.limit]
762
@@:
763
	mov	ecx, max_height
764
	lea	edi, [ebp + editor_data.linedata_start]
765
.1:
766
	mov	eax, esi
767
	stosd	; editor_line.block
768
	mov	eax, ebx
769
	stosw	; editor_line.offs
770
	push	ecx
771
	call	editor_find_newline
772
	;mov	eax, ecx
773
	;stosd	; editor_line.length
774
	xor	eax, eax
775
	mov	ecx, [EditPlugInfo]
776
	rep	stosb
777
	pop	ecx
778
	loop	.1
779
	ret
780
 
781
editor_draw_status:
782
	lea	edi, [ebp + editor_data.buf]
783
	mov	ah, [edit_status_color]
784
	mov	ecx, [cur_width]
785
	sub	ecx, 56
786
	cmp	ecx, 25
787
	jge	@f
788
	push	25
789
	pop	ecx
790
@@:
791
	call	viewedit_draw_filename
792
	inc	ecx
793
	rep	stosw
794
	test	[ebp + editor_data.flags], 80h
795
	jz	@f
796
	mov	al, '*'
797
@@:
798
	stosw
799
	mov	al, ' '
800
	test	[ebp + editor_data.flags], 40h
801
	jz	@f
802
	mov	al, '-'
803
@@:
804
	stosw
805
	mov	al, ' '
806
	test	[ebp + editor_data.flags], 20h
807
	jz	@f
808
	mov	al, '"'
809
@@:
810
	stosw
811
	mov	al, ' '
812
	mov	cl, 10
813
        rep     stosw
814
        movzx   esi, [ebp+editor_data.encoding]
815
        lea     esi, [encodings.names+esi*8]
816
        push    edi esi
817
        dec     edi
818
        dec     edi
819
        std
820
        add     esi, 8
821
@@:
822
        dec     esi
823
        cmp     byte [esi], ' '
824
        jz      @b
825
@@:
826
        lodsb
827
        stosw
828
        cmp     esi, [esp]
829
        jae     @b
830
        cld
831
        pop     esi edi
832
	mov	esi, aLine
833
	mov	cl, 8
834
@@:
835
	lodsb
836
	stosw
837
	loop	@b
838
	mov	cl, 13
839
	mov	al, ' '
840
	rep	stosw
841
	std
842
	push	edi
843
	dec	edi
844
	dec	edi
845
	push	eax
846
	mov	eax, [ebp + editor_data.numlines]
847
	mov	cl, 10
848
@@:
849
	xor	edx, edx
850
	div	ecx
851
	xchg	eax, edx
852
	add	al, '0'
853
	mov	ah, [edit_status_color]
854
	stosw
855
	xchg	eax, edx
856
	test	eax, eax
857
	jnz	@b
858
	mov	al, '/'
859
	mov	ah, [edit_status_color]
860
	stosw
861
	mov	eax, [ebp + editor_data.curline]
862
	add	eax, [ebp + editor_data.cursor_y]
863
@@:
864
	xor	edx, edx
865
	div	ecx
866
	xchg	eax, edx
867
	add	al, '0'
868
	mov	ah, [edit_status_color]
869
	stosw
870
	xchg	eax, edx
871
	test	eax, eax
872
	jnz	@b
873
	pop	eax
874
	stosw
875
	cld
876
	pop	edi
877
	mov	ah, [edit_status_color]
878
	mov	esi, aCol
879
	mov	cl, 7
880
@@:
881
	lodsb
882
	stosw
883
	loop	@b
884
	mov	eax, [ebp + editor_data.curcol]
885
	add	eax, [ebp + editor_data.cursor_x]
886
	inc	eax
887
	mov	cl, 10
888
	push	-'0'
889
@@:
890
	xor	edx, edx
891
	div	ecx
892
	push	edx
893
	test	eax, eax
894
	jnz	@b
895
@@:
896
	pop	eax
897
	mov	ah, [edit_status_color]
898
	add	al, '0'
899
	jz	@f
900
	stosw
901
	jmp	@b
902
@@:
903
	mov	al, ' '
904
	mov	cl, 13
905
	rep	stosw
906
	xor	eax, eax
907
	xor	edx, edx
908
	call	get_console_ptr
909
	lea	esi, [ebp + editor_data.buf]
910
	mov	ecx, [cur_width]
911
	shr	ecx, 1
912
	rep	movsd
913
	adc	ecx, ecx
914
	rep	movsw
915
	cmp	[ebp + editor_data.cur_delta], -1
916
	jnz	.a
917
	mov	al, ' '
918
	mov	byte [edi-4*2], al
919
	mov	byte [edi-3*2], al
920
	mov	byte [edi-2*2], al
921
	mov	byte [edi-1*2], al
922
	mov	eax, [ebp + editor_data.cur_block]
923
	add	eax, ebp
924
	add	eax, [ebp + editor_data.cur_offs]
925
	movzx	eax, byte [eax]
926
	mov	cl, 100
927
	;xor	edx, edx	; edx=0 already
928
	div	ecx
929
	test	al, al
930
	jz	@f
931
	add	al, '0'
932
	mov	[edi-3*2], al
933
@@:
934
	xchg	eax, edx
935
	aam
936
	test	ah, ah
937
	jnz	.b
938
	cmp	byte [edi-3*2], ' '
939
	jz	@f
940
.b:
941
	add	ah, '0'
942
	mov	[edi-2*2], ah
943
@@:
944
	add	al, '0'
945
	mov	[edi-1*2], al
946
.a:
947
	ret
948
 
949
editor_draw_line:
950
	push	ecx
951
	mov	ecx, [cur_width]
952
	test	esi, esi
953
	jz	.2
954
	lea	edi, [ebp + editor_data.buf]
955
	push	edx edi
956
	mov	edx, [ebp + editor_data.curcol]
957
	call	editor_get_string
958
	mov	al, ' '
959
	rep	stosw
960
	pop	esi edx
961
	xor	eax, eax
962
	call	get_console_ptr
963
	mov	ecx, [cur_width]
964
	shr	ecx, 1
965
	rep	movsd
966
	adc	ecx, ecx
967
	rep	movsw
968
	pop	ecx
969
	ret
970
.2:
971
	xor	eax, eax
972
	call	get_console_ptr
973
	mov	al, ' '
974
	mov	ah, [edit_normal_color]
975
	rep	stosw
976
	pop	ecx
977
	ret
978
 
979
editor_draw_text:
980
	call	editor_draw_status
981
	push	1
982
	pop	edx
983
	lea	ecx, [ebp + editor_data.linedata_start]
984
.1:
985
	mov	esi, [ecx + editor_line.block]
986
	movzx	ebx, [ecx + editor_line.offs]
987
	add	ecx, editor_line.plugdata
988
	add	ecx, [EditPlugInfo]
989
	call	editor_draw_line
990
	inc	edx
991
	mov	eax, [cur_height]
992
	dec	eax
993
	cmp	edx, eax
994
	jb	.1
995
	jmp	draw_image
996
 
997
editor_set_keybar:
998
	mov	eax, keybar_editor
999
	movzx	esi, [ebp+editor_data.encoding]
1000
	dec	esi
1001
	jz	@f
1002
	push	1
1003
	pop	esi
1004
@@:
1005
	lea	esi, [encodings.names+esi*8]
1006
	lea	edi, [eax+keybar_cp2-keybar_editor]
1007
	movsd
1008
	movsw
1009
	jmp	draw_keybar
1010
 
1011
editor_up_scroll:
1012
	push	ecx
1013
	sub	[ebp + editor_data.curline], ecx
1014
	mov	edx, [EditPlugInfo]
1015
	add	edx, editor_line.plugdata
1016
	imul	eax, edx, max_height
1017
	imul	ecx, edx
1018
	sub	ecx, eax
1019
	neg	ecx
1020
	lea	esi, [ebp + ecx + editor_data.linedata_start - 4]
1021
	lea	edi, [ebp + eax + editor_data.linedata_start - 4]
1022
	shr	ecx, 2
1023
	std
1024
	rep	movsd
1025
	cld
1026
	jnc	@f
1027
	mov	cx, [esi+2]
1028
	mov	[edi+2], cx
1029
	sub	edi, 2
1030
@@:
1031
	pop	ecx
1032
	add	edi, 4
1033
	movzx	ebx, [edi + editor_line.offs]
1034
	mov	esi, [edi + editor_line.block]
1035
@@:
1036
	push	ecx
1037
	call	editor_prev_newline
1038
	sub	edi, edx
1039
	push	edi
1040
	mov	eax, esi
1041
	stosd	; editor_line.offs
1042
	mov	eax, ebx
1043
	stosw	; editor_line.block
1044
	;mov	eax, ecx
1045
	;stosd	; editor_line.length
1046
	mov	ecx, [EditPlugInfo]
1047
	xor	eax, eax
1048
	rep	stosb
1049
	pop	edi
1050
	pop	ecx
1051
	loop	@b
1052
; fall through to editor_update_cur
1053
 
1054
editor_update_cur:
1055
	mov	ecx, [ebp + editor_data.cursor_x]
1056
	add	ecx, [ebp + editor_data.curcol]
1057
	call	editor_curline_start
1058
	xor	edx, edx	; current position in the line
1059
	cmp	ebx, [esi + edit_block_header.limit]
1060
	jz	.notfound
1061
.scan:
1062
	mov	al, [esi+ebx]
1063
	cmp	al, 13
1064
	jz	.notfound
1065
	cmp	al, 10
1066
	jz	.notfound
1067
	test	ecx, ecx
1068
	jz	.found
1069
	cmp	al, 9
1070
	jz	.tab
1071
	inc	edx
1072
	dec	ecx
1073
	call	editor_step_forward
1074
	jc	.scan
1075
.notfound:
1076
	test	esi, esi
1077
	jnz	@f
1078
	mov	esi, [ebp + editor_data.last_block]
1079
	add	esi, ebp
1080
	mov	ebx, [esi + edit_block_header.limit]
1081
@@:
1082
	mov	[ebp + editor_data.cur_delta], ecx
1083
	xor	eax, eax
1084
	jmp	.reta
1085
.found:
1086
	xor	eax, eax
1087
.founda:
1088
	or	[ebp + editor_data.cur_delta], -1
1089
.reta:
1090
	sub	esi, ebp
1091
	mov	[ebp + editor_data.cur_block], esi
1092
	mov	[ebp + editor_data.cur_offs], ebx
1093
	ret
1094
.tab:
1095
	push	edx
1096
	mov	eax, edx
1097
	xor	edx, edx
1098
	div	[editor_tabsize]
1099
	sub	edx, [editor_tabsize]
1100
	neg	edx
1101
	add	[esp], edx
1102
	cmp	ecx, edx
1103
	jb	.curintab
1104
	sub	ecx, edx
1105
	pop	edx
1106
	call	editor_step_forward
1107
	jnc	.notfound
1108
	test	ecx, ecx
1109
	jz	.found
1110
	jmp	.scan
1111
.curintab:
1112
	sub	[esp], edx
1113
	pop	edx
1114
	cmp	edx, [ebp + editor_data.curcol]
1115
	setc	al
1116
	jae	@f
1117
	mov	[ebp + editor_data.curcol], edx
1118
@@:
1119
	sub	edx, [ebp + editor_data.curcol]
1120
	mov	[ebp + editor_data.cursor_x], edx
1121
	mov	[cursor_x], edx
1122
	jmp	.founda
1123
 
1124
editor_down_scroll:
1125
	push	ecx
1126
	lea	edi, [ebp + editor_data.linedata_start]
1127
	mov	edx, [EditPlugInfo]
1128
	add	edx, editor_line.plugdata
1129
	imul	ecx, edx
1130
	lea	esi, [edi + ecx]
1131
	imul	eax, edx, max_height
1132
	sub	eax, ecx
1133
	mov	ecx, eax
1134
	shr	ecx, 2
1135
	rep	movsd
1136
	adc	ecx, ecx
1137
	rep	movsw
1138
@@:
1139
	mov	esi, edi
1140
	sub	esi, edx
1141
	movzx	ebx, [esi + editor_line.offs]
1142
	mov	esi, [esi + editor_line.block]
1143
	pop	ecx
1144
	jecxz	.ret
1145
@@:
1146
	push	ecx
1147
	call	editor_find_newline
1148
	mov	eax, esi
1149
	stosd	; editor_line.block
1150
	mov	eax, ebx
1151
	stosw	; editor_line.offs
1152
	;mov	eax, ecx
1153
	;stosd	; editor_line.length
1154
	mov	ecx, [EditPlugInfo]
1155
	xor	eax, eax
1156
	rep	stosb
1157
	pop	ecx
1158
	loop	@b
1159
.ret:
1160
	ret
1161
 
1162
editor_end_scroll:
1163
	call	editor_curline_start
1164
; calculate visible length of the line (it differs from the real length if tabulations are present)
1165
	xor	ecx, ecx
1166
	cmp	ebx, [esi + edit_block_header.limit]
1167
	jz	.calcdone
1168
.calcloop:
1169
	mov	al, [esi+ebx]
1170
	cmp	al, 10
1171
	jz	.calcdone
1172
	cmp	al, 13
1173
	jz	.calcdone
1174
	cmp	al, 9
1175
	jz	.calctab
1176
	inc	ecx
1177
.calcnext:
1178
	call	editor_step_forward
1179
	jc	.calcloop
1180
	jmp	.calcdone
1181
.calctab:
1182
	mov	eax, ecx
1183
	xor	edx, edx
1184
	div	[editor_tabsize]
1185
	sub	edx, [editor_tabsize]
1186
	sub	ecx, edx
1187
	jmp	.calcnext
1188
.calcdone:
1189
	test	esi, esi
1190
	jnz	@f
1191
	mov	esi, [ebp + editor_data.last_block]
1192
	add	esi, ebp
1193
	mov	ebx, [esi + edit_block_header.limit]
1194
@@:
1195
	sub	esi, ebp
1196
	mov	[ebp + editor_data.cur_block], esi
1197
	mov	[ebp + editor_data.cur_offs], ebx
1198
	and	[ebp + editor_data.cur_delta], 0
1199
; ecx = number of symbols in the line
1200
; calculate new position of view range
1201
	mov	eax, [ebp + editor_data.curcol]
1202
	cmp	ecx, eax
1203
	jb	.toleft
1204
	add	eax, [cur_width]
1205
	cmp	ecx, eax
1206
	jae	.toright
1207
	sub	ecx, [ebp + editor_data.curcol]
1208
	mov	[ebp + editor_data.cursor_x], ecx
1209
	mov	[cursor_x], ecx
1210
	ret
1211
.toleft:
1212
	mov	[ebp + editor_data.curcol], ecx
1213
	and	[ebp + editor_data.cursor_x], 0
1214
	and	[cursor_x], 0
1215
	stc
1216
	ret
1217
.toright:
1218
	mov	eax, [cur_width]
1219
	dec	eax
1220
	sub	ecx, eax
1221
	mov	[ebp + editor_data.curcol], ecx
1222
	mov	[ebp + editor_data.cursor_x], eax
1223
	mov	[cursor_x], eax
1224
	stc
1225
	ret
1226
 
1227
editor_move_linestart:
1228
; in: esi = block, ebx = start offset, ecx = delta
1229
	lea	edi, [ebp + editor_data.linedata_start]
1230
	mov	edx, max_height
1231
.0:
1232
	cmp	[edi + editor_line.block], esi
1233
	jnz	.1
1234
	movzx	eax, [edi + editor_line.offs]
1235
	cmp	eax, ebx
1236
	ja	.2
1237
;	push	eax
1238
;	add	eax, [edi + editor_line.length]
1239
;	cmp	eax, ebx
1240
;	jb	@f
1241
;	add	[edi + editor_line.length], ecx
1242
;@@:
1243
;	pop	eax
1244
	cmp	eax, [esi + edit_block_header.limit]
1245
	jb	.1
1246
	push	esi ebx
1247
	mov	ebx, eax
1248
	jmp	.3
1249
.2:
1250
	push	esi ebx
1251
	mov	ebx, eax
1252
	add	ebx, ecx
1253
.3:
1254
	cmp	ebx, [esi + edit_block_header.limit]
1255
	jb	.4
1256
	cmp	[esi + edit_block_header.next], 0
1257
	jz	.4
1258
	sub	ebx, [esi + edit_block_header.limit]
1259
	mov	esi, [esi + edit_block_header.next]
1260
	add	esi, ebp
1261
	add	ebx, [EditBlockStart]
1262
	jmp	.3
1263
.4:
1264
	mov	[edi + editor_line.block], esi
1265
	mov	[edi + editor_line.offs], bx
1266
	pop	ebx esi
1267
.1:
1268
	add	edi, editor_line.plugdata
1269
	add	edi, [EditPlugInfo]
1270
	dec	edx
1271
	jnz	.0
1272
	;lea	edx, [ebp + editor_data.curpos_block]
1273
	;call	.5
1274
	;add	edx, editor_data.cur_block - editor_data.curpos_block
1275
	lea	edx, [ebp + editor_data.cur_block]
1276
;	call	.5
1277
;	ret
1278
.5:
1279
	mov	eax, [edx]
1280
	add	eax, ebp
1281
	cmp	eax, esi
1282
	jnz	.6
1283
	cmp	[edx+4], ebx
1284
	jbe	@f
1285
	add	[edx+4], ecx
1286
@@:
1287
	mov	eax, [edx+4]
1288
	sub	eax, [esi + edit_block_header.limit]
1289
	jb	.6
1290
	push	ecx
1291
	mov	ecx, [esi + edit_block_header.next]
1292
	add	ecx, ebp
1293
	add	eax, [EditBlockStart]
1294
	mov	[edx], ecx
1295
	mov	[edx+4], eax
1296
	pop	ecx
1297
.6:
1298
	ret
1299
 
1300
editor_reserve_symbol:
1301
	push	1
1302
	pop	ecx
1303
 
1304
editor_reserve_space:
1305
; ‚áâ ¢«ï¥â ¯ãá⮥ ¬¥áâ® ¢­ãâàì 楯®çª¨ ¡«®ª®¢
1306
; in: ecx = number of symbols to add, esi = block, ebx = offset
1307
	mov	eax, [esi + edit_block_header.limit]
1308
	add	eax, ecx
1309
	cmp	eax, 4096
1310
	ja	.add
1311
	mov	[esi + edit_block_header.limit], eax
1312
	push	esi ecx
1313
	sub	eax, ecx
1314
	lea	esi, [esi + eax - 1]
1315
	lea	edi, [esi + ecx]
1316
	sub	eax, ebx
1317
	mov	ecx, eax
1318
	std
1319
	rep	movsb
1320
	cld
1321
	pop	ecx esi
1322
	call	editor_move_linestart
1323
	clc
1324
	ret
1325
.add:
1326
	push	ecx
1327
	mov	eax, [esi + edit_block_header.limit]
1328
	sub	eax, [EditBlockStart]
1329
	add	eax, ecx
1330
	push	eax
1331
	xor	edx, edx
1332
	div	[EditBlockSize]
1333
	push	eax
1334
	sub	eax, [ebp + editor_data.numfree]
1335
	jbe	.norealloc
1336
	mov	edx, [ebp + editor_data.memsize]
1337
	push	eax edx
1338
	add	eax, edx
1339
	mov	ecx, eax
1340
	shl	ecx, 12
1341
	mov	edx, ebp
1342
	call	xpgrealloc
1343
	pop	edx ecx
1344
	test	eax, eax
1345
	jz	.nomem
1346
	add	[ebp + editor_data.memsize], ecx
1347
	sub	eax, ebp
1348
	add	ebp, eax
1349
	add	esi, eax
1350
	push	ecx
1351
	mov	ecx, max_height
1352
	lea	edi, [ebp + editor_data.linedata_start]
1353
@@:
1354
	add	[edi + editor_line.block], eax
1355
	add	edi, editor_line.plugdata
1356
	add	edi, [EditPlugInfo]
1357
	loop	@b
1358
	pop	ecx
1359
	shl	edx, 12
1360
	add	[ebp + editor_data.numfree], ecx
1361
	lea	edi, [edx + ebp]
1362
	mov	eax, [ebp + editor_data.freeblocks]
1363
	mov	[ebp + editor_data.freeblocks], edx
1364
@@:
1365
	add	edx, 1000h
1366
	mov	[edi], edx
1367
	add	edi, 1000h
1368
	loop	@b
1369
	mov	[edi-1000h], eax
1370
.norealloc:
1371
	pop	edx
1372
	push	[esi + edit_block_header.next]
1373
	push	esi
1374
	sub	[ebp + editor_data.numfree], edx
1375
	mov	edi, [ebp + editor_data.freeblocks]
1376
@@:
1377
	mov	[esi + edit_block_header.next], edi
1378
	add	edi, ebp
1379
	push	edi
1380
	push	dword [edi]
1381
	stosd	; edit_block_header.next - will be filled later
1382
	mov	eax, esi
1383
	sub	eax, ebp
1384
	stosd	; edit_block_header.prev
1385
	mov	eax, 4096 - edit.RESERVE_IN_BLOCK
1386
	stosd	; edit_block_header.limit
1387
	mov	eax, [EditBlockSize]
1388
	sub	[esp+16], eax
1389
	xor	eax, eax
1390
	mov	ecx, [EditPlugInfo]
1391
	rep	stosb
1392
	pop	edi
1393
	pop	esi
1394
	dec	edx
1395
	jnz	@b
1396
	mov	[ebp + editor_data.freeblocks], edi
1397
	mov	edi, esi
1398
	pop	esi
1399
	pop	[edi + edit_block_header.next]
1400
	pop	ecx
1401
	add	ecx, [EditBlockSize]
1402
	mov	edx, ecx
1403
	shr	edx, 1;2
1404
	mov	eax, ecx
1405
	sub	eax, edx
1406
	cmp	eax, [EditBlockSize]
1407
	jb	@f
1408
	mov	eax, [EditBlockSize]
1409
	mov	edx, ecx
1410
	sub	edx, eax
1411
@@:
1412
	add	eax, [EditBlockStart]
1413
	add	edx, [EditBlockStart]
1414
	mov	ecx, [esi + edit_block_header.limit]
1415
	mov	[esi + edit_block_header.limit], eax
1416
	mov	[edi + edit_block_header.limit], edx
1417
	sub	ecx, ebx
1418
	push	ecx
1419
	push	esi edi ecx
1420
	add	esi, ecx
1421
	add	esi, ebx
1422
	push	edx
1423
	sub	edx, [EditBlockStart]
1424
	cmp	ecx, edx
1425
	jb	@f
1426
	mov	ecx, edx
1427
@@:
1428
	pop	edx
1429
	sub	[esp], ecx
1430
	add	edi, edx
1431
	sub	esi, ecx
1432
	sub	edi, ecx
1433
	rep	movsb
1434
	pop	ecx edi esi
1435
	push	esi edi
1436
	lea	edi, [esi + eax - 1]
1437
	add	esi, ebx
1438
	lea	esi, [esi + ecx - 1]
1439
	std
1440
	rep	movsb
1441
	cld
1442
	pop	edi esi
1443
	pop	ecx
1444
	mov	ecx, ebx
1445
	sub	ecx, eax
1446
	jb	@f
1447
	push	esi edi
1448
	add	esi, eax
1449
	add	edi, [EditBlockStart]
1450
	rep	movsb
1451
	pop	edi esi
1452
@@:
1453
	push	esi edi
1454
	sub	esi, ebp
1455
	sub	edi, ebp
1456
	cmp	[ebp + editor_data.last_block], esi
1457
	jnz	@f
1458
	mov	[ebp + editor_data.last_block], edi
1459
@@:
1460
	pop	edi esi
1461
	pop	ecx
1462
	call	editor_move_linestart
1463
	cmp	ebx, [esi + edit_block_header.limit]
1464
	jb	@f
1465
	sub	ebx, [esi + edit_block_header.limit]
1466
	mov	esi, [esi + edit_block_header.next]
1467
	add	esi, ebp
1468
	add	ebx, [EditBlockStart]
1469
@@:
1470
	clc
1471
	ret
1472
.nomem:
1473
	pop	eax
1474
	pop	ecx
1475
	pop	ecx
1476
	add	esi, ebp
1477
	stc
1478
	ret
1479
 
1480
editor_delete_symbol:
1481
	push	1
1482
	pop	ecx
1483
 
1484
editor_delete_space:
1485
; “¤ «ï¥â ecx ¡ ©â ¨§ ⥪áâ , ­ ç¨­ ï á esi:ebx
1486
; ecx, esi, ebx à §àãè îâáï
1487
	mov	eax, [esi + edit_block_header.limit]
1488
	sub	eax, ebx
1489
	cmp	eax, ecx
1490
	jb	.more1
1491
	push	esi
1492
	sub	[esi + edit_block_header.limit], ecx
1493
	sub	eax, ecx
1494
	lea	edi, [esi+ebx]
1495
	lea	esi, [edi+ecx]
1496
	mov	ecx, eax
1497
	rep	movsb
1498
	pop	esi
1499
.done:
1500
	call	.collapse_prev
1501
	call	.collapse_next
1502
	call	editor_init_lines
1503
	jmp	editor_update_cur
1504
.more1:
1505
	mov	[esi + edit_block_header.limit], ebx
1506
	sub	ecx, eax
1507
@@:
1508
	mov	esi, [esi + edit_block_header.next]
1509
	add	esi, ebp
1510
	mov	eax, [esi + edit_block_header.limit]
1511
	sub	eax, [EditBlockStart]
1512
	sub	ecx, eax
1513
	jb	@f
1514
	call	.delete_block
1515
	jmp	@b
1516
@@:
1517
	add	ecx, eax
1518
	push	esi
1519
	mov	eax, [esi + edit_block_header.limit]
1520
	sub	[esi + edit_block_header.limit], ecx
1521
	add	eax, esi
1522
	add	esi, [EditBlockStart]
1523
	mov	edi, esi
1524
	add	esi, ecx
1525
	sub	eax, esi
1526
	mov	ecx, esi
1527
	rep	movsb
1528
	pop	esi
1529
	call	.collapse_next
1530
	mov	esi, [esi + edit_block_header.prev]
1531
	add	esi, ebp
1532
	jmp	.done
1533
 
1534
.delete_block:
1535
	mov	eax, [esi + edit_block_header.next]
1536
	mov	edx, [esi + edit_block_header.prev]
1537
	test	eax, eax
1538
	jz	.dbfirst
1539
	mov	[eax + ebp + edit_block_header.prev], edx
1540
	jmp	@f
1541
.dbfirst:
1542
	mov	[ebp + editor_data.first_block], edx
1543
@@:
1544
	test	edx, edx
1545
	jz	.dblast
1546
	mov	[edx + ebp + edit_block_header.next], eax
1547
	jmp	@f
1548
.dblast:
1549
	mov	[ebp + editor_data.last_block], eax
1550
@@:
1551
	mov	eax, [ebp + editor_data.freeblocks]
1552
	mov	[esi], eax
1553
	sub	esi, ebp
1554
	mov	[ebp + editor_data.freeblocks], esi
1555
	inc	[ebp + editor_data.numfree]
1556
	ret
1557
 
1558
.collapse_prev:
1559
	mov	eax, [esi + edit_block_header.prev]
1560
	test	eax, eax
1561
	jz	.cpno
1562
	add	eax, ebp
1563
	mov	edx, [esi + edit_block_header.limit]
1564
	sub	edx, [EditBlockStart]
1565
	add	edx, [eax + edit_block_header.limit]
1566
	cmp	edx, 4096 - edit.RESERVE_IN_BLOCK
1567
	ja	.cpno
1568
	mov	edi, eax
1569
.collapse:	; (edi) + (esi) -> (edi)
1570
	push	edi
1571
	push	esi
1572
	mov	ecx, [esi + edit_block_header.limit]
1573
	sub	ecx, [EditBlockStart]
1574
	add	esi, [EditBlockStart]
1575
	mov	eax, [edi + edit_block_header.limit]
1576
	add	[edi + edit_block_header.limit], ecx
1577
	add	edi, eax
1578
	rep	movsb
1579
	pop	esi
1580
	call	.delete_block
1581
	pop	esi
1582
.cpno:
1583
	ret
1584
.collapse_next:
1585
	mov	eax, [esi + edit_block_header.next]
1586
	test	eax, eax
1587
	jz	.cpno
1588
	add	eax, ebp
1589
	mov	edx, [esi + edit_block_header.limit]
1590
	sub	edx, [EditBlockStart]
1591
	add	edx, [eax + edit_block_header.limit]
1592
	cmp	edx, 4096 - edit.RESERVE_IN_BLOCK
1593
	ja	.cpno
1594
	mov	edi, esi
1595
	mov	esi, eax
1596
	jmp	.collapse
1597
 
1598
editor_OnKey:
1599
	test	al, 80h
1600
	jnz	.ret
1601
	test	[ebp + editor_data.flags], 20h
1602
	jnz	.symbol
1603
	mov	esi, editor_ctrlkeys
1604
	call	process_ctrl_keys
1605
	jnc	.ret
1606
.symbol:
1607
	and	[ebp + editor_data.flags], not 20h
1608
	test	[ebp + editor_data.flags], 40h
1609
	jnz	.ret
1610
	or	[ebp + editor_data.flags], 80h
1611
	movzx	eax, al
1612
	call	get_ascii_char
1613
	mov	esi, [ebp + editor_data.cur_block]
1614
	add	esi, ebp
1615
	mov	ebx, [ebp + editor_data.cur_offs]
1616
	cmp	al, 10
1617
	jz	.insert_newline
1618
	cmp	al, 13
1619
	jz	.insert_newline
1620
	cmp	[ebp + editor_data.cur_delta], -1
1621
	jnz	.insert_after_eol
1622
	test	[ebp + editor_data.flags], 10h
1623
	jnz	.replace_symbol
1624
	push	eax
1625
	call	editor_reserve_symbol
1626
	pop	eax
1627
	jc	.ret
1628
.replace_symbol:
1629
	cmp	ebx, [esi + edit_block_header.limit]
1630
	jnz	@f
1631
	mov	esi, [esi + edit_block_header.next]
1632
	add	esi, ebp
1633
	mov	ebx, [EditBlockStart]
1634
@@:
1635
	mov	[esi + ebx], al
1636
.symb_inserted:
1637
	call	.redraw_curline
1638
	jmp	.right
1639
.redraw_curline:
1640
	call	editor_curline_start
1641
	mov	edx, [cursor_y]
1642
	call	editor_draw_line
1643
.ret:
1644
	ret
1645
.insert_after_eol:
1646
	mov	ecx, [ebp + editor_data.cur_delta]
1647
	inc	ecx
1648
	push	eax
1649
	call	editor_reserve_space
1650
	pop	eax
1651
	jc	.ret
1652
	push	eax
1653
	mov	edx, ecx
1654
.2:
1655
	mov	ecx, [esi + edit_block_header.limit]
1656
	sub	ecx, ebx
1657
	lea	edi, [esi + ebx]
1658
	cmp	ecx, edx
1659
	jb	@f
1660
	mov	ecx, edx
1661
@@:
1662
	add	ebx, ecx
1663
	sub	edx, ecx
1664
	mov	al, ' '
1665
	rep	stosb
1666
	jz	@f
1667
	mov	esi, [esi + edit_block_header.next]
1668
	add	esi, ebp
1669
	mov	ebx, [EditBlockStart]
1670
	jmp	.2
1671
@@:
1672
	pop	eax
1673
	mov	[edi-1], al
1674
	dec	ebx
1675
	sub	esi, ebp
1676
	mov	[ebp + editor_data.cur_block], esi
1677
	mov	[ebp + editor_data.cur_offs], ebx
1678
	or	[ebp + editor_data.cur_delta], -1
1679
	jmp	.symb_inserted
1680
.insert_newline:
1681
	push	1
1682
	pop	ecx
1683
	cmp	[ebp + editor_data.eol], 2
1684
	adc	ecx, 0
1685
	call	editor_reserve_space
1686
	jc	.ret
1687
; à®áâ® â ª ¢áâ ¢«ïâì ᨬ¢®« ­®¢®© áâப¨ çॢ â® - ¨§-§  áãé¥á⢮¢ ­¨ï ¤¢ãå¡ ©â®¢ëå ª®¬¡¨­ æ¨© ¯¥à¥¢®¤  áâப¨
1688
; áâ àë© á¨¬¢®« ¬®¦¥â ᫨âìáï á ­®¢ë¬. ‚ â ª®¬ á«ãç ¥ ¯à¨¤ñâáï § ­¨¬ âìáï ª®à४â¨à®¢ª®©.
1689
; ஡«¥¬  ¡ë¢ ¥â ¢ ¤¢ãå á«ãç ïå:
1690
; ¥á«¨ । ªâ®à ­ áâ஥­ ­  Unix-áâ¨«ì ¨ ­®¢ë© ¯¥à¥¢®¤ áâப¨ ¢áâ ¢«ï¥âáï ­¥¯®á।á⢥­­® ¯®á«¥
1691
;	¯¥à¥¢®¤  áâப¨ ¢ Mac-á⨫¥;
1692
; ¥á«¨ । ªâ®à ­ áâ஥­ ­  Mac-áâ¨«ì ¨ ­®¢ë© ¯¥à¥¢®¤ áâப¨ ¢áâ ¢«ï¥âáï ­¥¯®á।á⢥­­® ¯¥à¥¤
1693
;	¯¥à¥¢®¤®¬ áâப¨ ¢ Unix-á⨫¥.
1694
; ‚ íâ¨å á«ãç ïå ä®àá¨à㥬 ¯¥à¥¢®¤ áâப¨ ¢ ⥪ã饬 á⨫¥ ä ©« .
1695
	mov	al, [ebp + editor_data.eol]
1696
	cmp	al, edit.eol_dos
1697
	jz	.insert_eol_dos
1698
	cmp	al, edit.eol_mac
1699
	jz	.insert_eol_mac
1700
	mov	al, 10	; Unix-style for end-of-line
1701
	push	esi ebx
1702
	call	editor_step_backward
1703
	jc	@f
1704
	cmp	byte [esi+ebx], 13
1705
	jnz	@f
1706
	mov	al, 13	; force Mac-style to avoid collapse
1707
@@:
1708
	pop	ebx esi
1709
	mov	[esi+ebx], al
1710
	jmp	.eol_correct
1711
.insert_eol_mac:
1712
	mov	al, 13	; Mac-style for end-of-line
1713
	push	esi ebx
1714
	call	editor_step_forward
1715
	jnc	@f
1716
	cmp	byte [esi+ebx], 10
1717
	jnz	@f
1718
	mov	al, 10	; force Unix-style to avoid collapse
1719
@@:
1720
	pop	ebx esi
1721
	mov	[esi+ebx], al
1722
	jmp	.eol_correct
1723
.insert_eol_dos:
1724
	mov	byte [esi+ebx], 13
1725
	call	editor_step_forward
1726
	mov	byte [esi+ebx], 10
1727
.eol_correct:
1728
	call	editor_step_forward
1729
	test	esi, esi
1730
	jnz	@f
1731
	mov	esi, [ebp + editor_data.last_block]
1732
	add	esi, ebp
1733
	mov	ebx, [esi + edit_block_header.limit]
1734
@@:
1735
	and	[ebp + editor_data.cur_delta], 0
1736
	cmp	ebx, [esi + edit_block_header.limit]
1737
	jz	@f
1738
	mov	al, [esi+ebx]
1739
	cmp	al, 10
1740
	jz	@f
1741
	cmp	al, 13
1742
	jz	@f
1743
	dec	[ebp + editor_data.cur_delta]
1744
@@:
1745
; ­ã çâ® ¦¥, ¢ ⥪áâ ­ã¦­ë¥ á¨¬¢®«ë ¢áâ ¢¨«¨, ⥯¥àì ­ ¤® ᪮à४â¨à®¢ âì ¨­ä®à¬ æ¨î ® ­ ç «¥ áâப ­  íªà ­¥
1746
	mov	edi, [ebp + editor_data.cursor_y]
1747
	mov	ecx, max_height-1
1748
	sub	ecx, edi
1749
	dec	edi
1750
	mov	eax, [EditPlugInfo]
1751
	add	eax, editor_line.plugdata
1752
	imul	edi, eax, max_height
1753
	imul	ecx, eax
1754
	lea	edi, [ebp + edi + editor_data.linedata_start - 2]
1755
	push	esi
1756
	mov	esi, edi
1757
	sub	esi, eax
1758
	shr	ecx, 1
1759
	std
1760
	rep	movsw
1761
	cld
1762
	pop	esi
1763
	add	edi, 2
1764
	sub	edi, eax
1765
	push	esi
1766
	mov	esi, edi
1767
	sub	esi, eax
1768
	pop	eax
1769
	stosd	; editor_line.block
1770
	sub	eax, ebp
1771
	mov	[ebp + editor_data.cur_block], eax
1772
	mov	eax, ebx
1773
	stosw	; editor_line.offs
1774
	mov	[ebp + editor_data.cur_offs], eax
1775
	;mov	eax, ecx
1776
	;stosd	; editor_line.length
1777
	mov	ecx, [EditPlugInfo]
1778
	xor	eax, eax
1779
	rep	stosb
1780
; ­  ®¤­ã áâபã áâ «® ¡®«ìè¥
1781
	inc	[ebp + editor_data.numlines]
1782
; ªãàá®à ®ª ¦¥âáï ¢ ­ ç «¥ áâப¨
1783
	mov	[ebp + editor_data.cursor_x], eax
1784
	mov	[ebp + editor_data.curcol], eax
1785
	mov	[cursor_x], eax
1786
; ¨ ¯¥à¥¤¢¨­¥âáï ­  áâப㠭¨¦¥
1787
	mov	eax, [ebp + editor_data.cursor_y]
1788
	inc	eax
1789
	mov	edx, [cur_height]
1790
	dec	edx
1791
	cmp	eax, edx
1792
	jae	.down_scroll
1793
	mov	[ebp + editor_data.cursor_y], eax
1794
	mov	[cursor_y], eax
1795
	jmp	editor_draw_text
1796
 
1797
.exit_confirm:
1798
	test	[ebp + editor_data.flags], 80h
1799
	jz	.exit
1800
	push	aFileModified
1801
	mov	eax, esp
1802
	push	EditorExitBtn
1803
	push	3
1804
	push	eax
1805
	push	1
1806
	push	aEditorTitle
1807
	call	SayErrTitle
1808
	pop	ecx
1809
	test	eax, eax
1810
	jz	.save
1811
	dec	eax
1812
	jz	.exit
1813
	ret
1814
.exit_save:
1815
	test	[ebp + editor_data.flags], 80h
1816
	jz	.exit
1817
.save:
1818
	call	editor_save
1819
.exit:
1820
	call	editor_OnExit
1821
	jmp	delete_active_screen
1822
.f2:
1823
	call	editor_save
1824
	jmp	.redraw_status
1825
 
1826
.up_scroll:
1827
	cmp	[ebp + editor_data.curline], 0
1828
	jz	.ret
1829
	push	1
1830
	pop	ecx
1831
	call	editor_up_scroll
1832
	jmp	editor_draw_text
1833
.up:
1834
	mov	eax, [ebp + editor_data.cursor_y]
1835
	dec	eax
1836
	jz	.up_scroll
1837
.set_cursor_y:
1838
	mov	[ebp + editor_data.cursor_y], eax
1839
	mov	[cursor_y], eax
1840
	call	editor_update_cur
1841
	test	al, al
1842
	jnz	editor_draw_text
1843
.redraw_status:
1844
	call	editor_draw_status
1845
	jmp	draw_image
1846
.down:
1847
	mov	eax, [ebp + editor_data.cursor_y]
1848
	inc	eax
1849
	push	eax
1850
	add	eax, [ebp + editor_data.curline]
1851
	cmp	eax, [ebp + editor_data.numlines]
1852
	pop	eax
1853
	ja	.ret
1854
	mov	edx, [cur_height]
1855
	dec	edx
1856
	cmp	eax, edx
1857
	jnz	.set_cursor_y
1858
.down_scroll:
1859
	inc	[ebp + editor_data.curline]
1860
	lea	edi, [ebp + editor_data.linedata_start]
1861
	mov	eax, [EditPlugInfo]
1862
	add	eax, editor_line.plugdata
1863
	lea	esi, [edi + eax]
1864
	imul	ecx, eax, max_height-1
1865
	shr	ecx, 2
1866
	rep	movsd
1867
	adc	ecx, ecx
1868
	rep	movsw
1869
	sub	esi, eax
1870
	sub	esi, eax
1871
	movzx	ebx, [esi + editor_line.offs]
1872
	mov	esi, [esi + editor_line.block]
1873
	call	editor_find_newline
1874
	mov	eax, esi
1875
	stosd	; editor_line.block
1876
	mov	eax, ebx
1877
	stosw	; editor_line.offs
1878
	;mov	eax, ecx
1879
	;stosd	; editor_line.length
1880
	mov	ecx, [EditPlugInfo]
1881
	xor	eax, eax
1882
	rep	stosb
1883
	jmp	.ret2
1884
 
1885
.pgup:
1886
	mov	ecx, [cur_height]
1887
	sub	ecx, 3
1888
	mov	edx, [ebp + editor_data.curline]
1889
	mov	eax, edx
1890
	push	edx
1891
	sub	edx, ecx
1892
	jnc	@f
1893
	xor	edx, edx
1894
@@:
1895
	mov	[ebp + editor_data.curline], edx
1896
	add	eax, [ebp + editor_data.cursor_y]
1897
	dec	eax
1898
	sub	eax, ecx
1899
	jnc	@f
1900
	xor	eax, eax
1901
@@:
1902
	sub	eax, edx
1903
	inc	eax
1904
	mov	[ebp + editor_data.cursor_y], eax
1905
	mov	[cursor_y], eax
1906
	pop	ecx
1907
	sub	ecx, edx
1908
	push	ecx
1909
	mov	edx, [EditPlugInfo]
1910
	add	edx, editor_line.plugdata
1911
	imul	ecx, edx
1912
	imul	eax, edx, max_height
1913
	lea	edi, [ebp + editor_data.linedata_start + eax - 2]
1914
	mov	esi, edi
1915
	sub	esi, ecx
1916
	sub	eax, ecx
1917
	mov	ecx, eax
1918
	shr	ecx, 1
1919
	std
1920
	rep	movsw
1921
	cld
1922
	pop	ecx
1923
	jecxz	.ret2
1924
	inc	edi
1925
	inc	edi
1926
	mov	esi, [edi + editor_line.block]
1927
	movzx	ebx, [edi + editor_line.offs]
1928
@@:
1929
	push	ecx
1930
	call	editor_prev_newline
1931
	sub	edi, edx
1932
	push	edi
1933
	mov	eax, esi
1934
	stosd	; editor_line.block
1935
	mov	eax, ebx
1936
	stosw	; editor_line.offs
1937
	;mov	eax, ecx
1938
	;stosd	; editor_line.length
1939
	mov	ecx, [EditPlugInfo]
1940
	xor	eax, eax
1941
	rep	stosb
1942
	pop	edi
1943
	pop	ecx
1944
	loop	@b
1945
.ret2:
1946
	call	editor_update_cur
1947
	jmp	editor_draw_text
1948
.pgdn:
1949
	mov	edx, [cur_height]
1950
	sub	edx, 2
1951
	mov	ecx, [ebp + editor_data.curline]
1952
	push	ecx
1953
	lea	ecx, [edx + ecx - 1]
1954
	mov	eax, [ebp + editor_data.numlines]
1955
	sub	eax, edx
1956
	jnc	@f
1957
	xor	eax, eax
1958
@@:
1959
	cmp	ecx, eax
1960
	jb	@f
1961
	mov	ecx, eax
1962
@@:
1963
	mov	[ebp + editor_data.curline], ecx
1964
	pop	eax
1965
	push	eax
1966
	add	eax, [ebp + editor_data.cursor_y]
1967
	lea	eax, [eax + edx - 1]
1968
	cmp	eax, [ebp + editor_data.numlines]
1969
	jb	@f
1970
	mov	eax, [ebp + editor_data.numlines]
1971
@@:
1972
	sub	eax, ecx
1973
	mov	[ebp + editor_data.cursor_y], eax
1974
	mov	[cursor_y], eax
1975
	pop	edx
1976
	sub	ecx, edx
1977
	call	editor_down_scroll
1978
	jmp	.ret2
1979
 
1980
.left:
1981
	call	editor_cursor_left
997 diamond 1982
	jnc	.redraw_status
814 diamond 1983
	jmp	editor_draw_text
1984
.ret3:
1985
	ret
1986
 
1987
.right:
1988
	cmp	[ebp + editor_data.cur_delta], -1
1989
	jz	.right_in_text
1990
	cmp	[ebp + editor_data.curcol], 0x80000000 - 0x1000
1991
	jae	.ret3
1992
	inc	[ebp + editor_data.cur_delta]
1993
	push	1
1994
	pop	edx
1995
	jmp	.right_char
1996
.right_in_text:
1997
	mov	esi, [ebp + editor_data.cur_block]
1998
	add	esi, ebp
1999
	mov	ebx, [ebp + editor_data.cur_offs]
2000
	mov	al, [esi + ebx]
2001
	push	eax
2002
	call	editor_step_forward
2003
	test	esi, esi
2004
	jz	.right_eol0
2005
	mov	al, [esi + ebx]
2006
	cmp	al, 10
2007
	jz	.right_eol
2008
	cmp	al, 13
2009
	jz	.right_eol
2010
	jmp	.right_ok
2011
.right_eol0:
2012
	mov	esi, [ebp + editor_data.last_block]
2013
	add	esi, ebp
2014
	mov	ebx, [esi + edit_block_header.limit]
2015
.right_eol:
2016
	inc	[ebp + editor_data.cur_delta]
2017
.right_ok:
2018
	sub	esi, ebp
2019
	mov	[ebp + editor_data.cur_block], esi
2020
	mov	[ebp + editor_data.cur_offs], ebx
2021
	pop	eax
2022
	push	1
2023
	pop	edx
2024
	cmp	al, 9
2025
	jnz	.right_char
2026
	mov	eax, [ebp + editor_data.curcol]
2027
	add	eax, [ebp + editor_data.cursor_x]
2028
	xor	edx, edx
2029
	div	[editor_tabsize]
2030
	sub	edx, [editor_tabsize]
2031
	neg	edx
2032
.right_char:
2033
	mov	eax, [ebp + editor_data.cursor_x]
2034
	add	eax, edx
2035
	cmp	eax, [cur_width]
2036
	jb	.set_cursor_x
2037
	add	eax, [ebp + editor_data.curcol]
2038
	mov	edx, [cur_width]
2039
	dec	edx
2040
	sub	eax, edx
2041
	mov	[ebp + editor_data.cursor_x], edx
2042
	mov	[cursor_x], edx
2043
	mov	[ebp + editor_data.curcol], eax
2044
	jmp	editor_draw_text
2045
.set_cursor_x:
2046
	mov	[ebp + editor_data.cursor_x], eax
2047
	mov	[cursor_x], eax
2048
	jmp	.redraw_status
2049
 
2050
.home:
2051
	call	editor_curline_start
2052
	and	[ebp + editor_data.cur_delta], 0
2053
	cmp	ebx, [esi + edit_block_header.limit]
2054
	jz	@f
2055
	mov	al, [esi+ebx]
2056
	cmp	al, 10
2057
	jz	@f
2058
	cmp	al, 13
2059
	jz	@f
2060
	dec	[ebp + editor_data.cur_delta]
2061
@@:
2062
	sub	esi, ebp
2063
	mov	[ebp + editor_data.cur_block], esi
2064
	mov	[ebp + editor_data.cur_offs], ebx
2065
	xor	eax, eax
2066
	mov	[ebp + editor_data.cursor_x], eax
2067
	mov	[cursor_x], eax
2068
	xchg	eax, [ebp + editor_data.curcol]
2069
	test	eax, eax
2070
	jnz	editor_draw_text
2071
	jmp	.redraw_status
2072
 
2073
.end:
2074
	call	editor_end_scroll
2075
	jc	editor_draw_text
2076
	jmp	.redraw_status
2077
 
2078
.ins:
2079
	xor	[ebp + editor_data.flags], 10h
2080
	mov	eax, cursor_normal_size
2081
	test	[ebp + editor_data.flags], 10h
2082
	jz	@f
2083
	mov	eax, cursor_big_size
2084
@@:
2085
	mov	[cursor_size], eax
2086
	jmp	draw_image
2087
 
2088
.backspace:
2089
	cmp	[ebp + editor_data.cur_delta], -1
2090
	jz	@f
2091
	cmp	[ebp + editor_data.cur_delta], 0
2092
	jnz	.left
2093
@@:
2094
	test	[ebp + editor_data.flags], 40h
2095
	jnz	.ret3
2096
	mov	esi, [ebp + editor_data.cur_block]
2097
	add	esi, ebp
2098
	mov	ebx, [ebp + editor_data.cur_offs]
2099
	call	editor_step_backward
2100
	jc	.ret3
2101
	push	esi ebx
2102
	call	editor_cursor_left
2103
	pop	ebx esi
2104
	setc	al
2105
	push	eax
2106
	push	esi ebx
2107
	cmp	byte [esi+ebx], 10
2108
	jnz	@f
2109
	call	editor_step_backward
2110
	jc	@f
2111
	cmp	byte [esi+ebx], 13
2112
	jnz	@f
2113
	pop	eax eax
2114
	jmp	.del_char
2115
@@:
2116
	pop	ebx esi
2117
	jmp	.del_char
2118
.del:
2119
	test	[ebp + editor_data.flags], 40h
2120
	jnz	.ret3
2121
	mov	esi, [ebp + editor_data.cur_block]
2122
	add	esi, ebp
2123
	mov	ebx, [ebp + editor_data.cur_offs]
2124
	call	editor_normalize_offs
2125
	jnc	.ret3
2126
	push	0
2127
.del_char:
2128
	or	[ebp + editor_data.flags], 80h
2129
	mov	al, [esi+ebx]
2130
	push	1
2131
	pop	ecx
2132
	push	eax
2133
	push	esi ebx
2134
	cmp	al, 13
2135
	jnz	@f
2136
	call	editor_step_forward
2137
	jnc	@f
2138
	cmp	byte [esi+ebx], 10
2139
	jnz	@f
2140
	inc	ecx
2141
@@:
2142
	pop	ebx esi
2143
	call	editor_delete_space
2144
	pop	eax
2145
	cmp	al, 13
2146
	jz	@f
2147
	cmp	al, 10
2148
	jz	@f
2149
	pop	eax
2150
	test	al, al
2151
	jnz	.del1
2152
	call	.redraw_curline
2153
	jmp	.redraw_status
2154
@@:
2155
	pop	eax
2156
	dec	[ebp + editor_data.numlines]
2157
	call	editor_test_cursor_y
2158
.del1:
2159
	jmp	editor_draw_text
2160
 
997 diamond 2161
.f7:
2162
	call	find_in_file_dlg
2163
	jz	.shift_f7
2164
.f7.ret:
2165
	ret
2166
.shift_f7:
2167
; search string SearchString in file starting from current cursor position
2168
	mov	ebx, SearchString
2169
	xor	eax, eax
2170
	cmp	byte [ebx], al
2171
	jz	.f7.ret
2172
	mov	esi, tolower_table
2173
	test	[find_in_file_dlgdata.flags_case], 10h
2174
	jz	@f
2175
	mov	esi, identical_table
2176
@@:
2177
	test	[find_in_file_dlgdata.flags_whole], 10h
2178
	setnz	al
2179
	push	eax
2180
	push	dword [ebp+editor_data.encoding]; always cp866 for now
2181
				; needs to be revisited after Unicode support in editor
2182
	call	search_string_pre
2183
	mov	esi, [ebp + editor_data.cur_block]
2184
	add	esi, ebp
2185
	mov	ebx, [ebp + editor_data.cur_offs]
2186
	call	editor_normalize_offs
2187
	jnc	.f7.notfound
2188
	xor	edi, edi
2189
	push	ebx esi
2190
	push	edi
2191
	push	edi
2192
	test	[find_in_file_dlgdata.flags_whole], 10h
2193
	jnz	@f
2194
	movzx	eax, byte [esi+ebx]
2195
	jmp	.search_loop_next
2196
@@:
2197
	mov	edi, edx
2198
.search_loop:
2199
; edx -> FSM, ecx = last state, esi:ebx -> current data,
2200
; edi = current state
2201
; [esp] = row, [esp+4] = delta in lines
2202
; get current symbol
2203
	movzx	eax, byte [esi+ebx]
2204
; calculate next state
2205
	movzx	edi, byte [edi+eax]
2206
; done?
2207
	cmp	edi, ecx
2208
	jz	.f7.found
2209
.search_loop_next:
2210
; no; proceed to next symbol
2211
	add	ebx, 1
2212
	shl	edi, 8
2213
	add	dword [esp], 1
2214
	add	edi, edx
2215
	cmp	ebx, [esi + edit_block_header.limit]
2216
	jae	.f7.nextblock
2217
.f7.nonextblock:
2218
	cmp	al, 10
2219
	jz	.f7.newline
2220
	cmp	al, 13
2221
	jnz	.search_loop
2222
	cmp	byte [esi+ebx], 10
2223
	jnz	.f7.newline
2224
	call	editor_step_forward
2225
	jnc	.f7.notfound_pop
2226
.f7.newline:
2227
	mov	dword [esp], 0
2228
	add	dword [esp+4], 1
2229
	mov	dword [esp+8], esi
2230
	mov	dword [esp+12], ebx
2231
	jmp	.search_loop
2232
.f7.nextblock:
2233
	call	editor_normalize_offs
2234
	jc	.f7.nonextblock
2235
.f7.notfound_pop:
2236
; last chance - if we are looking for a whole word, EOF is ok for last symbol
2237
	test	[find_in_file_dlgdata.flags_whole], 10h
2238
	jz	@f
2239
	mov	esi, [ebp + editor_data.last_block]
2240
	add	esi, ebp
2241
	mov	ebx, [esi + edit_block_header.limit]
2242
	movzx	edi, byte [edi+' ']
2243
	cmp	edi, ecx
2244
	jz	.f7.found
2245
@@:
2246
	add	esp, 10h
2247
.f7.notfound:
2248
	jmp	search_failed
2249
.f7.found:
2250
	or	[ebp + editor_data.cur_delta], -1
2251
	sub	ebx, ecx
2252
	inc	ebx
2253
	test	[find_in_file_dlgdata.flags_whole], 10h
2254
	jz	@f
2255
	inc	ebx
2256
@@:
2257
	cmp	ebx, [EditBlockStart]
2258
	jge	@f
2259
	sub	ebx, [EditBlockStart]
2260
	mov	esi, [esi + edit_block_header.prev]
2261
	add	esi, ebp
2262
	add	ebx, [esi + edit_block_header.limit]
2263
	jmp	@b
2264
@@:
2265
	sub	esi, ebp
2266
	mov	[ebp + editor_data.cur_block], esi
2267
	add	esi, ebp
2268
	mov	[ebp + editor_data.cur_offs], ebx
2269
	push	ecx
2270
	mov	ecx, edx
2271
	call	pgfree
2272
	pop	ecx
2273
	pop	eax
2274
	pop	edi
2275
; esi:ebx -> last symbol of match, eax = row, edi = delta in lines
2276
	pop	esi ebx
2277
	test	[find_in_file_dlgdata.flags_whole], 10h
2278
	jz	@f
2279
	dec	ecx
2280
@@:
2281
	push	ebx esi
2282
	sub	eax, ecx
2283
	lea	edx, [eax+1]
2284
	mov	eax, [ebp + editor_data.curcol]
2285
	add	eax, [ebp + editor_data.cursor_x]
2286
	test	edi, edi
2287
	jz	@f
2288
	xor	eax, eax
2289
@@:
2290
	test	edx, edx
2291
	jz	.f7.foundpos1
2292
.f7.findpos1:
2293
	cmp	byte [ebx+esi], 9
2294
	jz	.f7.findpos1.tab
2295
	inc	eax
2296
	call	editor_step_forward
2297
	dec	edx
2298
	jnz	.f7.findpos1
2299
	jmp	.f7.foundpos1
2300
.f7.findpos1.tab:
2301
	push	edx eax
2302
	xor	edx, edx
2303
	div	[editor_tabsize]
2304
	pop	eax
2305
	sub	edx, [editor_tabsize]
2306
	sub	eax, edx
2307
	call	editor_step_forward
2308
	pop	edx
2309
	dec	edx
2310
	jnz	.f7.findpos1
2311
.f7.foundpos1:
2312
	pop	esi ebx
2313
	push	eax
2314
	cmp	eax, [ebp + editor_data.curcol]
2315
	jb	.f7.scrollleft
2316
	sub	eax, [ebp + editor_data.curcol]
2317
	sub	eax, [cur_width]
2318
	jb	.f7.xset
2319
	inc	eax
2320
	inc	edx
2321
	add	[ebp + editor_data.curcol], eax
2322
	jmp	.f7.xset
2323
.f7.scrollleft:
2324
	inc	edx
2325
	mov	[ebp + editor_data.curcol], eax
2326
.f7.xset:
2327
	pop	eax
2328
	push	edx
2329
	sub	eax, [ebp + editor_data.curcol]
2330
	mov	[ebp + editor_data.cursor_x], eax
2331
	mov	[cursor_x], eax
2332
	add	edi, [ebp + editor_data.cursor_y]
2333
	push	edi
2334
	inc	edi
2335
	cmp	edi, [cur_height]
2336
	pop	edi
2337
	jae	.f7.newview
2338
	mov	[ebp + editor_data.cursor_y], edi
2339
	mov	[cursor_y], edi
2340
	jmp	.f7.yset
2341
.f7.newview:
2342
	dec	edi
2343
	mov	[ebp + editor_data.linedata_start + editor_line.block], esi
2344
	mov	[ebp + editor_data.linedata_start + editor_line.offs], bx
2345
	add	[ebp + editor_data.curline], edi
2346
	xor	eax, eax
2347
	inc	eax
2348
	mov	[ebp + editor_data.cursor_y], eax
2349
	mov	[cursor_y], eax
2350
	call	editor_init_lines
2351
	call	editor_test_cursor_y
2352
	inc	dword [esp]
2353
.f7.yset:
2354
	pop	eax
2355
	test	eax, eax
2356
	jz	.redraw_status
2357
	jmp	editor_draw_text
2358
 
814 diamond 2359
editor_cursor_left:
2360
	cmp	[ebp + editor_data.cur_delta], -1
2361
	jz	.in_text
2362
	dec	[ebp + editor_data.cur_delta]
2363
	cmp	[ebp + editor_data.cur_delta], -1
2364
	jnz	.left_cursor
2365
.in_text:
2366
	mov	esi, [ebp + editor_data.cur_block]
2367
	add	esi, ebp
2368
	mov	ebx, [ebp + editor_data.cur_offs]
2369
	call	editor_step_backward
2370
	jc	.ret_clc
2371
	mov	al, [esi + ebx]
2372
	cmp	al, 13
2373
	jz	.eol
2374
	cmp	al, 10
2375
	jz	.eol2
2376
	cmp	al, 9
2377
	jz	.tab
2378
	sub	esi, ebp
2379
	mov	[ebp + editor_data.cur_block], esi
2380
	mov	[ebp + editor_data.cur_offs], ebx
2381
.left_cursor:
2382
	mov	eax, [ebp + editor_data.cursor_x]
2383
	test	eax, eax
2384
	jz	@f
2385
	dec	eax
2386
.set_cursor_x:
2387
	mov	[ebp + editor_data.cursor_x], eax
2388
	mov	[cursor_x], eax
2389
.ret_clc:
2390
	clc
2391
	ret
2392
@@:
2393
	dec	[ebp + editor_data.curcol]
2394
	jmp	.ret_stc
2395
.tab:
2396
	mov	eax, [ebp + editor_data.cursor_x]
2397
	test	eax, eax
2398
	jz	@f
2399
	dec	eax
2400
	mov	[ebp + editor_data.cursor_x], eax
2401
	mov	[cursor_x], eax
2402
	call	editor_update_cur
2403
	test	al, al
2404
	jz	.ret_clc
2405
.ret_stc:
2406
	stc
2407
	ret
2408
@@:
2409
	dec	[ebp + editor_data.curcol]
2410
	call	editor_update_cur
2411
	jmp	.ret_stc
2412
.eol2:
2413
	push	esi ebx
2414
	call	editor_step_backward
2415
	jc	@f
2416
	cmp	byte [esi + ebx], 13
2417
	jnz	@f
2418
	pop	eax eax
2419
	push	esi ebx
2420
@@:
2421
	pop	ebx esi
2422
.eol:
2423
	mov	eax, [ebp + editor_data.cursor_y]
2424
	dec	eax
2425
	jz	.scroll_left_toup
2426
	push	0	; no full redraw
2427
	mov	[ebp + editor_data.cursor_y], eax
2428
	mov	[cursor_y], eax
2429
	jmp	.scroll_left_toend
2430
.scroll_left_toup:
2431
	push	1
2432
	pop	ecx
2433
	call	editor_up_scroll
2434
	push	1	; full redraw required
2435
.scroll_left_toend:
2436
	call	editor_end_scroll
2437
	pop	eax
2438
	adc	al, 0
2439
	jnz	.ret_stc
2440
	jmp	.ret_clc
2441
 
2442
editor_test_cursor_x:
2443
	mov	ecx, [cur_width]
2444
	dec	ecx
2445
	mov	eax, [ebp + editor_data.cursor_x]
2446
	sub	eax, ecx
2447
	jbe	@f
2448
	add	[ebp + editor_data.curcol], eax
2449
	mov	[ebp + editor_data.cursor_x], ecx
2450
	mov	[cursor_x], ecx
2451
@@:
2452
	ret
2453
 
2454
editor_test_cursor_y:
2455
	mov	ecx, [ebp + editor_data.cursor_y]
2456
	mov	edx, [cur_height]
2457
	dec	edx
2458
	dec	edx
2459
	sub	ecx, edx
2460
	ja	.scroll_down
2461
	mov	ecx, [ebp + editor_data.curline]
2462
	add	ecx, edx
2463
	sub	ecx, [ebp + editor_data.numlines]
2464
	ja	.scroll_up
2465
.clc_ret:
2466
	clc
2467
	ret
2468
.scroll_down:
2469
	add	[ebp + editor_data.curline], ecx
2470
	sub	[ebp + editor_data.cursor_y], ecx
2471
	sub	[cursor_y], ecx
2472
	call	editor_down_scroll
2473
	stc
2474
	ret
2475
.scroll_up:
2476
	cmp	ecx, [ebp + editor_data.curline]
2477
	jb	@f
2478
	mov	ecx, [ebp + editor_data.curline]
2479
@@:
2480
	jecxz	.clc_ret
2481
	add	[ebp + editor_data.cursor_y], ecx
2482
	add	[cursor_y], ecx
2483
	call	editor_up_scroll
2484
	stc
2485
	ret
2486
 
2487
editor_OnExit:
2488
	mov	edx, [ebp+editor_data.hPlugin]
2489
	test	edx, edx
2490
	jz	@f
2491
	mov	ebx, [ebp+editor_data.hFile]
2492
	call	close_handle_if_unused
2493
@@:
2494
	ret
997 diamond 2495
 
2496
find_in_file_dlg:
2497
        mov     ebx, find_in_file_dlgdata
2498
        mov     eax, [cur_width]
2499
        sub     eax, 12
2500
        mov     [ebx + dlgtemplate.width], eax
2501
        dec     eax
2502
        dec     eax
2503
        mov     [ebx - find_in_file_dlgdata + find_in_file_dlgdata.width2], eax
2504
        shr     eax, 1
2505
        dec     eax
2506
        dec     eax
2507
        mov     [ebx - find_in_file_dlgdata + find_in_file_dlgdata.search_x2], eax
2508
        sub     eax, aSearchBLength-1
2509
        mov     [ebx - find_in_file_dlgdata + find_in_file_dlgdata.search_x1], eax
2510
        add     eax, aSearchBLength+3
2511
        mov     [ebx - find_in_file_dlgdata + find_in_file_dlgdata.cnl_x1], eax
2512
        add     eax, aCancelBLength - 1
2513
        mov     [ebx - find_in_file_dlgdata + find_in_file_dlgdata.cnl_x2], eax
2514
        mov     byte [ebx - find_in_file_dlgdata + find_in_file_dlgdata.flags0], 0xC
2515
        and     byte [ebx - find_in_file_dlgdata + find_in_file_dlgdata.flags1], not 4
2516
        and     byte [ebx - find_in_file_dlgdata + find_in_file_dlgdata.flags2], not 4
2517
	and	byte [ebx - find_in_file_dlgdata + find_in_file_dlgdata.flags_case], not 4
2518
	and	byte [ebx - find_in_file_dlgdata + find_in_file_dlgdata.flags_whole], not 4
2519
        push    ebx
2520
        call    DialogBox
2521
	cmp	eax, find_in_file_dlgdata.search_btn
2522
	ret