forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress_data.rev
More file actions
50 lines (42 loc) · 1.17 KB
/
compress_data.rev
File metadata and controls
50 lines (42 loc) · 1.17 KB
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
#! /usr/bin/revolution -ui
# $1 = source file
# $2 = dst file
# $3 = var name
on startup
try
generate
catch tError
write tError & return to stderr
end try
end startup
on generate
local tSource
set the itemDelimiter to comma
local tText, tCText, tBinary, tLength
put the compress of url ("binfile:" & $1) into tBinary
put the length of tBinary into tLength
put binaryToC(tBinary) into tCText
put "unsigned char " & $3 & "[] =" & return after tText
put "{" & return after tText
put " " & tCText & return after tText
put "};" & return after tText
put "unsigned int " & $3 & "_length = " & tLength & ";" & return after tText
put tText into url ("file:" & $2)
end generate
function binaryToC pBinary
local tData, tIndex
put 0 into tIndex
repeat for each character tByte in pBinary
put format("0x%02x, ", charToNum(tByte)) after tData
add 1 to tIndex
if tIndex mod 16 is 0 then
put return & " " after tData
end if
end repeat
if tIndex mod 16 is 0 then
delete char -5 to -1 of tData
else
delete char -2 to -1 of tData
end if
return tData
end binaryToC