diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-03-27 14:26:11 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-03-27 14:26:11 +0800 |
commit | c17b1ec0c4c66cbe2761fa0e8c83831e6258d11d (patch) | |
tree | 21e0d184cdf9f58095dce3c486522e2266449391 /common/bbs | |
parent | 3e774d4829229f4132e3b6895b572a117f60c99d (diff) | |
download | pttbbs-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
Diffstat (limited to 'common/bbs')
-rw-r--r-- | common/bbs/Makefile | 2 | ||||
-rw-r--r-- | common/bbs/file.c | 8 | ||||
-rw-r--r-- | common/bbs/names.c | 29 | ||||
-rw-r--r-- | common/bbs/path.c | 110 |
4 files changed, 148 insertions, 1 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 ªºÀɦW³¡¤À + */ +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)); +} + |