Execute CopyPasta Language: Difference between revisions

m
No edit summary
Line 181:
=={{header|Nanoquery}}==
<lang Nanoquery>// a function to handle fatal errors
def fatal_error($errtext)
println "%" + $errtext
println "usage: " + $args[1] + " [filename.cp]"
exit
end
 
// get a filename from the command line and read the file in
$fname = $null
$source = $null
try
$fname = $args[2]
$source = new(Nanoquery.IO.File, $fname).readAll()
catch
fatal_error("error while trying to read from specified file")
end
 
// convert the source to lines of code
$lines = split($source, "\n")
 
// a variable to represent the 'clipboard'
$clipboard = ""
 
// loop over the lines that were read
$loc = 0
while ($loc < len($lines))
// check which command is on this line
$command = trim($lines[$loc])
 
try
if ($command = "Copy")
$clipboard = $clipboard + $lines[$loc + 1]
else if ($command = "CopyFile")
if ($lines[$loc + 1] = "TheF*ckingCode")
$clipboard = $clipboard + $source
else
$filetext = new(Nanoquery.IO.File, $lines[$loc + 1]).readAll()
$clipboard = $clipboard + $filetext
end
else if ($command = "Duplicate")
$clipboard = $clipboard + $clipboard * ((int($lines[$loc + 1])) - 1)
else if ($command = "Pasta!")
println $clipboard
exit
else
fatal_error("unknown command '" + $command + "' encountered on line " + ($loc + 1))
end
catch
fatal_error("error while executing command '" + $command + "' on line " + ($loc + 1))
end
 
// increment past the command and the next line
$loc = $loc + 2
end</lang>
 
Anonymous user