/* Licensed under the Creative Commons GNU GPL Copyright (C) 2007 Shawn Biddle This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A Human Readable version can be found at http://creativecommons.org/licenses/GPL/2.0/ Title: Basic Webpage Generation Application Author: Shawn Biddle Date of Last Access: Feb 25, 2007 Description: Takes user input for the Title, Heading and Body Text of the page. All get functions are separate as well as the writePage so "modules" can easily be added on later. */ #include #include #include #include #include #include using namespace std; struct page { int tcolor; int bgcolor; char heading[50]; char body[256]; char title[50]; char center; char bcenter; char bold; bool correct; } MyPage; void getColors(page *ptrMyPage); void getHeading(page *ptrMyPage); void getTitle(page *ptrMyPage); void getBody(page *ptrMyPage); void writePage(page *ptrMyPage); void verify(page *ptrMyPage); ofstream output; //ate=put cursor at end of file, trunc=write over existing file data to start clean int main(){ int errorcode=0; MyPage.correct=true; SetConsoleTitleA("Basic Webpage Generation Application"); cout<< "\xC9" << setfill('\xCD') << setw(54); cout<< "\xBB"<< endl; cout<<"\xBA Welcome to the Basic Webpage Generation Application \xBA"<< endl; cout<<"\xBA Created by Shawn Biddle (C) 2007 \xBA"<< endl; cout<< "\xC8" << setfill('\xCD') << setw(54); cout<< "\xBC"<< endl; cout<<"\tPlease wait to be taken to the menu. . ."; Sleep(5000); system("cls"); getColors(&MyPage); system("cls"); getTitle(&MyPage); system("cls"); getHeading(&MyPage); system("cls"); getBody(&MyPage); system("cls"); if (tolower(MyPage.center)!='y' && tolower(MyPage.center)!='n') {MyPage.correct=false; errorcode+=1;} if (tolower(MyPage.bcenter)!='y' && tolower(MyPage.bcenter)!='n'){MyPage.correct=false; errorcode+=2;} if (tolower(MyPage.bold)!='y' && tolower(MyPage.bold)!='n'){ MyPage.correct=false; errorcode+=3;} if (MyPage.correct!=false) { // correct value is written by the verify function verify(&MyPage); writePage(&MyPage); } else { cout<<"\aThe following Errors occured."<< endl; switch(errorcode){ case 1: cout<<" Error Code: 1 - Value input for Property (Center) not valid."<< endl; break; case 2: cout<<" Error Code: 2 - Value input for Property (Body Center) not valid."<< endl; break; case 3: cout<<" Error Code: 3 - Value input for Property (Bold) not valid."<< endl; break; case 4: cout<<" Error Code: 1 - Value input for Property (Center) not valid."<< endl; cout<<" Error Code: 3 - Value input for Property (Bold) not valid."<< endl; break; case 5: cout<<" Error Code: 2 - Value input for Property (Body Center) not valid."<< endl; cout<<" Error Code: 3 - Value input for Property (Bold) not valid."<< endl; break; case 6: cout<<" Error Code: 1 - Value input for Property (Center) not valid."<< endl; cout<<" Error Code: 2 - Value input for Property (Body Center) not valid."<< endl; cout<<" Error Code: 3 - Value input for Property (Bold) not valid."<< endl; break; default: cout<<" Error Code: 0 - Given input was not usable. File was not generated."<< endl; break; } } if (output.is_open()){ // if file is not closed by the writePage function cout<<"File I/O Failed. Closing File."<< endl; output.close(); } cout<<"Exiting. . ."<< endl; Sleep(5000); return 0; } void getTitle(page *ptrMyPage){ cin.get(); cout<<"What do you want the title of the webpage to be?"; cin.getline(ptrMyPage->title, 50); } void getHeading(page *ptrMyPage){ cout<<"What would you like the heading to be?"; cin.getline(ptrMyPage->heading, 50); cout<<"Do you want the heading to be centered? Y or N:"; cin>> ptrMyPage->center; } void getBody(page *ptrMyPage){ cout<<"What would you like the body text to be? Type # to end"; cout<<"\nNote that HTML tags are accepted Ex. Text
\n"; cin.getline(ptrMyPage->body, 256, '#'); cout<<"Do you want the text to be centered? Y or N:"; cin>> ptrMyPage->bcenter; cout<<"\nWould you like the text to be bold? Y or N:"; cin>> ptrMyPage->bold; } void writePage(page *ptrMyPage){ string filename; cout<<"What do you want the file to be called? .html is added automatically"<< endl; cout<<"Note that the file can be found in your My Documents folder."<< endl; cout<<"-->"; cin >> filename; filename = filename + ".html"; filename = "C:/DOCUME~1/ADMINI~1/MYDOCU~1/" + filename; output.open(filename.c_str(), ios::ate | ios::trunc); cout<<"Creating page based on input. . ."<< endl; Sleep(1000); output << "\n"<< ptrMyPage->title << ""; /* HTML Colors 0 Black 4 Gray 8 Silver 12 White 1 Yellow 5 Lime 9 Aqua 13 Fuchsia 2 Red 6 Green 10 Blue 14 Purple 3 Maroon 7 Olive 11 Navy 15 Teal */ switch(ptrMyPage->bgcolor){ case 0: output << ""<< endl; break; case 1: output << ""<< endl; break; case 2: output << ""<< endl; break; case 3: output << ""<< endl; break; case 4: output << ""<< endl; break; case 5: output << ""<< endl; break; case 6: output << ""<< endl; break; case 7: output << ""<< endl; break; case 8: output << ""<< endl; break; case 9: output << ""<< endl; break; case 10: output << ""<< endl; break; case 11: output << ""<< endl; break; case 12: output << ""<< endl; break; case 13: output << ""<< endl; break; case 14: output << ""<< endl; break; case 15: output << ""<< endl; break; default: output << ""<< endl; break; } output << "" << endl; switch(ptrMyPage->tcolor){ case 0: output << ""<< endl; break; case 1: output << ""<< endl; break; case 2: output << ""<< endl; break; case 3: output << ""<< endl; break; case 4: output << ""<< endl; break; case 5: output << ""<< endl; break; case 6: output << ""<< endl; break; case 7: output << ""<< endl; break; case 8: output << ""<< endl; break; case 9: output << ""<< endl; break; case 10: output << ""<< endl; break; case 11: output << ""<< endl; break; case 12: output << ""<< endl; break; case 13: output << ""<< endl; break; case 14: output << ""<< endl; break; case 15: output << ""<< endl; break; default: break; } if (tolower(ptrMyPage->center)=='n'){ output <<"

" << ptrMyPage->heading << "

"<< endl; } else if (tolower(ptrMyPage->center)=='y'){ output <<"

" << ptrMyPage->heading << "

"<< endl; } output <<"
\n"; //HTML Linebreak if (tolower(ptrMyPage->bcenter)=='y' && tolower(ptrMyPage->bold)=='y'){ output <<"
" << ptrMyPage->body << "\n
\n"<< endl; } else if (tolower(ptrMyPage->bcenter)=='y' && tolower(ptrMyPage->bold)=='n'){ output <<"
" << ptrMyPage->body << "\n
\n"<< endl; } else if (tolower(ptrMyPage->bcenter)=='n' && tolower(ptrMyPage->bold)=='y'){ output <<"" << ptrMyPage->body << "\n\n"<< endl; } else if (tolower(ptrMyPage->bcenter)=='n' && tolower(ptrMyPage->bold)=='n'){ output << ptrMyPage->body << endl; } output << "
\n \n"; output.close(); cout<<"File was generated successfully."<< endl; Sleep(1000); cout<<"Please wait while I open the generated file. . ."<< endl; system(filename.c_str()); } void verify(page *ptrMyPage){ char H_Verify, B_Verify, T_Verify; cout<<"Are you sure these are the correct values for the page title?"<< endl; cout<<"\nTitle: "<< ptrMyPage->title << endl; cout<<"\nEnter Y for correct and N if these are incorrect:"; cin>> T_Verify; if (tolower(T_Verify)=='n'){ cout<<"\a\nIncorrect Values. Ending Execution."<< endl; Sleep(1000); ptrMyPage->correct=false; system("cls"); return; } else { cout<<"\nValues Correct. Press Enter to verify Heading values. . ."; cin.get(); cin.get(); system("cls");} cout<<"Are you sure these are the correct values for the heading?"<< endl; cout<<"\nHeading: "<< ptrMyPage->heading << endl; if (tolower(ptrMyPage->center)=='y') cout<<"\nCentered=TRUE"<< endl; else if (tolower(ptrMyPage->center)=='n') cout<<"\nCentered=FALSE"<< endl; cout<<"Enter Y for correct and N if these are incorrect:"; cin>> H_Verify; if (tolower(H_Verify)=='n'){ cout<<"\a\nIncorrect Values. Ending Execution."<< endl; ptrMyPage->correct=false; system("cls"); return; } else { cout<<"\nValues Correct. Press Enter to verify Body Text Values. . ."; cin.get(); cin.get(); system("cls");} cout<<"Are you sure these are the correct values for the body text?"<< endl; cout<<"Body Text: "<< ptrMyPage->body << endl; if (tolower(ptrMyPage->bcenter)=='y') cout<<"\nCentered=TRUE"<< endl; else if (tolower(ptrMyPage->bcenter)=='n') cout<<"\nCentered=FALSE"<< endl; if (tolower(ptrMyPage->bold)=='y') cout<<"Bold=TRUE"<< endl; else if (tolower(ptrMyPage->bold)=='n') cout<<"Bold=FALSE"<< endl; cout<<"Enter Y for correct and N if these are incorrect:"; cin>> B_Verify; if (tolower(B_Verify)=='n'){ cout<<"Incorrect Values. Ending Execution."<< endl; ptrMyPage->correct=false; system("cls"); return; } else { cout<<"Values Correct. Proceeding to File Generation."; cout<<"\nPress ENTER to continue. . ."; cin.get(); cin.get(); system("cls"); return;} } void getColors(page *ptrMyPage){ char preview; cout<<" 0 Black 4 Gray 8 Silver 12 White"<< endl; cout<<" 1 Yellow 5 Lime 9 Aqua 13 Fuchsia"<< endl; cout<<" 2 Red 6 Green 10 Blue 14 Purple"<< endl; cout<<" 3 Maroon 7-Olive 11 Navy 15 Teal"<< endl; cout<<"Colors with a - have no preview."<< endl; cout<<"Please type the number of the corresponding text color: "; cin>> ptrMyPage->tcolor; cout<<"\nPlease type the number of the corresponding background color. "<< endl; cout<<"TIP: Do not use the same background and text color.\n>"; cin>> ptrMyPage->bgcolor; cout<<"If you would like a preview type P or anything else to continue on."<< endl; cin >> preview; if (tolower(preview)=='p'){ cout<<"Text Color Preview, Wait for Background Color Preview."<< endl; switch(ptrMyPage->tcolor){ case 0: cout<<"Cannot Preview Black on Black"<< endl; break; case 1: system("color E"); break; case 2: system("color C"); break; case 3: system("color 4"); break; case 4: cout<<"Current Color"<< endl; break; case 5: system("color A"); break; case 6: system("color 2"); break; case 7: cout<<"No Preview"<< endl; break; case 8: system("color 8"); break; case 9: system("color 3"); break; case 10: system("color 9"); break; case 11: system("color 1"); break; case 12: system("color F"); break; case 13: system("color D"); break; case 14: system("color 5"); break; case 15: system("color B"); break; default: cout<<"No Preview Available"<< endl; } Sleep(3000); cout<<"Background Color Preview."<< endl; switch(ptrMyPage->bgcolor){ case 0: cout<<"Current Background"<< endl; break; case 1: system("color E7"); break; case 2: system("color C7"); break; case 3: system("color 47"); break; case 4: system("color 87"); break; case 5: system("color A7"); break; case 6: system("color 27"); break; case 7: cout<<"No Preview"<< endl; break; case 8: system("color 87"); break; case 9: system("color 37"); break; case 10: system("color 97"); break; case 11: system("color 17"); break; case 12: system("color F7"); break; case 13: system("color D7"); break; case 14: system("color 57"); break; case 15: system("color B7"); break; default: cout<<"No Preview Available"<< endl; } Sleep(3000); cout<<"Ending Preview. Returning to Default Colors."<< endl; system("color 07"); cout<<"Please Wait. Proceeding with File Generation."<< endl; Sleep(2000); return; } else { cout<<"Please Wait. Proceeding with File Generation."<< endl; Sleep(2000); return; } }