Subversion Repositories Kolibri OS

Rev

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

Rev 3780 Rev 5363
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2011. 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
 
7
 
8
;-------------------------------------------------------------------------
8
;-------------------------------------------------------------------------
9
;
9
;
10
;  File path partial substitution (according to configuration)
10
;  File path partial substitution (according to configuration)
11
;
11
;
12
;
12
;
13
;     SPraid
13
;     SPraid
14
;
14
;
15
;-------------------------------------------------------------------------
15
;-------------------------------------------------------------------------
16
 
16
 
17
$Revision: 3780 $
17
$Revision: 5363 $
18
 
18
 
19
 
19
 
20
iglobal
20
iglobal
21
; pointer to memory for path replace table,
21
; 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
22
; size of one record is 128 bytes: 64 bytes for search pattern + 64 bytes for replace string
23
 
23
 
24
; start with one entry: sys -> 
24
; start with one entry: sys -> 
25
full_file_name_table dd sysdir_name
25
full_file_name_table dd sysdir_name
26
.size           dd      1
26
.size           dd      1
27
 
27
 
28
tmp_file_name_size dd   1
28
tmp_file_name_size dd   1
29
endg
29
endg
30
 
30
 
31
uglobal
31
uglobal
32
; Parser_params will initialize: sysdir_name = "sys", sysdir_path = 
32
; Parser_params will initialize: sysdir_name = "sys", sysdir_path = 
33
sysdir_name     rb      64
33
sysdir_name     rb      64
34
sysdir_path     rb      64
34
sysdir_path     rb      64
35
sysdir_name1    rb      64
35
sysdir_name1    rb      64
36
sysdir_path1    rb      64
36
sysdir_path1    rb      64
37
 
37
 
38
; for example:
38
; for example:
39
;dir_name1      db 'KolibriOS',0
39
;dir_name1      db 'KolibriOS',0
40
;               rb 64-8
40
;               rb 64-8
41
;dir_path1      db 'HD0/1',0
41
;dir_path1      db 'HD0/1',0
42
;               rb 64-6
42
;               rb 64-6
43
endg
43
endg
44
 
44
 
45
uglobal
45
uglobal
46
tmp_file_name_table dd  ?
46
tmp_file_name_table dd  ?
47
endg
47
endg
48
 
48
 
49
; use bx_from_load and init system directory /sys
49
; use bx_from_load and init system directory /sys
50
proc Parser_params
50
proc Parser_params
51
locals
51
locals
52
  buff db 4 dup(?)              ; for test cd
52
  buff db 4 dup(?)              ; for test cd
53
endl
53
endl
54
        mov     eax, [OS_BASE+0x10000+bx_from_load]
54
        mov     eax, [OS_BASE+0x10000+bx_from_load]
55
        mov     ecx, sysdir_path
55
        mov     ecx, sysdir_path
56
        mov     [ecx-64], dword 'sys'
56
        mov     [ecx-64], dword 'sys'
57
        cmp     al, 'r'; if ram disk
57
        cmp     al, 'r'; if ram disk
58
        jnz     @f
58
        jnz     @f
59
        mov     [ecx], dword 'RD/?'
59
        mov     [ecx], dword 'RD/?'
60
        mov     [ecx+3], byte ah
60
        mov     [ecx+3], byte ah
61
        mov     [ecx+4], byte 0
61
        mov     [ecx+4], byte 0
62
        ret
62
        ret
63
@@:
63
@@:
64
        cmp     al, 'm'; if ram disk
64
        cmp     al, 'm'; if ram disk
65
        jnz     @f
65
        jnz     @f
66
        mov     [ecx], dword 'CD?/'; if cd disk {m}
66
        mov     [ecx], dword 'CD?/'; if cd disk {m}
67
        mov     [ecx+4], byte '1'
67
        mov     [ecx+4], byte '1'
68
        mov     [ecx+5], dword '/KOL'
68
        mov     [ecx+5], dword '/KOL'
69
        mov     [ecx+9], dword 'IBRI'
69
        mov     [ecx+9], dword 'IBRI'
70
        mov     [ecx+13], byte 0
70
        mov     [ecx+13], byte 0
71
.next_cd:
71
.next_cd:
72
        mov     [ecx+2], byte ah
72
        mov     [ecx+2], byte ah
73
        inc     ah
73
        inc     ah
74
        cmp     ah, '5'
74
        cmp     ah, '5'
75
        je      .not_found_cd
75
        je      .not_found_cd
76
        lea     edx, [buff]
76
        lea     edx, [buff]
77
        pushad
77
        pushad
78
        stdcall read_file, read_firstapp, edx, 0, 4
78
        stdcall read_file, read_firstapp, edx, 0, 4
79
        popad
79
        popad
80
        cmp     [edx], dword 'MENU'
80
        cmp     [edx], dword 'MENU'
81
        jne     .next_cd
81
        jne     .next_cd
82
        jmp     .ok
82
        jmp     .ok
83
 
83
 
84
@@:
84
@@:
85
        sub     al, 49
85
        sub     al, 49
86
        mov     [ecx], dword 'HD?/'; if hard disk
86
        mov     [ecx], dword 'HD?/'; if hard disk
87
        mov     [ecx+2], byte al
87
        mov     [ecx+2], byte al
88
        mov     [ecx+4], byte ah
88
        mov     [ecx+4], byte ah
89
        mov     [ecx+5], dword '/KOL'
89
        mov     [ecx+5], dword '/KOL'
90
        mov     [ecx+9], dword 'IBRI'
90
        mov     [ecx+9], dword 'IBRI'
91
        mov     [ecx+13], byte 0
91
        mov     [ecx+13], byte 0
92
.ok:
92
.ok:
93
.not_found_cd:
93
.not_found_cd:
94
        ret
94
        ret
95
endp
95
endp
96
 
96
 
97
proc load_file_parse_table
97
proc load_file_parse_table
98
        stdcall kernel_alloc, 0x1000
98
        stdcall kernel_alloc, 0x1000
99
        mov     [tmp_file_name_table], eax
99
        mov     [tmp_file_name_table], eax
100
        mov     edi, eax
100
        mov     edi, eax
101
        mov     esi, sysdir_name
101
        mov     esi, sysdir_name
102
        mov     ecx, 128/4
102
        mov     ecx, 128/4
103
        rep movsd
103
        rep movsd
104
 
104
 
105
        invoke  ini.enum_keys, conf_fname, conf_path_sect, get_every_key
105
        invoke  ini.enum_keys, conf_fname, conf_path_sect, get_every_key
106
 
106
 
107
        mov     eax, [tmp_file_name_table]
107
        mov     eax, [tmp_file_name_table]
108
        mov     [full_file_name_table], eax
108
        mov     [full_file_name_table], eax
109
        mov     eax, [tmp_file_name_size]
109
        mov     eax, [tmp_file_name_size]
110
        mov     [full_file_name_table.size], eax
110
        mov     [full_file_name_table.size], eax
111
        ret
111
        ret
112
endp
112
endp
113
 
113
 
114
uglobal
114
uglobal
115
def_val_1 db 0
115
def_val_1 db 0
116
endg
116
endg
117
 
117
 
118
proc get_every_key stdcall, f_name, sec_name, key_name
118
proc get_every_key stdcall, f_name, sec_name, key_name
119
        mov     esi, [key_name]
119
        mov     esi, [key_name]
120
        mov     ecx, esi
120
        mov     ecx, esi
121
        cmp     byte [esi], '/'
121
        cmp     byte [esi], '/'
122
        jnz     @f
122
        jnz     @f
123
        inc     esi
123
        inc     esi
124
@@:
124
@@:
125
        mov     edi, [tmp_file_name_size]
125
        mov     edi, [tmp_file_name_size]
126
        shl     edi, 7
126
        shl     edi, 7
127
        cmp     edi, 0x1000
127
        cmp     edi, 0x1000
128
        jae     .stop_parse
128
        jae     .stop_parse
129
        add     edi, [tmp_file_name_table]
129
        add     edi, [tmp_file_name_table]
130
        lea     ebx, [edi+64]
130
        lea     ebx, [edi+64]
131
@@:
131
@@:
132
        cmp     edi, ebx
132
        cmp     edi, ebx
133
        jae     .skip_this_key
133
        jae     .skip_this_key
134
        lodsb
134
        lodsb
135
        test    al, al
135
        test    al, al
136
        jz      @f
136
        jz      @f
137
        or      al, 20h
137
        or      al, 20h
138
        stosb
138
        stosb
139
        jmp     @b
139
        jmp     @b
140
@@:
140
@@:
141
        stosb
141
        stosb
142
 
142
 
143
        invoke  ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1
143
        invoke  ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1
144
 
144
 
145
        cmp     byte [ebx], '/'
145
        cmp     byte [ebx], '/'
146
        jnz     @f
146
        jnz     @f
147
        lea     esi, [ebx+1]
147
        lea     esi, [ebx+1]
148
        mov     edi, ebx
148
        mov     edi, ebx
149
        mov     ecx, 63
149
        mov     ecx, 63
150
        rep movsb
150
        rep movsb
151
@@:
151
@@:
152
        push    ebp
152
        push    ebp
153
        mov     ebp, [tmp_file_name_table]
153
        mov     ebp, [tmp_file_name_table]
154
        mov     ecx, [tmp_file_name_size]
154
        mov     ecx, [tmp_file_name_size]
155
        jecxz   .noreplace
155
        jecxz   .noreplace
156
        mov     eax, ecx
156
        mov     eax, ecx
157
        dec     eax
157
        dec     eax
158
        shl     eax, 7
158
        shl     eax, 7
159
        add     ebp, eax
159
        add     ebp, eax
160
.replace_loop:
160
.replace_loop:
161
        mov     edi, ebx
161
        mov     edi, ebx
162
        mov     esi, ebp
162
        mov     esi, ebp
163
@@:
163
@@:
164
        lodsb
164
        lodsb
165
        test    al, al
165
        test    al, al
166
        jz      .doreplace
166
        jz      .doreplace
167
        mov     dl, [edi]
167
        mov     dl, [edi]
168
        inc     edi
168
        inc     edi
169
        test    dl, dl
169
        test    dl, dl
170
        jz      .replace_loop_cont
170
        jz      .replace_loop_cont
171
        or      dl, 20h
171
        or      dl, 20h
172
        cmp     al, dl
172
        cmp     al, dl
173
        jz      @b
173
        jz      @b
174
        jmp     .replace_loop_cont
174
        jmp     .replace_loop_cont
175
.doreplace:
175
.doreplace:
176
        cmp     byte [edi], 0
176
        cmp     byte [edi], 0
177
        jz      @f
177
        jz      @f
178
        cmp     byte [edi], '/'
178
        cmp     byte [edi], '/'
179
        jnz     .replace_loop_cont
179
        jnz     .replace_loop_cont
180
@@:
180
@@:
181
        lea     esi, [ebp+64]
181
        lea     esi, [ebp+64]
182
        call    .replace
182
        call    .replace
183
        jc      .skip_this_key2
183
        jc      .skip_this_key2
184
.replace_loop_cont:
184
.replace_loop_cont:
185
        sub     ebp, 128
185
        sub     ebp, 128
186
        loop    .replace_loop
186
        loop    .replace_loop
187
.noreplace:
187
.noreplace:
188
        pop     ebp
188
        pop     ebp
189
 
189
 
190
        inc     [tmp_file_name_size]
190
        inc     [tmp_file_name_size]
191
.skip_this_key:
191
.skip_this_key:
192
        xor     eax, eax
192
        xor     eax, eax
193
        inc     eax
193
        inc     eax
194
        ret
194
        ret
195
.skip_this_key2:
195
.skip_this_key2:
196
        pop     ebp
196
        pop     ebp
197
        jmp     .skip_this_key
197
        jmp     .skip_this_key
198
.stop_parse:
198
.stop_parse:
199
        xor     eax, eax
199
        xor     eax, eax
200
        ret
200
        ret
201
endp
201
endp
202
 
202
 
203
proc get_every_key.replace
203
proc get_every_key.replace
204
; in: ebx->destination, esi->first part of name, edi->second part of name
204
; in: ebx->destination, esi->first part of name, edi->second part of name
205
; maximum length is 64 bytes
205
; maximum length is 64 bytes
206
; out: CF=1 <=> overflow
206
; out: CF=1 <=> overflow
207
; 1) allocate temporary buffer in stack
207
; 1) allocate temporary buffer in stack
208
        sub     esp, 64
208
        sub     esp, 64
209
; 2) save second part of name to temporary buffer
209
; 2) save second part of name to temporary buffer
210
        push    esi
210
        push    esi
211
        lea     esi, [esp+4]    ; esi->tmp buffer
211
        lea     esi, [esp+4]    ; esi->tmp buffer
212
        xchg    esi, edi        ; edi->tmp buffer, esi->source
212
        xchg    esi, edi        ; edi->tmp buffer, esi->source
213
@@:
213
@@:
214
        lodsb
214
        lodsb
215
        stosb
215
        stosb
216
        test    al, al
216
        test    al, al
217
        jnz     @b
217
        jnz     @b
218
; 3) copy first part of name to destination
218
; 3) copy first part of name to destination
219
        pop     esi
219
        pop     esi
220
        mov     edi, ebx
220
        mov     edi, ebx
221
@@:
221
@@:
222
        lodsb
222
        lodsb
223
        test    al, al
223
        test    al, al
224
        jz      @f
224
        jz      @f
225
        stosb
225
        stosb
226
        jmp     @b
226
        jmp     @b
227
@@:
227
@@:
228
; 4) restore second part of name from temporary buffer to destination
228
; 4) restore second part of name from temporary buffer to destination
229
; (may cause overflow)
229
; (may cause overflow)
230
        lea     edx, [ebx+64]   ; limit of destination
230
        lea     edx, [ebx+64]   ; limit of destination
231
        mov     esi, esp
231
        mov     esi, esp
232
@@:
232
@@:
233
        cmp     edi, edx
233
        cmp     edi, edx
234
        jae     .overflow
234
        jae     .overflow
235
        lodsb
235
        lodsb
236
        stosb
236
        stosb
237
        test    al, al
237
        test    al, al
238
        jnz     @b
238
        jnz     @b
239
; all is OK
239
; all is OK
240
        add     esp, 64         ; CF is cleared
240
        add     esp, 64         ; CF is cleared
241
        ret
241
        ret
242
.overflow:
242
.overflow:
243
; name is too long
243
; name is too long
244
        add     esp, 64
244
        add     esp, 64
245
        stc
245
        stc
246
        ret
246
        ret
247
endp
247
endp