//  List Link Module Descriptors in Folder

/*
	Recursively scan the current folder or project and generates a list 
	of Link Module Descriptors (LMD's).
	
	Output is to a CSV file. 
	
	Tony Goodman.
*/


pragma runLim,0  /* turn off timeout dialog */


DB  dbMain        = null
DBE dbeExport     = null
DBE dbeExportPath = null

Folder currFolder = null
Buffer  outBuf    = null
 

/******************************************************************************
	scanFolder
******************************************************************************/
void scanFolder(Folder f) 
{
	LinkModuleDescriptor lmd
	
	Item   itm
	string s
	string t
	string l
   
	if (null f) return
	
	for lmd in f do
	{
		outBuf += fullName(f) ", " getSourceName(lmd) "," getTargetName(lmd) "," getName(lmd) "\n"
	}
			
	for itm in f do 
	{
		if (null itm) continue
		if (isDeleted(itm)) continue
	   
		if ((type (itm) == "Project") || (type (itm) == "Folder"))
		{
			scanFolder(folder(itm))	   
		}
	}
}


/******************************************************************************
	doClose
******************************************************************************/
void doClose(DB db)
{
	release(dbMain)
}


/******************************************************************************
	doList
******************************************************************************/
void doList(DB db)
{
	outBuf = create
    outBuf = ""

	string fName = get(dbeExportPath)
	
	Stream outfile = write(fName)
	
	outfile << "Folder, Source Module, Target Module, Link Module\n"
	
	scanFolder(currFolder)
	
	outfile << outBuf
	close(outfile)
	delete(outBuf)
	
	doClose(db)
}


/******************************************************************************
	MAIN
******************************************************************************/
currFolder = current Folder

dbMain = create("List Link Module Descriptors")

label(dbMain, "This utility exports a list of all link module descriptors\n" //-
              "Output is to a CSV file as follows:\n" //-
              "Folder, Source Module, Target Module, Link Module\n")
              
dbeExport     = field(dbMain, "Folder", fullName(currFolder), 50, true)
dbeExportPath = fileName(dbMain, "Report File", "C:/Temp/" name(currFolder) " Link Module Descriptors.csv")

ok(dbMain, "OK", doList)
close(dbMain, true, doClose)
realize dbMain

block(dbMain)

destroy(dbMain)
dbMain = null


sitemap