-
-
Save anonymous/ab8ecfd09bddba0d4fcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <locale> | |
#include <cstdlib> | |
using namespace std; | |
#define tab " " | |
static void show_usage( ) | |
{ | |
cerr << "Error: Incorrect number of parameters [1]." << endl; | |
cerr << "Usage: txt2html [-q] sourcefile [destfile]" << endl; | |
} | |
int main(int argc, char* argv []) | |
{ | |
ifstream infile; | |
bool quiet = false; //Output flag in case the user enters the quiet switch. | |
ofstream outfile; //Used for the destinational file if the user provides it. | |
string outfilename (argv[1]); | |
char ch; //Will be used to parse through the text in the input file and output to a dest file. | |
int inputLines = 0; | |
int outputParas = 0; | |
locale here(""); | |
cout.imbue( here ); | |
if( strcmp( argv[1], "-q" ) != 0) //This is an example of what I am trying to do. | |
{ | |
quiet = true; | |
infile.open( argv[2] ); | |
} | |
if( argc < 2 ) | |
{ | |
show_usage( ); | |
return EXIT_FAILURE; | |
} | |
if( argc == 3) | |
{ | |
outfile.open( argv[2] ); | |
} | |
else | |
{ | |
outfilename.erase(outfilename.find_last_of("."), string::npos).append(".html"); | |
outfile.open(outfilename.c_str( ) ); | |
} | |
//Hardcode the tags into the html document. | |
outfilename.erase(outfilename.find_last_of("."), string::npos); | |
outfile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | |
outfile << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"; | |
outfile << "<head>\n"; | |
outfile << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"; | |
outfile << "<title>" << "cunt lips" << "</title\n"; | |
outfile << "</head>\n"; | |
outfile << "<body>\n"; | |
while( infile.get( ch ) ) | |
{ | |
switch( ch ) | |
{ | |
case '\n': | |
outfile << "<br />"; | |
break; | |
case '\t': | |
outfile << tab; | |
outputParas++; | |
break; | |
case '&': | |
outfile << "&"; | |
break; | |
case '<': | |
outfile << "<"; | |
break; | |
case '>': | |
outfile << ">"; | |
break; | |
case '"': | |
outfile << """; | |
break; | |
default: | |
break; | |
} | |
outfile << ch; | |
if( ch == '\n' ) | |
{ | |
inputLines++; | |
} | |
} | |
outfile << "</body>\n"; | |
outfile << "</html>"; | |
infile.close(); | |
cout << "Number of input lines processed: " << inputLines << "." << endl; | |
cout << "Number of output paragraphs processed: " << outputParas << "." << endl; | |
}//end main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment