看板SetupBBS
标 题Maple-itoc内附fb2usr 好友清单修正
发信站台大电机 Maxwell BBS (Tue May 4 15:53:28 2004)
转信站ptt!ctu-reader!ctu-peer!news.nctu!freebsd.ntu!bbs.ee.ntu!Maxwell
小程式地二弹...
想直接下载的话
http://vega.cs.tku.edu,tw/~u91193131/friend.cpp
/*
friend.cpp
解决Maple-itoc内附/src/util/tran/fb2usr转档後,
好友清单异常(使用者清单无法正确显示好友)的问题
(用g++ compile)
By 淡江资工 黄兆选
(
[email protected])
2004/05/04
说明:
Friend里面的struct:
class frif
{
public:
char name[14]; //帐号名称
char dscp[46]; //说明
int num; //使用者编号
};
好友清单的使用者编号是对应.USR内的编号
class user
{
public:
int num;
char name[12];
};
问题就出在使用者编号
由於转档程式一律将friend中使用者编号这个栏位设成63 00 00 00
於是便无法对应到正确的使用者
程式功能:
如上面所述之问题,解决方法便是将Friend中的编号对应到正确的编号
除此之外,一并将错误(已不存在,因为帐号被砍)的项目删除
使用方法:
friend /home/bbs/usr 2
/home/bbs/usr为你的bbs的usr directory
2的话指的是从usr开始算起,两层子目录
(这个在这边可以不管他,只管输入2就是了)
Bug:
(1)
从字串反查编号的结果,造成可能清单上的某一帐号已经不是你认识的那个人
Ex:你的使用者清单有一帐号AAA,在.USR中编号为1152
之後他的帐号被砍了,於是又有人申请同一帐号AAA,但编号变成0079
这样的情况在经过本程式反查的结果,
造成好友清单上的AAA已经和之前的编号不同
也就是不同人
(2)
可能因为记忆体不够造成无法开启档案的问题
解决方法就是将执行命令改为 friend /home/bbs/usr/a 1
^
从a~z自己替换,一次做一个资料夹
(0~9和@因为这个在FB是无效的名称,所以这边不需要顾虑到)
*/
#include<iostream>
#include<fstream>
#include<string>
#include<cstdio>
#include<sys/types.h>
#include<dirent.h>
#include<cstdlib>
int depth;
using namespace std;
fstream dotusr,fri,tmp;
class user
{
public:
int num;
char name[12];
};
class frif
{
public:
char name[14];
char dscp[46];
int num;
};
user data[3000];
long count=0;
int search(char x[])
{
int j;
for(j=0 ; j<=count-1 ; j++)
{
if(strcmp(x,data[j].name)==0)
return j+1;
}
return 0;
}
int tour(char current[],int l)
{
frif *f;
f = new frif;
struct dirent *p;
int result;
DIR *d;
char c[100];
char command1[100];
char command2[100];
if((d=opendir(current))==NULL || l>=depth)
{
return 0;
}
l++;
strcpy(c,current);
while((p = readdir(d))!=NULL)
{
if(strcmp(".",p->d_name)!=0 && strcmp("..",p->d_name)!=0)
{
strcat(c,"/");
strcat(c,p->d_name);
if(l==depth)
{
strcpy(command1,c);
strcat(command1,"/friend");
fri.open(command1,ios::out|ios::in|ios::binary);
if(!fri)
{
cerr << "Cannot open " << command1 << endl;
exit(0);
}
strcpy(command2,c);
strcat(command2,"/friend.tmp");
cout << "Comm1:" << command1 << endl;;
cout << "Comm2:" << command2 << endl;;
tmp.open(command2,ios::out|ios::in|ios::binary);
if(!tmp)
{
cerr << "cannot open " <<command2<< endl;
exit(0);
}
fri.read((char *) f,sizeof(frif));
while(!fri.eof())
{
if((result=search(f->name))==0)
cout << f->name << "do not exist"<<endl;
else
{
f->num=result;
tmp.write((char *) f,sizeof(frif));
}
fri.read((char *) f,sizeof(frif));
}
fri.close();
tmp.close();
if(remove(command1)!=0)
{
cout << "File Remove failure!!" << endl;
exit(0);
}
if(rename(command2,command1)!=0)
{
cout << "File Rename failure!!" << endl;
exit(0);
}
}
if(l<=depth)
tour(c,l);
strcpy(c,current);
}
}
closedir(d);
}
int main (int argc, char* argv[])
{
user *u;
u = new user;
if(argc!=3)
{
printf("Usage: dir <directory name> <depth>\n");
exit(0);
}
dotusr.open("/home/bbs/.USR",ios::out|ios::in|ios::binary);
dotusr.read((char *) u,sizeof(user));
while(!dotusr.eof())
{
data[count].num = u->num;
data[count].name = u->name;
dotusr.read((char *) u,sizeof(user));
count++;
}
dotusr.close();
depth=atoi(argv[2]);
tour(argv[1],0);
return 0;
}
--
※ Origin: 台大电机 Maxwell 站 ◆ From: 61-229-169-241.dynamic.hinet.net