diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-03-07 23:13:44 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-03-07 23:13:44 +0800 |
commit | ae31e19f92e717919ac8e3db9039eb38d2b89aae (patch) | |
tree | c70164d6a1852344f44b04a653ae2815043512af /util/topusr.c | |
download | pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.gz pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.bz2 pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.lz pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.xz pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.zst pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.zip |
Initial revision
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/topusr.c')
-rw-r--r-- | util/topusr.c | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/util/topusr.c b/util/topusr.c new file mode 100644 index 00000000..22b95e94 --- /dev/null +++ b/util/topusr.c @@ -0,0 +1,205 @@ +/* $Id: topusr.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 使用者 上站記錄/文章篇數 排行榜 */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "common.h" +#include "util.h" + +#define REAL_INFO +struct manrec +{ + char userid[IDLEN + 1]; + char username[23]; + int values[3]; +}; +typedef struct manrec manrec; +struct manrec *allman[3]; + +userec_t aman; +manrec theman; +int num; +FILE *fp; + +#define TYPE_POST 0 +#define TYPE_LOGIN 1 +#define TYPE_MONEY 2 + + +void + top(type) +{ + static char *str_type[3] = + {"發表次數", "進站次數", " 大富翁 "}; + int i, j, rows = (num + 1) / 2; + char buf1[80], buf2[80]; + + if (type != 2) + fprintf(fp, "\n\n"); + + fprintf(fp, "\ +[1;36m ╭─────╮ [%dm %8.8s排行榜 [36;40m ╭─────╮[m\n\ +[1;36m 名次─代號───暱稱──────數目──名次─代號───暱稱──────數目[m\ +", type + 44, str_type[type]); + for (i = 0; i < rows; i++) + { + char ch=' '; + int value; + + if(allman[type][i].values[type] > 1000000000) + { value=allman[type][i].values[type]/1000000; ch='M';} + else if(allman[type][i].values[type] > 1000000) + { value=allman[type][i].values[type]/1000; ch='K';} + else {value=allman[type][i].values[type]; ch=' ';} + sprintf(buf1, "[%2d] %-11.11s%-16.16s%5d%c", + i + 1, allman[type][i].userid, allman[type][i].username, + value, ch); + j = i + rows; + if(allman[type][j].values[type] > 1000000000) + { value=allman[type][j].values[type]/1000000; ch='M';} + else if(allman[type][j].values[type] > 1000000) + { value=allman[type][j].values[type]/1000; ch='K';} + else {value=allman[type][j].values[type]; ch=' ';} + + sprintf(buf2, "[%2d] %-11.11s%-16.16s%4d%c", + j + 1, allman[type][j].userid, allman[type][j].username, + value, ch); + if (i < 3) + fprintf(fp, "\n [1;%dm%-40s[0;37m%s", 31 + i, buf1, buf2); + else + fprintf(fp, "\n %-40s%s", buf1, buf2); + } +} + + +#ifdef HAVE_TIN +int + post_in_tin(char *name) +{ + char buf[256]; + FILE *fh; + int counter = 0; + + sprintf(buf, "%s/home/%c/%s/.tin/posted", home_path, name[0], name); + fh = fopen(buf, "r"); + if (fh == NULL) + return 0; + else + { + while (fgets(buf, 255, fh) != NULL) + counter++; + fclose(fh); + return counter; + } +} +#endif /* HAVE_TIN */ +int + not_alpha(ch) +register char ch; +{ + return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +int + not_alnum(ch) +register char ch; +{ + return (ch < '0' || (ch > '9' && ch < 'A') || + (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +int + bad_user_id(userid) +char *userid; +{ + register char ch; + if (strlen(userid) < 2) + return 1; + if (not_alpha(*userid)) + return 1; + while((ch = *(++userid))) + { + if (not_alnum(ch)) + return 1; + } + return 0; +} + +int main(argc, argv) +int argc; +char **argv; +{ + int i, j; + + if (argc < 3) + { + printf("Usage: %s <num_top> <out-file>\n", argv[0]); + exit(1); + } + + num = atoi(argv[1]); + if (num == 0) + num = 30; + + if(passwd_mmap()) + { + printf("Sorry, the data is not ready.\n"); + exit(0); + } + for(i=0; i<3; i++) + { + allman[i]=malloc(sizeof(manrec) * num); + memset(allman[i],0,sizeof(manrec) * num); + } + for(j = 1; j <= MAX_USERS; j++) { + passwd_query(j, &aman); + aman.userid[IDLEN]=0; + aman.username[22]=0; + if((aman.userlevel & PERM_NOTOP) || !aman.userid[0] || + bad_user_id(aman.userid) || + strchr(aman.userid, '.')) + { + continue; + } + else { + strcpy(theman.userid, aman.userid); + strcpy(theman.username, aman.username); + theman.values[TYPE_LOGIN] = aman.numlogins; + theman.values[TYPE_POST] = aman.numposts; + theman.values[TYPE_MONEY] = aman.money; + for(i=0; i<3; i++) + { + int k,l; + for(k=num-1; k>=0 && allman[i][k].values[i]<theman.values[i]; + k--); + k++; + if(k<num) + { + for(l=num-1; l>k; l--) + memcpy(&allman[i][l], &allman[i][l-1], + sizeof(manrec)); + memcpy(&allman[i][k], &theman, sizeof(manrec)); + } + } + } + } + + + if ((fp = fopen(argv[2], "w")) == NULL) + { + printf("cann't open topusr\n"); + return 0; + } + + top(TYPE_MONEY); + top(TYPE_POST); + top(TYPE_LOGIN); + + fclose(fp); + return 0; +} |