From 9a12adf6d29cdefc98afe2566a9e5479489f111b Mon Sep 17 00:00:00 2001
From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>
Date: Wed, 12 Dec 2007 01:42:23 +0000
Subject:  * extract common functions as library.

git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3673 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 include/bbs.h        |  9 +++---
 include/common.h     |  2 --
 include/libbbs.h     |  7 +++++
 include/libbbsutil.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/modes.h      |  6 ++--
 include/proto.h      | 42 +------------------------
 6 files changed, 102 insertions(+), 52 deletions(-)
 create mode 100644 include/libbbs.h
 create mode 100644 include/libbbsutil.h

(limited to 'include')

diff --git a/include/bbs.h b/include/bbs.h
index 8d51000a..ead0861e 100644
--- a/include/bbs.h
+++ b/include/bbs.h
@@ -43,11 +43,10 @@ extern "C" {
 
 /* our header */
 #include "config.h"
-#ifdef TIMET64
-typedef uint32_t time4_t;
-#else
-typedef time_t time4_t;
-#endif
+
+#include "libbbsutil.h"
+#include "libbbs.h"
+
 #include "ansi.h"
 #include "statistic.h"
 #include "uflags.h"
diff --git a/include/common.h b/include/common.h
index 34b18bf0..a6fb23ec 100644
--- a/include/common.h
+++ b/include/common.h
@@ -229,8 +229,6 @@
 #define REPLYING        0
 #define RECVINREPLYING  1
 
-#define LOG_CREAT       1
-#define LOG_VF          2
 
 
 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
diff --git a/include/libbbs.h b/include/libbbs.h
new file mode 100644
index 00000000..de042a03
--- /dev/null
+++ b/include/libbbs.h
@@ -0,0 +1,7 @@
+#ifndef _LIBBBS_H_
+#define _LIBBBS_H_
+
+extern int give_tax(int money);
+extern const char* money_level(int money);
+
+#endif
diff --git a/include/libbbsutil.h b/include/libbbsutil.h
new file mode 100644
index 00000000..8f9ac4f3
--- /dev/null
+++ b/include/libbbsutil.h
@@ -0,0 +1,88 @@
+#ifndef _LIBBBSUTIL_H_
+#define _LIBBBSUTIL_H_
+
+#include <stdint.h>
+#include <sys/types.h>
+#ifdef __GNUC__
+#define GCC_CHECK_FORMAT(a,b) __attribute__ ((format (printf, a, b)))
+#else
+#define GCC_CHECK_FORMAT(a,b)
+#endif
+enum STRIP_FLAG {
+    STRIP_ALL = 0, ONLY_COLOR, NO_RELOAD
+};
+enum LOG_FLAG {
+    LOG_CREAT = 1,
+};
+
+
+#ifdef TIMET64
+typedef int32_t time4_t;
+#else
+typedef time_t time4_t;
+#endif
+
+/* file.c */
+extern off_t dashs(const char *fname);
+time4_t dasht(const char *fname);
+extern int dashl(const char *fname);
+extern int dashf(const char *fname);
+extern int dashd(const char *fname);
+extern int copy_file_to_file(const char *src, const char *dst);
+extern int copy_file_to_dir(const char *src, const char *dst);
+extern int copy_dir_to_dir(const char *src, const char *dst);
+extern int copy_file(const char *src, const char *dst);
+extern int Rename(const char *src, const char *dst);
+extern int Copy(const char *src, const char *dst);
+extern int CopyN(const char *src, const char *dst, int n);
+extern int AppendTail(const char *src, const char *dst, int off);
+extern int Link(const char *src, const char *dst);
+
+/* lock.c */
+extern void PttLock(int fd, int start, int size, int mode);
+
+/* net.c */
+extern unsigned int ipstr2int(const char *ip);
+extern int tobind(const char * host, int port);
+extern int toconnect(const char *host, int port);
+extern int toread(int fd, void *buf, int len);
+extern int towrite(int fd, const void *buf, int len);
+
+/* sort.c */
+extern int cmp_int(const void *a, const void *b);
+extern int cmp_int_desc(const void * a, const void * b);
+
+/* string.h */
+extern void str_lower(char *t, const char *s);
+extern void trim(char *buf);
+extern void chomp(char *src);
+extern int strip_blank(char *cbuf, char *buf);
+extern int strip_ansi(char *buf, const char *str, enum STRIP_FLAG flag);
+extern int  strlen_noansi(const char *s);
+extern void strip_nonebig5(unsigned char *str, int maxlen);
+extern int invalid_pname(const char *str);
+extern int is_number(const char *p);
+extern unsigned StringHash(const char *s);
+extern char * qp_encode (char *s, size_t slen, const char *d, const char *tocode);
+
+/* time.c */
+extern int is_leap_year(int year);
+extern int getHoroscope(int m, int d);
+extern char* Cdate(const time4_t *clock);
+extern char* Cdatelite(const time4_t *clock);
+extern char* Cdatedate(const time4_t * clock);
+extern char* my_ctime(const time4_t * t, char *ans, int len);
+#ifdef TIMET64
+    struct tm *localtime4(const time4_t *);
+    time4_t time4(time4_t *);
+    char *ctime4(const time4_t *);
+#else
+    #define localtime4(a) localtime(a)
+    #define time4(a)      time(a)
+    #define ctime4(a)     ctime(a)
+#endif
+
+extern int log_filef(const char *fn, int flag, const char *fmt,...) GCC_CHECK_FORMAT(3,4);
+extern int log_file(const char *fn, int flag, const char *msg);
+
+#endif
diff --git a/include/modes.h b/include/modes.h
index b5bc9833..24b8a01a 100644
--- a/include/modes.h
+++ b/include/modes.h
@@ -155,13 +155,11 @@
 #define AUTHOR_PREV     (RS_AUTHOR)
 
 /* DBCS aware modes */
-enum {
+enum _DBCS_STATUS {
     DBCS_ASCII,
     DBCS_LEADING,
     DBCS_TRAILING,
-} _DBCS_STATUS;
-
-enum {STRIP_ALL = 0, ONLY_COLOR, NO_RELOAD};
+};
 
 #define SIG_PK          0
 #define SIG_TALK        1
diff --git a/include/proto.h b/include/proto.h
index e1985ce6..f62c1e7e 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -62,7 +62,6 @@ int inc_badsale(const char *, int num);
 /* bbs */
 void delete_allpost(const char *userid);
 int invalid_brdname(const char *brd);
-void chomp(char *src);
 int del_range(int ent, const fileheader_t *fhdr, const char *direct);
 int cmpfowner(fileheader_t *fhdr);
 int b_note_edit_bname(int bid);
@@ -327,20 +326,12 @@ int getdata_str(int line, int col, const char *prompt, char *buf, int len, int e
 int getdata_buf(int line, int col, const char *prompt, char *buf, int len, int echo);
 void add_io(int fd, int timeout);
 void oflush(void);
-int strip_ansi(char *buf, const char *str, int mode);
-void strip_nonebig5(unsigned char *str, int maxlen);
 int oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo);
 void output(const char *s, int len);
 int num_in_buf(void);
 int ochar(int c);
-int strlen_noansi(const char *buf);
 
 /* kaede */
-int Rename(const char* src, const char* dst);
-int Copy(const char *src, const char *dst);
-int CopyN(const char *src, const char *dst, int n);
-int AppendTail(const char *src, const char *dst, int off);
-int Link(const char* src, const char* dst);
 char *Ptt_prints(char *str, size_t size, int mode);
 char *my_ctime(const time4_t *t, char *ans, int len);
 
@@ -600,7 +591,6 @@ void grayout_lines(int start, int end, int level);
 #define not_alnum(ch) (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a') || ch > 'z')
 #define pressanykey() vmsg(NULL)
 int log_user(const char *fmt, ...) GCC_CHECK_FORMAT(1,2);
-unsigned int ipstr2int(const char *ip);
 time4_t gettime(int line, time4_t dt, const char* head);
 void setcalfile(char *buf, char *userid);
 void stand_title(const char *title);
@@ -608,43 +598,30 @@ char getans(const char *fmt,...) GCC_CHECK_FORMAT(1,2);
 int getkey(const char *fmt,...) GCC_CHECK_FORMAT(1,2);
 int vmsgf(const char *fmt,...) GCC_CHECK_FORMAT(1,2);
 int vmsg(const char *msg);
-void trim(char *buf);
 int show_file(const char *filename, int y, int lines, int mode);
 void bell(void);
 void setbpath(char *buf, const char *boardname);
-int dashf(const char *fname);
 void sethomepath(char *buf, const char *userid);
 void sethomedir(char *buf, const char *userid);
-char *Cdate(const time4_t *clock);
 void sethomefile(char *buf, const char *userid, const char *fname);
-int log_file(const char *fn, int flag, const char *fmt,...);
-void str_lower(char *t, const char *s);
 int cursor_key(int row, int column);
 int search_num(int ch, int max);
 void setuserfile(char *buf, const char *fname);
 int is_BM(const char *list);
-time4_t dasht(const char *fname);
-int dashd(const char *fname);
-int invalid_pname(const char *str);
 void setbdir(char *buf, const char *boardname);
 void setbfile(char *buf, const char *boardname, const char *fname);
 void setbnfile(char *buf, const char *boardname, const char *fname, int n);
-int dashl(const char *fname);
 char *subject(char *title);
+int is_validuserid(const char *id);
 void setdirpath(char *buf, const char *direct, const char *fname);
 int str_checksum(const char *str);
 void show_help(const char * const helptext[]);
 void show_helpfile(const char * helpfile);
-int copy_file(const char *src, const char *dst);
 int belong(const char *filelist, const char *key);
-char *Cdatedate(const time4_t *clock);
 void sethomeman(char *buf, const char *userid);
-off_t dashs(const char *fname);
 void cursor_clear(int row, int column);
 void cursor_show(int row, int column);
 void printdash(const char *mesg, int msglen);
-char *Cdatelite(const time4_t *clock);
-int is_validuserid(const char *ident);
 int userid_is_BM(const char *userid, const char *list);
 int is_uBM(const char *list, const char *id);
 inline int *intbsearch(int key, const int *base0, int nmemb);
@@ -657,24 +634,9 @@ int qsort_intcompar(const void *a, const void *b);
     void *MALLOC(int size);
     void FREE(void *ptr);
 #endif
-#ifdef OUTTACACHE
-int tobind(const char *iface_ip, int port);
-int toconnect(const char *host, int port);
-int toread(int fd, void *buf, int len);
-int towrite(int fd, const void *buf, int len);
-#endif
 #ifdef PLAY_ANGEL
 void pressanykey_or_callangel(void);
 #endif
-#ifdef TIMET64
-    struct tm *localtime4(const time4_t *);
-    time4_t time4(time4_t *);
-    char *ctime4(const time4_t *);
-#else
-    #define localtime4(a) localtime(a)
-    #define time4(a)      time(a)
-    #define ctime4(a)     ctime(a)
-#endif
 
 /* syspost */
 int post_msg(const char* bname, const char* title, const char *msg, const char* author);
@@ -811,7 +773,6 @@ int note(void);
 int Goodbye(void);
 
 /* toolkit */
-unsigned StringHash(const char *s);
 unsigned DBCS_StringHash(const char *s);
 
 /* passwd */
@@ -829,7 +790,6 @@ int freecuser(void);
 /* calendar */
 int calendar(void);
 int ParseDate(const char *date, int *year, int *month, int *day);
-int getHoroscope(int m, int d);
 
 /* util */
 void touchbtotal(int bid);
-- 
cgit v1.2.3