View previous topic :: View next topic |
Author |
Message |
Daaark DeleD PRO user
Joined: 01 Sep 2004 Posts: 2696 Location: Ottawa, Canada
|
Posted: Mon Oct 31, 2005 9:20 am Post subject: |
|
|
**laughing at self**
No it doesn't. The forum cut half of it off. It's been mailed. I'm about to go injure myself in frustration now...
I wonder why it errors out and repeats the last line?
Code: |
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
int main()
{
fstream fLog;
stringstream ss;
fLog.open("log.txt",fstream::in);
if (!fLog.is_open())
{
cout << "Error opening file!\nProgram aborting!";
return EXIT_FAILURE;
}
ss << fLog.rdbuf();
fLog.close();
char ca[1024]; memset(ca,0,sizeof(ca));
string sLine;
int nLine = 0;
int nPos;
string sHTML;
sHTML += "<html>\n";
sHTML += "<body margin=\"20\" bgcolor=\"#FFEBCD\" TEXT=\"000000\">\n";
while (!ss.eof())
{
ss.getline(ca,1024,'\n');
if (strlen(ca) == 0) break;
//cout << nLine << ":" << ca << endl;
++nLine;
//replace any < brackets with [
for (int i = 0; i < strlen(ca); ++i)
{
if (ca[i] == '<') ca[i] = '[';
if (ca[i] == '>') ca[i] = ']';
}
//convert the line to html
if (ca[0] == '[') sLine = "<b>";
else sLine == "";
sLine += ca;
//unbold after the second ']'
//and add coloured text
nPos = sLine.rfind("]");
if (nPos != string::npos)
{
sLine.insert(nPos+1,"</b> <font color=\"0000FF\">");
sLine += "</font><br>";
}
else sLine += "<br>";
sLine += "\n";
sHTML += sLine;
}
fLog.close();
sHTML += "\n</font></body>\n</html>";
fstream fHTML;
fHTML.open("Log.html",fstream::out| fstream::trunc);
if (!fHTML.is_open())
{
cout << "Error opening file!\nProgram aborting!";
return EXIT_FAILURE;
}
fHTML << sHTML.c_str();
fHTML.close();
cout << "\n\n *** Log converted. " << nLine << " lines. ***\n\n";
return EXIT_SUCCESS;
} |
|
|
Back to top |
|
|
Paul-Jan Site Admin
Joined: 08 Aug 2004 Posts: 3066 Location: Lage Zwaluwe
|
Posted: Wed Nov 02, 2005 7:19 am Post subject: |
|
|
*lol* I didn't format the log on purpose, because I thought it was part of IRC 'etiquette' to leave the logs at what they are: simple textfiles (i.e. don't force html formatting down people's troats when all they want is to download the text)... Perhaps I am just old and sad
Thanks a lot for all the effort, guys. I'll put a formatted version of the log online in a minute. |
|
Back to top |
|
|
Paul-Jan Site Admin
Joined: 08 Aug 2004 Posts: 3066 Location: Lage Zwaluwe
|
Posted: Wed Nov 02, 2005 7:22 am Post subject: |
|
|
MrFletcher: Your request has been noted. It's a good idea, thanks! |
|
Back to top |
|
|
Paul-Jan Site Admin
Joined: 08 Aug 2004 Posts: 3066 Location: Lage Zwaluwe
|
Posted: Wed Nov 02, 2005 7:28 am Post subject: |
|
|
Vampyre: Haven't got a clue why the code above would error out, really I always have to resort to hands-on debugging with C++. |
|
Back to top |
|
|
Daaark DeleD PRO user
Joined: 01 Sep 2004 Posts: 2696 Location: Ottawa, Canada
|
Posted: Wed Nov 02, 2005 7:48 am Post subject: |
|
|
Paul-Jan wrote: |
Vampyre: Haven't got a clue why the code above would error out, really I always have to resort to hands-on debugging with C++. |
I officially do't care anymore. Just wanted to help out. Was in the mood to code, but not work on my projects, so I wrote that to help. It just repeats the last line in the log for some reason. *shrug*
I just found the txt file hard to read as it was black on white, and it didn't wrap at all. |
|
Back to top |
|
|
Paul-Jan Site Admin
Joined: 08 Aug 2004 Posts: 3066 Location: Lage Zwaluwe
|
Posted: Thu Nov 03, 2005 10:36 am Post subject: |
|
|
The effort is much appreciated!
I just replaced the text-log with a formatted version. Should have done so yesterday, but I am just slow. |
|
Back to top |
|
|
|