#include #include #include #include "select.h" #include "Classes.h" using namespace std; TAG tagextractor(fstream &fin); void tagprocessor(TAG &ReturnedTag, fstream &fin, fstream &fout); TAG ReturnedTag; char inp; string buffer; Page *afile; SPage SearchPage; // This function accomodates embedded tables, The parameters are: // T obj: an object of the class to be applied to table // tablenum: The number of the table being sought out // numofFuncs: the number of mutator functions being passed in // f[] an array of function pointers containing pointers to the mutator functions // sin an input file stream of the Html file // numargs: the number of arguments that will pinpoint the target table's location // if it is an embedded table (a table within a bunch of other tables) // NOTE: if the Table is not embedded, numargs should be set to zero and nothing should follow it template vector GetRowTP( T obj , int tablenum ,int numofFuncs ,void (T::*f[])(string *name), fstream &sin, int numargs, ...){ va_list arguments; va_start(arguments, numargs); vector::iterator the_iterator; vector selectline; vector Container; int keepnumargs = numargs; ofstream sout("out.txt"); if( numargs > 0 ){ selectline.push_back(va_arg(arguments, int)); --numargs; the_iterator = selectline.begin(); } while(numargs > 0){ --numargs; selectline.insert(the_iterator,va_arg(arguments, int)); the_iterator = selectline.begin(); } vector keeper = selectline; string *result = new string; // First row is not extracted, assumed to be table titles for (int i= 1; ; i++ ){ for( int j = 0; j < numofFuncs; j ++){ if(keepnumargs > 0){ selectline.insert(the_iterator,tablenum); } else{ selectline.push_back(tablenum); } the_iterator = selectline.begin(); selectline.insert(the_iterator,i+1); the_iterator = selectline.begin(); selectline.insert(the_iterator,j+1); //debug for(int k = 0; k < selectline.size(); k++) cout << selectline[k]; *result = SearchPage.Select(sin, sout, selectline); if ( *result == "nothing" ) return Container; else (obj.*f[j])(result) ; selectline = keeper; } Container.push_back(obj); } return Container; } template vector GetColTP( T obj , int tablenum ,int numofFuncs ,void (T::*f[])(string *name), fstream &sin, int numargs, ...){ va_list arguments; va_start(arguments, numargs); vector::iterator the_iterator; vector selectline; vector Container; int keepnumargs = numargs; ofstream sout("out.txt"); if( numargs > 0 ){ selectline.push_back(va_arg(arguments, int)); --numargs; the_iterator = selectline.begin(); } while(numargs > 0){ --numargs; selectline.insert(the_iterator,va_arg(arguments, int)); the_iterator = selectline.begin(); } vector keeper = selectline; string *result = new string; // First row is not extracted, assumed to be table titles for (int i= 1; ; i++ ){ for( int j = 0; j < numofFuncs; j ++){ if(keepnumargs > 0){ selectline.insert(the_iterator,tablenum); } else{ selectline.push_back(tablenum); } the_iterator = selectline.begin(); selectline.insert(the_iterator,j+1); the_iterator = selectline.begin(); selectline.insert(the_iterator,i+1); //debug for(int k = 0; k < selectline.size(); k++) cout << selectline[k]; *result = SearchPage.Select(sin, sout, selectline); if ( *result == "nothing" ) return Container; else (obj.*f[j])(result) ; selectline = keeper; } Container.push_back(obj); } return Container; } void begindocument(){ afile = new Page; } void tagprocessor(TAG &ReturnedTag, fstream &fin, ofstream &fout){ if(ReturnedTag == TABLE){ afile->AddTable(fin, fout); } else if(ReturnedTag == CTABLE){ } else if (ReturnedTag == HTML){ begindocument(); } else if (ReturnedTag == TR){ } else if (ReturnedTag == TD){ } else if (ReturnedTag == OTHER){} else if (ReturnedTag == CHTML) cout << "Html closed\n"; else if (ReturnedTag == CTR){ } else if (ReturnedTag == CTD){ } else if (ReturnedTag == LIST){ } else if (ReturnedTag == LI){ } else if (ReturnedTag == CLIST){ } else if (ReturnedTag == SCRIPT){ //bool golook = false; while( fin.get(inp) ){ // Find the /script tag if(inp == '<'){ int count = 0; string buffer; const int lengthofcscript = 7; while( 1 ){ fin.get(inp); strlwr(cp); if(buffer != "/script"){ buffer.append(cp); ++ count; if(count > lengthofcscript){ buffer.erase(); count = 0; break; } } else return; } } } } else if (ReturnedTag == CSCRIPT){ } else if (ReturnedTag == P){ } else if (ReturnedTag == CP){ } else if (ReturnedTag == STYLE){ while( fin.get(inp) ){ // Find the /script tag if(inp == '<'){ int count = 0; string buffer; const int lengthofcscript = 6; while( 1 ){ fin.get(inp); strlwr(cp); if(buffer != "/style"){ buffer.append(cp); ++ count; if(count > lengthofcscript){ buffer.erase(); count = 0; break; } } else return; } } } } } TAG tagextractor(fstream &fin){ buffer.erase(); while( fin.peek() != '>'){ fin.get(inp); strlwr(cp); if( (buffer != "table") && (buffer != "td") && (buffer != "tr") && (buffer != "script") && (buffer != "style") && (buffer != "/script")) buffer.append(cp); } // Throw away the closing '>' fin.get(); // Handle Table TAGS if(buffer == "table") return TABLE; if(buffer == "tr") return TR; if(buffer == "td") return TD; if(buffer == "/table") return CTABLE; if(buffer == "/tr") return CTR; if(buffer == "/td") return CTD; // Handle List TAGS if(buffer == "dir" || buffer == "menu" || buffer == "ol" || buffer == "ul") return LIST; if(buffer == "li") return LI; if(buffer == "/dir" || buffer == "/menu" || buffer == "/ol" || buffer == "/ul") return CLIST; //Other tags if(buffer == "html") return HTML; if(buffer == "/html") return CHTML; //SCRIPTS if(buffer == "script") return SCRIPT; if(buffer == "/script") return CSCRIPT; if(buffer == "p") return P; if(buffer == "/p") return CP; if(buffer == "style") return STYLE; if(buffer == "/style") return CSTYLE; return OTHER; }