i dont like tree structures at the moment
but here ya go
void Spider(xTreeItem CurrentItem)
{
int s;
CString spaces;
CString xStr;
//There Could Probably Be More Vars Here To Save Space
//Down There... There Also Needs To Be Some Space
//Generating Loop Code Put Into A Function
//CurrentItem Is Either A Branch Or A Leaf
//The Processing Of CurrentItem Will Be Different
//For Each State Of CurrentItem
if(CurrentItem.IsBranch())
{
CString currentpath;
CString currenturl;
//Set Up All The Path Variables And File Names
//And Levels
CurrentLevel ++;
currentpath = BasePath;
currenturl = BaseURL;
CurrentItem.FileName = "index.txt";
CurrentItem.Level = CurrentLevel;
DirectoryL[CurrentLevel] = CurrentItem.Directory;
for(int l = 1; l <= CurrentLevel; l ++)
{
currentpath += "\\" + DirectoryL[l];
currenturl += "/" + DirectoryL[l];
}
CurrentItem.LocalHtmlPath=currentpath + "\\index.html";
CurrentItem.Url = currenturl + "/index.html";
currentpath += "\\index.txt";
//Add This Branch Item To The Flat List
xTreeItems.Add(xTreeItem(CurrentItem));
spaces = MakeSpace(CurrentLevel);
TocFile.WriteString(spaces);//Toc File Was Opened For Append Each
//Write To Eat Bugs
//Start A New Division
TocFile.WriteString("<UL>\n<LI>\n");
TocFile.WriteString(CurrentItem.MakeSiteMapObject());
//This Is A New Branch So Keep Spidering
InputIndexFile[CurrentLevel].Open(currentpath,
CFile::modeRead |
CFile::typeText);
HtmlOutputFile[CurrentLevel].Open(CurrentItem.LocalHtmlPath,
CFile::modeCreate |
CFile::modeWrite | CFile::typeText );
//Start A Fresh Html Page
HtmlOutputFile[CurrentLevel].WriteString("<HTML>\n<Body>\n");
//Create A Link From The Entry
HrefL[CurrentLevel] = CurrentItem.MakeHref();
//Make A Line Hrefs That Link To The Parent Level(s)
CString DirectoryBar;
DirectoryBar="";
for(int h = 1; h < CurrentLevel; h++)
{
DirectoryBar += HrefL[h] + " / ";
}
//Put The DirectoryBar On The Page
HtmlOutputFile[CurrentLevel].WriteString(DirectoryBar +
CurrentItem.Name +
"<BR><BR>\n");
//If This Is Not The Root
if(CurrentLevel > 1)
{
//Then Put A Link To This Page
//On This Item's Parent's Page
HtmlOutputFile[CurrentLevel - 1].WriteString(
CurrentItem.MakeHref() +
"<BR>\n");
}
for(;;)
{
//If We Don't Hit EOF Spider Recursively
if(InputIndexFile[CurrentLevel].ReadString(xStr))
{
xTreeItem NewTreeItem;
NewTreeItem.InitFromTxtEntry(xStr);
Spider(NewTreeItem);
}
//If We Do Hit EOF
else
{
//Close This Division
TocFile.WriteString("</UL>\n");
//Close This Input File
InputIndexFile[CurrentLevel].Close();
//This Could Be A (Nifty Page Ground)
//HtmlOutputFile[CurrentLevel].WriteString(themeFooter);
//Close The Html And Body Tags And The File
HtmlOutputFile[CurrentLevel].WriteString(
"</Body>\n</Html>\n");
HtmlOutputFile[CurrentLevel].Close();
//Decrement The CurrentLevel And Break Out Of The Loop
//So We Can Return To Whence We Came Which Was
//Probably Up There Where It Says Spider(NewTreeItem);
CurrentLevel --;
break;
//Maybe This Is Where The Recursive Action Ends Hmmm...
//All Those pMFs Pushed On The Stack Get Popped Right
//Back On To IP... OH Wait The Class This Function Used
//To Belong To Has Probably Been Removed For The Sake
//Of Simpleness So pFs If So
}
}
}
//Here Is Where The Leaf Gets Processed
else
{
//First We Need To Make Sure CurrentItem Has A URL
if(CurrentItem.Url)
{
xTreeItem LeafTreeItem;
LeafTreeItem.copy(CurrentItem);
//The Leaf Is As Far As The Spider Will Crawl
//So There's No Need To Increment The CurrentLevel
//Just Set The LeafTreeItem's Level To CurrentLevel + 1
LeafTreeItem.Level = CurrentLevel + 1;
//Ah Add The Item To The Flat List
xTreeItems.Add(xTreeItem(LeafTreeItem));
//Nothing Done With Spaces Yet Here
//Need To Standardize And Functionize The TocFile Writes
spaces = MakeSpace(CurentLevel + 1);
//Start A New Division I The Toc And Put This Item
//In As The Head Of The Division
TocFile.WriteString("<UL>\n<LI>\n");
TocFile.WriteString(LeafTreeItem.MakeSiteMapObject());
//Throw It In It's Parent's List Of Links
HtmlOutputFile[CurrentLevel].WriteString(LeafTreeItem.MakeHref() +
"<BR>\n");
//Loop Through The Rest Of The File
//Here Is Where It's Assumed That All
//Items That Follow Are Leaves
//This Is Fine For Our DirectoryTree Spider
//Where All The Links In The Deepest Folder
//Are Outside Of The Crawler's Space
//But Not For A Web Crawler
for(;;)
{
if(InputIndexFile[CurrentLevel].ReadString(xStr))
{
//Again As Above
LeafTreeItem.InitFromTxtEntry(xStr);
LeafTreeItem.Level = CurrentLevel + 1;
xTreeItems.Add(xTreeItem(LeafTreeItem));
//Those Spaces Again
spaces = MakeSpace(CurrentLevel + 1);
//We Are Allready In A Division So Just
//Make A New Entry
TocFile.WriteString("<LI>\n");
TocFile.WriteString(LeafTreeItem.MakeSiteMapObject());
//Throw It In It's Parent's List Of Links
HtmlOutputFile[CurrentLevel].WriteString(
LeafTreeItem.MakeHref() + "<BR>\n");
}
else
{
//Close The Division... We Ran Out Of File
TocFile.WriteString("</UL>\n");
//Get Out Of The Loop And Return To Next Line Of Caller
//Which Was Probably This Very Function
break;
//This Could Be Where The Recursive Action Ends
//Nah I Think It's Up There At The Branch Break
//Cause You Have To Start The Spider On A Branch
//Unless The Spider Drops From Another Tree And
//Lands On A Leaf
}
}
}
}
}