Subversion Repositories Kolibri OS

Rev

Rev 847 | Rev 851 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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