Subversion Repositories Kolibri OS

Rev

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

Rev 5363 Rev 6262
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
-
 
8
;-------------------------------------------------------------------------
-
 
9
;
-
 
10
;  File path partial substitution (according to configuration)
-
 
11
;
-
 
12
;
-
 
13
;     SPraid
-
 
14
;
-
 
15
;-------------------------------------------------------------------------
-
 
16
 
7
 
17
$Revision: 5363 $
8
$Revision: 6262 $
18
 
9
 
19
 
10
 
20
iglobal
11
iglobal
21
; pointer to memory for path replace table,
12
; pointer to memory for path replace table,
22
; size of one record is 128 bytes: 64 bytes for search pattern + 64 bytes for replace string
13
; size of one record is 128 bytes: 64 bytes for search pattern + 64 bytes for replace string
23
 
14
 
24
; start with one entry: sys -> 
15
; start with one entry: sys -> 
25
full_file_name_table dd sysdir_name
16
full_file_name_table dd sysdir_name
26
.size           dd      1
17
.size           dd      1
27
 
18
 
28
tmp_file_name_size dd   1
19
tmp_file_name_size dd   1
29
endg
20
endg
30
 
21
 
31
uglobal
22
uglobal
32
; Parser_params will initialize: sysdir_name = "sys", sysdir_path = 
23
; Parser_params will initialize: sysdir_name = "sys", sysdir_path = 
33
sysdir_name     rb      64
24
sysdir_name     rb      64
34
sysdir_path     rb      64
25
sysdir_path     rb      64
35
sysdir_name1    rb      64
26
sysdir_name1    rb      64
36
sysdir_path1    rb      64
27
sysdir_path1    rb      64
37
 
28
 
38
; for example:
29
; for example:
39
;dir_name1      db 'KolibriOS',0
30
;dir_name1      db 'KolibriOS',0
40
;               rb 64-8
31
;               rb 64-8
41
;dir_path1      db 'HD0/1',0
32
;dir_path1      db 'HD0/1',0
42
;               rb 64-6
33
;               rb 64-6
43
endg
34
endg
44
 
35
 
45
uglobal
36
uglobal
46
tmp_file_name_table dd  ?
37
tmp_file_name_table dd  ?
47
endg
38
endg
48
 
39
 
49
; use bx_from_load and init system directory /sys
40
; use bx_from_load and init system directory /sys
50
proc Parser_params
41
proc Parser_params
51
locals
42
locals
52
  buff db 4 dup(?)              ; for test cd
43
  buff db 4 dup(?)              ; for test cd
53
endl
44
endl
54
        mov     eax, [OS_BASE+0x10000+bx_from_load]
45
        mov     eax, [OS_BASE+0x10000+bx_from_load]
55
        mov     ecx, sysdir_path
46
        mov     ecx, sysdir_path
56
        mov     [ecx-64], dword 'sys'
47
        mov     [ecx-64], dword 'sys'
57
        cmp     al, 'r'; if ram disk
48
        cmp     al, 'r'; if ram disk
58
        jnz     @f
49
        jnz     @f
59
        mov     [ecx], dword 'RD/?'
50
        mov     [ecx], dword 'RD/?'
60
        mov     [ecx+3], byte ah
51
        mov     [ecx+3], byte ah
61
        mov     [ecx+4], byte 0
52
        mov     [ecx+4], byte 0
62
        ret
53
        ret
63
@@:
54
@@:
64
        cmp     al, 'm'; if ram disk
55
        cmp     al, 'm'; if ram disk
65
        jnz     @f
56
        jnz     @f
66
        mov     [ecx], dword 'CD?/'; if cd disk {m}
57
        mov     [ecx], dword 'CD?/'; if cd disk {m}
67
        mov     [ecx+4], byte '1'
58
        mov     [ecx+4], byte '1'
68
        mov     [ecx+5], dword '/KOL'
59
        mov     [ecx+5], dword '/KOL'
69
        mov     [ecx+9], dword 'IBRI'
60
        mov     [ecx+9], dword 'IBRI'
70
        mov     [ecx+13], byte 0
61
        mov     [ecx+13], byte 0
71
.next_cd:
62
.next_cd:
72
        mov     [ecx+2], byte ah
63
        mov     [ecx+2], byte ah
73
        inc     ah
64
        inc     ah
74
        cmp     ah, '5'
65
        cmp     ah, '5'
75
        je      .not_found_cd
66
        je      .not_found_cd
76
        lea     edx, [buff]
67
        lea     edx, [buff]
77
        pushad
68
        pushad
78
        stdcall read_file, read_firstapp, edx, 0, 4
69
        stdcall read_file, read_firstapp, edx, 0, 4
79
        popad
70
        popad
80
        cmp     [edx], dword 'MENU'
71
        cmp     [edx], dword 'MENU'
81
        jne     .next_cd
72
        jne     .next_cd
82
        jmp     .ok
73
        jmp     .ok
83
 
74
 
84
@@:
75
@@:
85
        sub     al, 49
76
        sub     al, 49
86
        mov     [ecx], dword 'HD?/'; if hard disk
77
        mov     [ecx], dword 'HD?/'; if hard disk
87
        mov     [ecx+2], byte al
78
        mov     [ecx+2], byte al
88
        mov     [ecx+4], byte ah
79
        mov     [ecx+4], byte ah
89
        mov     [ecx+5], dword '/KOL'
80
        mov     [ecx+5], dword '/KOL'
90
        mov     [ecx+9], dword 'IBRI'
81
        mov     [ecx+9], dword 'IBRI'
91
        mov     [ecx+13], byte 0
82
        mov     [ecx+13], byte 0
92
.ok:
83
.ok:
93
.not_found_cd:
84
.not_found_cd:
94
        ret
85
        ret
95
endp
86
endp
96
 
87
 
97
proc load_file_parse_table
88
proc load_file_parse_table
98
        stdcall kernel_alloc, 0x1000
89
        stdcall kernel_alloc, 0x1000
99
        mov     [tmp_file_name_table], eax
90
        mov     [tmp_file_name_table], eax
100
        mov     edi, eax
91
        mov     edi, eax
101
        mov     esi, sysdir_name
92
        mov     esi, sysdir_name
102
        mov     ecx, 128/4
93
        mov     ecx, 128/4
103
        rep movsd
94
        rep movsd
104
 
95
 
105
        invoke  ini.enum_keys, conf_fname, conf_path_sect, get_every_key
96
        invoke  ini.enum_keys, conf_fname, conf_path_sect, get_every_key
106
 
97
 
107
        mov     eax, [tmp_file_name_table]
98
        mov     eax, [tmp_file_name_table]
108
        mov     [full_file_name_table], eax
99
        mov     [full_file_name_table], eax
109
        mov     eax, [tmp_file_name_size]
100
        mov     eax, [tmp_file_name_size]
110
        mov     [full_file_name_table.size], eax
101
        mov     [full_file_name_table.size], eax
111
        ret
102
        ret
112
endp
103
endp
113
 
104
 
114
uglobal
105
uglobal
115
def_val_1 db 0
106
def_val_1 db 0
116
endg
107
endg
117
 
108
 
118
proc get_every_key stdcall, f_name, sec_name, key_name
109
proc get_every_key stdcall, f_name, sec_name, key_name
119
        mov     esi, [key_name]
110
        mov     esi, [key_name]
120
        mov     ecx, esi
111
        mov     ecx, esi
121
        cmp     byte [esi], '/'
112
        cmp     byte [esi], '/'
122
        jnz     @f
113
        jnz     @f
123
        inc     esi
114
        inc     esi
124
@@:
115
@@:
125
        mov     edi, [tmp_file_name_size]
116
        mov     edi, [tmp_file_name_size]
126
        shl     edi, 7
117
        shl     edi, 7
127
        cmp     edi, 0x1000
118
        cmp     edi, 0x1000
128
        jae     .stop_parse
119
        jae     .stop_parse
129
        add     edi, [tmp_file_name_table]
120
        add     edi, [tmp_file_name_table]
130
        lea     ebx, [edi+64]
121
        lea     ebx, [edi+64]
131
@@:
122
@@:
132
        cmp     edi, ebx
123
        cmp     edi, ebx
133
        jae     .skip_this_key
124
        jae     .skip_this_key
134
        lodsb
125
        lodsb
135
        test    al, al
126
        test    al, al
136
        jz      @f
127
        jz      @f
137
        or      al, 20h
128
        or      al, 20h
138
        stosb
129
        stosb
139
        jmp     @b
130
        jmp     @b
140
@@:
131
@@:
141
        stosb
132
        stosb
142
 
133
 
143
        invoke  ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1
134
        invoke  ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1
144
 
135
 
145
        cmp     byte [ebx], '/'
136
        cmp     byte [ebx], '/'
146
        jnz     @f
137
        jnz     @f
147
        lea     esi, [ebx+1]
138
        lea     esi, [ebx+1]
148
        mov     edi, ebx
139
        mov     edi, ebx
149
        mov     ecx, 63
140
        mov     ecx, 63
150
        rep movsb
141
        rep movsb
151
@@:
142
@@:
152
        push    ebp
143
        push    ebp
153
        mov     ebp, [tmp_file_name_table]
144
        mov     ebp, [tmp_file_name_table]
154
        mov     ecx, [tmp_file_name_size]
145
        mov     ecx, [tmp_file_name_size]
155
        jecxz   .noreplace
146
        jecxz   .noreplace
156
        mov     eax, ecx
147
        mov     eax, ecx
157
        dec     eax
148
        dec     eax
158
        shl     eax, 7
149
        shl     eax, 7
159
        add     ebp, eax
150
        add     ebp, eax
160
.replace_loop:
151
.replace_loop:
161
        mov     edi, ebx
152
        mov     edi, ebx
162
        mov     esi, ebp
153
        mov     esi, ebp
163
@@:
154
@@:
164
        lodsb
155
        lodsb
165
        test    al, al
156
        test    al, al
166
        jz      .doreplace
157
        jz      .doreplace
167
        mov     dl, [edi]
158
        mov     dl, [edi]
168
        inc     edi
159
        inc     edi
169
        test    dl, dl
160
        test    dl, dl
170
        jz      .replace_loop_cont
161
        jz      .replace_loop_cont
171
        or      dl, 20h
162
        or      dl, 20h
172
        cmp     al, dl
163
        cmp     al, dl
173
        jz      @b
164
        jz      @b
174
        jmp     .replace_loop_cont
165
        jmp     .replace_loop_cont
175
.doreplace:
166
.doreplace:
176
        cmp     byte [edi], 0
167
        cmp     byte [edi], 0
177
        jz      @f
168
        jz      @f
178
        cmp     byte [edi], '/'
169
        cmp     byte [edi], '/'
179
        jnz     .replace_loop_cont
170
        jnz     .replace_loop_cont
180
@@:
171
@@:
181
        lea     esi, [ebp+64]
172
        lea     esi, [ebp+64]
182
        call    .replace
173
        call    .replace
183
        jc      .skip_this_key2
174
        jc      .skip_this_key2
184
.replace_loop_cont:
175
.replace_loop_cont:
185
        sub     ebp, 128
176
        sub     ebp, 128
186
        loop    .replace_loop
177
        loop    .replace_loop
187
.noreplace:
178
.noreplace:
188
        pop     ebp
179
        pop     ebp
189
 
180
 
190
        inc     [tmp_file_name_size]
181
        inc     [tmp_file_name_size]
191
.skip_this_key:
182
.skip_this_key:
192
        xor     eax, eax
183
        xor     eax, eax
193
        inc     eax
184
        inc     eax
194
        ret
185
        ret
195
.skip_this_key2:
186
.skip_this_key2:
196
        pop     ebp
187
        pop     ebp
197
        jmp     .skip_this_key
188
        jmp     .skip_this_key
198
.stop_parse:
189
.stop_parse:
199
        xor     eax, eax
190
        xor     eax, eax
200
        ret
191
        ret
201
endp
192
endp
202
 
193
 
203
proc get_every_key.replace
194
proc get_every_key.replace
204
; in: ebx->destination, esi->first part of name, edi->second part of name
195
; in: ebx->destination, esi->first part of name, edi->second part of name
205
; maximum length is 64 bytes
196
; maximum length is 64 bytes
206
; out: CF=1 <=> overflow
197
; out: CF=1 <=> overflow
207
; 1) allocate temporary buffer in stack
198
; 1) allocate temporary buffer in stack
208
        sub     esp, 64
199
        sub     esp, 64
209
; 2) save second part of name to temporary buffer
200
; 2) save second part of name to temporary buffer
210
        push    esi
201
        push    esi
211
        lea     esi, [esp+4]    ; esi->tmp buffer
202
        lea     esi, [esp+4]    ; esi->tmp buffer
212
        xchg    esi, edi        ; edi->tmp buffer, esi->source
203
        xchg    esi, edi        ; edi->tmp buffer, esi->source
213
@@:
204
@@:
214
        lodsb
205
        lodsb
215
        stosb
206
        stosb
216
        test    al, al
207
        test    al, al
217
        jnz     @b
208
        jnz     @b
218
; 3) copy first part of name to destination
209
; 3) copy first part of name to destination
219
        pop     esi
210
        pop     esi
220
        mov     edi, ebx
211
        mov     edi, ebx
221
@@:
212
@@:
222
        lodsb
213
        lodsb
223
        test    al, al
214
        test    al, al
224
        jz      @f
215
        jz      @f
225
        stosb
216
        stosb
226
        jmp     @b
217
        jmp     @b
227
@@:
218
@@:
228
; 4) restore second part of name from temporary buffer to destination
219
; 4) restore second part of name from temporary buffer to destination
229
; (may cause overflow)
220
; (may cause overflow)
230
        lea     edx, [ebx+64]   ; limit of destination
221
        lea     edx, [ebx+64]   ; limit of destination
231
        mov     esi, esp
222
        mov     esi, esp
232
@@:
223
@@:
233
        cmp     edi, edx
224
        cmp     edi, edx
234
        jae     .overflow
225
        jae     .overflow
235
        lodsb
226
        lodsb
236
        stosb
227
        stosb
237
        test    al, al
228
        test    al, al
238
        jnz     @b
229
        jnz     @b
239
; all is OK
230
; all is OK
240
        add     esp, 64         ; CF is cleared
231
        add     esp, 64         ; CF is cleared
241
        ret
232
        ret
242
.overflow:
233
.overflow:
243
; name is too long
234
; name is too long
244
        add     esp, 64
235
        add     esp, 64
245
        stc
236
        stc
246
        ret
237
        ret
247
endp
238
endp
-
 
239
 
-
 
240
 
-
 
241
char_todown:
-
 
242
; convert character in al to downcase, using cp866 encoding
-
 
243
        cmp     al, 'A'
-
 
244
        jb      .ret
-
 
245
        cmp     al, 'Z'
-
 
246
        jbe     .az
-
 
247
        cmp     al, 0x80 ; 'А'
-
 
248
        jb      .ret
-
 
249
        cmp     al, 0x90 ; 'Р'
-
 
250
        jb      .rus
-
 
251
        cmp     al, 0xF0 ; 'Ё'
-
 
252
        jz      .yo
-
 
253
        cmp     al, 0x9F ; 'Я'
-
 
254
        ja      .ret
-
 
255
; 0x90-0x9F -> 0xE0-0xEF
-
 
256
        add     al, 0xE0-0x90
-
 
257
.ret:
-
 
258
        ret
-
 
259
 
-
 
260
.az:
-
 
261
.rus:  ; 0x80-0x8F -> 0xA0-0xAF
-
 
262
        add     al, 0x20
-
 
263
        ret
-
 
264
 
-
 
265
.yo:
-
 
266
        inc     al
-
 
267
        ret
-
 
268
 
-
 
269
 
-
 
270
char_toupper:
-
 
271
; convert character in al to uppercase, using cp866 encoding
-
 
272
        cmp     al, 'a'
-
 
273
        jb      .ret
-
 
274
        cmp     al, 'z'
-
 
275
        jbe     .az
-
 
276
        cmp     al, 0xA0 ; 'а'
-
 
277
        jb      .ret
-
 
278
        cmp     al, 0xE0 ; 'р'
-
 
279
        jb      .rus
-
 
280
        cmp     al, 0xF1 ; 'ё'
-
 
281
        jz      .yo
-
 
282
        cmp     al, 0xEF ; 'я'
-
 
283
        ja      .ret
-
 
284
; 0xE0-0xEF -> 0x90-0x9F
-
 
285
        sub     al, 0xE0-0x90
-
 
286
.ret:
-
 
287
        ret
-
 
288
 
-
 
289
.az:
-
 
290
.rus:  ; 0xA0-0xAF -> 0x80-0x8F
-
 
291
        and     al, not 0x20
-
 
292
        ret
-
 
293
 
-
 
294
.yo:
-
 
295
        dec     al
-
 
296
        ret
-
 
297
 
-
 
298
 
-
 
299
uni2ansi_str:
-
 
300
; convert UNICODE zero-terminated string to ASCII-string (codepage 866)
-
 
301
; in: esi->source, edi->buffer (may be esi=edi)
-
 
302
; destroys: eax,esi,edi
-
 
303
        lodsw
-
 
304
        call    uni2ansi_char
-
 
305
        stosb
-
 
306
        test    al, al
-
 
307
        jnz     uni2ansi_str
-
 
308
        ret
-
 
309
 
-
 
310
 
-
 
311
uni2ansi_char:
-
 
312
; convert UNICODE character in ax to ANSI character in al using cp866 encoding
-
 
313
        cmp     ax, 0x80
-
 
314
        jb      .ret
-
 
315
        cmp     ax, 0xB6
-
 
316
        jz      .B6
-
 
317
        cmp     ax, 0x400
-
 
318
        jb      .unk
-
 
319
        cmp     ax, 0x410
-
 
320
        jb      @f
-
 
321
        cmp     ax, 0x440
-
 
322
        jb      .rus1
-
 
323
        cmp     ax, 0x450
-
 
324
        jb      .rus2
-
 
325
        cmp     ax, 0x460
-
 
326
        jb      @f
-
 
327
.unk:
-
 
328
        mov     al, '_'
-
 
329
.ret:
-
 
330
        ret
-
 
331
 
-
 
332
.B6:
-
 
333
        mov     al, 20
-
 
334
        ret
-
 
335
 
-
 
336
.rus1:  ; 0x410-0x43F -> 0x80-0xAF
-
 
337
        add     al, 0x70
-
 
338
        ret
-
 
339
 
-
 
340
.rus2:  ; 0x440-0x44F -> 0xE0-0xEF
-
 
341
        add     al, 0xA0
-
 
342
        ret
-
 
343
 
-
 
344
@@:
-
 
345
        push    ecx edi
-
 
346
        mov     ecx, 8
-
 
347
        mov     edi, .table
-
 
348
        repnz scasb
-
 
349
        mov     ah, cl
-
 
350
        pop     edi ecx
-
 
351
        jnz     .unk
-
 
352
        mov     al, 0xF7
-
 
353
        sub     al, ah
-
 
354
        ret
-
 
355
 
-
 
356
.table  db  1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh
-
 
357
 
-
 
358
 
-
 
359
ansi2uni_char:
-
 
360
; convert ANSI character in al to UNICODE character in ax, using cp866 encoding
-
 
361
        movzx   eax, al
-
 
362
        cmp     al, 0x80
-
 
363
        jb      @f      ; 0x00-0x7F - trivial map
-
 
364
        cmp     al, 0xB0
-
 
365
        jb      .rus    ; 0x80-0xAF -> 0x410-0x43F
-
 
366
        cmp     al, 0xE0
-
 
367
        jb      .unk
-
 
368
        cmp     al, 0xF0
-
 
369
        jb      .rus2   ; 0xE0-0xEF -> 0x440-0x44F
-
 
370
        cmp     al, 0xF8
-
 
371
        jnc     .unk
-
 
372
        mov     al, [eax+uni2ansi_char.table-0xF0]
-
 
373
        add     ax, 400h
-
 
374
        ret
-
 
375
 
-
 
376
@@:
-
 
377
        cmp     al, 20
-
 
378
        jnz     .ret
-
 
379
        mov     al, 0xB6
-
 
380
.ret:
-
 
381
        ret
-
 
382
 
-
 
383
.rus:
-
 
384
        add     ax, 0x410-0x80
-
 
385
        ret
-
 
386
 
-
 
387
.rus2:
-
 
388
        add     ax, 0x440-0xE0
-
 
389
        ret
-
 
390
 
-
 
391
.unk:
-
 
392
        mov     al, '_'
-
 
393
        ret