Subversion Repositories Kolibri OS

Rev

Rev 827 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 827 Rev 987
1
diff16 'tp-files.asm',0,$
1
diff16 'tp-files.asm',0,$
2
 
2
 
3
;-----------------------------------------------------------------------------
3
;-----------------------------------------------------------------------------
4
proc save_file ;//////////////////////////////////////////////////////////////
4
proc save_file ;//////////////////////////////////////////////////////////////
5
;-----------------------------------------------------------------------------
5
;-----------------------------------------------------------------------------
6
	mov	esi,tb_opensave.text
6
	mov	esi,tb_opensave.text
7
	mov	edi,f_info.path
7
	mov	edi,f_info.path
8
	movzx	ecx,[tb_opensave.length]
8
	movzx	ecx,[tb_opensave.length]
9
	mov	[f_info.length],ecx
9
	mov	[f_info.length],ecx
10
	cld
10
	cld
11
	rep	movsb
11
	rep	movsb
12
	mov	byte[edi],0
12
	mov	byte[edi],0
13
 
13
 
14
	mov	esi,[cur_editor.Lines]
14
	mov	esi,[cur_editor.Lines]
15
 
15
 
16
	xor	ebx,ebx
16
	xor	ebx,ebx
17
	mov	ecx,[cur_editor.Lines.Count]
17
	mov	ecx,[cur_editor.Lines.Count]
18
    @@: call	get_real_length
18
    @@: call	get_real_length
19
	add	ebx,eax
19
	add	ebx,eax
20
	movzx	eax,word[esi]
20
	mov	eax,[esi+EDITOR_LINE_DATA.Size]
21
	lea	esi,[esi+eax+4]
21
	lea	esi,[esi+eax+sizeof.EDITOR_LINE_DATA]
22
	loop	@b
22
	loop	@b
23
	mov	eax,[cur_editor.Lines.Count]
23
	mov	eax,[cur_editor.Lines.Count]
24
	shl	eax,1
24
	shl	eax,1
25
	lea	eax,[eax+ebx+1024]
25
	lea	eax,[eax+ebx+1024]
26
	stdcall mem.Alloc,eax
26
	stdcall mem.Alloc,eax
27
	push	eax
27
	push	eax
28
	mov	esi,[cur_editor.Lines]
28
	mov	esi,[cur_editor.Lines]
29
	mov	edi,eax
29
	mov	edi,eax
30
 
30
 
31
  .new_string:
31
  .new_string:
32
	call	save_string
32
	call	save_string
33
	cmp	dword[esi],0
33
	cmp	dword[esi+EDITOR_LINE_DATA.Size],0
34
	jne	.new_string
34
	jne	.new_string
35
	pop	eax
35
	pop	eax
36
	sub	edi,eax
36
	sub	edi,eax
37
	add	edi,-2			; minus last CRLF
37
	add	edi,-2			; minus last CRLF
38
 
38
 
39
  .systree_save:
39
  .systree_save:
40
	mov	[f_info70+0],2
40
	mov	[f_info70+0],2
41
	mov	[f_info70+12],edi
41
	mov	[f_info70+12],edi
42
	mov	[f_info70+16],eax
42
	mov	[f_info70+16],eax
43
	mov	byte[f_info70+20],0
43
	mov	byte[f_info70+20],0
44
	mov	[f_info70+21],f_info.path
44
	mov	[f_info70+21],f_info.path
45
	mcall	70,f_info70
45
	mcall	70,f_info70
46
 
46
 
47
	call	set_status_fs_error
47
	call	set_status_fs_error
48
 
48
 
49
	or	eax,eax
49
	or	eax,eax
50
	jnz	.exit.2
50
	jnz	.exit.2
51
 
51
 
52
  .exit:
52
  .exit:
53
	mov	ebp,cur_editor
53
	mov	ebp,cur_editor
54
	call	update_tab_filename
54
	call	update_tab_filename
55
	mov	[cur_editor.Modified],0
55
	mov	[cur_editor.Modified],0
56
	clc
56
	clc
57
	ret
57
	ret
58
 
58
 
59
  .exit.2:
59
  .exit.2:
60
	stc
60
	stc
61
	ret
61
	ret
62
endp
62
endp
63
 
63
 
64
;-----------------------------------------------------------------------------
64
;-----------------------------------------------------------------------------
65
proc save_string ;////////////////////////////////////////////////////////////
65
proc save_string ;////////////////////////////////////////////////////////////
66
;-----------------------------------------------------------------------------
66
;-----------------------------------------------------------------------------
67
	movzx	ecx,word[esi]
67
	mov	ecx,[esi+EDITOR_LINE_DATA.Size]
68
	test	dword[esi],0x00010000
68
	test	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_MOFIFIED
69
	jz	@f
69
	jz	@f
70
	or	dword[esi],0x00020000
70
	or	[esi+EDITOR_LINE_DATA.Flags],EDITOR_LINE_FLAG_SAVED
71
    @@: add	esi,4
71
    @@: add	esi,sizeof.EDITOR_LINE_DATA
72
 
72
 
73
    @@: cmp	byte[esi+ecx-1],' '
73
    @@: cmp	byte[esi+ecx-1],' '
74
	jne	@f
74
	jne	@f
75
	loop	@b
75
	loop	@b
76
    @@: jecxz	.endcopy
76
    @@: jecxz	.endcopy
77
	xor	edx,edx
77
	xor	edx,edx
78
	mov	ebx,edx
78
	mov	ebx,edx
79
	mov	ah,dl
79
	mov	ah,dl
80
 
80
 
81
  .next_char:
81
  .next_char:
82
	mov	al,[esi+ebx]
82
	mov	al,[esi+ebx]
83
	inc	ebx
83
	inc	ebx
84
	test	[options],OPTS_OPTIMSAVE
84
	test	[optim_save],1
85
	jz	.put
85
	jz	.put
86
	test	ah,00000001b
86
	test	ah,00000001b
87
	jnz	.char
87
	jnz	.char
88
	cmp	al,'"'
88
	cmp	al,'"'
89
	jne	@f
89
	jne	@f
90
	xor	ah,00000100b
90
	xor	ah,00000100b
91
	jmp	.char
91
	jmp	.char
92
    @@: cmp	al,"'"
92
    @@: cmp	al,"'"
93
	jne	@f
93
	jne	@f
94
	xor	ah,00000010b
94
	xor	ah,00000010b
95
	jmp	.char
95
	jmp	.char
96
    @@: test	ah,00000110b
96
    @@: test	ah,00000110b
97
	jnz	.char
97
	jnz	.char
98
	cmp	al,';'
98
	cmp	al,';'
99
	jne	@f
99
	jne	@f
100
	test	ah,00000001b
100
	test	ah,00000001b
101
	jnz	.char
101
	jnz	.char
102
	xor	ah,00000001b
102
	xor	ah,00000001b
103
	jmp	.char
103
	jmp	.char
104
    @@: cmp	al,' '
104
    @@: cmp	al,' '
105
	jne	.char
105
	jne	.char
106
	inc	edx
106
	inc	edx
107
	test	ebx,ATABW-1
107
	test	ebx,ATABW-1
108
	jnz	@f
108
	jnz	@f
109
	dec	edx
109
	dec	edx
110
	jle	.put
110
	jle	.put
111
	mov	al,9
111
	mov	al,9
112
	xor	edx,edx
112
	xor	edx,edx
113
	jmp	.put
113
	jmp	.put
114
  .char:
114
  .char:
115
	or	edx,edx
115
	or	edx,edx
116
	jz	.put
116
	jz	.put
117
	push	ecx eax
117
	push	ecx eax
118
	mov	ecx,edx
118
	mov	ecx,edx
119
	mov	al,' '
119
	mov	al,' '
120
	rep	stosb
120
	rep	stosb
121
	pop	eax ecx
121
	pop	eax ecx
122
	xor	edx,edx
122
	xor	edx,edx
123
  .put:
123
  .put:
124
	stosb
124
	stosb
125
    @@: loop	.next_char
125
    @@: loop	.next_char
126
 
126
 
127
  .endcopy:
127
  .endcopy:
128
	mov	eax,0x0A0D
128
	mov	eax,0x0A0D
129
	stosw
129
	stosw
130
	movzx	eax,word[esi-4]
-
 
131
	add	esi,eax;[esi-4]
130
	add	esi,[esi-sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size]
132
	ret
131
	ret
133
endp
132
endp
134
 
133
 
135
proc set_status_fs_error
134
proc set_status_fs_error
136
	push	eax
135
	push	eax
137
	mov	esi,s_fs_error
136
	mov	esi,s_fs_error
138
    @@: dec	eax
137
    @@: dec	eax
139
	js	@f
138
	js	@f
140
	movzx	ecx,byte[esi]
139
	movzx	ecx,byte[esi]
141
	lea	esi,[esi+ecx+1]
140
	lea	esi,[esi+ecx+1]
142
	jmp	@b
141
	jmp	@b
143
    @@: inc	esi
142
    @@: inc	esi
144
	mov	[s_status],esi
143
	mov	[s_status],esi
145
	pop	eax
144
	pop	eax
146
	call	draw_statusbar
145
	call	draw_statusbar
147
	ret
146
	ret
148
endp
147
endp
149
 
148
 
150
;-----------------------------------------------------------------------------
149
;-----------------------------------------------------------------------------
151
proc load_file ;//////////////////////////////////////////////////////////////
150
proc load_file ;//////////////////////////////////////////////////////////////
152
;-----------------------------------------------------------------------------
151
;-----------------------------------------------------------------------------
153
	cmp	[tb_opensave.length],0
152
	cmp	[tb_opensave.length],0
154
	jne	@f
153
	jne	@f
155
	stc
154
	stc
156
	ret
155
	ret
157
 
156
 
158
    @@: mov	esi,tb_opensave.text
157
    @@: mov	esi,tb_opensave.text
159
	mov	edi,f_info.path
158
	mov	edi,f_info.path
160
	movzx	ecx,[tb_opensave.length]
159
	movzx	ecx,[tb_opensave.length]
161
	mov	[f_info.length],ecx
160
	mov	[f_info.length],ecx
162
	cld
161
	cld
163
	rep	movsb
162
	rep	movsb
164
	mov	byte[edi],0
163
	mov	byte[edi],0
165
 
164
 
166
	xor	eax,eax
165
	xor	eax,eax
167
	mov	[f_info70+0],5
166
	mov	[f_info70+0],5
168
	mov	[f_info70+4],eax
167
	mov	[f_info70+4],eax
169
	mov	[f_info70+8],eax
168
	mov	[f_info70+8],eax
170
	mov	[f_info70+12],eax
169
	mov	[f_info70+12],eax
171
	mov	[f_info70+16],file_info
170
	mov	[f_info70+16],file_info
172
	mov	byte[f_info70+20],al
171
	mov	byte[f_info70+20],al
173
	mov	[f_info70+21],f_info.path
172
	mov	[f_info70+21],f_info.path
174
	mcall	70,f_info70
173
	mcall	70,f_info70
175
	mov	[f_info70+0],0
174
	mov	[f_info70+0],0
176
	mov	eax,dword[file_info.Size]
175
	mov	eax,dword[file_info.Size]
-
 
176
	or	eax, eax
-
 
177
	jnz	@f
-
 
178
	mov	eax, 1024
177
	mov	[f_info70+12],eax
179
    @@: mov	[f_info70+12],eax
178
	stdcall mem.Alloc,eax
180
	stdcall mem.Alloc,eax
179
	mov	[f_info70+16],eax
181
	mov	[f_info70+16],eax
180
	mcall	70,f_info70
182
	mcall	70,f_info70
181
 
183
 
182
	call	set_status_fs_error
184
	call	set_status_fs_error
183
 
185
 
184
	mov	esi,[f_info70+16]
186
	mov	esi,[f_info70+16]
185
 
187
 
186
	xchg	eax,ebx
188
	xchg	eax,ebx
187
	test	ebx,ebx
189
	test	ebx,ebx
188
	je	.file_found
190
	je	.file_found
189
	cmp	ebx,6		 ;// ATV driver fix (6 instead of 5)
191
	cmp	ebx,6		 ;// ATV driver fix (6 instead of 5)
190
	je	.file_found
192
	je	.file_found
191
 
193
 
192
	stdcall mem.Free,[f_info70+16]
194
	stdcall mem.Free,[f_info70+16]
193
	stc
195
	stc
194
	ret
196
	ret
195
 
197
 
196
  .file_found:
198
  .file_found:
197
	mov	ecx,eax
199
	mov	ecx,eax
198
	cmp	[tab_bar.Items.Count],1
200
	cmp	[tab_bar.Items.Count],1
199
	jne	@f
201
	jne	@f
200
	cmp	[cur_editor.FilePath],0
202
	cmp	[cur_editor.FilePath],0
201
	jne	@f
203
	jne	@f
202
	cmp	[cur_editor.Modified],0
204
	cmp	[cur_editor.Modified],0
203
	jne	@f
205
	jne	@f
204
	mov	ebp,cur_editor
206
	mov	ebp,cur_editor
205
	jmp	.lp1
207
	jmp	.lp1
206
    @@: inc	[do_not_draw]
208
    @@: inc	[do_not_draw]
207
	call	create_tab
209
	call	create_tab
208
	dec	[do_not_draw]
210
	dec	[do_not_draw]
209
  .lp1: call	update_tab_filename
211
  .lp1: call	update_tab_filename
210
	call	load_from_memory
212
	call	load_from_memory
211
	stdcall mem.Free,[f_info70+16]
213
	stdcall mem.Free,[f_info70+16]
212
 
214
 
213
	xor	eax,eax
215
	xor	eax,eax
214
	mov	[cur_editor.TopLeft.Y],eax
216
	mov	[cur_editor.TopLeft.Y],eax
215
	mov	[cur_editor.TopLeft.X],eax
217
	mov	[cur_editor.TopLeft.X],eax
216
	mov	[cur_editor.Caret.X],eax
218
	mov	[cur_editor.Caret.X],eax
217
	mov	[cur_editor.Caret.Y],eax
219
	mov	[cur_editor.Caret.Y],eax
218
	mov	[cur_editor.SelStart.X],eax
220
	mov	[cur_editor.SelStart.X],eax
219
	mov	[cur_editor.SelStart.Y],eax
221
	mov	[cur_editor.SelStart.Y],eax
220
	mov	[cur_editor.Modified],al
222
	mov	[cur_editor.Modified],al
221
 
223
 
222
	clc
224
	clc
223
	ret
225
	ret
224
endp
226
endp
225
 
227
 
226
;-----------------------------------------------------------------------------
228
;-----------------------------------------------------------------------------
227
proc load_from_memory ;///////////////////////////////////////////////////////
229
proc load_from_memory ;///////////////////////////////////////////////////////
228
;-----------------------------------------------------------------------------
230
;-----------------------------------------------------------------------------
229
; ECX = data length
231
; ECX = data length
230
; ESI = data pointer
232
; ESI = data pointer
231
; EBP = EDITOR*
233
; EBP = EDITOR*
232
;-----------------------------------------------------------------------------
234
;-----------------------------------------------------------------------------
233
	call	get_lines_in_file
235
	call	get_lines_in_file
234
	mov	[ebp+EDITOR.Lines.Count],eax
236
	mov	[ebp+EDITOR.Lines.Count],eax
235
	lea	edx,[ebx+ecx]
237
	lea	edx,[ebx+ecx]
236
	imul	ebx,eax,14
238
	imul	ebx,eax,16
237
	add	ebx,edx
239
	add	ebx,edx
238
	mov	[ebp+EDITOR.Lines.Size],ebx
240
	mov	[ebp+EDITOR.Lines.Size],ebx
239
	stdcall mem.ReAlloc,[ebp+EDITOR.Lines],ebx
241
	stdcall mem.ReAlloc,[ebp+EDITOR.Lines],ebx
240
	mov	[ebp+EDITOR.Lines],eax
242
	mov	[ebp+EDITOR.Lines],eax
241
 
243
 
242
	mov	[ebp+EDITOR.Columns.Count],0
244
	mov	[ebp+EDITOR.Columns.Count],0
243
	mov	edi,eax
245
	mov	edi,eax
244
	mov	edx,ecx
246
	mov	edx,ecx
245
 
247
 
246
  .next_line:
248
  .next_line:
247
	mov	ebx,edi
249
	mov	ebx,edi
248
	add	edi,4
250
	add	edi,sizeof.EDITOR_LINE_DATA
249
  .next_char:
251
  .next_char:
250
	or	edx,edx
252
	or	edx,edx
251
	jle	.exit
253
	jle	.exit
252
	lodsb
254
	lodsb
253
	dec	edx
255
	dec	edx
254
	cmp	al,13
256
	cmp	al,13
255
	je	.CR
257
	je	.CR
256
	cmp	al,10
258
	cmp	al,10
257
	je	.LF
259
	je	.LF
258
	cmp	al,9
260
	cmp	al,9
259
	je	.TB
261
	je	.TB
260
	cmp	al,0
262
	cmp	al,0
261
	je	.exit
263
	je	.exit
262
	stosb
264
	stosb
263
	jmp	.next_char
265
	jmp	.next_char
264
 
266
 
265
  .exit:
267
  .exit:
266
	mov	ecx,10
268
	mov	ecx,10
267
	mov	al,' '
269
	mov	al,' '
268
	rep	stosb
270
	rep	stosb
269
	lea	eax,[edi-4]
271
	lea	eax,[edi-sizeof.EDITOR_LINE_DATA]
270
	sub	eax,ebx
272
	sub	eax,ebx
271
	mov	[ebx],eax
273
	mov	[ebx+EDITOR_LINE_DATA.Size],eax
272
	mov	dword[ebx+eax+4],0
274
	mov	[ebx+eax+sizeof.EDITOR_LINE_DATA+EDITOR_LINE_DATA.Size],0
273
	sub	eax,10
275
	sub	eax,10
274
	jnz	@f
276
	jnz	@f
275
	inc	eax
277
	inc	eax
276
    @@: cmp	eax,[ebp+EDITOR.Columns.Count]
278
    @@: cmp	eax,[ebp+EDITOR.Columns.Count]
277
	jbe	@f
279
	jbe	@f
278
	mov	[ebp+EDITOR.Columns.Count],eax
280
	mov	[ebp+EDITOR.Columns.Count],eax
279
    @@: mov	[ebp+EDITOR.Modified],0
281
    @@: mov	[ebp+EDITOR.Modified],0
280
	ret
282
	ret
281
 
283
 
282
  .CR:	cmp	byte[esi],10
284
  .CR:	cmp	byte[esi],10
283
	jne	.LF
285
	jne	.LF
284
	lodsb
286
	lodsb
285
	dec	edx
287
	dec	edx
286
  .LF:	mov	ecx,10
288
  .LF:	mov	ecx,10
287
	mov	al,' '
289
	mov	al,' '
288
	rep	stosb
290
	rep	stosb
289
	lea	eax,[edi-4]
291
	lea	eax,[edi-sizeof.EDITOR_LINE_DATA]
290
	sub	eax,ebx
292
	sub	eax,ebx
291
	mov	[ebx],eax
293
	mov	[ebx+EDITOR_LINE_DATA.Size],eax
292
	add	eax,-10
294
	add	eax,-10
293
	cmp	eax,[ebp+EDITOR.Columns.Count]
295
	cmp	eax,[ebp+EDITOR.Columns.Count]
294
	jbe	.next_line
296
	jbe	.next_line
295
	mov	[ebp+EDITOR.Columns.Count],eax
297
	mov	[ebp+EDITOR.Columns.Count],eax
296
	jmp	.next_line
298
	jmp	.next_line
297
 
299
 
298
  .TB:	lea	eax,[edi-4]
300
  .TB:	lea	eax,[edi-sizeof.EDITOR_LINE_DATA]
299
	sub	eax,ebx
301
	sub	eax,ebx
300
	mov	ecx,eax
302
	mov	ecx,eax
301
	add	ecx,ATABW
303
	add	ecx,ATABW
302
	and	ecx,not(ATABW-1)
304
	and	ecx,not(ATABW-1)
303
	sub	ecx,eax
305
	sub	ecx,eax
304
	mov	al,' '
306
	mov	al,' '
305
	rep	stosb
307
	rep	stosb
306
	jmp	.next_char
308
	jmp	.next_char
307
endp
309
endp
308
 
310
 
309
;-----------------------------------------------------------------------------
311
;-----------------------------------------------------------------------------
310
proc update_tab_filename ;////////////////////////////////////////////////////
312
proc update_tab_filename ;////////////////////////////////////////////////////
311
;-----------------------------------------------------------------------------
313
;-----------------------------------------------------------------------------
312
; EBP = TABITEM*
314
; EBP = TABITEM*
313
;-----------------------------------------------------------------------------
315
;-----------------------------------------------------------------------------
314
	push	ecx esi edi
316
	push	ecx esi edi
315
	inc	[do_not_draw]
317
	inc	[do_not_draw]
316
	mov	esi,tb_opensave.text
318
	mov	esi,tb_opensave.text
317
	lea	edi,[ebp+TABITEM.Editor.FilePath]
319
	lea	edi,[ebp+TABITEM.Editor.FilePath]
318
	movzx	ecx,[tb_opensave.length]
320
	movzx	ecx,[tb_opensave.length]
319
	cld
321
	cld
320
	rep	movsb
322
	rep	movsb
321
	mov	byte[edi],0
323
	mov	byte[edi],0
322
	lea	edi,[ebp+TABITEM.Editor.FilePath]
324
	lea	edi,[ebp+TABITEM.Editor.FilePath]
323
	movzx	ecx,[tb_opensave.length]
325
	movzx	ecx,[tb_opensave.length]
324
	inc	ecx
326
	inc	ecx
325
    @@: dec	ecx
327
    @@: dec	ecx
326
	jz	@f
328
	jz	@f
327
	cmp	byte[edi+ecx-1],'/'
329
	cmp	byte[edi+ecx-1],'/'
328
	jne	@b
330
	jne	@b
329
    @@: mov	[ebp+TABITEM.Editor.FileName],ecx
331
    @@: mov	[ebp+TABITEM.Editor.FileName],ecx
330
	call	flush_cur_tab
332
	call	flush_cur_tab
331
	call	update_caption
333
	call	update_caption
332
	dec	[do_not_draw]
334
	dec	[do_not_draw]
333
 
335
 
334
	mov	[cur_editor.AsmMode],0
336
	mov	[cur_editor.AsmMode],0
335
	movzx	ecx,[tb_opensave.length]
337
	movzx	ecx,[tb_opensave.length]
336
	mov	ecx,dword[ecx+tb_opensave.text-3]
338
	mov	ecx,dword[ecx+tb_opensave.text-3]
337
	or	ecx,0x202020
339
	or	ecx,0x202020
338
	cmp	ecx,'asm'
340
	cmp	ecx,'asm'
339
	jne	@f
341
	jne	@f
340
	inc	[cur_editor.AsmMode]
342
	inc	[cur_editor.AsmMode]
341
	jmp	.exit
343
	jmp	.exit
342
    @@: cmp	ecx,'inc'
344
    @@: cmp	ecx,'inc'
343
	jne	.exit
345
	jne	.exit
344
	inc	[cur_editor.AsmMode]
346
	inc	[cur_editor.AsmMode]
345
 
347
 
346
  .exit:
348
  .exit:
347
	pop	edi esi ecx
349
	pop	edi esi ecx
348
	ret
350
	ret
349
endp
351
endp