void CImportExportApp::OnFileOpen() { CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, NULL, NULL ); CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir()); initdir += "\\Data"; dlg.m_ofn.lpstrInitialDir = initdir; CString strFilter; CString strDefault; POSITION pos = GetFirstDocTemplatePosition(); CDocTemplate* pTemplate = GetNextDocTemplate(pos); CString strFilterExt, strFilterName; if (pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt) && !strFilterExt.IsEmpty() && pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) && !strFilterName.IsEmpty()) { // add to filter strFilter += strFilterName; ASSERT(!strFilter.IsEmpty()); // must have a file type name strFilter += (TCHAR)'\0'; // next string please strFilter += (TCHAR)'*'; strFilter += strFilterExt; strFilter += (TCHAR)'\0'; // next string please dlg.m_ofn.nMaxCustFilter++; } // append the "*.*" all files filter CString allFilter; VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER)); strFilter += allFilter; strFilter += (TCHAR)'\0'; // next string please strFilter += _T("*.*"); strFilter += (TCHAR)'\0'; // last string dlg.m_ofn.nMaxCustFilter++; dlg.m_ofn.lpstrFilter = strFilter; if (dlg.DoModal() == IDOK) { AfxGetApp()->OpenDocumentFile(dlg.GetPathName()); } }
int create_account(char *username) { struct passwd *pw; int opt, type; char pwbuf[PWLEN + 1]; int ret; type = 0; if ((pw=newacc(username)) == 0) { fprintf(stderr, "Account not created\n"); return EXIT_FAILURE; } initdir(pw->pw_dir, pw->pw_uid, pw->pw_gid); if ((ret = get_passwd(pwbuf, type)) == -1) return EXIT_FAILURE; pw->pw_passwd = ret ? passwd_stub : nil_passwd; if (!lock_passwd()) { fprintf(stderr,"unable to lock password database (%s)\n",strerror(errno)); return PasswdBusy; } if ((opt = addpwent(pw)) == 0) { if (pw->pw_passwd && *pw->pw_passwd) { struct spwd spw; spw.sp_namp = pw->pw_name; spw.sp_pwdp = pwbuf; spw.sp_lstchg = time(0); spw.sp_max = 0; spw.sp_min = 0; spw.sp_warn = 0; spw.sp_inact = 0; spw.sp_expire = 0; spw.sp_flag = 0; if ((opt = addshent(&spw))) { fputs("cannot create shadow entry\n",stderr); delpw_name(pw->pw_name); } } } else { fputs("cannot create password entry\n", stderr); } unlock_passwd(); return opt; }
/*主函数*/ 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; }
/* * Update the file(s) if they are different. * destdir = 1 if destination should be a directory * (i.e., more than one source is being copied to the same destination). */ int install (char *src, char *dest, int destdir, int opts) { char *rname; char destcopy[BUFSIZ]; if (dest == NULL) { opts &= ~WHOLE; /* WHOLE mode only useful if renaming */ dest = src; } if (nflag || debug) { printf("%s%s%s%s%s%s %s %s\n", opts & VERIFY ? "verify":"install", opts & WHOLE ? " -w" : "", opts & YOUNGER ? " -y" : "", opts & COMPARE ? " -b" : "", opts & REMOVE ? " -R" : "", opts & QUERYM ? " -Q" : "", src, dest); if (nflag) return; } rname = exptilde(target, src); if (rname == NULL) return; tp = target; strcpy (basename, target); while (*tp) tp++; /* * If we are renaming a directory and we want to preserve * the directory heirarchy (-w), we must strip off the leading * directory name and preserve the rest. */ if (opts & WHOLE) { rname = target; while (*rname == '/') rname++; destdir = 1; } else { rname = rindex(target, '/'); if (rname == NULL) rname = target; else rname++; } if (debug) printf("target = %s, rname = %s\n", target, rname); /* * Pass the destination file/directory name to remote. */ if (initdir (destdir, dest) < 0) return; strcpy(destcopy, dest); Tdest = destcopy; sendf(rname, opts); Tdest = 0; }