#! /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 tInput, tOutput, tLength
  put url ("file:" & $1) into tInput

  put "const char *" & $3 & "[] =" & return after tOutput
  put "{" & return after tOutput
  repeat for each line tLine in tInput
    replace "\" with "\\" in tLine
    replace quote with "\" & quote in tLine
    put tab & quote & tLine & "\n" & quote & comma & return after tOutput
  end repeat
  put tab & 0 & return after tOutput
  put "}" & return after tOutput
  put ";" & return after tOutput

  put tOutput into url ("file:" & $2)
end generate
