#!./ginsbasic001ok
include "wxbasicscript/basefunctions.inc"

orglist = readfiletolist("gins.c-body-norefs")
templist = {} 
foundrefs = {}
originals = {}
newrefs = {}
i = 0
for each theline in orglist

	if instr(theline , "+li") then

		print theline

		argslist = explode(theline , ",")
		
		for each argline in argslist
			if instr(argline , "+li") then
				argline = cutrightfromleft(argline , "->data")
				argline = replace(argline , "&" , "")
				argline = trim(argline)
originals[i] = argline & "->data"
				'print " --  " & argline 
				objecttype = cutright(argline , "+")
				objectline = replace(argline , "+li" , " *x" & objecttype) & ";"
				'print objectline
 				foundrefs[i] = objectline
				templist[i] = objectline
				newobject = cutleft(objectline , "*")
				newobject = cutright(newobject , ";")
				newrefs[i] = newobject
				i += 1
			end if
		next
	end if

next


natsort(templist)
sortedrefs = reducelist(templist)

for each theline in sortedrefs
	print theline
next

writelisttofile("gins-references.c" , sortedrefs)

print
for i=0 to count(foundrefs)-1

	print foundrefs[i] ," -- " &  originals[i]," -- " &  newrefs[i]

next

i=0
newlist = {}
for each theline in orglist

	oldline = theline
	if instr(theline , "+li") then
		'print "found..." & theline
		for n=0 to count(originals)-1
			theline = replace(theline , originals[n] , newrefs[n])
		next
	end if
	newlist[i] = theline
	i+=1
	for n=0 to 5

		if instr(oldline , "+li" & n) then
			ref = cutright(oldline , "+li" & n)
			ref = cutleftfromright(ref , "&")
			ref = "x" & ref & n
print "..." & ref
			newlist[i] = "GO[GOcount].obj = " & ref & ";"
			i+=1	

			newlist[i] = "createnewreturnobjectnosignal(arg" & n & ");"
			i+=1	

		end if

	next


next

writelisttofile("gins.c-body" , newlist)

















