Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: AFL_Glossary_Converter
Author/Uploader: Dennis Brown - see3d [at] writeme.com
Date/Time added: 2008-10-11 18:07:48
Origin: Original
Keywords: glossary
Level: advanced
Flags: indicator,commentary

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

Release #5. This AFL program is to aid in the AFL Glossary Project. Generates formated TXT or RTF Documents from Glossary database files. Will also sort and filter entries.

#5 Adds a Functional Hierarchical Listing Option.

Put database text files listed into a folder called AFL_Glossary in your main AmiBroker Folder:
AFL_Glossary_1.afl
AFL_Glossary_2.afl
AFL_Glossary_3.afl
AFL_Glossary_Groups.afl

This is just an experiment for now.

Formula:

//================================================================
// AmiBroker AFL Glossary database converter
// Modified by Dennis Brown 20081011 Release #5
//
// This program will read in a database text file and write out a reformatted
text file
//  see the sample database template for format (AFL_Glossary_1.txt or
AFL_Glossary_1.afl)
//  also see sample functional hierarchy document (AFL_Glossary.Groups.txt or
.afl)
// Formatting options are selected via parameters
//
// The process starts by reading a line at a time of the database text file(s)
// and saving the data items in variables that mimic
// string arrays of the form DataItemName + entryNum
// The DataItemName list:
//
// Name_entry
// Name_long
// Discription
// Return_type
// Return_name
// Left_type
// Left_name
// Right_type
// Right_name
// Right_close
// Arg_type_list
// Arg_name_list
// Arg_default_list
// Link_url_list
// Link_name_list
// Version_AB
// Tag_group_list
// Tag_search_list
// Related_entry_list
//
// In addition there is an item string of just the filtered entry numbers in 
//  output sort order that is created to generate the document.
//
// When generating a Full Groups listing, a separate pass is made using each
line of the Groups file
// as a filter.  This way entries can appear in more than one group.
//
spaces = "                                                                     
            "; //80 spaces

function getItem(LineText){ // get the keyword parameter item
	n = StrFind(LineText, ":"); // find end of keyword
	LineText = StrRight(LineText, StrLen(LineText) - n); // remove keyword
	while(StrLeft(LineText, 1)==" " OR StrLeft(LineText, 1)=="	"){ // remove
leading blanks
		LineText = StrRight(LineText, StrLen(LineText) - 1);
	}
	LineText = StrLeft(LineText, StrLen(LineText) - 1); // remove trailing EOL
char
	return LineText;
}

function TypeToName(type){ // Returns a default name for a type code
	while(True){
		if(StrFind(type, "Stmt")){typeName = "Statement"; break;}
		if(StrFind(type, "s")){typeName = "string"; break;}
		if(StrFind(type, "n")){typeName = "number"; break;}
		if(StrFind(type, "N")){typeName = "NumArray"; break;}
		if(StrFind(type, "b")){typeName = "boolean"; break;}
		if(StrFind(type, "B")){typeName = "BoolArray"; break;}
		if(StrFind(type, "d")){typeName = "dateTime"; break;}
		if(StrFind(type, "D")){typeName = "DateTimeArray"; break;}
		if(StrFind(type, "c")){typeName = "color"; break;}
		if(StrFind(type, "C")){typeName = "ColorArray"; break;}
		typeName=""; break;
	}
	return typeName;
}

function getType(type){ // Returns a formatted return type for a type code
	while(True){
		if(type=="s"){typeName = "s <-- "; break;}
		if(type=="n"){typeName = "n <-- "; break;}
		if(type=="N"){typeName = "N <-- "; break;}
		if(type=="b"){typeName = "b <-- "; break;}
		if(type=="B"){typeName = "B <-- "; break;}
		if(type=="d"){typeName = "d <-- "; break;}
		if(type=="D"){typeName = "D <-- "; break;}
		if(type=="c"){typeName = "c <-- "; break;}
		if(type=="C"){typeName = "C <-- "; break;}
		typeName="     "; break;
	}
	return typeName;
}
procedure saveItem(varName, entryCount, LineText){ // save first item to a
list
	LineText = getItem(LineText); // get the keyword parameter item
	VarSetText(varName+NumToStr(entryCount,1.0,0),LineText);
}

procedure addItem(varName, entryCount, LineText){ // add next item to a list
	item = getItem(LineText); //get the keyword parameter item
	varName = varName + NumToStr(entryCount, 1.0, 0);
	LineText = VarGetText(varName);
	if(LineText != ""){LineText += ",";} //no leading comma on first item
	VarSetText(varName, LineText + item);
}

procedure replaceItem(varName, entryCount, LineText){ // replace last item in
the list
	item = getItem(LineText); // get the keyword parameter item 
	varName = varName + NumToStr(entryCount, 1.0, 0);
	LineText = VarGetText(varName);
	while(StrRight(LineText, 1) != "," AND StrLen(LineText)>0){ // remove last
item
		LineText = StrLeft(LineText, StrLen(LineText) - 1);
	}
	LineText += Item; // replace it with the new item
	VarSetText(varName, LineText);
}

procedure addArgItem(entryCount, LineText){ // add 3 items for an arguments
list
	type = getItem(LineText); // get the keyword parameter item 
	LineText = VarGetText("Arg_type_list"+NumToStr(entryCount,1.0,0));
	if(LineText== ""){Comma = "";}else{Comma = ",";}
	VarSetText("Arg_type_list"+NumToStr(entryCount,1.0,0),LineText + comma +
type);
	LineText = VarGetText("Arg_name_list"+NumToStr(entryCount,1.0,0)) + comma +
TypeToName(type);
	VarSetText("Arg_name_list"+NumToStr(entryCount,1.0,0),LineText);
	LineText = VarGetText("Arg_default_list"+NumToStr(entryCount,1.0,0)) + comma;
	VarSetText("Arg_default_list"+NumToStr(entryCount,1.0,0),LineText);
}

procedure addUrlItem(entryCount, LineText, defaultName){ // add  2 items for a
links list
	url = getItem(LineText); // get the keyword parameter item 
	LineText = VarGetText("Link_url_list"+NumToStr(entryCount,1.0,0));
	if(LineText== ""){Comma = "";}else{Comma = ",";}
	VarSetText("Link_url_list"+NumToStr(entryCount,1.0,0),LineText + Comma +
url);
	if(defaultName==""){defaultName=url;}
	LineText = VarGetText("Link_name_list"+NumToStr(entryCount,1.0,0)) + Comma +
defaultName;
	VarSetText("Link_name_list"+NumToStr(entryCount,1.0,0),LineText);
}
sortedList = "";
function getSorted(varName, item){ // get the entry data that is indexed by the
sorted list numbers
	return VarGetText(varName+StrExtract(sortedList, item));
}

function tabStop(string, number){ // fixed-space out to a particular tab stop
(not just the next one)
	return StrLeft(string+spaces,Max(number,StrLen(string+" ")));
}

//================================================================
// Parameters
//
// Output options
doit = ParamTrigger("Convert Database", "Click to Write File");
pRtfOut = ParamToggle("RTF Output","OFF|ON",0);
pTxtOut = ParamToggle("TXT Output","OFF|ON",0);
// Sorting options
pFmtSort = ParamList("Sort Order","None|Alphabetic|Group",1);
// Filter options
pFmtFilter = ParamList("Filter","OFF|ON",1);
pFmtGroupText = ParamStr(".  Group Tag Text", "AFL");
pFmtSearchText = ParamStr(".  Search Tag Text", "");

_SECTION_BEGIN("TXT Format Options");
	// Page dimensions
	pTxtTab1 = Param("Margin Tab", 0, 0, 20, 1); // indent
	pTxtTab2 = Param(".  Tab 2", 6, 0, 40, 1); // Entry Start
	pTxtTab3 = Param(".  Tab 3", 8, 0, 40, 1); // Other line Start
	pTxtTab4 = Param(".  Tab 4", 24, 0, 40, 1); // Second tab
	// Line 1 Format options (entry)
	pTxtRet = ParamList("Return Format","Name|Type|None",1);
	pTxtOperand = ParamList("L/R Operand Format","Name|Type|None",1);
	pTxtArg = ParamList("Arguments Format","Name|Type|None",1);
	pTxtDef = ParamToggle("Show Arg Defaults","OFF|ON",1);
	// Line1/2 Format options (full name or Description, AB version)
	pTxtName = ParamToggle("Show Full Name","OFF|Line1",1);
	pTxtDesc = ParamList("Show Description","OFF|Line1|Line2",2);
	pTxtVer = ParamList("Show AB Version","OFF|Line1|Line2",1);
	// Next Line Format options (Functional Group Tags)
	pTxtGrp = ParamToggle("Show Group Tags","OFF|ON",1);
	// Next Line Format options (Search Term Tags)
	pTxtSearch = ParamToggle("Show Search Tags","OFF|ON",1);
	// Next Line Format options (Related entries)
	pTxtRelated = ParamToggle("Show Related Entries","OFF|ON",1);
	// Next Line Format options (Links)
	pTxtLinks = ParamList("Show Links","OFF|Link|Name:Link",1);
_SECTION_END();

_SECTION_BEGIN("RTF Format Options");
	// Page dimensions
	pRtfMgn = Param("Margin Tab", 0, 0, 11, .01); // Margin
	pRtfTab2 = NumToStr(1440 * (pRtfMgn + Param(".  Tab 2", .5, 0, 11,
.01)),1.0,0); // Entry Start
	pRtfTab3 = NumToStr(1440 * (pRtfMgn + Param(".  Tab 3", .625, 0, 11,
.01)),1.0,0); // Other line start
	pRtfTab4 = NumToStr(1440 * (pRtfMgn + Tab4 = Param(".  Tab 4", 1.75, 0, 11,
.01)),1.0,0); // Second tab
	pRtfTab5 = NumToStr(1440 * (pRtfMgn + Tab4+.5) ,1.0,0); // safety tabs
	pRtfTab6 = NumToStr(1440 * (pRtfMgn + Tab4+1) ,1.0,0); // safety tabs
	pRtfTab7 = NumToStr(1440 * (pRtfMgn + Tab4+1.5) ,1.0,0); // safety tabs
	pRtfTab1 = NumToStr(1440 * pRtfMgn, 1.0, 0); // Margin
	// Line 1 Format options (entry)
	pRtfEntry = ParamList("Entry Format","Bold|Link",2); 
	pRtfRet = ParamList("Return Format","Name|Type|None",1);
	pRtfOperand = ParamList("L/ROperand Format","Name|Type|None",1);
	pRtfArg = ParamList("Arguments Format","Name|Type|None",1);
	pRtfDef = ParamToggle("Show Arg Defaults","OFF|ON",1);
	// Line1/2 Format options (full name or Description, AB version)
	pRtfVer = ParamList("Show AB Version","OFF|Line1|Line2",1);
	pRtfName = ParamToggle("Show Full Name","OFF|Line1",1);
	pRtfDesc = ParamList("Show Description","OFF|Line1|Line2",2);
	// Next Line Format options (Functional Group Tags)
	pRtfGrp = ParamToggle("Show Group Tags","OFF|ON",1);
	// Next Line Format options (Search Term Tags)
	pRtfSearch = ParamToggle("Show Search Tags","OFF|ON",1);
	// Next Line Format options (Related entries)
	pRtfRelated = ParamToggle("Show Related Entries","OFF|ON",1);
	// Next Line Format options (Links)
	pRtfLinks = ParamList("Show Links","OFF|Name:Link|Name=Link",1);
_SECTION_END();

//================================================================
// Do the conversion
//
// Input files are AFL_Glossary_1 to AFL_Glossary_n in unbroken numerical
sequence
//
while(doit){ //doit is a one shot, but a while loop so we can abort easily
	groupLines = ""; //debug
	StaticVarSet("GL_Output",0); //number of entries output
	filePathTop = "AFL_Glossary//AFL_Glossary_";
	fileOutMode = "w"; //will change to "a"ppend for subsequent passes of group
sort
	if(pFmtSort =="Group"){ // make sure we have a groups file
		filePath = filePathTop + "Groups.txt";
		fhg = fopen(filePath, "r");
		if(NOT fhg){ // no .txt file, so let's try a .afl file
			filePath = filePathTop + "Groups.afl";
			fhg = fopen(filePath, "r");
		}
		if(NOT fhg){PopupWindow(filePath +" NOT found","FILE ERROR" ,5, -1, -1 );
break;}
	}
	//
	fileCount = 1;
	filePath = filePathTop + "1.txt";
	fh = fopen(filePath, "r");
	if(NOT fh){ // no .txt file, so let's try a .afl file
		filePath = filePathTop + "1.afl";
		fh = fopen(filePath, "r");
	}
	if(NOT fh){PopupWindow(filePath +" NOT found","FILE ERROR" ,5, -1, -1 );
break;}

	// Parse the Glossary file into faked string arrays
	fileCount = 1;
	entryActive=0;
	entryCount=0;
	do{ // for each file
		while(! feof(fh)){ // we have more lines
			while(True){ // different way of doing switch...case
			Line = fgets(fh); // get the next line of the file and handle parse it

			if(StrFind(Line, "Begin_entry:")==1){entryCount++; entryActive=1; break;}
			if(StrFind(Line, "End_entry:")==1){entryActive=0; break;}
			if(entryActive==0){break;} //ignore all lines outside of an entry

			if(StrFind(Line, "Name_entry:")==1){saveItem("Name_entry", entryCount,
Line); break;}
			if(StrFind(Line, "Name_long:")==1){saveItem("Name_long", entryCount, Line);
break;}
			if(StrFind(Line, "Description:")==1){saveItem("Description", entryCount,
Line); break;}
			if(StrFind(Line, "Return_type:")==1){saveItem("Return_type", entryCount,
Line); break;}
			if(StrFind(Line, "Return_name:")==1){saveItem("Return_name", entryCount,
Line); break;}
			if(StrFind(Line, "Left_type:")==1){saveItem("Left_type", entryCount, Line);
break;}
			if(StrFind(Line, "Left_name:")==1){saveItem("Left_name", entryCount, Line);
break;}
			if(StrFind(Line, "Right_type:")==1){saveItem("Right_type", entryCount,
Line); break;}
			if(StrFind(Line, "Right_name:")==1){saveItem("Right_name", entryCount,
Line); break;}
			if(StrFind(Line, "Right_close:")==1){saveItem("Right_close", entryCount,
Line); break;}
			if(StrFind(Line, "Version_AB:")==1){saveItem("Version_AB", entryCount,
Line); break;}

			if(StrFind(Line, "Tag_group:")==1){addItem("Tag_group_list", entryCount,
Line); break;}
			if(StrFind(Line, "Tag_search:")==1){addItem("Tag_search_list", entryCount,
Line); break;}
			if(StrFind(Line, "Related_entry:")==1){addItem("Related_entry_list",
entryCount, Line); break;}

			if(StrFind(Line, "Arg_type:")==1){addArgItem(entryCount, Line); break;}
			if(StrFind(Line, "Arg_name:")==1){replaceItem("Arg_name_list", entryCount,
Line); break;}
			if(StrFind(Line, "Arg_default:")==1){replaceItem("Arg_default_list",
entryCount, Line); break;}

			if(StrFind(Line, "Link_ABdoc:")==1){addUrlItem(entryCount, Line,
"AB_Guide"); break;}
			if(StrFind(Line, "Link_video:")==1){addUrlItem(entryCount, Line,
"AB_Video"); break;}
			if(StrFind(Line, "Link_tutorial:")==1){addUrlItem(entryCount, Line,
"AB_Tutorial"); break;}
			if(StrFind(Line, "Link_KBdoc:")==1){addUrlItem(entryCount, Line,
"AB_Article"); break;}
			if(StrFind(Line, "Link_KBdoc:")==1){addUrlItem(entryCount, Line,
"UKB_Article"); break;}
			if(StrFind(Line, "Link_url:")==1){addUrlItem(entryCount, Line, ""); break;}
			if(StrFind(Line, "Link_name:")==1){replaceItem("Link_name_list", entryCount,
Line); break;}

			break; //ignore lines that do not start with a keyword
			}
		}
		fclose(fh);
		filePath = filePathTop + NumToStr(++fileCount,1.0,0)+".txt";
		fh = fopen(filePath, "r");
		if(NOT fh){ // no .txt file, so let's try a .afl file
			filePath = filePathTop + NumToStr(fileCount,1.0,0)+".afl";
			fh = fopen(filePath, "r");
		}
	}while(fh);
	StaticVarSet("GL_Entries", entryCount);
	totalEntries = entryCount;
	while(True){ //loop through groups list or just once
		entryCount = totalEntries;
		if(pFmtSort =="Group"){ // generate group tags from the group file entries
			while(True){ // find the next good line
				grpLine = fgets(fhg); // get the next line of the file and parse it
				grpLine = StrReplace(grpLine, "\n", ""); //remove new line char
				if(eof = feof(fhg)){break;} //end of lines
				if(StrLeft(grpLine, 2) == "//"){continue;} //next line (skip comment)
				if(grpLine == ""){continue;} //next line (skip blank lines)
				group1 =  StrToUpper(StrExtract(grpLine, 0));//pick up the search terms
				group2 =  StrToUpper(StrExtract(grpLine, 1));//pick up the search terms
				group3 =  StrToUpper(StrExtract(grpLine, 2));//pick up the search terms
				group4 =  StrToUpper(StrExtract(grpLine, 3));//pick up the search terms
				group5 =  StrToUpper(StrExtract(grpLine, 4));//pick up the search terms
				if(StrRight(grpLine, 1) == ","){topGroup =  True;} // a group entry flag
				else{topGroup = False;} 
				groupLine = StrReplace(grpLine, ",", ": "); // pretty it up for various
outputs
				break; //go generate the entries
			}
			if(eof){fclose(fhg); break;} //end of lines
		}
		StaticVarSet("GL_Files", fileCount-1);
		// Now that we have collected all the entries, it is time to make a sorted
list
		// lets do alphabetical first
		// The most straight forward way to sort is to just "insert" items into a
list string
		//  of entry number items in the right order
		if(pFmtSort == "Alphabetic"){
			sortedList = ",1,,"; // we want every entry to be surrounded by commas so we
don't find partials
			for(i=2; i<=entryCount; i++){ // get the next entry and figure where it
goes
				iStr = NumToStr(i, 1.0, 0);
				iText = StrToLower(VarGetText("Name_entry"+iStr));
				j=0;
				while(True){ // look through the sorted list for the place to insert it
					j++;
					jStr = StrExtract(sortedList, j);
					jText = StrToLower(VarGetText("Name_entry"+jStr));
					if(iText < jText OR jText==""){ // insert the item before the higher item
in the sorted list
						index = StrFind(sortedList, ","+ StrExtract(sortedList, j)+",");
						rightLen = StrLen(sortedList) - index ;
						sortedList = StrLeft(sortedList, index) + iStr + "," +
StrRight(sortedList, rightLen);
						break;
					}
				}
			}
		}
		// Just make an unsorted list 
		if(pFmtSort == "None" OR pFmtSort == "Group"){ //group listings not
implimented yet
			sortedList = ",";
			for(i=1; i<=entryCount; i++){
				tStr = NumToStr(i, 1.0, 0);
				sortedList += tStr + ",";
			}
		}
		// Group sort
		if(pFmtSort == "Group"){ // filter for group entries
			// filter for group entries
			ShortList = ",";
			ShortCount = 0;
			for(j=1; j<=entryCount; j++){ 
				jStr = StrExtract(sortedList, j);
				jText = StrToUpper(VarGetText("Tag_group_list"+jStr));

				if(StrFind(jText, group1)
					AND StrFind(jText, group2)
					AND StrFind(jText, group3)
					AND StrFind(jText, group4)
					AND StrFind(jText, group5)){ // entry contains all terms (some are empty)
					if(topGroup){ // must have exact number of terms
						for(i=0; StrExtract(jText,i)!=""; i++){;} //get the group terms item
count
						for(k=1; k<=5; k++){if(VarGetText("Group" + NumToStr(k, 1.0, 0)) ==
""){break;}} //get the groups item count
						if(i != k-1){continue;} // no match, next entry
					}
					ShortList += jStr + ",";
					ShortCount++;
				}
			}
			sortedList = ShortList;
			entryCount = ShortCount;
		}
		// Group filter
		if(pFmtFilter == "ON"){ // filter for certain entries
			// filter for group term
			ShortList = ",";
			ShortCount = 0;
			pFmtGroupText = StrToLower(pFmtGroupText);
			for(j=1; j<=entryCount; j++){ 
				jStr = StrExtract(sortedList, j);
				jText = StrToLower(VarGetText("Tag_group_list"+jStr));
				if(StrFind(jText, pFmtGroupText)){ // part of group
					ShortList += jStr + ",";
					ShortCount++;
				}
			}
			sortedList = ShortList;
			entryCount = ShortCount;
			// filter for search term
			ShortList = ",";
			ShortCount = 0;
			pFmtSearchText = StrToLower(pFmtSearchText);
			for(j=1; j<=entryCount; j++){ 
				jStr = StrExtract(sortedList, j);
				jText = StrToLower(VarGetText("Tag_search_list"+jStr));
				if(StrFind(jText, pFmtSearchText)){ // part of search tags
					ShortList += jStr + ",";
					ShortCount++;
				}
			}
			sortedList = ShortList;
			entryCount = ShortCount;
		}
		// Now it is time to assemble entries into to output format and write the
file
		//
		if(pTxtOut){ // If generating a .txt file
			filePath = filePathTop + "Out.txt";
			fh = fopen(filePath, fileOutMode);
			if(pFmtSort == "Group"){fputs("\n\n"+groupLine+"\n\n", fh);} // filter for
group entries
			// generate output one entry at a time in sorted order
			for(i=1; i<=entryCount; i++){ 
				iStr = NumToStr(i, 1.0, 0);
				// Grab all the variables for this entry
				Name_Entry = getSorted("Name_entry", i);
				Name_long = getSorted("Name_long", i);
				Description = getSorted("Description", i);
				Return_type = getSorted("Return_type", i);
				Return_name = getSorted("Return_name", i);
				Left_type = getSorted("Left_type", i);
				Left_name = getSorted("Left_name", i);
				Right_type = getSorted("Right_type", i);
				Right_name = getSorted("Right_name", i);
				Right_close = getSorted("Right_close", i);
				Arg_type_list = getSorted("Arg_type_list", i);
				Arg_name_list = getSorted("Arg_name_list", i);
				Arg_default_list = getSorted("Arg_default_list", i);
				Link_url_list = getSorted("Link_url_list", i);
				Link_name_list = getSorted("Link_name_list", i);
				Version_AB = getSorted("Version_AB", i);
				Tag_group_list = getSorted("Tag_group_list", i);
				Tag_search_list = getSorted("Tag_search_list", i);
				Related_entry_list = getSorted("Related_entry_list", i);
				// Generate line 1 of entry output
				// [return = ][left] name [right] [([arg[=default][,]...)]
				Line1 = tabStop("", pTxtTab1);
				// Return formatting
				if(Return_type != "" AND pTxtRet=="Name"){Line1 += Return_name+" <-- ";}
				if(Return_type != "" AND pTxtRet=="Type"){Line1 = StrLeft(Line1 +
getType(Return_type) + spaces, pTxtTab2);}
				if(Return_type == ""){Line1 = StrLeft(Line1 + spaces, pTxtTab2);}
				// Left operand formatting
				if(Left_type != "" AND pTxtOperand=="Name"){Line1 += Left_name + " ";}
				if(Left_type != "" AND pTxtOperand=="Type"){Line1 += Left_type + " ";}
				// Entry Name Formatting
				Line1 += Name_Entry;
				// Arguments Formatting
				if(Arg_type_list != "" AND pTxtArg != "None"){ //need to stuff the whole
list inside the ()
					Line1 = StrLeft(Line1, StrLen(Line1)-1) + " "; // remove the trailing )
					j=0;
					while(True){ //we will break out when out of list items
						itemType = StrExtract(Arg_type_list, j);
						itemName = StrExtract(Arg_name_list, j);
						// Argument Formatting
						if(pTxtArg=="Type"){itemName = itemType;}
						itemDefault = StrExtract(Arg_default_list, j);
						Line1 += itemName;
						// Argument Defaults formatting
						if(itemDefault != "" AND pTxtDef){Line1 += "=" + itemDefault;}
						j++;
						if(StrExtract(Arg_type_list, j) == ""){Line1 += " )"; break;}
						else{Line1 += ", ";}
					}
				}
				// Right operand formatting
				if(Right_type != "" AND pTxtOperand=="Name"){Line1 += " " + Right_name + "
";}
				if(Right_type != "" AND pTxtOperand=="Type"){Line1 += " " + Right_type + "
";}
				if(Right_close != ""){Line1 += " " + Right_close + " ";}
				// line 1 Version
				if(pTxtVer=="Line1" AND Version_AB != ""){Line1 += " [AB " + Version_AB
+"]";}
				// line 1 Long name
				if(pTxtName){Line1 += " ~ " + Name_long;}
				// line 1 description
				if(pTxtDesc=="Line1"){Line1 += " ~ " + Description;}
				Line1 = "\n" + Line1 + "\n";
				fputs(Line1, fh);
				// Generate Line2 of entry output
				Line1 = tabStop("", pTxtTab1);
				// line 2 version
				if(pTxtVer=="Line2" AND Version_AB != ""){
					Line1 = tabStop(Line1, pTxtTab3) + "[AB " + Version_AB +"]";
					// line 2 version + description
					if(pTxtDesc=="Line2"){Line1 += "~ " + Description;} 
					Line1 += "\n";
				}
				else if(pTxtDesc=="Line2"){Line1 = tabStop(Line1, pTxtTab3) + "~ " +
Description + "\n";}
				fputs(Line1, fh);
				// Generate Group Tag Line of entry output
				Line1 = tabStop("", pTxtTab1);
				if(Tag_group_list != "" AND pTxtGrp){ //put the list on one line
					Line1 = tabStop(tabStop(Line1, pTxtTab3)+"~ Group Tags:", pTxtTab4) +
Tag_group_list + "\n";
					fputs(Line1, fh);
				}
				// Generate Search Tag Line of entry output
				Line1 = tabStop("", pTxtTab1);
				if(Tag_search_list != "" AND pTxtSearch){ //put the list on one line
					Line1 = tabStop(tabStop(Line1, pTxtTab3)+"~ Search Tags:", pTxtTab4) +
Tag_search_list + "\n";
					fputs(Line1, fh);
				}
				// Generate Related entries Line of entry output
				Line1 = tabStop("", pTxtTab1);
				if(Related_entry_list != "" AND pTxtRelated){ //put the list on one line
					Line1 = tabStop(tabStop(Line1, pTxtTab3)+"~ See Also:", pTxtTab4) +
Related_entry_list + "\n";
					fputs(Line1, fh);
				}
				// Generate Links Line(s) of entry output
				if(Link_url_list != "" AND pTxtLinks != "OFF"){ //need to put links on own
lines
					j=0;
					while(True){ //we will break out when out of list items
						Line1 = tabStop("", pTxtTab3);
						itemUrl = StrExtract(Link_url_list, j);
						itemName = StrExtract(Link_name_list, j++);
						if(itemUrl==""){break;}
						// Argument Formatting
						if(pTxtLinks=="Name:Link"){Line1 = tabStop(Line1 + "~ " + itemName + ":",
pTxtTab4) + itemUrl + "\n";}
						else{Line1 += "" + itemUrl + "\n";}
						fputs(Line1, fh);
					}
				}
			}
			fclose(fh); //end of .txt file generation
		}
		//
		if(pRtfOut){ // If generating a .rtf file
			filePath = filePathTop + "Out.rtf";
			fh = fopen(filePath, fileOutMode);
			if(fileOutMode=="w"){ // Generate the rtf header I swiped from my WP file
first time only
				rtfHeader1 = "{\\rtf1\\ansi\\ansicpg1252\\cocoartf949\\cocoasubrtf330\n" +

				"{\\fonttbl\\f0\\fswiss\\fcharset0 ArialMT;\\f1\\fmodern\\fcharset0
Courier-Bold;}\n" +
				"{\\colortbl;\\red255\\green255\\blue255;}\n" +
				"\\margl0\\margr0\\vieww17680\\viewh17140\\viewkind0\n" +
				"\\pard\\tx"+pRtfTab2+"\\tx"+pRtfTab3+"\\tx"+pRtfTab4+"\\tx"+pRtfTab5+"\\tx"+pRtfTab6+"\\tx"+pRtfTab7
+
				"\\li"+pRtfTab1+"\\fi-0\\ql\\qnatural\\pardirnatural\n"+
//				"\n\\f0\\fs24 \\cf0\n\\\n";
				"\n\\f0\\fs20 \\cf0\n\\\n";
				fputs(rtfHeader1, fh);
			}
			if(pFmtSort == "Group"){fputs("\\n\\par \\b \\fs30 "+groupLine +"\\fs20
\\n\\b0 \\par ", fh);} // filter for group entries
			// generate output one entry at a time in sorted order
			for(i=1; i<=entryCount; i++){ 
				iStr = NumToStr(i, 1.0, 0);
				// Grab all the variables for this entry
				Name_Entry = getSorted("Name_entry", i);
				Name_Entry = StrReplace(Name_Entry, "{", "\\{");

				Name_long = getSorted("Name_long", i);
				Description = getSorted("Description", i);
				Return_type = getSorted("Return_type", i);
				Return_name = getSorted("Return_name", i);
				Left_type = getSorted("Left_type", i);
				Left_name = getSorted("Left_name", i);
				Right_type = getSorted("Right_type", i);
				Right_name = getSorted("Right_name", i);

				Right_close = getSorted("Right_close", i);
				Right_close = StrReplace(Right_close , "{", "\\{");
				Right_close = StrReplace(Right_close , "}", "\\}");

				Arg_type_list = getSorted("Arg_type_list", i);
				Arg_name_list = getSorted("Arg_name_list", i);
				Arg_default_list = getSorted("Arg_default_list", i);
				Link_url_list = getSorted("Link_url_list", i);
				Link_name_list = getSorted("Link_name_list", i);
				Version_AB = getSorted("Version_AB", i);
				Tag_group_list = getSorted("Tag_group_list", i);
				Tag_search_list = getSorted("Tag_search_list", i);
				Related_entry_list = getSorted("Related_entry_list", i);
				// Generate line 1 of entry output
				// [return = ][left] name [right] [([arg[=default][,]...)]
				Line1 = "";
				// Return formatting
				if(Return_type != "" AND pRtfRet=="Name"){Line1 += Return_name + " <-- ";}
				if(pRtfRet=="Type"){Line1 += getType(Return_type) + "\\tab ";}
				// Left operand formatting
				if(Left_type != "" AND pRtfOperand=="Name"){Line1 += Left_name + " ";}
				if(Left_type != "" AND pRtfOperand=="Type"){Line1 += Left_type + " ";}
				// Entry Name Formatting --bold link
				if(pRtfEntry == "Link"){
					itemUrl = StrExtract(Link_url_list, 0);
					if(StrFind(Name_Entry,"()")){itemName = StrReplace(Name_Entry, "()",
"");}
					else{itemName = Name_Entry;}
					Line1 += "{\\field{\\*\\fldinst{HYPERLINK \"" + itemUrl + "\"}}{\\fldrslt
\\f1\\b\\fs24 " + itemName + "\\f0\\b0 }}\\ ";
					if(StrFind(Name_Entry,"()")){Line1 += "()";}
				}
				// Entry Name Formatting --bold
				if(pRtfEntry == "Bold"){
					if(StrFind(Name_Entry,"()")){Line1 = StrReplace(Line1 + "\\f1\\b\\fs24 " +
Name_Entry, "()", "") + "\\f0\\b0 ()";}
					else{Line1 += "\\b " + Name_Entry + "\\b0 ";}
				}
				Line1 += "\\b "; //bold the syntax portion
				// Arguments Formatting
				if(Arg_type_list != "" AND pRtfArg != "None"){ //need to stuff the whole
list inside the ()
					Line1 = StrReplace(Line1, "()", "( "); // remove the trailing ()
					j=0;
					while(True){ //we will break out when out of list items
						itemType = StrExtract(Arg_type_list, j);
						itemName = StrExtract(Arg_name_list, j);
						// Argument Formatting
						if(pRtfArg=="Type"){itemName = itemType;}
						itemDefault = StrExtract(Arg_default_list, j);
						Line1 += itemName;
						// Argument Defaults formatting
						if(itemDefault != "" AND pRtfDef){Line1 += "=" + itemDefault;}
						j++;
						if(StrExtract(Arg_type_list, j) == ""){Line1 += " )"; break;}
						else{Line1 = Line1 + ", ";}
					}
				}
				// Right operand formatting
				if(Right_type != "" AND pRtfOperand=="Name"){Line1 += " " + Right_name + "
";}
				if(Right_type != "" AND pRtfOperand=="Type"){Line1 += " " + Right_type + "
";}
				if(Right_close != ""){Line1 += " " + Right_close + " ";}
				Line1 += "\\b0 ";
				// line 1 version
				if(pRtfVer=="Line1" AND Version_AB != ""){Line1 += " [AB " + Version_AB
+"]";}
				// line 1 long name
				if(pRtfName){Line1 += " ~ " + Name_long;}
				// line 1 description
				if(pRtfDesc=="Line1"){Line1 += " ~ " + Description;}
				Line1 = "\\par " + Line1 + "\\par ";
				fputs(Line1, fh);
				// Generate Line2 of entry output
				Line1 = "\\tab ";
				// line 2 version
				if(pRtfVer=="Line2" AND Version_AB != ""){
					Line1 += "[AB " + Version_AB +"]";
					// line 2 description
					if(pRtfDesc=="Line2"){Line1 += "~ " + Description;} 
					Line1 = Line1 +  "\\par ";
				}
				else if(pRtfDesc=="Line2"){Line1 += "\\tab ~ " + Description + "\\par ";}
				fputs(Line1, fh);
				// Generate Group Tag Line of entry output
				if(Tag_group_list != "" AND pRtfGrp){ //put the list on one line
					Line1 = "\\tab\\tab ~ Group Tags:\\tab " + Tag_group_list + "\\par ";
					fputs(Line1, fh);
				}
				// Generate Search Tag Line of entry output
				if(Tag_search_list != "" AND pRtfSearch){ //put the list on one line
					Line1 = "\\tab\\tab ~ Search Tags:\\tab " + Tag_search_list + "\\par ";
					fputs(Line1, fh);
				}
				// Generate Related entries Line of entry output
				if(Related_entry_list != "" AND pRtfRelated){ //put the list on one line
					Line1 = "\\tab\\tab ~ See Also:\\f1\\tab " + Related_entry_list +
"\\f0\\par ";
					fputs(Line1, fh);
				}
				// Generate Links Line(s) of entry output
				j = IIf(pRtfEntry == "Link", 1, 0); // skip first entry if already linked
to name
				if(StrExtract(Link_url_list, j) != "" AND pRtfLinks == "Name:Link"){ //need
to put links on own lines
					while(True){ //we will break out when out of list items
						Line1 = "\\tab\\tab ~ ";
						itemUrl = StrExtract(Link_url_list, j);
						itemName = StrExtract(Link_name_list, j++);
						if(itemUrl==""){break;}
						// Argument Formatting
						if(pRtfLinks=="Name:Link"){Line1 += itemName + ":\\tab " + itemUrl +
"\\par ";}
						else{Line1 += "" + itemUrl + "\\par ";}
						fputs(Line1, fh);
					}
				}
				// Generate Links on one Line of entry output
				j = IIf(pRtfEntry == "Link", 1, 0); // skip first entry if already linked
to name
				if(StrExtract(Link_url_list, j) != "" AND pRtfLinks == "Name=Link"){ //need
to put linked names on one lines
					Line1 = "\\tab\\tab ~ Links:\\tab ";
					while(True){ //we will break out when out of list items
						itemUrl = StrExtract(Link_url_list, j);
						itemName = StrExtract(Link_name_list, j++);
						if(itemUrl==""){break;}
						// Argument Formatting
						Line1 += "{\\field{\\*\\fldinst{HYPERLINK \"" + itemUrl + "\"}}{\\fldrslt
" + itemName + "}}\\  ";
					}
					fputs(Line1 + "\\par ", fh);
				}
				fputs("\n ", fh);
			}
			if(pFmtSort != "Group" OR group1=="END"){fputs("}", fh);} // last one only
			fclose(fh); //end of .rtf file generation
		}
		StaticVarSet("GL_Output",StaticVarGet("GL_Output")+entryCount);
		if(pFmtSort != "Group"){break;}
		fileOutMode = "a"; // append for next group sort
		groupLines += "\n"+groupLine+" (" + entryCount + ")";//debug
	} // end of groups list
	StaticVarSetText("groupLine",groupLines );
	StaticVarSetText("sortedList",sortedList);
	break;
}

if(pFmtSort == "Group"){string = "\nGlossary Groups:
"+StaticVarGet("groupLine");}
else{string = "\nGlossary Entries: " + StaticVarGetText("sortedList");}

Title = "Glossary Files Processed: "+NumToStr(StaticVarGet("GL_Files"),1.0)+
"\nGlossary Entries Processed: "+NumToStr(StaticVarGet("GL_Entries"),1.0)+
"\nGlossary Entries Output: "+NumToStr(StaticVarGet("GL_Output"),1.0)+
string;

Comments:


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM