Subversion Repositories Kolibri OS

Rev

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

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