diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-02-22 23:28:58 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-02-22 23:28:58 +0800 |
commit | e5c7ab45880f9d0b6feb176ff1aad59225e379d8 (patch) | |
tree | e005c0a3ad1a3d33796a5019ad10ecb00a0303ab /mbbsd | |
parent | 35717df2c4adcf1365447341fc6a8ecb87977e0f (diff) | |
download | pttbbs-e5c7ab45880f9d0b6feb176ff1aad59225e379d8.tar pttbbs-e5c7ab45880f9d0b6feb176ff1aad59225e379d8.tar.gz pttbbs-e5c7ab45880f9d0b6feb176ff1aad59225e379d8.tar.bz2 pttbbs-e5c7ab45880f9d0b6feb176ff1aad59225e379d8.tar.lz pttbbs-e5c7ab45880f9d0b6feb176ff1aad59225e379d8.tar.xz pttbbs-e5c7ab45880f9d0b6feb176ff1aad59225e379d8.tar.zst pttbbs-e5c7ab45880f9d0b6feb176ff1aad59225e379d8.zip |
subscription should be perform after choice, move some code from board.c to fav.c
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1559 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/board.c | 70 | ||||
-rw-r--r-- | mbbsd/fav.c | 64 | ||||
-rw-r--r-- | mbbsd/user.c | 2 |
3 files changed, 71 insertions, 65 deletions
diff --git a/mbbsd/board.c b/mbbsd/board.c index cd2bd5e1..e26b6c74 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -269,7 +269,6 @@ brc_unread(const char *fname, int bnum, const int *blist) #define BRD_TAG 16 #define BRD_UNREAD 32 -#define FAVNB ".favnb" #define B_TOTAL(bptr) (SHM->total[(bptr)->bid - 1]) #define B_LASTPOSTTIME(bptr) (SHM->lastposttime[(bptr)->bid - 1]) @@ -284,60 +283,6 @@ static char choose_board_depth = 0; static short brdnum; static char yank_flag = 1; -#define BRD_OLD 0 -#define BRD_NEW 1 -#define BRD_END 2 - -void updatenewfav(int mode) -{ - /* mode: 0: don't write to fav 1: write to fav */ - int i, fd; - char fname[80], *brd; - - if(!(cuser.uflag2 & FAVNEW_FLAG)) - return; - - setuserfile(fname, FAVNB); - - if( (fd = open(fname, O_RDWR, 0600)) != -1 ){ - - brd = (char *)malloc((numboards + 1) * sizeof(char)); - memset(brd, 0, (numboards + 1) * sizeof(char)); - read(fd, brd, (numboards + 1) * sizeof(char)); - - for(i = 0; i < numboards + 1 && brd[i] != BRD_END; i++){ - if(brd[i] == BRD_NEW){ - if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ // check the permission if the board exsits - if(mode) - fav_add_board(i + 1); - brd[i] = BRD_OLD; - } - } - else{ - if(!bcache[i].brdname[0]) - brd[i] = BRD_NEW; - } - } - if( i < numboards) // the board number may change - for(i-- ; i < numboards; i++){ - if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ - if(mode) - fav_add_board(i + 1); - brd[i] = BRD_OLD; - } - else - brd[i] = BRD_NEW; - } - - brd[i] = BRD_END; - - lseek(fd, 0, SEEK_SET); - write(fd, brd, (numboards + 1 ) * sizeof(char)); - free(brd); - close(fd); - } -} - void imovefav(int old) { char buf[5]; @@ -1269,17 +1214,12 @@ choose_board(int newflag) break; cuser.uflag2 ^= FAVNEW_FLAG; - if(cuser.uflag2 & FAVNEW_FLAG){ - char fname[80]; - - setuserfile(fname, FAVNB); - - if( (tmp = open(fname, O_RDONLY, 0600)) != -1 ){ - close(tmp); - updatenewfav(0); - } + if (cuser.uflag2 & FAVNEW_FLAG) { + subscribe_newfav(); + vmsg("ち传璹綷\穝狾家Α"); } - vmsg((cuser.uflag2 & FAVNEW_FLAG) ? "ち传璹綷\穝狾家Α" : "ち传タ盽家Α"); + else + vmsg("璹綷\穝狾"); } break; case 'v': diff --git a/mbbsd/fav.c b/mbbsd/fav.c index 26c2f02d..e01fb4bc 100644 --- a/mbbsd/fav.c +++ b/mbbsd/fav.c @@ -854,6 +854,70 @@ void fav_set_folder_title(fav_type_t *ft, char *title) strlcpy(cast_folder(ft)->title, title, sizeof(cast_folder(ft)->title)); } +#define BRD_OLD 0 +#define BRD_NEW 1 +#define BRD_END 2 +void updatenewfav(int mode) +{ + /* mode: 0: don't write to fav 1: write to fav */ + int i, fd; + char fname[80], *brd; + + if(!(cuser.uflag2 & FAVNEW_FLAG)) + return; + + setuserfile(fname, FAVNB); + + if( (fd = open(fname, O_RDWR | O_CREAT, 0600)) != -1 ){ + + brd = (char *)malloc((numboards + 1) * sizeof(char)); + memset(brd, 0, (numboards + 1) * sizeof(char)); + read(fd, brd, (numboards + 1) * sizeof(char)); + + for(i = 0; i < numboards + 1 && brd[i] != BRD_END; i++){ + if(brd[i] == BRD_NEW){ + if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ // check the permission if the board exsits + if(mode) + fav_add_board(i + 1); + brd[i] = BRD_OLD; + } + } + else{ + if(!bcache[i].brdname[0]) + brd[i] = BRD_NEW; + } + } + if( i < numboards) // the board number may change + for(i-- ; i < numboards; i++){ + if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ + if(mode) + fav_add_board(i + 1); + brd[i] = BRD_OLD; + } + else + brd[i] = BRD_NEW; + } + + brd[i] = BRD_END; + + lseek(fd, 0, SEEK_SET); + write(fd, brd, (numboards + 1 ) * sizeof(char)); + free(brd); + close(fd); + } +} + +void subscribe_newfav(void) +{ + char fname[80]; + + setuserfile(fname, FAVNB); + if (dashf(fname)) + updatenewfav(0); +} + +/** backward compatible **/ + /* old struct */ #define BRD_UNREAD 1 #define BRD_FAV 2 diff --git a/mbbsd/user.c b/mbbsd/user.c index f7a623a4..f48a5f4f 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -246,6 +246,8 @@ static void Customize(void) case 'C': case 'c': cuser.uflag2 ^= FAVNEW_FLAG; + if (cuser.uflag2 & FAVNEW_FLAG) + subscribe_newfav(); break; case 'D': case 'd':{ |