Created
April 13, 2016 17:47
-
-
Save ssg/b1f67829a0a23b2194b28f7dc165cf65 to your computer and use it in GitHub Desktop.
Converts custom IRC log snippets to HTML. Probably the first app I wrote that worked with HTML, and interestingly, in C. (December 1997)
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 <stdio.h> | |
char indexheader[] = | |
"<!-- Generated by LOG2HTM by SSG/aRtEffECt --> \n \ | |
<body bgcolor=\"#000000\" text=\"#FFFFFF\" link=\"#C9C298\" vlink=\"#808080\" alink=\"#FF0000\"> \n \ | |
<h1>Best of #coders</h1><font size=\"+1\" color=\"#7a8daf\"> \n \ | |
All those are selections from SSG''s log of #coders on irc.raksnet.com.tr. \n \ | |
</font><center><table align=\"center\" bgcolor=\"#695852\" cellspacing=1 cellpadding=4> \n \ | |
<tr bgcolor=\"#000000\"><th>Title</th><th>Date</th></tr>\n"; | |
char indexfooter[] = | |
"</table></center>\n"; | |
char indextemplate[] = | |
"<tr><td nowrap><a href=\"%s\">%s</a></td><td>%s</td></tr>\n"; | |
char headertemplate[] = | |
"<body bgcolor=\"#C1A379\" text=\"#000000\" link=\"#FFFFFF\" vlink=\"#808080\">\n | |
<h2>%s (%s)</h2><hr><tt><b>"; | |
char footer[] = | |
"</b></tt><hr><center><i><h5>Generated by Log2HTML by SSG/aRtEffECt</h5></i></center>\n"; | |
void error(char *msg) | |
{ | |
puts(msg); | |
exit(1); | |
} | |
void safecpy(char *dst,char *src,size_t size) | |
{ | |
char *tmp; | |
tmp = (char *)malloc(size); | |
if (tmp==NULL) error("safecpy failed"); | |
memcpy(tmp,src,size); | |
memcpy(dst,tmp,size); | |
free(tmp); | |
} | |
void replace(char *s, char *src, char *dst) | |
{ | |
int lastpos=0; | |
int destlen=strlen(dst); | |
int srclen=strlen(src); | |
int len; | |
char *p; | |
do { | |
p = (char *)strstr(s,src); | |
if (p==NULL) break; | |
len = ((int)strlen(s)+(int)s)-(int)p; | |
safecpy((p+destlen)-srclen,p,len); | |
p[(destlen-srclen)+len]=0; | |
safecpy(p,dst,destlen); | |
} while(-1); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
FILE *i,*o,*n; | |
char title[80],date[20],temp[80],s[1000]; | |
int cntr=0; | |
puts("Log2HTML Converter v2.00a - (c) Dec 97 SSG\n"); | |
if (argc!=3) error("Usage: log2html infile outfile"); | |
i = fopen(argv[1],"rt"); | |
if (i==NULL) error("input open error"); | |
o = fopen(argv[2],"wt"); | |
fprintf(o,"%s",indexheader); | |
while (!feof(i)) { | |
fgets(temp,sizeof(temp),i); | |
if (temp[0]=='@') { | |
strcpy(title,(char *)(strstr(temp, "(")+1)); | |
((char *)strstr(title,")"))[0]=0; | |
((char *)strstr(temp,"("))[0]=0; | |
strcpy(date,temp+1); | |
while (date[strlen(date)-1]==' ') date[strlen(date)-1]=0; | |
fgets(temp,sizeof(temp),i); | |
if (strstr(temp,"===")!=NULL) { | |
sprintf(temp,"irc%d.html",cntr); | |
cntr++; | |
fprintf(o,indextemplate,temp,title,date); | |
n = fopen(temp,"wt"); | |
if (n==NULL) error("cannot create a fuckin file"); | |
fprintf(n,headertemplate,title,date); | |
do { | |
fgets(s,sizeof(s),i); | |
if (s[0]=='\n') break; | |
if (s[strlen(s)-1]=='\n') s[strlen(s)-1]=0; | |
replace(s,"<","<"); | |
replace(s,">",">"); | |
fprintf(n,"%s<br>\n",s); | |
} while(!feof(i)); | |
fprintf(n,footer); | |
fclose(n); | |
} else break; | |
} | |
} | |
fprintf(o,indexfooter); | |
fclose(i); | |
fclose(o); | |
puts("SSG operation complete"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment