summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-11-28 12:01:10 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-11-28 12:01:10 +0800
commit30edc2d47868e24f54a9505f7eb66c0a42c64b4d (patch)
treea6f58e9065121bf8b7f5451f8816dc3038ad46f2 /mbbsd
parent93e11784d623e3d0e178f13bfe560ebad6ffbaf9 (diff)
downloadpttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.gz
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.bz2
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.lz
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.xz
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.zst
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.zip
merge gb branch back
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1379 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/Makefile4
-rw-r--r--mbbsd/convert.c66
-rw-r--r--mbbsd/fav.c2
-rw-r--r--mbbsd/io.c49
-rw-r--r--mbbsd/mbbsd.c16
5 files changed, 128 insertions, 9 deletions
diff --git a/mbbsd/Makefile b/mbbsd/Makefile
index 911c3273..126a8317 100644
--- a/mbbsd/Makefile
+++ b/mbbsd/Makefile
@@ -9,8 +9,8 @@ LDFLAGS+= -L/usr/local/lib/mysql -lmysqlclient
PROG= mbbsd
OBJS= admin.o announce.o args.o assess.o bbs.o board.o cache.o cal.o card.o\
- chat.o chc.o chicken.o dark.o edit.o fav.o friend.o gamble.o gomo.o\
- guess.o indict.o io.o kaede.o lovepaper.o mail.o mbbsd.o menu.o\
+ chat.o chc.o chicken.o convert.o dark.o edit.o fav.o friend.o gamble.o\
+ gomo.o guess.o indict.o io.o kaede.o lovepaper.o mail.o mbbsd.o menu.o\
more.o name.o osdep.o othello.o page.o read.o record.o\
register.o screen.o stuff.o talk.o term.o topsong.o user.o\
vice.o vote.o xyz.o voteboard.o syspost.o var.o passwd.o calendar.o
diff --git a/mbbsd/convert.c b/mbbsd/convert.c
new file mode 100644
index 00000000..c7140d03
--- /dev/null
+++ b/mbbsd/convert.c
@@ -0,0 +1,66 @@
+/* $Id: convert.c 1374 2003-11-27 14:11:40Z victor $ */
+/*
+ * The following code is copied and modified from "autoconvert" with GPL.
+ */
+
+#include "convert.h"
+
+#define BtoG_bad1 0xa1
+#define BtoG_bad2 0xf5
+#define GtoB_bad1 0xa1
+#define GtoB_bad2 0xbc
+
+char *hzconvert(char *, int *, char *, void (*dbcvrt)());
+
+extern unsigned char GtoB[], BtoG[];
+
+#define c1 (unsigned char)(s[0])
+#define c2 (unsigned char)(s[1])
+
+static void g2b(char *s)
+{
+ unsigned int i;
+
+ if ((c2 >= 0xa1) && (c2 <= 0xfe)) {
+ if ((c1 >= 0xa1) && (c1 <= 0xa9)) {
+ i = ((c1 - 0xa1) * 94 + (c2 - 0xa1)) * 2;
+ s[0] = GtoB[i++]; s[1] = GtoB[i];
+ return;
+ } else if ((c1 >= 0xb0) && (c1 <= 0xf7)) {
+ i = ((c1 - 0xb0 + 9) * 94 + (c2 - 0xa1)) * 2;
+ s[0] = GtoB[i++]; s[1] = GtoB[i];
+ return;
+ }
+ }
+ s[0] = GtoB_bad1; s[1] = GtoB_bad2;
+}
+
+static void b2g(char *s)
+{
+ int i;
+
+ if ((c1 >= 0xa1) && (c1 <= 0xf9)) {
+ if ((c2 >= 0x40) && (c2 <= 0x7e)) {
+ i = ((c1 - 0xa1) * 157 + (c2 - 0x40)) * 2;
+ s[0] = BtoG[i++]; s[1] = BtoG[i];
+ return;
+ } else if ((c2 >= 0xa1) && (c2 <= 0xfe)) {
+ i = ((c1 - 0xa1) * 157 + (c2 - 0xa1) + 63) * 2;
+ s[0] = BtoG[i++]; s[1] = BtoG[i];
+ return;
+ }
+ }
+ s[0] = BtoG_bad1; s[1] = BtoG_bad2;
+}
+
+signed char *gb2big(unsigned char *s, int plen)
+{
+ unsigned char c = 0;
+ return hzconvert(s, &plen, &c, g2b);
+}
+
+unsigned char *big2gb(unsigned char *s, int plen)
+{
+ unsigned char c = 0;
+ return hzconvert(s, &plen, &c, b2g);
+}
diff --git a/mbbsd/fav.c b/mbbsd/fav.c
index 12aca076..6fc88d0a 100644
--- a/mbbsd/fav.c
+++ b/mbbsd/fav.c
@@ -436,7 +436,7 @@ static void write_favrec(int fd, fav_t *fp)
int fav_save(void)
{
int fd;
- char buf[128], buf2[128];
+ char buf[128];
fav_t *fp = get_fav_root();
#ifdef MEM_CHECK
if (fav_memcheck() != MEM_CHECK)
diff --git a/mbbsd/io.c b/mbbsd/io.c
index ef5d76da..273017b8 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -15,14 +15,54 @@ static int obufsize = 0, ibufsize = 0;
static int icurrchar = 0;
/* ----------------------------------------------------- */
-/* output routines */
+/* convert routines */
/* ----------------------------------------------------- */
+typedef int (* read_write_type)(int, void *, size_t);
+static read_write_type write_type = (read_write_type)write;
+static read_write_type read_type = read;
+
+int converting_read(int fd, void *buf, size_t count)
+{
+ int len = read(fd, buf, count);
+ if (len >= 0)
+ gb2big(buf, len);
+ return len;
+}
+int converting_write(int fd, void *buf, size_t count)
+{
+ big2gb(buf, count);
+ return write(fd, buf, count);
+}
+
+void set_converting_type(int which)
+{
+ if (which == 0) {
+ read_type = read;
+ write_type = (read_write_type)write;
+ }
+ else if (which == 1) {
+ read_type = converting_read;
+ write_type = converting_write;
+ }
+}
+
+inline static int read_wrapper(int fd, void *buf, size_t count) {
+ return (*read_type)(fd, buf, count);
+}
+
+inline static int write_wrapper(int fd, void *buf, size_t count) {
+ return (*write_type)(fd, buf, count);
+}
+
+/* ----------------------------------------------------- */
+/* output routines */
+/* ----------------------------------------------------- */
void
oflush()
{
if (obufsize) {
- write(1, outbuf, obufsize);
+ write_wrapper(1, outbuf, obufsize);
obufsize = 0;
}
}
@@ -40,7 +80,7 @@ output(char *s, int len)
assert(len<OBUFSIZE);
if (obufsize + len > OBUFSIZE) {
- write(1, outbuf, obufsize);
+ write_wrapper(1, outbuf, obufsize);
obufsize = 0;
}
memcpy(outbuf + obufsize, s, len);
@@ -51,6 +91,7 @@ int
ochar(int c)
{
if (obufsize > OBUFSIZE - 1) {
+ /* suppose one byte data doesn't need to be converted. */
write(1, outbuf, obufsize);
obufsize = 0;
}
@@ -134,7 +175,7 @@ dogetch()
#ifdef SKIP_TELNET_CONTROL_SIGNAL
do{
#endif
- while ((len = read(0, inbuf, IBUFSIZE)) <= 0) {
+ while ((len = read_wrapper(0, inbuf, IBUFSIZE)) <= 0) {
if (len == 0 || errno != EINTR)
abort_bbs(0);
/* raise(SIGHUP); */
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index e99fa7e5..2bfb225b 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -498,8 +498,9 @@ inline static void mkuserdir(char *userid)
static void
login_query()
{
- char uid[IDLEN + 1], passbuf[PASSLEN];
- int attempts;
+ /* uid 加一位, for gb login */
+ char uid[IDLEN + 2], passbuf[PASSLEN];
+ int attempts, len;
resolve_garbage();
now = time(0);
@@ -526,6 +527,16 @@ login_query()
#endif
getdata(20, 0, "請輸入代號,或以[guest]參觀,以[new]註冊:",
uid, sizeof(uid), DOECHO);
+
+ /* switch to gb mode if uid end with '.' */
+ len = strlen(uid);
+ if (uid[0] && uid[len - 1] == '.') {
+ set_converting_type(1);
+ uid[len - 1] = 0;
+ }
+ else if (len == IDLEN + 1)
+ uid[len - 1] = 0;
+
if (strcasecmp(uid, str_new) == 0) {
#ifdef LOGINASNEW
new_register();
@@ -995,6 +1006,7 @@ start_client()
do_term_init();
signal(SIGALRM, abort_bbs);
alarm(600);
+
login_query(); /* Ptt 加上login time out */
m_init(); /* init the user mail path */
user_login();