Subversion Repositories Kolibri OS

Rev

Rev 280 | 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
;-----------------------------------------------------------------------------
280 mikedld 149
	cmp	[tb_opensave.text],0
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
203
    @@: call	create_tab
204
  .lp1: push	ecx esi edi
178 heavyiron 205
	mov	esi,tb_opensave.text
259 mikedld 206
	lea	edi,[ebp+TABITEM.Editor.FilePath]
178 heavyiron 207
	movzx	ecx,[tb_opensave.length]
208
	rep	movsb
209
	mov	byte[edi],0
259 mikedld 210
	lea	edi,[ebp+TABITEM.Editor.FilePath]
211
	movzx	ecx,[tb_opensave.length]
212
    @@: cmp	byte[edi+ecx-1],'/'
213
	je	@f
214
	dec	ecx
215
	jmp	@b
216
    @@: mov	[ebp+TABITEM.Editor.FileName],ecx
217
	call	flush_cur_tab
218
	pop	edi esi ecx
219
	call	load_from_memory
220
	mov	eax,[f_info70+16]
221
	call	mem.Free
297 mikedld 222
 
223
	xor	eax,eax
224
	mov	[cur_editor.TopLeft.Y],eax
225
	mov	[cur_editor.TopLeft.X],eax
226
	mov	[cur_editor.Caret.X],eax
227
	mov	[cur_editor.Caret.Y],eax
228
	mov	[cur_editor.SelStart.X],eax
229
	mov	[cur_editor.SelStart.Y],eax
230
	mov	[cur_editor.Modified],al
231
	mov	[cur_editor.AsmMode],al
232
 
233
	lea	ebx,[cur_editor.FilePath]
234
	mov	eax,ebx
235
	call	strlen
236
	mov	ecx,dword[ebx+eax-3]
237
	or	ecx,0x202020
238
	cmp	ecx,'asm'
239
	jne	@f
240
	inc	[cur_editor.AsmMode]
241
	jmp	.nocol
242
    @@: cmp	ecx,'inc'
243
	jne	.nocol
244
	inc	[cur_editor.AsmMode]
245
    .nocol:
246
	call	update_caption
247
 
259 mikedld 248
	clc
249
	ret
250
endf
178 heavyiron 251
 
259 mikedld 252
;-----------------------------------------------------------------------------
253
func load_from_memory ;///////////////////////////////////////////////////////
254
;-----------------------------------------------------------------------------
255
; ECX = data length
256
; ESI = data pointer
257
; EBP = EDITOR*
258
;-----------------------------------------------------------------------------
259
	call	get_lines_in_file
267 mikedld 260
	mov	[ebp+EDITOR.Lines.Count],eax
280 mikedld 261
	lea	edx,[ebx+ecx]
259 mikedld 262
	imul	ebx,eax,14
280 mikedld 263
	add	ebx,edx
267 mikedld 264
	mov	eax,[ebp+EDITOR.Lines]
280 mikedld 265
	mov	[ebp+EDITOR.Lines.Size],ebx
259 mikedld 266
	call	mem.ReAlloc
267 mikedld 267
	mov	[ebp+EDITOR.Lines],eax
178 heavyiron 268
 
267 mikedld 269
	mov	[ebp+EDITOR.Columns.Count],0
259 mikedld 270
	mov	edi,eax
271
	mov	edx,ecx
178 heavyiron 272
 
273
  .next_line:
274
	mov	ebx,edi
275
	add	edi,4
276
  .next_char:
277
	or	edx,edx
278
	jle	.exit
279
	lodsb
280
	dec	edx
281
	cmp	al,13
282
	je	.CR
283
	cmp	al,10
284
	je	.LF
285
	cmp	al,9
286
	je	.TB
287
	cmp	al,0
288
	je	.exit
289
	stosb
290
	jmp	.next_char
291
 
292
  .exit:
293
	mov	ecx,10
294
	mov	al,' '
295
	rep	stosb
296
	lea	eax,[edi-4]
297
	sub	eax,ebx
298
	mov	[ebx],eax
299
	mov	dword[ebx+eax+4],0
300
	sub	eax,10
301
	jnz	@f
302
	inc	eax
297 mikedld 303
    @@: cmp	eax,[ebp+EDITOR.Columns.Count]
178 heavyiron 304
	jbe	@f
297 mikedld 305
	mov	[ebp+EDITOR.Columns.Count],eax
306
    @@: mov	[ebp+EDITOR.Modified],0
178 heavyiron 307
	ret
308
 
309
  .CR:	cmp	byte[esi],10
310
	jne	.LF
311
	lodsb
312
	dec	edx
313
  .LF:	mov	ecx,10
314
	mov	al,' '
315
	rep	stosb
316
	lea	eax,[edi-4]
317
	sub	eax,ebx
318
	mov	[ebx],eax
319
	add	eax,-10
297 mikedld 320
	cmp	eax,[ebp+EDITOR.Columns.Count]
178 heavyiron 321
	jbe	.next_line
297 mikedld 322
	mov	[ebp+EDITOR.Columns.Count],eax
178 heavyiron 323
	jmp	.next_line
324
 
325
  .TB:	lea	eax,[edi-4]
326
	sub	eax,ebx
327
	mov	ecx,eax
328
	add	ecx,ATABW
329
	and	ecx,not(ATABW-1)
330
	sub	ecx,eax
331
	mov	al,' '
332
	rep	stosb
333
	jmp	.next_char
334
endf