Subversion Repositories Kolibri OS

Rev

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

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