FB to Maple 3.0 文章轉換程式

看板Maple (BBS架站)作者時間23年前 (2001/10/30 08:17), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/2 (看更多)
/* */ /* National Kaohsiung University of Applied Sciences */ /* Campus Computer Network Association */ /* 國立高雄應用科技大學 校園網路策進會 */ /* */ /* Firebird to Maple 3.0 文章轉換 */ /* */ /* File : transpost.c */ /* Code : Hao-Chine Hung */ /* E-Mail: chine@ccna.kuas.edu.tw */ /* Mobile: +886-958734768 */ /* Tel : +886-7-3814526 Ext.3141 */ /* Ver. : (2001/10/30) */ /* */ #define FBHOME "/home/news/bbs/boards" /* Firebird的boards目錄位置 */ #define BRDHOME "/home/news" /* brd要建的位置 */ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #include <time.h> #include <dirent.h> void archiv32m(time_t chrono, char *fname) { char *str; int n; str=fname+8; *str='\0'; *fname='A'; while(--str>fname) { n=chrono&31; n+='0'; if(n>'9') n+='A'-'9'- 1; *str=n; chrono>>=5; } } typedef struct { time_t chrono; /* timestamp */ int xmode; int xid; /* reserved */ char xname[32]; /* 檔案名稱 */ char owner[80]; /* 作者 (E-mail address) */ char nick[50]; /* 暱稱 */ char date[9]; /* [96/12/01] */ char title[73]; /* 主題 (TTLEN + 1) */ } HDR; int transdate(char *time,char *date) { int i; char year[5],mouth[4],day[3]; for(i=4;i<7;i++) mouth[i-4]=time[i]; mouth[i-4]='\0'; if(!strcmp(mouth,"Jan")) strcpy(mouth,"01"); if(!strcmp(mouth,"Feb")) strcpy(mouth,"02"); if(!strcmp(mouth,"Mar")) strcpy(mouth,"03"); if(!strcmp(mouth,"Apr")) strcpy(mouth,"04"); if(!strcmp(mouth,"May")) strcpy(mouth,"05"); if(!strcmp(mouth,"Jun")) strcpy(mouth,"06"); if(!strcmp(mouth,"Jul")) strcpy(mouth,"07"); if(!strcmp(mouth,"Aug")) strcpy(mouth,"08"); if(!strcmp(mouth,"Sep")) strcpy(mouth,"09"); if(!strcmp(mouth,"Oct")) strcpy(mouth,"10"); if(!strcmp(mouth,"Nov")) strcpy(mouth,"11"); if(!strcmp(mouth,"Dec")) strcpy(mouth,"12"); if(time[8]==' ') day[0]='0'; else day[0]=time[8]; day[1]=time[9]; day[2]='\0'; for(i=22;i<25;i++) year[i-22]=time[i]; year[i-22]='\0'; sprintf(date,"%s/%s/%s",year,mouth,day); if(strlen(date)==8) return 1; else return 0; } int main(void) { int fd0,fd1,fd2,i,chrono,set=1,xok,xcount; char buf,wrbuf[1024]; char username[100],nickname[100],board[100],title[100],time[100]; DIR *dp1,*dp2; struct dirent *dirp1,*dirp2; char oldfile[128],newfile[128]; HDR fname; /*建立brd目錄*/ sprintf(oldfile,"%s/brd",BRDHOME); mkdir(oldfile,0700); if((dp1=opendir(FBHOME))==NULL) { printf("開啟目錄錯誤: %s",FBHOME); exit(-1); } for(;(dirp1=readdir(dp1))!=NULL;chrono=0x100000) { if(*(dirp1->d_name)!='.') { sprintf(oldfile,"%s/%s",FBHOME,dirp1->d_name); if((dp2=opendir(oldfile))==NULL) { printf("開啟目錄錯誤: %s",oldfile); exit(-1); } /*建立討論區目錄 */ sprintf(oldfile,"%s/brd/%s",BRDHOME,dirp1->d_name); mkdir (oldfile, 0700); /*建立討論區目錄結構 */ for(buf='0';;) { sprintf(oldfile,"%s/brd/%s/%c",BRDHOME,dirp1->d_name,buf); mkdir(oldfile,0700); if(buf=='9') buf='@'; else if(++buf=='W') break; } /*建立.DIR索引檔*/ sprintf(oldfile,"%s/brd/%s/.DIR",BRDHOME,dirp1->d_name); if((fd2=open(oldfile,O_WRONLY|O_CREAT,0600))<0) { printf("建立檔案錯誤: %s",oldfile); exit(-1); } printf("進入 %s 討論區\n\n",dirp1->d_name); xok=0; for(xcount=0;(dirp2=readdir(dp2))!=NULL;xcount++) { if(*(dirp2->d_name)!='.') { chrono++; memset(&fname,0,sizeof(fname)); archiv32m(chrono,fname.xname); sprintf(newfile,"%s/brd/%s/%c/%s",BRDHOME,dirp1->d_name,fname.xname[7],fname.xname); sprintf (oldfile,"%s/%s/%s",FBHOME,dirp1->d_name,dirp2->d_name); if((fd0=open(oldfile,O_RDWR))<0) { printf("開啟檔案錯誤: %s\n",oldfile); exit(-1); } if((fd1=open(newfile,O_WRONLY|O_CREAT,0600))<0) { printf("建立檔案錯誤: %s\n",newfile); exit(-1); } printf("%s => %s\n",oldfile,newfile); /*確認是否符合格式*/ for(i=0;read(fd0,&buf,1);i++) if(buf==':'|buf=='\n'|buf=='\0'|buf==' ') break; else wrbuf[i]=buf; wrbuf[i]='\0'; if(!strcmp(wrbuf,"發信人")) { /*取得username*/ read(fd0,&buf,1); for(i=0;read(fd0,&buf,1);i++) if(buf==' ') break; else username[i]=buf; username[i]='\0'; strcpy(fname.owner,username); /*取得nickname */ for(;read(fd0,&buf,1);) if(buf=='(') break; for(i=0;read(fd0,&buf,1);i++) if(buf==')') break; else nickname[i]=buf; nickname[i]='\0'; strcpy(fname.nick,nickname); /*取得board */ for(;read(fd0,&buf,1);) if(buf==',') break; for(i=0;i<7;i++) read(fd0,&buf,1); for(i=0;read(fd0,&buf,1);i++) if(buf=='\n') break; else board[i]=buf; board[i]='\0'; /*取得title */ for(i=0;i<8;i++) read(fd0,&buf,1); for(i=0;read(fd0,&buf,1);i++) if(buf=='\n') break; else title[i] = buf; title[i]='\0'; strcpy(fname.title,title); /*取得time */ for(;read(fd0,&buf,1);) if(buf=='(') break; for(i=0;read(fd0,&buf,1);i++) if(buf==')') break; else time[i]=buf; time[i]='\0'; if(transdate(time,fname.date)) { fname.chrono=chrono; fname.xmode=1024; fname.xid=0; sprintf(wrbuf,"作者: %s (%s) 看板: %s\n標題: %s\n時間: %s\n",username,nickname,board,title,time); write(fd1,wrbuf,strlen(wrbuf)); while(read(fd0,&buf,1)) if(buf =='\n') break; memset(wrbuf,0,sizeof(wrbuf)); while(read(fd0,wrbuf,sizeof(wrbuf))) write(fd1,wrbuf,sizeof(wrbuf)); write(fd2,&fname,sizeof(fname)); xok++; } } else { printf("\033[1;32m該檔案無法存取標頭內容: %s\033[0m\n",oldfile); unlink(newfile); } close(fd0); close(fd1); } } closedir(dp2); close(fd2); printf("處理總數 %d ==> %d 轉換總數\n\n",xcount,xok); } } closedir(dp1); return 0; } -- ※ Origin: 楓橋驛站<bbs.cs.nthu.edu.tw> ◆ From: 61-217-160-202.HINET-IP.hinet.net

06/09 17:46, , 1F
06/09 17:46, 1F
文章代碼(AID): #xtV5-00 (Maple)
文章代碼(AID): #xtV5-00 (Maple)