FILE(READ ${infile} f0)
STRING( LENGTH "${f0}" f0_LEN )
SET( f4 "// This is automatically generated code -- do not edit!\n// Generated from ${file} \n#include <vector>\nnamespace skeletons\n{\n\n" )
SET( idx 0 )

# Max size for MSVC is 65K, but we're adding CRLFs here too.
SET( chunklength 55000)

WHILE( f0_LEN GREATER 0 )
  MATH( EXPR idx "${idx} + 1" )
  IF( f0_LEN GREATER ${chunklength} )
    STRING( SUBSTRING "${f0}" 0 ${chunklength} f3_CHUNK )
    STRING( REGEX REPLACE "\\\\" "\\\\\\\\" f1 "${f3_CHUNK}" )
    STRING( REGEX REPLACE "\"" "\\\\\"" f2 "${f1}" )
    STRING( REGEX REPLACE "\r?\n" "\\\\r\\\\n\"\n  \"" f3 "${f2}" )
    
    SET( f4 "${f4}\n  const char * ${var}${idx} = \"${f3}\";" )
    MATH( EXPR f0_LEN "${f0_LEN} - ${chunklength}" )
    STRING( SUBSTRING "${f0}" ${chunklength} ${f0_LEN} f0)       
  ELSE(f0_LEN GREATER ${chunklength})
    STRING( SUBSTRING "${f0}" 0 ${f0_LEN} f3_CHUNK )
    STRING( REGEX REPLACE "\\\\" "\\\\\\\\" f1 "${f3_CHUNK}" )
    STRING( REGEX REPLACE "\"" "\\\\\"" f2 "${f1}" )
    STRING( REGEX REPLACE "\r?\n" "\\\\r\\\\n\"\n  \"" f3 "${f2}" )
    SET( f4 "${f4}\n  const char * ${var}${idx} = \"${f3}\";" )
    SET( f0_LEN 0 )
  ENDIF(f0_LEN GREATER ${chunklength})
ENDWHILE( f0_LEN GREATER 0 )
MATH( EXPR idx "${idx} + 1" )
SET( f4 "${f4}\n  std::vector<const char *> ${var}()\n  {" )
SET( f4 "${f4}\n    std::vector<const char *> retval;\n")
SET( id 1 )
WHILE( ${id} LESS ${idx} )
  SET( f4 "${f4}\n    retval.push_back(${var}${id});\n")
  MATH( EXPR id "${id} + 1" )
ENDWHILE( ${id} LESS ${idx} )
SET( f4 "${f4}\n    return retval;\n  }")
SET( f4 "${f4}\n}")
FILE(WRITE ${outfile} "${f4}")

