荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: Rog (我要开始努力学习), 信区: InstallBBS
标 题: [转载] [范文][BBSInstall]FBBBS精华区数据HTML化并打包tgz ((转寄)
发信站: BBS 荔园晨风站 (Fri Dec 18 23:21:35 1998), 站内信件
【 以下文字转载自 Linux 讨论区 】
【 原文由 Lg 所发表 】
【 以下文字转载自 Lg 的信箱 】
寄信人: spiceboy (子夜二时请你叫醒我)
标 题: [范文][BBSInstall]FBBBS精华区数据HTML化并打包tgz (转载)
发信站: BBS 水木清华站 (Sun Nov 22 01:57:03 1998)
来 源: 166.111.11.192
发信人: Leeward (X 14% completed), 信区: Linux
标 题: FireBirdBBS 精华区数据 HTML 化并打包成 tgz
发信站: BBS 水木清华站 (Sun Jun 14 18:04:51 1998)
补充说明:使用方式:Xhtml 精华区目录名
运行成功时,生成的 tgz 文件位于程序中的 WORKDIR 下。
/* Making the X of a board into HTML format and then tar, gzip -- compress. */
/* */
/* Leeward 1998.02.17 (Modified 1998.05.22) */
/* */
/* This little program scans a X directory for a board */
/* and converts all its files into HTML format new files */
/* and finally compress the new into a UNIX tgz format package. */
/* */
/* This program uses shell command "ls -AFR" to get a temp control file of */
/* all X directory files, and then convert the recursive directory structure */
/* into a linear structure. */
/* */
/* Also this program duplicates all source files and renames all of them */
/* into digital MS-DOS 8.3 format file names (avoiding easily re-produce). */
/* */
/* Build: */
/* make Xhtml */
/* */
/* Known shortcomings: do not check if disk space is enough */
/* */
#include <stdio.h>
#include <string.h>
#include <sys/mode.h>
#define MAXLINELEN 8192
#define MAXPATHLEN 256
#define MAXFILENUM 1024 /* max directories/files in a directory */
#define DOTNAMES ".Names"
#define INDEXTMP "index.tmp"
#define INDEXHTML "index.htm"
#define HEADER "BBS水木清华站∶精华区"
#define FOOTER "BBS水木清华站∶精华区"
/* Leeward 98.05.22: Use another fixed disk as run-time working directorry;
Do NOT use BBS' data disk space! */
/*#define WORKDIR "/opt/bbsbackup"*/
#define WORKDIR "." /* hehe, since 2GB disk recovered, not using /opt */
int
main(int argc, char **argv)
{
char srcLine[MAXLINELEN] = "", dstLine[MAXLINELEN] = "";
char srcDir[MAXPATHLEN] = "", dstDir[MAXPATHLEN] = "";
char srcFile[MAXPATHLEN] = "", dstFile[MAXPATHLEN] = "";
char srcX[MAXPATHLEN] = "", dstX[MAXPATHLEN] = "";
char anchor[MAXLINELEN] = "";
char Buf[MAXLINELEN] = "", Buf2[MAXLINELEN] = "";
char srcFX[MAXFILENUM][MAXPATHLEN], dstFX[MAXFILENUM][MAXPATHLEN];
char srcDX[MAXFILENUM][MAXPATHLEN];
char srcD[MAXPATHLEN], dstD[MAXPATHLEN];
char cwD[MAXPATHLEN] = "";
char *ptr;
FILE *psrcFile, *pdstFile;
FILE *pDOTNames;
FILE *pINDEXhtml;
FILE *pHasDOTNames;
FILE *pls_AFR;
int NumDir = 0, NumFile = 0;
int NOTsrcX = - 1;
int i, j, k;
time_t now;
printf("This application creates compressed HTML package for BBS.\n");
printf("Initializing...\n");
if (argc < 2)
{
printf("Syntax: %s XDIR\n", argv[0]);
exit(-1);
}
strcpy(srcX, argv[1]);
getcwd(cwD, MAXPATHLEN);
if (chdir(srcX))
{
printf("XDIR \"%s\" not found\n", srcX);
exit(-1);
}
else
{
chdir(cwD);
sprintf(dstX, "%s/%s.AIX", WORKDIR, srcX);
if (mkdir(dstX, 0000755)) /* drwxr-xr-x */
{
printf("Unexpected error: Can not create directory \"%s\"\n", dstX);
exit(-2);
}
strcpy(srcDir, srcX);
sprintf(srcDX[NumDir ++], "%s", srcDir);
}
sprintf(Buf, "ls -AFR %s > %ld.Xhtml", srcX, now = time(0));
system(Buf);
sprintf(Buf, "echo Terminator\":\" >> %ld.Xhtml", now); /* NOT lack last */
system(Buf);
printf("X Starting...\n");
sprintf(Buf, "%ld.Xhtml", now);
if (NULL == (pls_AFR = fopen(Buf, "rt")))
{
printf("Unexpected error: Can not open control file\n");
exit(-3);
}
printf("Processing directory \"%s\"...\n", srcDir);
while (!feof(pls_AFR))
{
fgets(Buf, MAXLINELEN, pls_AFR);
if (feof(pls_AFR))
break;
else
Buf[strlen(Buf) - 1] = 0;
if ('/' == Buf[strlen(Buf) - 1])
{ /* directory */
Buf[strlen(Buf) - 1] = 0;
sprintf(srcDX[NumDir ++], "%s/%s", srcDir, Buf);
if (NumDir >= MAXFILENUM)
{
printf("Fatal error: direcotry number in this X exceeds %s\n",
MAXFILENUM);
fclose(pls_AFR);
exit(-3);
}
continue;
}
if (':' == Buf[strlen(Buf) - 1])
{ /* enter a new directory */
Buf[strlen(Buf) - 1] = 0;
strcpy(srcD, srcDir);
NOTsrcX ++;
strcpy(srcDir, Buf);
printf("Finalizing directory \"%s\"...\n", srcD);
sprintf(Buf, "%s/%s", dstDir, INDEXTMP);
if (NULL == (pdstFile = fopen(Buf, "rt")))
{
/*printf("Unexpected error: Can not open file \"%s\"\n", Buf);*/
printf("ATTENTION!!! Directory \"%s\" contains nothing!!!\n", srcD);
continue;
/*fclose(pls_AFR);
exit(-3);*/
}
sprintf(Buf, "%s/%s", dstDir, INDEXHTML);
if (NULL == (pINDEXhtml = fopen(Buf, "wt")))
{
printf("Unexpected error: Can not write file \"%s\"\n", Buf);
fclose(pdstFile);
fclose(pls_AFR);
exit(-3);
}
while (!feof(pdstFile))
{ /* replace URLs in INDEXTMP into digital names */
fgets(dstLine, MAXLINELEN, pdstFile);
if (feof(pdstFile))
break;
else
dstLine[strlen(dstLine) - 1] = 0;
if (ptr = strstr(dstLine, "<A HREF=\""))
{ /* URL lines in INDEXTMP */
char *ptr2 = strstr(ptr + 9, "\">"); /* Leeward: 97.12.15 */
if (NULL == ptr2)
{
printf("Unexpected error: URL analyzation failed\n");
fclose(pINDEXhtml);
fclose(pdstFile);
fclose(pls_AFR);
exit (-4);
}
else
*ptr2 = 0;
for (i = 0; i < NumFile; i ++)
if (!strcmp(ptr + 9, srcFX[i]))
{ /* URL: point a file */
sprintf(Buf, "<A HREF=\"%s\"%s", dstFX[i], ptr2 + 1);
break;
}
*ptr2 = '"';
if (NumFile == i)
{ /* URL: point a directory */
strcpy(Buf, ptr + 9);
ptr = strstr(Buf, "\">");
if (NULL == ptr)
{
printf("Unexpected error: URL analyzation failed\n");
fclose(pINDEXhtml);
fclose(pdstFile);
fclose(pls_AFR);
exit (-4);
}
*ptr = 0;
strcat(srcD, "/");
strcat(srcD, Buf);
for (i = 0; i < NumDir; i ++)
if (!strcmp(srcDX[i], srcD))
{
sprintf(Buf2, "%s/%s", srcDX[i], DOTNAMES);
if (NULL == (pHasDOTNames = fopen(Buf2, "rt")))
{
sprintf(Buf, "<FONT COLOR=RED>此处版主整理精华区时只建了个空目
录</FONT><BR>");
ptr = strrchr(srcD, '/');
if (NULL == ptr)
{
printf("Unexpected error: string operation failed\n");
fclose(pINDEXhtml);
fclose(pdstFile);
fclose(pls_AFR);
exit (-4);
}
*ptr = 0;
break;
}
else
{
fclose(pHasDOTNames);
sprintf(dstD, "<A HREF=\"%s/%08d/%s\"%s", (NOTsrcX ? ".." :
"."), i, INDEXHTML, ptr + 1);
strcpy(Buf, dstD);
ptr = strrchr(srcD, '/');
if (NULL == ptr)
{
printf("Unexpected error: string operation failed\n");
fclose(pINDEXhtml);
fclose(pdstFile);
fclose(pls_AFR);
exit (-4);
}
*ptr = 0;
break;
}
}
if (i == NumDir)
sprintf(Buf, "<FONT COLOR=RED>此处版主整理精华区时操作错误</FONT>
<BR>\n");
} /* if (NumFile == i) */
} /* if (ptr = strstr(dstLine, "<A HREF=\"")) */
else
strcpy(Buf, dstLine);
fputs(Buf, pINDEXhtml);
fputs("\n", pINDEXhtml);
}
fclose(pdstFile);
fclose(pINDEXhtml);
sprintf(Buf, "%s/%s", dstDir, INDEXTMP);
unlink(Buf);
printf("Processing directory \"%s\"...\n", srcDir);
continue;
}
for (i = 0; i < strlen(Buf); i ++)
if (' ' != Buf[i])
break;
if (i >= strlen(Buf))
continue;
if (!strcmp(Buf, DOTNAMES))
{ /* DOTNAME file */
printf("Analyzing directory \"%s\"...\n", srcDir);
sprintf(Buf, "%s/%s", srcDir, DOTNAMES);
if (NULL == (pDOTNames = fopen(Buf, "rt")))
{
printf("Unexpected error: Can not open file \"%s\"\n", DOTNAMES);
fclose(pls_AFR);
exit(-3);
}
NumFile = 0;
if (NumDir > 1)
{ /* obtain the corresponding digital directory name */
for (i = 0; i < Num2 + 1);
else if ('>' == srcLine[0])
sprintf(dstLine, "><I>%s</I><BR>\n", Buf2 + 4);
else
sprintf(dstLine, "%s<BR>\n", Buf2);
fputs(dstLine, pdstFile);
}
fputs("\n\n<CENTER><H1>", pdstFile);
fputs(FOOTER, pdstFile);
fputs("</H1></CENTER>\n\n", pdstFile);
fputs("\n\n</BODY>\n\n</HTML>", pdstFile);
fclose(pdstFile);
fclose(psrcFile);
} /* if (!strcmp(Buf, DOTNAMES)) else ... */
} /* while (!feof(pls_AFR)) */
printf("Finished creating HTML files...\n");
fclose(pls_AFR);
printf("Compressing HTML files...\n");
printf("Calling \"tar\"...\n");
sprintf(Buf, "%s/%s.html.tar", WORKDIR, srcX);
unlink(Buf);
sprintf(Buf, "tar cf %s/%s.html.tar %s", WORKDIR, srcX, dstX);
system(Buf);
printf("Cleaning working directory/data...\n");
sprintf(Buf, "rm -fr %s %ld.Xhtml", dstX, now);
system(Buf);
if (0 == chdir(dstX))
{
printf("Unexpected error: Can not erase directory \"%s\"\n", dstX);
exit(-2);
}
printf("Calling \"gzip\"...\n");
sprintf(Buf, "%s/%s.html.tar.gz", WORKDIR, srcX);
unlink(Buf);
sprintf(Buf, "gzip %s/%s.html.tar", WORKDIR, srcX);
system(Buf);
sprintf(Buf, "mv -f %s/%s.html.tar.gz %s/%s.html.tgz", WORKDIR, srcX, WORKDIR,
srcX);
system(Buf);
printf("Finished Xhtml: %s.html.tgz\n", srcX);
return 0;
}
※ 修改:·spiceboy 於 Nov 22 02:16:06 修改本文·[FROM: 166.111.11.192]
m6m※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 166.111.120.84]m
--
※ 转载:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: 192.168.0.1]
--
※ 转载:.BBS 荔园晨风站 bbs.szu.edu.cn.[FROM: 192.168.1.159]
※ 修改:·jjk 於 Dec 3 15:21:01 修改本文·[FROM: 192.168.0.146]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店