Subversion Repositories Kolibri OS

Rev

Rev 845 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
845 mikedld 1
;;================================================================================================;;
2
;;//// libio_p.asm //// (c) mike.dld, 2006-2008 //////////////////////////////////////////////////;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
1001 diamond 8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; of the License, or (at your option) any later version.                                         ;;
845 mikedld 10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
1001 diamond 13
;; Lesser General Public License for more details.                                                ;;
845 mikedld 14
;;                                                                                                ;;
1001 diamond 15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
845 mikedld 17
;;                                                                                                ;;
18
;;================================================================================================;;
19
 
20
mem.alloc   dd ?
21
mem.free    dd ?
22
mem.realloc dd ?
23
dll.load    dd ?
24
 
25
;;================================================================================================;;
26
proc libio._.init ;///////////////////////////////////////////////////////////////////////////////;;
27
;;------------------------------------------------------------------------------------------------;;
28
;? Library entry point (called after library load)                                                ;;
29
;;------------------------------------------------------------------------------------------------;;
30
;> eax = memory allocation routine                                                    ;;
31
;> ebx = memory freeing routine                                                        ;;
32
;> ecx = memory reallocation routine                                                ;;
33
;> edx = library loading routine                                                       ;;
34
;;------------------------------------------------------------------------------------------------;;
35
;< eax = 1 (fail) / 0 (ok) (library initialization result)                                        ;;
36
;;================================================================================================;;
37
	mov	[mem.alloc], eax
38
	mov	[mem.free], ebx
39
	mov	[mem.realloc], ecx
40
	mov	[dll.load], edx
41
	xor	eax, eax
42
	ret
43
endp
44
 
45
;;================================================================================================;;
46
proc libio._.match_wildcard _str, _wcard ;////////////////////////////////////////////////////////;;
47
;;------------------------------------------------------------------------------------------------;;
48
;? Match string against wildcard                                                                  ;;
49
;? Based on http://user.cs.tu-berlin.de/~schintke/references/wildcards/                           ;;
50
;? 1997-2001 (c) Florian Schintke                                                                 ;;
51
;;------------------------------------------------------------------------------------------------;;
52
;> _str = string (filename in most cases)                                                 ;;
53
;> _wcard = mask expressed using wilcards (?, *, [..])                                    ;;
54
;;------------------------------------------------------------------------------------------------;;
55
;< eax = false / true (match result)                                                              ;;
56
;;================================================================================================;;
57
	push	ecx edx esi edi
58
	mov	dl, 1 ; fit
59
	mov	esi, [_wcard]
60
	mov	edi, [_str]
61
  .loop_wildcard:
62
	mov	al, [esi]
63
	or	al, al
64
	jz	.loop_wildcard_exit
65
	or	dl, dl
66
	jz	.loop_wildcard_exit
67
	cmp	byte[edi], 0
68
	je	.loop_wildcard_exit
69
 
70
	cmp	al, '['
71
	je	.process_set
72
	cmp	al, '?'
73
	je	.process_question
74
	cmp	al, '*'
75
	je	.process_asterisk
76
 
77
	xor	dl, dl
78
	cmp	[edi], al
79
	jne	@f
80
	inc	dl
81
    @@: inc	edi
82
 
83
  .loop_wildcard_next:
84
	inc	esi
85
	jmp	.loop_wildcard
86
 
87
 
88
  .process_set:
89
	inc	esi
90
	xor	dl, dl ; fit
91
	xor	dh, dh ; negation
92
	mov	cl, 1  ; at_beginning
93
	cmp	byte[esi], '^'
94
	jne	.loop_set_wildcard
95
	inc	dh
96
	inc	esi
97
 
98
    .loop_set_wildcard:
99
	mov	al, [esi]
100
	cmp	al, ']'
101
	jne	@f
102
	or	cl, cl
103
	jz	.loop_set_wildcard_exit
104
    @@: or	dl, dl
105
	jnz	.loop_set_wildcard_fit
106
	cmp	al, '-'
107
	jne	.loop_set_wildcard_not_range
108
	mov	ch, [esi - 1]
109
	cmp	[esi + 1], ch
110
	jbe	.loop_set_wildcard_not_range
111
	cmp	byte[esi + 1], ']'
112
	je	.loop_set_wildcard_not_range
113
	or	cl, cl
114
	jnz	.loop_set_wildcard_not_range
115
	cmp	[edi], ch
116
	jb	.loop_set_wildcard_fit
117
	mov	ch, [esi + 1]
118
	cmp	[edi], ch
119
	ja	.loop_set_wildcard_fit
120
	mov	dl, 1
121
	inc	esi
122
	jmp	.loop_set_wildcard_fit
123
 
124
    .loop_set_wildcard_not_range:
125
	cmp	[edi], al
126
	jne	.loop_set_wildcard_fit
127
	mov	dl, 1
128
 
129
    .loop_set_wildcard_fit:
130
	inc	esi
131
	xor	cl, cl
132
	jmp	.loop_set_wildcard
133
 
134
    .loop_set_wildcard_exit:
135
	or	dh, dh
136
	jz	@f
137
	xor	dl, 1
138
    @@: or	dl, dl
139
	jz	@f
140
	inc	edi
141
    @@:
142
	jmp	.loop_wildcard_next
143
 
144
  .process_question:
145
	inc	edi
146
	jmp	.loop_wildcard_next
147
 
148
  .process_asterisk:
149
	mov	dl, 1
150
	inc	esi
151
 
152
    .loop_asterisk_del_shit:
153
	lodsb
154
	cmp	byte[edi], 0
155
	je	.loop_asterisk_del_shit_exit
156
	cmp	al, '?'
157
	jne	@f
158
	inc	edi
159
	jmp	.loop_asterisk_del_shit
160
    @@: cmp	al, '*'
161
	je	.loop_asterisk_del_shit
162
 
163
    .loop_asterisk_del_shit_exit:
164
 
165
    @@: cmp	al, '*'
166
	jne	@f
167
	lodsb
168
	jmp	@b
169
    @@:
170
	dec	esi
171
	cmp	byte[edi], 0
172
	jne	.process_asterisk_skip_exit
173
	xor	dl, dl
174
	or	al, al
175
	jnz	@f
176
	inc	dl
177
    @@: dec	esi
178
	jmp	.loop_wildcard_next
179
 
180
    .process_asterisk_skip_exit:
181
	stdcall libio._.match_wildcard, edi, esi
182
	or	eax, eax
183
	jnz	.process_asterisk_not_match
184
 
185
    .loop_asterisk_match:
186
	inc	edi
187
 
188
    .loop_asterisk_char_match:
189
	mov	al, [esi]
190
	cmp	[edi], al
191
	je	.loop_asterisk_char_match_exit
192
	cmp	byte[esi], '['
193
	je	.loop_asterisk_char_match_exit
194
	cmp	byte[edi], 0
195
	je	.loop_asterisk_char_match_exit
196
	inc	edi
197
	jmp	.loop_asterisk_char_match
198
 
199
    .loop_asterisk_char_match_exit:
200
	cmp	byte[edi], 0
201
	je	@f
202
	stdcall libio._.match_wildcard, edi, esi
203
	or	eax, eax
204
	jnz	.loop_asterisk_match_exit
205
	jmp	.loop_asterisk_match
206
    @@:
207
	xor	dl, dl
208
 
209
    .loop_asterisk_match_exit:
210
 
211
    .process_asterisk_not_match:
212
	cmp	byte[esi], 0
213
	jne	@f
214
	cmp	byte[edi], 0
215
	jne	@f
216
	mov	dl, 1
217
    @@:
218
	dec	esi
219
	jmp	.loop_wildcard_next
220
 
221
  .loop_wildcard_exit:
222
	or	dl, dl
223
	jz	.exit
224
    @@: cmp	byte[esi], '*'
225
	jne	.exit
226
	inc	esi
227
	jmp	@b
228
 
229
  .exit:
230
	cmp	byte[esi], 0
231
	je	@f
232
	xor	dl, dl
233
    @@: cmp	byte[edi], 0
234
	je	@f
235
	xor	dl, dl
236
    @@:
237
	movzx	eax, dl
238
 
239
	pop	edi esi edx ecx
240
	ret
241
endp
242
 
243
;;================================================================================================;;
244
proc libio._.find_matching_file _ffb ;////////////////////////////////////////////////////////////;;
245
;;------------------------------------------------------------------------------------------------;;
246
;? Find file with matching attributes (`FindFileBlock.Options.Attributes`) and mask               ;;
247
;? (`FindFileBlock.Options.Mask`) starting from Nth (`FindFileBlock.InfoBlock.Position`) file in  ;;
248
;? directory (`FindFileBlock.InfoBlock.FileName`)                                                 ;;
249
;;------------------------------------------------------------------------------------------------;;
250
;> _ffb = find file block                                                         ;;
251
;;------------------------------------------------------------------------------------------------;;
252
;< eax = 0 (error) / matched file info pointer                                         ;;
253
;;================================================================================================;;
254
	push	ebx edx
255
	mov	edx, [_ffb]
256
  .loop_find:
257
	lea	ebx, [edx + FindFileBlock.InfoBlock]
258
	mcall	70
259
	or	eax, eax
260
	jnz	.loop_find_error
261
	mov	eax, [edx + FindFileBlock.Info.Attributes]
262
	and	eax, [edx + FindFileBlock.Options.Attributes]
263
	jz	.loop_find_next
264
	lea	eax, [edx + FindFileBlock.Info.FileName]
265
	stdcall libio._.match_wildcard, eax, [edx + FindFileBlock.Options.Mask]
266
	or	eax, eax
267
	jnz	.loop_find_exit
268
 
269
  .loop_find_next:
270
	inc	[edx + FindFileBlock.InfoBlock.Position]
271
	jmp	.loop_find
272
 
273
  .loop_find_error:
274
	xor	eax, eax
275
	pop	edx ebx
276
	ret
277
 
278
  .loop_find_exit:
279
	lea	eax, [edx + FindFileBlock.Info]
280
	pop	edx ebx
281
	ret
282
endp