summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-27 14:26:11 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-27 14:26:11 +0800
commitc17b1ec0c4c66cbe2761fa0e8c83831e6258d11d (patch)
tree21e0d184cdf9f58095dce3c486522e2266449391
parent3e774d4829229f4132e3b6895b572a117f60c99d (diff)
downloadpttbbs-c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d.tar
pttbbs-c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d.tar.gz
pttbbs-c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d.tar.bz2
pttbbs-c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d.tar.lz
pttbbs-c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d.tar.xz
pttbbs-c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d.tar.zst
pttbbs-c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d.zip
- (internal) move UTIL_C API from mbbsd/stuff to cmbbs.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4031 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--common/bbs/Makefile2
-rw-r--r--common/bbs/file.c8
-rw-r--r--common/bbs/names.c29
-rw-r--r--common/bbs/path.c110
-rw-r--r--include/cmbbs.h27
-rw-r--r--include/osdep.h7
-rw-r--r--include/proto.h21
-rw-r--r--include/pttstruct.h2
-rw-r--r--innbbsd/Makefile3
-rw-r--r--mbbsd/Makefile9
-rw-r--r--mbbsd/stuff.c103
-rw-r--r--upgrade/merge_sob.c (renamed from mbbsd/merge.c)2
-rw-r--r--util/Makefile6
13 files changed, 197 insertions, 132 deletions
diff --git a/common/bbs/Makefile b/common/bbs/Makefile
index 6ed3e554..ce53c79a 100644
--- a/common/bbs/Makefile
+++ b/common/bbs/Makefile
@@ -4,7 +4,7 @@ SRCROOT= ../..
CFLAGS+= -I$(SRCROOT)/include
-OBJS= log.o string.o money.o
+OBJS= log.o file.o money.o names.o path.o string.o
TARGET= libcmbbs.a
diff --git a/common/bbs/file.c b/common/bbs/file.c
new file mode 100644
index 00000000..a423f92b
--- /dev/null
+++ b/common/bbs/file.c
@@ -0,0 +1,8 @@
+#include "cmbbs.h"
+
+int
+belong(const char *filelist, const char *key)
+{
+ return file_exist_record(filelist, key);
+}
+
diff --git a/common/bbs/names.c b/common/bbs/names.c
new file mode 100644
index 00000000..d96b3b3e
--- /dev/null
+++ b/common/bbs/names.c
@@ -0,0 +1,29 @@
+/* $Id$ */
+
+// #include "bbs.h"
+#include "cmbbs.h"
+#include <assert.h>
+// #include <stdio.h>
+// #include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+int
+is_validuserid(const char *id)
+{
+ int len, i;
+ if(id==NULL)
+ return 0;
+ len = strlen(id);
+
+ if (len < 2 || len>IDLEN)
+ return 0;
+
+ if (!isalpha(id[0]))
+ return 0;
+ for (i = 1; i < len; i++)
+ if (!isalnum(id[i]))
+ return 0;
+ return 1;
+}
+
diff --git a/common/bbs/path.c b/common/bbs/path.c
new file mode 100644
index 00000000..a48d3a46
--- /dev/null
+++ b/common/bbs/path.c
@@ -0,0 +1,110 @@
+/* $Id$ */
+// #include "bbs.h"
+#include "cmbbs.h"
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+/* ----------------------------------------------------- */
+/* set file path for boards/user home */
+/* ----------------------------------------------------- */
+static const char * const str_home_file = "home/%c/%s/%s";
+static const char * const str_board_file = "boards/%c/%s/%s";
+static const char * const str_board_n_file = "boards/%c/%s/%s.%d";
+static const char * const str_dotdir = FN_DIR;
+
+/* XXX set*() all assume buffer size = PATHLEN */
+void
+sethomepath(char *buf, const char *userid)
+{
+ assert(is_validuserid(userid));
+ snprintf(buf, PATHLEN, "home/%c/%s", userid[0], userid);
+}
+
+void
+sethomedir(char *buf, const char *userid)
+{
+ assert(is_validuserid(userid));
+ snprintf(buf, PATHLEN, str_home_file, userid[0], userid, str_dotdir);
+}
+
+void
+sethomeman(char *buf, const char *userid)
+{
+ assert(is_validuserid(userid));
+ snprintf(buf, PATHLEN, str_home_file, userid[0], userid, "man");
+}
+
+
+void
+sethomefile(char *buf, const char *userid, const char *fname)
+{
+ assert(is_validuserid(userid));
+ assert(fname[0]);
+ snprintf(buf, PATHLEN, str_home_file, userid[0], userid, fname);
+}
+
+void
+setapath(char *buf, const char *boardname)
+{
+ //assert(boardname[0]);
+ snprintf(buf, PATHLEN, "man/boards/%c/%s", boardname[0], boardname);
+}
+
+void
+setadir(char *buf, const char *path)
+{
+ //assert(path[0]);
+ snprintf(buf, PATHLEN, "%s/%s", path, str_dotdir);
+}
+
+void
+setbpath(char *buf, const char *boardname)
+{
+ //assert(boardname[0]);
+ snprintf(buf, PATHLEN, "boards/%c/%s", boardname[0], boardname);
+}
+
+#if 0
+void
+setbdir(char *buf, const char *boardname)
+{
+ //assert(boardname[0]);
+ snprintf(buf, PATHLEN, str_board_file, boardname[0], boardname,
+ (currmode & MODE_DIGEST ? fn_mandex : str_dotdir));
+}
+#endif
+
+void
+setbfile(char *buf, const char *boardname, const char *fname)
+{
+ //assert(boardname[0]);
+ assert(fname[0]);
+ snprintf(buf, PATHLEN, str_board_file, boardname[0], boardname, fname);
+}
+
+void
+setbnfile(char *buf, const char *boardname, const char *fname, int n)
+{
+ //assert(boardname[0]);
+ assert(fname[0]);
+ snprintf(buf, PATHLEN, str_board_n_file, boardname[0], boardname, fname, n);
+}
+
+/*
+ * input direct
+ * output buf: copy direct
+ * fname: direct 的檔名部分
+ */
+void
+setdirpath(char *buf, const char *direct, const char *fname)
+{
+ char *p;
+ strcpy(buf, direct);
+ p = strrchr(buf, '/');
+ assert(p);
+ strlcpy(p + 1, fname, PATHLEN-(p+1-buf));
+}
+
diff --git a/include/cmbbs.h b/include/cmbbs.h
index de042a03..b6c69adb 100644
--- a/include/cmbbs.h
+++ b/include/cmbbs.h
@@ -1,6 +1,33 @@
#ifndef _LIBBBS_H_
#define _LIBBBS_H_
+#include "config.h"
+#include "common.h"
+#include "cmsys.h"
+#include "pttstruct.h"
+
+/* name.c */
+extern int is_validuserid(const char *id);
+
+/* path.c */
+/* XXX set*() all assume buffer size = PATHLEN */
+extern void setdirpath(char *buf, const char *direct, const char *fname);
+extern void setbpath (char *buf, const char *boardname);
+extern void setbfile (char *buf, const char *boardname, const char *fname);
+extern void setbnfile(char *buf, const char *boardname, const char *fname, int n);
+extern void setapath(char *buf, const char *boardname);
+extern void setadir (char *buf, const char *path);
+extern void sethomepath(char *buf, const char *userid);
+extern void sethomedir (char *buf, const char *userid);
+extern void sethomeman (char *buf, const char *userid);
+extern void sethomefile(char *buf, const char *userid, const char *fname);
+// setbdir
+// setuserfile
+
+/* file.c */
+extern int belong(const char *filelist, const char *key);
+
+/* money.c */
extern int give_tax(int money);
extern const char* money_level(int money);
diff --git a/include/osdep.h b/include/osdep.h
index 351d55af..89cb1edb 100644
--- a/include/osdep.h
+++ b/include/osdep.h
@@ -61,5 +61,12 @@
#define Signal (signal)
#endif
+#ifdef NEED_STRLCPY
+ size_t strlcpy(char *dst, const char *src, size_t size);
+#endif
+#ifdef NEED_STRLCAT
+ size_t strlcat(char *dst, const char *src, size_t size);
+#endif
+
#endif
diff --git a/include/proto.h b/include/proto.h
index c51afb43..2fabbfba 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -124,10 +124,8 @@ void touchbpostnum(int bid, int delta);
void reset_board(int bid);
void touch_boards(void);
void addbrd_touchcache(void);
-void setapath(char *buf, const char *boardname);
void setutmpmode(unsigned int mode);
unsigned int getutmpmode(void);
-void setadir(char *buf, const char *path);
int apply_boards(int (*func)(boardheader_t *));
int haspostperm(const char *bname);
const char * postperm_msg(const char *bname);
@@ -467,13 +465,6 @@ int cpuload(char *str);
void initsetproctitle(int argc, char **argv, char **envp);
void setproctitle(const char* format, ...) GCC_CHECK_FORMAT(1,2);
-#ifdef NEED_STRLCPY
- size_t strlcpy(char *dst, const char *src, size_t size);
-#endif
-
-#ifdef NEED_STRLCAT
- size_t strlcat(char *dst, const char *src, size_t size);
-#endif
/* othello */
int othello_main(void);
@@ -598,26 +589,16 @@ int vmsgf(const char *fmt,...) GCC_CHECK_FORMAT(1,2);
int vmsg(const char *msg);
int show_file(const char *filename, int y, int lines, int mode);
void bell(void);
-void setbpath(char *buf, const char *boardname);
-void sethomepath(char *buf, const char *userid);
-void sethomedir(char *buf, const char *userid);
-void sethomefile(char *buf, const char *userid, const char *fname);
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);
+void setuserfile(char *buf, const char *fname);
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);
void setaidfile(char *buf, const char *bn, aidu_t aidu);
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 belong(const char *filelist, const char *key);
-void sethomeman(char *buf, const char *userid);
void cursor_clear(int row, int column);
void cursor_show(int row, int column);
void printdash(const char *mesg, int msglen);
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 2dac5e79..4e8f6983 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -2,6 +2,8 @@
#ifndef INCLUDE_STRUCT_H
#define INCLUDE_STRUCT_H
+#include "statistic.h" // for MAX_STATS
+
#define IDLEN 12 /* Length of bid/uid */
/* 競標資訊 */
diff --git a/innbbsd/Makefile b/innbbsd/Makefile
index 749efb1b..bf1ae752 100644
--- a/innbbsd/Makefile
+++ b/innbbsd/Makefile
@@ -32,8 +32,7 @@ all: ${PROGS}
# bbs util
UTIL_DIR= $(SRCROOT)/util
UTIL_OBJS= \
- util_cache.o util_record.o util_passwd.o util_var.o \
- util_stuff.o
+ util_cache.o util_record.o util_passwd.o util_var.o
.for fn in ${UTIL_OBJS}
LINK_UTIL_OBJS+= ${UTIL_DIR}/${fn}
diff --git a/mbbsd/Makefile b/mbbsd/Makefile
index af0a28d6..439a55bb 100644
--- a/mbbsd/Makefile
+++ b/mbbsd/Makefile
@@ -83,10 +83,11 @@ DIETCC= diet -Os
LDFLAGS+=-Wl,--sort-common
.endif
-.if defined(MERGEBBS)
-CFLAGS+= -DMERGEBBS
-OBJS+= merge.o
-.endif
+#.if defined(MERGEBBS)
+#CFLAGS+= -DMERGEBBS
+#OBJS+= ../upgrade/merge_sob.o
+#.endif
+
LIBS+= $(SRCROOT)/common/bbs/libcmbbs.a \
$(SRCROOT)/common/sys/libcmsys.a
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c
index 2349a68d..1b3aace1 100644
--- a/mbbsd/stuff.c
+++ b/mbbsd/stuff.c
@@ -1,46 +1,16 @@
/* $Id$ */
#include "bbs.h"
+// TODO remove this
/* ----------------------------------------------------- */
/* set file path for boards/user home */
/* ----------------------------------------------------- */
static const char * const str_home_file = "home/%c/%s/%s";
static const char * const str_board_file = "boards/%c/%s/%s";
-static const char * const str_board_n_file = "boards/%c/%s/%s.%d";
-
static const char * const str_dotdir = FN_DIR;
/* XXX set*() all assume buffer size = PATHLEN */
-void
-sethomepath(char *buf, const char *userid)
-{
- assert(is_validuserid(userid));
- snprintf(buf, PATHLEN, "home/%c/%s", userid[0], userid);
-}
-
-void
-sethomedir(char *buf, const char *userid)
-{
- assert(is_validuserid(userid));
- snprintf(buf, PATHLEN, str_home_file, userid[0], userid, str_dotdir);
-}
-
-void
-sethomeman(char *buf, const char *userid)
-{
- assert(is_validuserid(userid));
- snprintf(buf, PATHLEN, str_home_file, userid[0], userid, "man");
-}
-
-
-void
-sethomefile(char *buf, const char *userid, const char *fname)
-{
- assert(is_validuserid(userid));
- assert(fname[0]);
- snprintf(buf, PATHLEN, str_home_file, userid[0], userid, fname);
-}
void
setuserfile(char *buf, const char *fname)
@@ -51,27 +21,6 @@ setuserfile(char *buf, const char *fname)
}
void
-setapath(char *buf, const char *boardname)
-{
- //assert(boardname[0]);
- snprintf(buf, PATHLEN, "man/boards/%c/%s", boardname[0], boardname);
-}
-
-void
-setadir(char *buf, const char *path)
-{
- //assert(path[0]);
- snprintf(buf, PATHLEN, "%s/%s", path, str_dotdir);
-}
-
-void
-setbpath(char *buf, const char *boardname)
-{
- //assert(boardname[0]);
- snprintf(buf, PATHLEN, "boards/%c/%s", boardname[0], boardname);
-}
-
-void
setbdir(char *buf, const char *boardname)
{
//assert(boardname[0]);
@@ -79,37 +28,6 @@ setbdir(char *buf, const char *boardname)
(currmode & MODE_DIGEST ? fn_mandex : str_dotdir));
}
-void
-setbfile(char *buf, const char *boardname, const char *fname)
-{
- //assert(boardname[0]);
- assert(fname[0]);
- snprintf(buf, PATHLEN, str_board_file, boardname[0], boardname, fname);
-}
-
-void
-setbnfile(char *buf, const char *boardname, const char *fname, int n)
-{
- //assert(boardname[0]);
- assert(fname[0]);
- snprintf(buf, PATHLEN, str_board_n_file, boardname[0], boardname, fname, n);
-}
-
-/*
- * input direct
- * output buf: copy direct
- * fname: direct 的檔名部分
- */
-void
-setdirpath(char *buf, const char *direct, const char *fname)
-{
- char *p;
- strcpy(buf, direct);
- p = strrchr(buf, '/');
- assert(p);
- strlcpy(p + 1, fname, PATHLEN-(p+1-buf));
-}
-
/**
* 給定文章標題 title,傳回指到主題的部分的指標。
* @param title
@@ -202,14 +120,7 @@ userid_is_BM(const char *userid, const char *list)
return 0;
}
-int
-belong(const char *filelist, const char *key)
-{
- return file_exist_record(filelist, key);
-}
-
-#ifndef _BBS_UTIL_C_ /* getdata_buf */
time4_t
gettime(int line, time4_t dt, const char*head)
{
@@ -259,12 +170,6 @@ void syncnow(void)
#endif
}
-#endif
-
-
-#ifndef _BBS_UTIL_C_
-/* 這一區都是有關於畫面處理的, 故 _BBS_UTIL_C_ 不須要 */
-
#ifdef PLAY_ANGEL
void
pressanykey_or_callangel(){
@@ -593,8 +498,6 @@ show_helpfile(const char *helpfile)
pressanykey();
}
-#endif // _BBS_UTIL_C_
-
/* ----------------------------------------------------- */
/* use mmap() to malloc large memory in CRITICAL_MEMORY */
/* ----------------------------------------------------- */
@@ -605,7 +508,7 @@ void *MALLOC(int size)
p = (int *)mmap(NULL, (size + 4), PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0);
p[0] = size;
-#if defined(DEBUG) && !defined(_BBS_UTIL_C_)
+#if defined(DEBUG)
vmsgf("critical malloc %d bytes", size);
#endif
return (void *)&p[1];
@@ -615,7 +518,7 @@ void FREE(void *ptr)
{
int size = ((int *)ptr)[-1];
munmap((void *)(&(((int *)ptr)[-1])), size);
-#if defined(DEBUG) && !defined(_BBS_UTIL_C_)
+#if defined(DEBUG)
vmsgf("critical free %d bytes", size);
#endif
}
diff --git a/mbbsd/merge.c b/upgrade/merge_sob.c
index 913f94f5..40a80822 100644
--- a/mbbsd/merge.c
+++ b/upgrade/merge_sob.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $Id: merge.c 3650 2007-12-08 02:37:03Z piaip $ */
#define _XOPEN_SOURCE
#define _ISOC99_SOURCE
/* this is a interface provided when we merge BBS */
diff --git a/util/Makefile b/util/Makefile
index a2d37a83..801489b1 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -8,12 +8,10 @@ CFLAGS+= -DPTTBBS_UTIL
BBSBASE= $(SRCROOT)/include/var.h
UTIL_OBJS= \
- util_cache.o util_record.o util_passwd.o util_var.o \
- util_stuff.o
+ util_cache.o util_record.o util_passwd.o util_var.o
MBBSD_OBJS= \
- cache record passwd var \
- stuff
+ cache record passwd var
# 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結
CPROG_WITH_UTIL= \