看到前幾篇有人覺得好友名單並不太方便...
想了一想 還是分享一下星空的好友名單改法(我是參照小魚紫色花園的名單格式)
至於好不好呢 由你們自己去判斷了.....:)
friend.c中修改增加一些東西....
還有一些美工的部份因為還得整理頗麻煩 所以我去掉了 請自己加
另外 有些名單會出問題(像上站通知名單 特別名單等 因為這些只有名字沒有描述)
這個請自己想辦法解決吧 我的方法是全砍了...:)
struct friend_data{
char pointer[5]; /*指標*/
int online; /*線上*/
int label; /*標籤 1:D*/
int num; /*編號*/
char name[20]; /*名字*/
char describe[40]; /*描述*/
};
typedef struct friend_data friend_data;
void
friend_add(uident, type)
char *uident;
int type;
{
char fpath[80];
setfriendfile(fpath,type);
if(file_list_count(fpath) > friend_max[type])
{
pressanykey("已達名單上限,無法再增加了..");
return;
}
if ((uident[0] > ' ') && !belong(fpath, uident))
{
FILE *fp;
char buf[40]="";
char t_uident[IDLEN + 1];
strcpy(t_uident, uident);
getdata(2, 0, friend_desc[type], buf, 40, DOECHO,0);
if (fp = fopen(fpath, "a"))
{
flock(fileno(fp), LOCK_EX);
fprintf(fp, "%-13s%s\n", t_uident, buf);
flock(fileno(fp), LOCK_UN);
fclose(fp);
}
}
}
void
friend_change(uident, type,buf)
char *uident,*buf;
int type;
{
FILE *fp, *nfp;
char fn[80], fnnew[80];
char genbuf[200];
setfriendfile(fn,type);
sprintf(fnnew, "%s-", fn);
if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w")))
{
int length = strlen(uident);
while (fgets(genbuf, STRLEN, fp))
{
if ( (genbuf[0] > ' ') &&
(strncmp(genbuf, uident, length) || genbuf[length] != ' '))
fputs(genbuf, nfp);
else if( (genbuf[0] > ' ') &&
(!strncmp(genbuf, uident, length)) )
{
sprintf(genbuf,"%-13s%s\n",uident,buf);
fputs(genbuf, nfp);
}
}
fclose(fp);
fclose(nfp);
Rename(fnnew, fn);
}
}
void
friend_edit_new(type,max) /*以取代原本的friend_edit()*/
int type,max;
{
struct friend_data myfriend[friend_max[type]+1];
char fpath[80],uident[20],ans[5],line[80];
char *chartmp;
int count,labelcount;
int datanew=1,screennew=1,listnew=1;
int dirty;
int tuid;
FILE *fp;
char genbuf[200];
int pagenum; /*控制頁數*/
int startnum; /*print起始個數*/
int i;
int ch;
int pointer;
int leave=0;
if(type == FRIEND_SPECIAL) friend_special();
setfriendfile(fpath,type);
if(type == FRIEND_ALOHA || type == FRIEND_POST)
{
if(dashf(fpath))
{
sprintf(genbuf, "/bin/cp %s %s.old", fpath, fpath);
system(genbuf);
}
}
dirty=0;
pagenum=1; /*第一頁*/
pointer=1;
do
{
if(screennew)
{
clear();
showtitle(friend_list[type],BoardName);
}
if(datanew)
{
extern cmpuids();
CreateNameList();
count=0;
strcpy(myfriend[count].pointer," ");
myfriend[count].num =count;
myfriend[count].label =0;
myfriend[count].online =0;
strcpy(myfriend[count].name,"0");
strcpy(myfriend[count].describe,"0");
if (fp = fopen(fpath, "r"))
{
while (fgets(genbuf,200, fp) && count<max)
{
user_info *uentp;
count++;
strcpy(myfriend[count].pointer," ");
myfriend[count].label =0;
myfriend[count].num =count;
chartmp=strtok(genbuf," ");
strcpy(myfriend[count].name,chartmp);
myfriend[count].online =0;
genbuf[53]=0;
strcpy(chartmp,genbuf+13);
sprintf(myfriend[count].describe,"1%s"
,chartmp);
AddNameList(myfriend[count].name);
}
fclose(fp);
}
datanew=0;
labelcount=0;
}
if(count == 0)
{
move(4,0);
prints("名單中無任何資料,請按 a 加入資料");
}
else
{
if(listnew ||screennew || pagenum!=(pointer-1)/20+1)
{
clrchyiuan(3,24);
pagenum=(pointer-1)/20+1;
startnum=(pagenum-1)*20+1;
for(i=startnum;i<startnum+20;i++)
{
if(i<=count)
{
move(3+i-startnum,0);
prints(
" [[0;37m%3d%s[[37m%-15s%s[[0;37m",
myfriend[i].num,
myfriend[i].label?
"[[1;33mˇ[[0m":(myfriend[i].online?"[[1;37m≒[[0m":"[[1;37m [[0m"),
myfriend[i].name,
myfriend[i].describe+1);
}
}
screennew=0;
listnew=0;
}
move(3+(pointer-1)%20,0);
prints("●");
}
ch=egetch();
move(3+(pointer-1)%20,0);
prints(" ");
switch(ch)
{
case 'a':
case 'A':
if(count<max)
{
move(1, 0);
usercomplete(msg_uid, uident);
if (uident[0] && searchuser(uident)
&& !InNameList(uident))
{
friend_add(uident, type);
dirty=1;
datanew=1;
}
}
else
{
pressanykey("人數已經達到上限了....");
}
screennew=1;
break;
case 'p':
case 'P':
friend_append(type,count);
dirty = 1;
datanew=1;
screennew=1;
break;
case 'd':
case 'D':
if(count>0)
{
move(1, 0);
strcpy(uident,myfriend[pointer].name);
sprintf(genbuf,
"將 %s 從名單中移除,您確定嗎 (y/N)?",uident);
getdata(1,0,genbuf,ans,3,LCECHO,0);
if( (ans[0]=='Y' || ans[0]=='y') &&
uident[0] && InNameList(uident) )
{
friend_delete(uident, type);
pointer--;
if(pointer<1) pointer=1;
dirty=1;
datanew=1;
}
else pressanykey("放棄此項動作");
}
screennew=1;
break;
case 'k':
case 'K':
if(count>0)
{
getdata(1,0,
"整份名單將會被刪除,您確定嗎 (y/N)?",uident,3,LCECHO,0);
if(*uident=='y' || *uident=='Y')
{
unlink(fpath);
pressanykey("名單刪除完畢....");
}
dirty=1;
datanew=1;
screennew=1;
}
break;
case 'c':
case 'C':
if(count>0)
{
int len=0;
sprintf(genbuf,"%s",friend_desc[type]);
if(len=
getdata(1, 0,genbuf,genbuf, 40, DOECHO,0))
{
strcpy(uident,myfriend[pointer].name);
friend_change(uident,type,genbuf);
dirty=1;
datanew=1;
}
screennew=1;
}
break;
case 'E':
case 'e':
case KEY_LEFT:
case 'Q':
ch='q';
case 'q':
leave=1;
break;
case KEY_PGUP:
if(pointer==1) pointer=count;
else
{
pointer-=20;
if(pointer<1) pointer=1;
}
break;
case KEY_PGDN:
case ' ':
if(pointer==count) pointer=1;
else
{
pointer+=20;
if(pointer>count) pointer=count;
}
break;
case KEY_DOWN:
pointer++;
if( pointer > count) pointer=1;
break;
case KEY_UP:
pointer--;
if(pointer < 1 ) pointer=count;
break;
case '0':
case KEY_HOME:
pointer=1;
break;
case '$':
case KEY_END:
pointer=count;
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if(count>0)
{
if ((i = search_num(ch,count)) >= 0)
{
pointer=i+1;
if(pointer>count)
pointer=count;
if(pointer<1) pointer=1;
}
}
screennew=1;
break;
case KEY_RIGHT:
case '\n':
case '\r':
case 'r':
if(count>0)
{
int mode;
strcpy(uident,myfriend[pointer].name);
my_query(uident,&mode);
move(b_lines-1);
prints("%d",mode);
screennew=1;
}
break;
case Ctrl('R'):
if (currutmp->msgs[0].last_pid)
{
show_last_call_in();
my_write(currutmp->msgs[0].last_pid,
"流星丟回去:",0);
}
screennew=1;
break;
case Ctrl('Z'):
every_Z();
break;
}
}while(leave!=1);
if(dirty)
{
clrchyiuan(3,23);
move(3,0);
outs("更新資料中..請稍候.....");
refresh();
if(type == FRIEND_ALOHA || type == FRIEND_POST)
{
sprintf(genbuf,"%s.old",fpath);
if (fp = fopen(genbuf, "r"))
{
while (fgets(genbuf, 200, fp))
{
/*sscanf(line,"%s",uident);*/
chartmp=strtok(genbuf," ");
strcpy(uident,chartmp);
sethomefile(genbuf,
uident,type == FRIEND_ALOHA ? "aloha" : "postnotify");
del_distinct(genbuf, cuser.userid);
}
fclose(fp);
}
sprintf(genbuf,"%s",fpath);
if (fp = fopen(genbuf, "r"))
{
while (fgets(genbuf, 200, fp))
{
/*sscanf(line,"%s",uident);*/
chartmp=strtok(genbuf," ");
strcpy(uident,chartmp);
sethomefile(genbuf, uident,
type == FRIEND_ALOHA ?
"aloha" : "postnotify");
add_distinct(genbuf, cuser.userid);
}
fclose(fp);
}
}
else if(type == FRIEND_SPECIAL)
{
genbuf[0]=0;
setuserfile(line,special_des);
if(fp = fopen(line,"r") )
{
fgets(genbuf,30,fp);
fclose(fp);
}
getdata(4,0,"請為此特別名單取一個簡短名稱:",
genbuf,30,DOECHO,0);
if(fp = fopen(line,"w") )
{
fprintf(fp,"%s",genbuf);
fclose(fp);
}
}
friend_load();
}
}