int main(int argc, char **argv) { struct boardheader fh, newfh; int pos; if (argc != 3) { fprintf(stderr, "Usage: %s --force <board>\n", argv[0]); exit(-1); } if (strcmp(argv[1], "--force")) { fprintf(stderr, "Usage: %s --force <board>\n", argv[0]); exit(-1); } chdir(BBSHOME); resolve_boards(); pos = getboardnum(argv[2], &fh); if (pos == 0) { fprintf(stderr, "%s not found.\n", argv[2]); exit(-1); } memcpy(&newfh, &fh, sizeof(newfh)); /*newfh.flag |= BOARD_SUPER_CLUB;*/ set_board(pos, &newfh, &fh); return 0; }
static void strip_fileheader(const fileheader_v1_2 *oldfh, fileheader *fh, const char *bname, const char *dir) { strncpy(fh->filename, oldfh->filename, FILENAME_LEN - 1); fh->filename[FILENAME_LEN - 1] = '\0'; fh->id = oldfh->id; fh->groupid = oldfh->groupid; fh->reid = oldfh->reid; #if defined(FILTER) || defined(COMMEND_ARTICLE) if (strcmp(bname, FILTER_BOARD) == 0 #ifdef COMMEND_ARTICLE || strcmp(bname, COMMEND_ARTICLE) == 0 #endif ) { if (oldfh->o_board[0] != '\0' && (fh->o_bid = getboardnum(oldfh->o_board, NULL)) == 0) { fprintf(stderr, "Warning: Cannot find original board <%s>: %s/%s/id<%d>.\n", oldfh->o_board, bname, dir, oldfh->id); } fh->o_id = oldfh->o_id; fh->o_groupid = oldfh->o_groupid; fh->o_reid = oldfh->o_reid; } #endif fh->innflag[0] = oldfh->innflag[0]; fh->innflag[1] = oldfh->innflag[1]; strncpy(fh->owner, oldfh->owner, OWNER_LEN - 1); fh->owner[OWNER_LEN - 1] = '\0'; fh->eff_size = oldfh->eff_size; set_posttime(fh); fh->attachment = oldfh->attachment; strncpy(fh->title, oldfh->title, ARTICLE_TITLE_LEN - 1); fh->title[ARTICLE_TITLE_LEN - 1] = '\0'; fh->accessed[0] = oldfh->accessed[0]; fh->accessed[1] = oldfh->accessed[1]; fh->accessed[sizeof(fh->accessed) - 1] = oldfh->accessed[sizeof(oldfh->accessed) - 1]; }
/*主函数*/ int main(int argc,char **argv) { FILE *fp; struct stat st; struct fileheader *dir1,*dir2,*dir; struct boardheader bh; struct BoardStatus *bs; char path1[512],path2[512],path[512],buf[512],*p1,*p2,*p; int ret; unsigned int size1,size2,pos1,pos2,pos,*offset1,*offset2; //初始化及错误检测 if (argc!=4) { printf("[%s] 错误的参数结构...\nUSAGE: %s <srcboard1> <srcboard2> <dstdir>\n",argv[0],argv[0]); return 0x11; } if (chdir(BBSHOME)) { printf("[%s] 切换到 BBS 主目录 %s 错误...\n",argv[0],BBSHOME); return 0x12; } /*初始化源版面数据*/ if ((ret=initdir(argv[0],path1,argv[1],&offset1,&size1,&dir1,&p1))!=0) return ret; if ((ret=initdir(argv[0],path2,argv[2],&offset2,&size2,&dir2,&p2))!=0) return ret; /*检测顺序并进行可能必要的顺序化*/ if (!checkseq(dir1,size1)&&!seqdir(dir1,size1)) { printf("[%s] 版面 %s .DIR 结构错误, 修复失败...\n",argv[0],argv[1]); return 0x51; } if (!checkseq(dir2,size2)&&!seqdir(dir2,size2)) { printf("[%s] 版面 %s .DIR 结构错误, 修复失败...\n",argv[0],argv[2]); return 0x51; } /*创建目标目录,用pid进行标识区分*/ sprintf(path,"boards/%s",argv[3]); sprintf(buf,"boards/%s_%d",argv[3], (int)getpid()); if (!stat(path,&st)&&S_ISDIR(st.st_mode)) rename(path,buf); else unlink(path); if (mkdir(path,(S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH))) { printf("[%s] 创建版面目录 %s 错误...\n",argv[0],path); return 0x31; } build_board_structure(argv[3]); p=path+strlen(path);*p++='/'; sprintf(p,".DIR"); /*准备目标.DIR文件的写操作*/ if (!(fp=fopen(path,"wb"))) { printf("[%s] 创建 %s 错误...\n",argv[0],path); return 0x32; } /*申请目标.DIR结构需要的内存空间*/ if (!(dir=(struct fileheader*)malloc((size1+size2)*sizeof(struct fileheader)))) { printf("[%s] 申请内存空间失败...\n",argv[0]); return 0x33; } //主处理 pos1=0;pos2=0;pos=0; while (true) { /*比较时间戳*/ if (pos1<size1&&pos2<size2) { //ret=strcmp(&dir1[pos1].filename[2],&dir2[pos2].filename[2]); ret = get_posttime(&dir1[pos1]) - get_posttime(&dir2[pos2]); } else if (pos1<size1)/*源版面2已经处理完成*/ ret=-1; else if (pos2<size2)/*源版面1已经处理完成*/ ret=1; else/*done*/ break; /*处理当前fileheader*/ if (!(ret>0)) {/*源版面1*/ process(argv[0],dir,dir1,offset1,pos,pos1,path,p,path1,p1); pos1++;pos++; } else {/*源版面2*/ process(argv[0],dir,dir2,offset2,pos,pos2,path,p,path2,p2); pos2++;pos++; } } /*写回目的.DIR*/ if (fwrite(dir,sizeof(struct fileheader),(size1+size2),fp)!=(size1+size2)) { printf("[%s] 写入文件错误...\n",argv[0]); return 0x41; } /*设定未读标记*/ resolve_boards(); ret=getboardnum(argv[3],&bh); if (ret) { bh.idseq=size1+size2; set_board(ret,&bh,NULL); bs=getbstatus(ret); bs->total=size1+size2; bs->lastpost=size1+size2; bs->updatemark=true; bs->updatetitle=true; bs->updateorigin=true; bs->nowid=size1+size2; bs->toptitle=0; } /*清理*/ fclose(fp); munmap(dir1,size1*sizeof(struct fileheader)); if (size1) free(offset1); munmap(dir2,size2*sizeof(struct fileheader)); if (size2) free(offset2); free(dir); return 0; }