#! /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 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 ("binfile:" & $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