diff options
-rw-r--r-- | mbbsd/bbs.c | 23 | ||||
-rw-r--r-- | mbbsd/read.c | 24 | ||||
-rw-r--r-- | mbbsd/record.c | 37 |
3 files changed, 62 insertions, 22 deletions
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 2c00c811..2a653505 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -2286,19 +2286,31 @@ show_filename(int ent, const fileheader_t * fhdr, const char *direct) static int view_postmoney(int ent, const fileheader_t * fhdr, const char *direct) { - if(currmode & MODE_SELECT){ - vmsg("請離開目前選擇/搜尋模式後再查詢"); - return FULLUPDATE; - } + fileheader_t hdr; + char genbuf[256]; + int num = 0, money=0; + if(fhdr->filemode & FILE_BOTTOM) - /* donothing because substitute_ref_record forgot to update multi.money */ + /* donothing because substitute_ref_record forgot to update multi.money */ vmsg("置底的文章很重要,記得看就好了,別理它的價格"); else if(fhdr->filemode & FILE_ANONYMOUS) /* When the file is anonymous posted, fhdr->multi.anon_uid is author. * see do_general() */ vmsg("匿名管理編號: %d (同一人號碼會一樣)", fhdr->multi.anon_uid + (int)currutmp->pid); + else if(currmode & MODE_SELECT && (fhdr->multi.refer.flag) && + (num = fhdr->multi.refer.ref)) + { + setdirpath(genbuf, direct, ".DIR"); + get_record(genbuf, &hdr, sizeof(hdr), num); + money = hdr.multi.money; + } else + money = fhdr->multi.money; + + vmsg("這一篇文章值 %d 銀", money); + +#ifdef WHATISIT if (vmsg("這一篇文章值 %d 銀", fhdr->multi.money) == 'Q') { /* enable money listing mode */ @@ -2307,6 +2319,7 @@ view_postmoney(int ent, const fileheader_t * fhdr, const char *direct) vmsg((currlistmode == LISTMODE_MONEY) ? "[測試中功\能] 開啟文章價格列表模式" : "停止列出文章價格"); } +#endif return FULLUPDATE; } diff --git a/mbbsd/read.c b/mbbsd/read.c index 638c060b..73ef43af 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -414,6 +414,7 @@ static int select_read(const keeploc_t * locmem, int sr_mode) { #define READSIZE 64 // 8192 / sizeof(fileheader_t) + time4_t filetime; fileheader_t fhs[READSIZE]; char newdirect[MAXPATHLEN]; char keyword[TTLEN + 1] = ""; @@ -499,12 +500,27 @@ select_read(const keeploc_t * locmem, int sr_mode) else setbfile(newdirect, currboard, genbuf); - if( now - dasht(newdirect) < 3600 ) + filetime = dasht(newdirect); + if( now - filetime < 180 ) count = dashs(newdirect) / sizeof(fileheader_t); else { - if( (fd = open(newdirect, O_CREAT | O_RDWR, 0600)) == -1 ) - return READ_REDRAW; + if( now - filetime > 3600) + len = O_CREAT | O_RDWR; + else + len = O_APPEND; + + if( (fd = open(newdirect, len, 0600)) == -1 ) + return READ_REDRAW; + if( (fr = open(currdirect, O_RDONLY, 0)) != -1 ) { + if( now - filetime <= 3600) + { + sprintf(fhs[0].filename, "X.%d", (int)filetime); + len = - getindex(currdirect, &fhs[0], 0); + if(len>0) + lseek(fr, len*sizeof(fileheader_t), SEEK_SET); + } + while( (len = read(fr, fhs, sizeof(fhs))) > 0 ){ len /= sizeof(fileheader_t); for( i = 0 ; i < len ; ++i ){ @@ -532,7 +548,7 @@ select_read(const keeploc_t * locmem, int sr_mode) continue; else if ((sr_mode & RS_MONEY) && // see view_postmoney - ( (fhs[i].filemode & (FILE_BOTTOM|FILE_ANONYMOUS)) || + ((fhs[i].filemode & (FILE_BOTTOM|FILE_ANONYMOUS)) || (fhs[i].multi.money < n_money))) continue; ++count; diff --git a/mbbsd/record.c b/mbbsd/record.c index c6779553..0ea79f80 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -160,33 +160,44 @@ substitute_ref_record(const char *direct, fileheader_t * fhdr, int ent) } int -getindex(const char *direct, fileheader_t *fh_o, int end) +getindex(const char *direct, fileheader_t *fhdr, int end) { // Ptt: 從前面找很費力 太暴力 - int fd = -1, begin = 1, i, stamp, s, times; + int fd = -1, begin = 1, i, s, times, stamp; fileheader_t fh; - if( end > (i = get_num_records(direct, sizeof(fileheader_t))) ) - end = i; - stamp = atoi(fh_o->filename + 2); - for( i = (begin + end) / 2, times = 0 ; - end > begin + 1 && times < 20 ; /* 最多只找 20 次 */ - i = (begin + end) / 2, ++times ){ + if( end > (i = get_num_records(direct, sizeof(fileheader_t))) || end<=0 ) + end = i; + stamp = atoi(fhdr->filename + 2); + for( i = (begin + end ) / 2, times = 0 ; + end >= begin && times < 20 ; /* 最多只找 20 次 */ + i = (begin + end ) / 2, ++times ){ if( get_record_keep(direct, &fh, sizeof(fileheader_t), i, &fd)==-1 || !fh.filename[0] ) break; s = atoi(fh.filename + 2); if( s > stamp ) - end = i + 1; + end = i - 1; else if( s == stamp ){ close(fd); - fh_o->multi.money = fh.multi.money; + fhdr->multi.money = fh.multi.money; return i; } else - begin = i; + begin = i + 1; } - if( times == 20 ){ + + if( times < 20) // Not forever loop. It any because of deletion. + { + close(fd); + return -i; + } + else{ /* 上面的 binary search 爛掉了, 那就改用 linear search */ + log_file("getindexerror", LOG_CREAT | LOG_VF, + "%s try to find: %d final i:%d\n", + direct, stamp, i); + // Ptt: log if there is still forever loop. + end = get_num_records(direct, sizeof(fileheader_t)); for( i = 1 ; i <= end ; ++i ){ if( get_record_keep(direct, &fh, @@ -197,7 +208,7 @@ getindex(const char *direct, fileheader_t *fh_o, int end) } if( atoi(fh.filename + 2) == stamp ){ close(fd); - fh_o->multi.money = fh.multi.money; + fhdr->multi.money = fh.multi.money; return i; } } |