Subversion Repositories Kolibri OS

Rev

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

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