小程式地二彈...
想直接下載的話
http://vega.cs.tku.edu,tw/~u91193131/friend.cpp
/*
friend.cpp
解決Maple-itoc內附/src/util/tran/fb2usr轉檔後,
好友清單異常(使用者清單無法正確顯示好友)的問題
(用g++ compile)
By 淡江資工 黃兆選
(eva4@seed.net.tw)
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