f2s.src
// f2s.src | FILE TO STRING file_to_lines = function(comp,inFilePath) content = comp.File(inFilePath).get_content.replace(char(9),"") lines = content.split(char(10)) parsedLines = [] rSearchTokens = ["if","or","in","for","and","end","not","else","then","true","false","while","return"] fSearchTokens = ["in","and","then"] for line in lines inString = false parenthesis = false line = line.trim if line.len != 0 and line.indexOf("//") != 0 then tmp = "" for i in range(0, line.len-1) //double quote if line[i] == char(34) then inString = inString == false // close parenthesis else if (line[i] == char(40) and line[i+1] == char(41)) or parenthesis == true then parenthesis = parenthesis == false continue // space else if line[i] == char(32) and inString == false then skip = true for token in fSearchTokens if line[i+1:i+token.len+1] == token then skip = false; break end if end for if skip == true then for token in rSearchTokens if line[i-token.len:i] == token then skip = false break end if end for end if if skip == true then continue end if tmp = tmp+line[i] end for parsedLines.push(tmp) end if end for return parsedLines end function main = function() if params.len < 1 then exit("USAGE: f2s [inFilePath] [(opt) outVarName]") lc = get_shell.host_computer inFilePath = params[0] inFileName = inFilePath.split("/")[-1] outFilePath = inFilePath.split("/")[:-1].join("/") outFileName = inFileName+".f2s" outVarName = "myVar" if params.len > 1 then outVarName = params[1] lines = file_to_lines(lc,inFilePath) lc.touch(outFilePath,outFileName) lc.File(outFilePath+"/"+outFileName).set_content(outVarName+"="+lines) print("file converted to string array at "+outFilePath+"/"+outFileName) end function main