diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-12 09:42:23 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-12 09:42:23 +0800 |
commit | 9a12adf6d29cdefc98afe2566a9e5479489f111b (patch) | |
tree | 6e2b911398cb6dcb08b183ab645817e098182968 /src/libbbs | |
parent | 3d16ea67c380607528e7c8df0b2cc5a2f2636b9f (diff) | |
download | pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.gz pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.bz2 pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.lz pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.xz pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.zst pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.zip |
* extract common functions as library.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3673 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'src/libbbs')
-rw-r--r-- | src/libbbs/Makefile | 20 | ||||
-rw-r--r-- | src/libbbs/log.c | 0 | ||||
-rw-r--r-- | src/libbbs/money.c | 37 | ||||
-rw-r--r-- | src/libbbs/string.c | 1 |
4 files changed, 58 insertions, 0 deletions
diff --git a/src/libbbs/Makefile b/src/libbbs/Makefile new file mode 100644 index 00000000..efbf9534 --- /dev/null +++ b/src/libbbs/Makefile @@ -0,0 +1,20 @@ + +SRCROOT= ../.. +.include "$(SRCROOT)/pttbbs.mk" + +CFLAGS+= -I$(SRCROOT)/include + +OBJS= log.o string.o money.o +TARGET= libbbs.a + + +.SUFFIXES: .c .o +.c.o: + $(CCACHE) $(DIETCC) $(CC) $(CFLAGS) -c $*.c + +$(TARGET): $(OBJS) + $(AR) cru $@ $(OBJS) + ranlib $@ + +clean: + rm -f $(OBJS) $(TARGET) diff --git a/src/libbbs/log.c b/src/libbbs/log.c new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/libbbs/log.c diff --git a/src/libbbs/money.c b/src/libbbs/money.c new file mode 100644 index 00000000..a6d54127 --- /dev/null +++ b/src/libbbs/money.c @@ -0,0 +1,37 @@ +#include <stdio.h> + +#include <libbbs.h> + +/* 計算贈與稅 */ +int +give_tax(int money) +{ + int i, tax = 0; + int tax_bound[] = {1000000, 100000, 10000, 1000, 0}; + double tax_rate[] = {0.4, 0.3, 0.2, 0.1, 0.08}; + for (i = 0; i <= 4; i++) + if (money > tax_bound[i]) { + tax += (money - tax_bound[i]) * tax_rate[i]; + money -= (money - tax_bound[i]); + } + return (tax <= 0) ? 1 : tax; +} + +const char* +money_level(int money) +{ + int i = 0; + + static const char *money_msg[] = + { + "債台高築", "赤貧", "清寒", "普通", "小康", + "小富", "中富", "大富翁", "富可敵國", "比爾蓋\天", NULL + }; + while (money_msg[i] && money > 10) + i++, money /= 10; + + if(!money_msg[i]) + i--; + return money_msg[i]; +} + diff --git a/src/libbbs/string.c b/src/libbbs/string.c new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/libbbs/string.c @@ -0,0 +1 @@ + |