home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
UTILITY
/
W2H01B3.ZIP
/
WWIV2HTM.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1999-04-18
|
7KB
|
313 lines
/*
* WWIV2HTM - WWIV *.MSG file to HTML conversion utility
* Copyright (c) 1999 Robert Clevenger
* All Rights Reserved.
*
* This utility may be used freely by WWIV Sysops. If you make any
* changes, please e-mail them to me so that I may incorporate them
* into my next version.
*
* email: rob@robsite.org
* FidoNet: 1:125/2112
* FILEnet: 1@561.FILENET
*/
#include "wwiv2htm.h"
VOID SetDefaultColors(VOID)
{
//
// Set Default Values...
//
strcpy(bgcolor, "#000000");
strcpy(colors[0], "#bbbbbb");
strcpy(colors[1], "#88FFF7");
strcpy(colors[2], "#ffff00");
strcpy(colors[3], "#e700d0");
strcpy(colors[4], "#0000ff");
strcpy(colors[5], "#00FF00");
strcpy(colors[6], "#ff0000");
strcpy(colors[7], "#0000FF");
strcpy(colors[8], "#969900");
strcpy(colors[9], "#009991");
}
BOOL LoadConfigFile(LPCTSTR pszConfigFileName)
{
FILE* hConfigFile = NULL;
char szBuffer[81];
if ((hConfigFile = fopen(pszConfigFileName, "rt")) == NULL)
{
SetDefaultColors();
}
else
{
//
// Read config file and process values...
//
fgets(szBuffer, 81, hConfigFile);
strcpy(bgcolor, szBuffer);
for (int nLoop=0; nLoop<10; nLoop++)
{
fgets(szBuffer, 81, hConfigFile);
strcpy(colors[nLoop], szBuffer);
}
fclose(hConfigFile);
}
return TRUE;
}
VOID ShowBanner(VOID)
{
COLOR(10);
cprintf("\r\n");
cprintf(TITLE);
cprintf("\r\n");
COLOR(10);
cprintf(VERSION);
cprintf("\r\n");
COLOR(13);
cprintf(COPYRIGHT);
cprintf("\r\n");
COLOR(11);
cprintf(COPYRIGHT2);
cprintf("\r\n\n");
}
VOID ShowUsage(VOID)
{
COLOR(12);
cprintf("USAGE: WWIV2HTML <*.MSG file> <HTML file>\r\n\n");
}
LPSTR AddToString(LPSTR pszOrig, LPCSTR pszAdd)
{
while (*pszAdd)
{
*pszOrig++ = *pszAdd++;
}
return pszOrig;
}
BOOL ConvertFile(LPCTSTR pszWWIVfile, LPCTSTR pszHTMLfile)
{
FILE *hWWIVfile = NULL, *hHTMLfile = NULL;
char szInBuffer[1025], szOutBuffer[1025], szBuffer[81];
char *pszInTemp = NULL, *pszOutTemp = NULL;
unsigned int nTemp = 0;
// open input and output file
if ((hWWIVfile = fopen(pszWWIVfile, "rt")) == NULL)
{
COLOR(12);
fprintf(stderr, "ERROR: Unable to open input file: %s", pszHTMLfile);
return FALSE;
}
if ((hHTMLfile = fopen(pszHTMLfile, "wt")) == NULL)
{
COLOR(12);
fprintf(stderr, "ERROR: Unable to create output file: %s", pszHTMLfile);
fclose(hWWIVfile); // don't leak handles.
return FALSE;
}
// everything should be ok now... (all file handles valid)
fputs("<HTML><HEAD><TITLE>WWIV Generated HTML File</TITLE></HEAD>\n",hHTMLfile);
fprintf(hHTMLfile, "<BODY BGCOLOR=\"%s\">\n",bgcolor);
fprintf(hHTMLfile, "<CODE>\n");
while (!feof(hWWIVfile))
{
szInBuffer[0] = '\0';
fgets(szInBuffer, 1024, hWWIVfile);
pszInTemp = szInBuffer;
pszOutTemp = szOutBuffer;
if (szInBuffer[0] != 0x03)
{
sprintf(szBuffer, "<FONT COLOR=\"%s\">", colors[0]);
pszOutTemp = AddToString(pszOutTemp, szBuffer);
}
while (*pszInTemp)
{
switch ((unsigned char)*pszInTemp)
{
case 3:
// WWIV colour code
pszInTemp++;
nTemp = (*pszInTemp-'0');
if ((nTemp>=0) && (nTemp<=9)) {
sprintf(szBuffer, "</FONT><FONT COLOR=\"%s\">", colors[nTemp]);
pszOutTemp = AddToString(pszOutTemp, szBuffer);
} // if colour ok
break;
case 32: // space
pszOutTemp = AddToString(pszOutTemp, " ");
break;
case 34: // "
pszOutTemp = AddToString(pszOutTemp, """);
break;
case 38: // ampersand
pszOutTemp = AddToString(pszOutTemp, "&");
break;
case 60: // <
pszOutTemp = AddToString(pszOutTemp, "<");
break;
case 62: // >
pszOutTemp = AddToString(pszOutTemp, ">");
break;
case 169: // evaluates to a plus symbol
case 170:
case 183:
case 184:
case 187:
case 188:
case 189:
case 190:
case 191:
case 192:
case 197:
case 200:
case 201:
case 206:
case 214:
case 217:
case 218:
pszOutTemp = AddToString(pszOutTemp, "+");
break;
case 205:
case 207:
case 216:
pszOutTemp = AddToString(pszOutTemp, "=");
break;
case 193:
case 194:
case 196:
case 202:
case 203:
case 210:
case 211:
case 212:
case 213:
case 215:
pszOutTemp = AddToString(pszOutTemp, "-");
break;
case 179:
case 180:
case 181:
case 182:
case 185:
case 186:
case 195:
case 198:
case 199:
case 204:
pszOutTemp = AddToString(pszOutTemp, "|");
break;
case 173:
pszOutTemp = AddToString(pszOutTemp, "!");
break;
case 174:
pszOutTemp = AddToString(pszOutTemp, "<");
break;
case 175:
pszOutTemp = AddToString(pszOutTemp, ">");
break;
case 176: // Block characters
case 177:
case 178:
case 219:
case 220:
case 221:
case 222:
case 223:
pszOutTemp = AddToString(pszOutTemp, "*");
break;
case 224:
case 225:
case 226:
case 227:
case 228:
case 229:
case 230:
case 231:
case 232:
case 233:
case 234:
case 235:
case 236:
case 237:
case 238:
case 239:
case 240:
case 241:
case 242:
case 243:
case 244:
case 245:
case 246:
case 247:
case 248:
case 249:
case 250:
case 251:
case 252:
case 253:
case 254: // all others, nothing to directly map to...
pszOutTemp = AddToString(pszOutTemp, "*");
break;
case 255: // 255 is blank
pszOutTemp = AddToString(pszOutTemp, " ");
break;
default:
// normal character
*pszOutTemp++ = *pszInTemp;
break;
} // switch
pszInTemp++;
}
pszOutTemp = AddToString(pszOutTemp, "</FONT> <BR>");
*pszOutTemp++ = '\0';
fprintf(hHTMLfile, "%s\n", szOutBuffer);
} // [end while loop]
fprintf(hHTMLfile, "</CODE>\n");
fputs("</BODY></HTML>",hHTMLfile);
fputs("<!-- generated with wwiv2htm -->",hHTMLfile);
// close handles
fclose(hWWIVfile);
fclose(hHTMLfile);
return TRUE;
}
int main(int argc, char* argv[])
{
// UNREFERENCED_PARAMETER(argv);
ShowBanner();
if (argc != 3)
{
ShowUsage();
return(1);
}
LoadConfigFile("WWIV2HTM.INI");
for (int i=0; i<10; i++)
{
printf("Color #%d = %s\n", i, colors[i]);
}
ConvertFile(argv[1], argv[2]);
return(0);
}