Subversion Repositories Kolibri OS

Rev

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

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