This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_strings.e
63 lines (56 loc) · 1.62 KB
/
extract_strings.e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- Èçâëå÷åíèå ñòðîê èç èñïîëíÿåìîãî ôàéëà
include std/map.e
include std/io.e
constant blocksize = 1024
function forbidden(integer i)
return find(i,"$;@^`{|}")
end function
function allowed(integer i)
return i='\r' or i='\t' or (i>=' ' and i<127 and not forbidden(i))
end function
function letter(integer i)
return (i>='A' and i<='Z') or (i>='a' and i<='z')
end function
-- Ïîëó÷èòü ñïèñîê ñòðîê â âèäå ñïèñêà ïàð {ñìåùåíèå, ñòðîêà}
sequence strings
function check_string(object key, object val, object fn, integer progress_code)
object buf
integer len
if progress_code <= 0 then
-- map is empty or the last call
return strings
end if
-- integer fn = user_data[1]
-- èñêëþ÷èòü ññûëêè íà ñåðåäèíû ñòðîê:
if length(strings)>0 and key <= strings[$][1]+length(strings[$][2]) then
return 0
end if
-- ñ÷èòûâàåì áëîê äàííûõ:
seek(fn, key)
buf = get_bytes(fn, blocksize)
if atom(buf) then
return -1
end if
-- ïðîâåðÿåì, ÿâëÿåòñÿ ëè äàííûé îáúåêò ñòðîêîé
len = -1
integer letters = 0
for i = 1 to length(buf) do
if buf[i] = 0 then
len = i-1
exit
elsif not allowed(buf[i]) then
exit
elsif letter(buf[i]) then
letters += 1
end if
end for
if len>0 and letters>0 then
strings = append(strings, {key, buf[1..len]})
end if
return 0
end function
public
function extract_strings_map(atom fn, map xrefs)
strings = {}
return for_each(xrefs,routine_id("check_string"),fn,1,1)
end function