diff options
author | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-12-03 09:08:29 +0800 |
---|---|---|
committer | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-12-03 09:08:29 +0800 |
commit | 3655862b3fa51afaf5c01a2cfea600169f3cd609 (patch) | |
tree | 7e8aa3d8e50b25920d421f62d59eae06837b26f6 | |
parent | 5cefa8237ce2a2c2ad86d956a086c386fb013364 (diff) | |
download | pttbbs-3655862b3fa51afaf5c01a2cfea600169f3cd609.tar pttbbs-3655862b3fa51afaf5c01a2cfea600169f3cd609.tar.gz pttbbs-3655862b3fa51afaf5c01a2cfea600169f3cd609.tar.bz2 pttbbs-3655862b3fa51afaf5c01a2cfea600169f3cd609.tar.lz pttbbs-3655862b3fa51afaf5c01a2cfea600169f3cd609.tar.xz pttbbs-3655862b3fa51afaf5c01a2cfea600169f3cd609.tar.zst pttbbs-3655862b3fa51afaf5c01a2cfea600169f3cd609.zip |
changed money in fileheader_t into union
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2363 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/osdep.h | 13 | ||||
-rw-r--r-- | include/pttstruct.h | 30 | ||||
-rw-r--r-- | mbbsd/bbs.c | 33 | ||||
-rw-r--r-- | mbbsd/read.c | 9 | ||||
-rw-r--r-- | mbbsd/record.c | 11 | ||||
-rw-r--r-- | mbbsd/voteboard.c | 16 | ||||
-rw-r--r-- | util/initbbs.c | 2 |
7 files changed, 78 insertions, 36 deletions
diff --git a/include/osdep.h b/include/osdep.h index 8e790595..84bd04fc 100644 --- a/include/osdep.h +++ b/include/osdep.h @@ -14,6 +14,12 @@ #define _XOPEN_SOURCE #define _ISOC99_SOURCE + + #if BYTE_ORDER == BIG_ENDIAN + #define _BIG_ENDIAN + #else + #define _LITTLE_ENDIAN + #endif #elif defined(__linux__) @@ -22,6 +28,13 @@ #include <sys/ioctl.h> #include <sys/file.h> /* for flock() */ #include <strings.h> /* for strcasecmp() */ + #include <endian.h> /* for __BYTE_ORDER */ + + #if __BYTE_ORDER == __BIG_ENDIAN + #define _BIG_ENDIAN + #else + #define _LITTLE_ENDIAN + #endif #define NEED_STRCASESTR #define NEED_STRLCPY diff --git a/include/pttstruct.h b/include/pttstruct.h index fcdb77bb..23979723 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -219,15 +219,39 @@ typedef struct boardheader_t { #define TTLEN 64 /* Length of title */ #define FNLEN 33 /* Length of filename */ -#define FHR_REFERENCE (1<<31) - typedef struct fileheader_t { char filename[FNLEN]; /* M.9876543210.A */ char recommend; /* important level */ char owner[IDLEN + 2]; /* uid[.] */ char date[6]; /* [02/02] or space(5) */ char title[TTLEN + 1]; - int money; /* rocker: if bit32 on ==> reference */ /* XXX dirty, split into flag and money if money of each file is less than 16bit? */ + union { + int money; + int anon_uid; + /* different order to match alignment */ +#ifdef _BIG_ENDIAN + struct { + unsigned char pad[2]; /* money & 0xffff0000 */ + unsigned char logins; /* money & 0xff00 */ + unsigned char posts; /* money & 0xff */ + } vote_limits; + struct { + unsigned int flag:1; + unsigned int ref:31; + } refer; +#else + struct { + unsigned char posts; /* money & 0xff */ + unsigned char logins; /* money & 0xff00 */ + unsigned char pad[2]; /* money & 0xffff0000 */ + } vote_limits; + struct { + unsigned int ref:31; + unsigned int flag:1; + } refer; +#endif + } multi; /* rocker: if bit32 on ==> reference */ + /* XXX dirty, split into flag and money if money of each file is less than 16bit? */ unsigned char filemode; /* must be last field @ boards.c */ } fileheader_t; diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 7396c22e..a3cec483 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -570,7 +570,7 @@ do_general(int isbid) if (unlikely(isbid)) { memset(&bidinfo,0,sizeof(bidinfo)); setupbidinfo(&bidinfo); - postfile.money=bidinfo.high; + postfile.multi.money=bidinfo.high; move(20,0); clrtobot(); } @@ -655,10 +655,10 @@ do_general(int isbid) aborted = (aborted > MAX_POST_MONEY * 2) ? MAX_POST_MONEY : aborted / 2; if(ifuseanony) { postfile.filemode |= FILE_ANONYMOUS; - postfile.money = currutmp->uid; + postfile.multi.anon_uid = currutmp->uid; } else if(!isbid) - postfile.money = aborted; + postfile.multi.money = aborted; strlcpy(postfile.owner, owner, sizeof(postfile.owner)); strlcpy(postfile.title, save_title, sizeof(postfile.title)); @@ -1727,9 +1727,9 @@ del_post(int ent, fileheader_t * fhdr, char *direct) bp = getbcache(currbid); if(fhdr->filemode & FILE_ANONYMOUS) - /* When the file is anonymous posted, fhdr->money is author. + /* When the file is anonymous posted, fhdr->multi.anon_uid is author. * see do_general() */ - tusernum = fhdr->money; + tusernum = fhdr->multi.anon_uid; else tusernum = searchuser(fhdr->owner); @@ -1797,18 +1797,18 @@ del_post(int ent, fileheader_t * fhdr, char *direct) #endif setbtotal(currbid); - if (fhdr->money < 0 || fhdr->filemode & FILE_ANONYMOUS) - fhdr->money = 0; + if (fhdr->multi.money < 0 || fhdr->filemode & FILE_ANONYMOUS) + fhdr->multi.money = 0; if (not_owned && strcmp(currboard, "Test")) { - deumoney(tusernum, -fhdr->money); + deumoney(tusernum, -fhdr->multi.money); } if (!not_owned && strcmp(currboard, "Test")) { if (cuser.numposts) cuser.numposts--; if (!(currmode & MODE_DIGEST && currmode & MODE_BOARD)){ - demoney(-fhdr->money); + demoney(-fhdr->multi.money); vmsg("您的文章減為 %d 篇,支付清潔費 %d 銀", - cuser.numposts, fhdr->money); + cuser.numposts, fhdr->multi.money); } } return DIRCHANGED; @@ -1834,12 +1834,12 @@ view_postmoney(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } if(fhdr->filemode & FILE_ANONYMOUS) - /* When the file is anonymous posted, fhdr->money is author. + /* When the file is anonymous posted, fhdr->multi.anon_uid is author. * see do_general() */ vmsg("匿名管理編號: %d (同一人號碼會一樣)", - fhdr->money + (int)currutmp->pid); + fhdr->multi.anon_uid + (int)currutmp->pid); else - vmsg("這一篇文章值 %d 銀", fhdr->money); + vmsg("這一篇文章值 %d 銀", fhdr->multi.money); return FULLUPDATE; } @@ -2177,7 +2177,8 @@ push_bottom(int ent, fileheader_t *fhdr, char *direct) vmsg("不得超過 5 篇重要公告 請精簡!"); return READ_REDRAW; } - fhdr->money = ent | FHR_REFERENCE; + fhdr->multi.refer.flag = 1; + fhdr->multi.refer.ref = ent; append_record(buf, fhdr, sizeof(fileheader_t)); } else{ @@ -2207,7 +2208,7 @@ good_post(int ent, fileheader_t * fhdr, char *direct) !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { deumoney(searchuser(fhdr->owner), -1000); if (!(currmode & MODE_SELECT)) - fhdr->money -= 1000; + fhdr->multi.money -= 1000; else delta = -1000; } @@ -2246,7 +2247,7 @@ good_post(int ent, fileheader_t * fhdr, char *direct) !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { deumoney(searchuser(fhdr->owner), 1000); if (!(currmode & MODE_SELECT)) - fhdr->money += 1000; + fhdr->multi.money += 1000; else delta = 1000; } diff --git a/mbbsd/read.c b/mbbsd/read.c index 1927d929..ebf632dd 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -440,7 +440,10 @@ select_read(keeploc_t * locmem, int sr_mode) continue; ++count; if(p == NULL) - fhs[i].money = reference | FHR_REFERENCE; + { + fhs[i].multi.refer.flag = 1; + fhs[i].multi.refer.ref = reference; + } write(fd, &fhs[i], sizeof(fileheader_t)); } } // end while @@ -498,7 +501,7 @@ i_read_key(const onekey_t * rcmdlist, keeploc_t * locmem, board_select(); setbdir(genbuf, currboard); locmem = getkeep(genbuf, 0, 1); - locmem->crs_ln = fhdr->money & ~FHR_REFERENCE; + locmem->crs_ln = fhdr->multi.refer.ref; num = locmem->crs_ln - p_lines + 1; locmem->top_ln = num < 1 ? 1 : num; mode = NEWDIRECT; @@ -649,7 +652,7 @@ i_read_key(const onekey_t * rcmdlist, keeploc_t * locmem, /* rocker.011112: 解決再select mode標記文章的問題 */ if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), (currmode & MODE_SELECT) ? - (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : + (headers[locmem->crs_ln - locmem->top_ln].multi.refer.ref) : locmem->crs_ln, TAG_TOGGLE)) locmem->crs_ln = locmem->crs_ln + 1; mode = PART_REDRAW; diff --git a/mbbsd/record.c b/mbbsd/record.c index 1ff65353..110ddd41 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -136,8 +136,8 @@ substitute_ref_record(char *direct, fileheader_t * fhdr, int ent) int num = 0; /* rocker.011018: 串接模式用reference增進效率 */ - if (!(fhdr->filemode & FILE_BOTTOM) && (fhdr->money & FHR_REFERENCE) && - (num = fhdr->money & ~FHR_REFERENCE)){ + if (!(fhdr->filemode & FILE_BOTTOM) && (fhdr->multi.refer.flag) && + (num = fhdr->multi.refer.ref)){ setdirpath(genbuf, direct, ".DIR"); get_record(genbuf, &hdr, sizeof(hdr), num); if (strcmp(hdr.filename, fhdr->filename)) { @@ -146,10 +146,11 @@ substitute_ref_record(char *direct, fileheader_t * fhdr, int ent) } } else if(num>0) { - fhdr->money = hdr.money; + fhdr->multi.money = hdr.multi.money; substitute_record(genbuf, fhdr, sizeof(*fhdr), num); } - fhdr->money = FHR_REFERENCE | num ; // Ptt: update now! + fhdr->multi.refer.flag = 1; + fhdr->multi.refer.ref = num; // Ptt: update now! } substitute_record(direct, fhdr, sizeof(*fhdr), ent); return num; @@ -175,7 +176,7 @@ getindex(char *direct, fileheader_t *fh_o, int end) else if(s == stamp) { close(fd); - fh_o->money = fh.money; + fh_o->multi.money = fh.multi.money; return i; } else begin = i; diff --git a/mbbsd/voteboard.c b/mbbsd/voteboard.c index 899885bd..5cfa3983 100644 --- a/mbbsd/voteboard.c +++ b/mbbsd/voteboard.c @@ -16,21 +16,21 @@ do_votelimitedit(int ent, fileheader_t * fhdr, char *direct) return DONOTHING; getdata(23, 0, "更改 (A)本篇 (B)本版預設連署限制 (C)取消?[C]", genbuf, 3, LCECHO); if (genbuf[0] == 'a' || genbuf[0] == 'A') { - sprintf(genbuf, "%u", ((fhdr->money >> 8) & 0xFF) * 10); + sprintf(genbuf, "%u", (unsigned int)(fhdr->multi.vote_limits.logins) * 10); do { getdata_buf(23, 0, "上站次數下限 (0~2550):", genbuf, 5, LCECHO); temp = atoi(genbuf); } while (temp < 0 || temp > 2550); temp /= 10; - fhdr->money = (fhdr->money & ~(0xFF00)) | (temp << 8); + fhdr->multi.vote_limits.logins = (unsigned char)temp; - sprintf(genbuf, "%u", (fhdr->money & 0xFF) * 10); + sprintf(genbuf, "%u", (unsigned int)(fhdr->multi.vote_limits.posts) * 10); do { getdata_buf(23, 0, "文章篇數下限 (0~2550):", genbuf, 5, LCECHO); temp = atoi(genbuf); } while (temp < 0 || temp > 2550); temp /= 10; - fhdr->money = (fhdr->money & ~(0xFF)) | temp; + fhdr->multi.vote_limits.posts = (unsigned char)temp; substitute_ref_record(direct, fhdr, ent); vmsg("修改完成!"); return FULLUPDATE; @@ -80,8 +80,8 @@ do_voteboardreply(fileheader_t * fhdr) vmsg("對不起,您目前無法在此發表文章!"); return; } - len = fhdr->money; - if ( cuser.numlogins < (((len >> 8) & 0xFF) * 10) || cuser.numposts < ((len & 0xFF) * 10) ) { + if ( cuser.numlogins < ((unsigned int)(fhdr->multi.vote_limits.logins) * 10) || + cuser.numposts < ((unsigned int)(fhdr->multi.vote_limits.posts) * 10) ) { move(5, 10); vmsg("你的上站數/文章數不足喔!"); return; @@ -395,8 +395,8 @@ do_voteboard(int type) temp = getbnum(currboard); /* use lower 16 bits of 'money' to store limits */ /* lower 8 bits are posts, higher 8 bits are logins */ - votefile.money = ( ((unsigned int)(bcache[temp - 1].limit_logins) << 8) | - (unsigned int)(bcache[temp - 1].limit_posts) ); + votefile.multi.vote_limits.logins = (unsigned int)bcache[temp - 1].limit_logins; + votefile.multi.vote_limits.posts = (unsigned int)bcache[temp - 1].limit_posts; setbdir(genbuf, currboard); if (append_record(genbuf, &votefile, sizeof(votefile)) != -1) setbtotal(currbid); diff --git a/util/initbbs.c b/util/initbbs.c index 9c154120..f952b7ef 100644 --- a/util/initbbs.c +++ b/util/initbbs.c @@ -194,7 +194,7 @@ static void initMan() { memset(&f, 0, sizeof(f)); strcpy(f.owner, "SYSOP"); sprintf(f.date, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday); - f.money = 0; + f.multi.money = 0; f.filemode = 0; if((fp = fopen("man/boards/N/Note/.DIR", "w"))) { |