发信人: Roland (罗兰), 信区: BBSdev
标 题: Re: 哪里有html2bbs
发信站: 快意灌水站 (2000年11月15日12:35:05 星期三), 站内信件
////////////////////////////////
/* HTML->BBS Version 1.5 */
/* Programmed by Cheetah, PKU */
/* danke@263.net */
////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#define BBSHOME "/home/bbs"
time_t ntime;
long nCount=0;
int AddPost(char *phHome,char *paHome)
{
FILE *fpA,*fpH;
char line[1024],*p,*q;
int nStart=0;
fpA=fopen(paHome,"w");
fpH=fopen(phHome,"r");
while (!feof(fpH))
{
if (!fgets(line,sizeof line,fpH))
continue;
if (strncmp(line,"<CENTER>",8)==0)
nStart++;
if (nStart==1 && line[0]=='\n') { nStart++; continue; }
if (nStart==2)
{
while (p=strstr(line," "))
{
strcpy(p+1,p+6);
*p=' ';
}
if (p=strstr(line,"<BR>"))
strcpy(p,"\n");
while (p=strstr(line,"<BR>"))
strcpy(p,p+4);
while (p=strstr(line,"</A>"))
strcpy(p,p+4);
while (p=strstr(line,"<A HREF=\""))
{
if (q=strstr(p,">"))
strcpy(p,q+1);
else *p='\0';
}
while (p=strstr(line,"<I>"))
strcpy(p,p+3);
while (p=strstr(line,"</I>"))
strcpy(p,p+4);
while (p=strstr(line,"&"))
{
strcpy(p+1,p+5);
*p='&';
}
while (p=strstr(line,"<"))
{
strcpy(p+1,p+4);
*p='<';
}
while (p=strstr(line,">"))
{
strcpy(p+1,p+4);
*p='>';
}
while (p=strstr(line,"&"))
{
strcpy(p+1,p+5);
*p='&';
}
while (p=strstr(line,"""))
{
strcpy(p+1,p+6);
*p='"';
}
fputs(line, fpA);
}
if (nStart==3) break;
}
fclose(fpA);
fclose(fpH);
}
int HtmlProcess(char *phHome,char *paHome)
{
char fnH[1024],line[1024],head[20],subname[20],subdir[20],subHome[1024];
char subPath[1024],strTitle[1024],strName[1024],strLine[50];
char *p;
int nNumb;
struct stat st;
FILE *fpH,*fpName;
strcpy(fnH,phHome);
strcat(fnH,"/index.htm");
if ((fpH=fopen(fnH,"r"))==NULL)
{
printf("File open error: %s.\n",fnH);
exit(-2);
}
if(stat(paHome,&st) == -1) {
if(mkdir(paHome,0755) == -1)
{
printf("BBS Announcement directory err: %s.\n",paHome);
exit(-2);
}
} else {
if(!(st.st_mode & S_IFDIR))
{
printf("BBS Announcement directory err: %s.\n",paHome);
exit(-2);
}
}
sprintf(strName,"%s/.Names",paHome);
fpName=fopen(strName,"a+");
if (!fpName)
{
printf(".Names open err: %s\n",paHome);
exit(-2);
}
if (ftell(fpName)>20)
fseek(fpName,SEEK_END,20);
nNumb=1;
line[0]=0;
while (!feof(fpName))
{
if (fgets(line,sizeof line,fpName))
{
if (strncmp(line,"Numb=",5))
nNumb=atoi(strchr(line,'=')+1)+1;
}
}
while (!feof(fpH))
{
line[0]=0;
if (!fgets(line,sizeof line,fpH)) continue;
strncpy(head,line,8);
head[8]=0;
p=strchr(line,'<');
if (p && strncmp(p,"<TITL",5)==0)
{
p=strchr(line,'>');
if (p)
strncpy(strTitle,p+1,36);
strTitle[36]=0;
if (p=strstr(strTitle,"</A><BR>"))
strcpy(p,p+8);
printf("Title: %s\n",strTitle); nCount++;
}
if (strcmp(head,"<A HREF=")==0)
{
p=strchr(line,'>');
if (p) strncpy(strLine,p+1,38);
strLine[38]=0;
if (p=strstr(strLine,"</A><BR>"))
strcpy(p,p+8);
p=strchr(line,'"')+1;
fprintf(fpName,"Name=%s\n",strLine);
if (*p=='.')
fprintf(fpName,"Path=~/%d\n",++ntime);
else
fprintf(fpName,"Path=~/M.%d.A\n",++ntime);
fprintf(fpName,"Numb=%d\n",nNumb++);
fprintf(fpName,"#\n");
if (*p=='.')
{
if (line[10]=='.')
{
strncpy(subdir,&line[9],11); subdir[11]=0;
}
else{
strncpy(subdir,&line[9],10); subdir[10]=0;
}
sprintf(subHome,"%s/%s",phHome,subdir);
sprintf(subPath,"%s/%d",paHome,ntime);
HtmlProcess(subHome,subPath);
}
else{
strncpy(subdir,&line[9],12); subdir[12]=0;
sprintf(subHome,"%s/%s",phHome,subdir);
sprintf(subPath,"%s/M.%d.A",paHome,ntime);
AddPost(subHome,subPath);
}
}
}
fclose(fpH);
fclose(fpName);
}
int main(int argc,char *argv[])
{
char HtmlHome[256],AnnHome[256];
if (argc!=3)
{
printf("Usage: html2ann HTML-DIR ANN-DIR\n");
exit(-1);
}
ntime=time(0);
strcpy(HtmlHome,argv[1]);
strcpy(AnnHome,argv[2]);
HtmlProcess(HtmlHome,AnnHome);
printf("\n\nFile processed: %ld\n",nCount);
}
【 在 soff (soff) 的大作中提到: 】
: 这里有一份html版的精华区
: 据说一个叫做html2bbs的工具
: 可以转过来
: 请问哪里可以找到该程序
: //bow
--
FROM 202.120.1.182