summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/admin.c9
-rw-r--r--mbbsd/announce.c10
-rw-r--r--mbbsd/bbs.c25
-rw-r--r--mbbsd/mail.c19
-rw-r--r--mbbsd/name.c65
5 files changed, 83 insertions, 45 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c
index 815bb854..66043aa4 100644
--- a/mbbsd/admin.c
+++ b/mbbsd/admin.c
@@ -1,4 +1,4 @@
-/* $Id: admin.c,v 1.9 2002/05/08 14:11:33 lwms Exp $ */
+/* $Id: admin.c,v 1.10 2002/05/10 19:34:51 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -14,6 +14,7 @@
#include "modes.h"
#include "proto.h"
+extern struct bcache_t *brdshm;
extern char *msg_uid;
extern userec_t xuser;
extern char *err_uid;
@@ -397,8 +398,10 @@ int m_board() {
char bname[32];
stand_title("看板設定");
- make_blist();
- namecomplete(msg_bid, bname);
+ generalnamecomplete(msg_bid, bname, sizeof(bname), brdshm->number,
+ completeboard_compar,
+ completeboard_permission,
+ completeboard_getname);
if(!*bname)
return 0;
m_mod_board(bname);
diff --git a/mbbsd/announce.c b/mbbsd/announce.c
index 2064ba9d..bc05fca6 100644
--- a/mbbsd/announce.c
+++ b/mbbsd/announce.c
@@ -1,4 +1,4 @@
-/* $Id: announce.c,v 1.6 2002/04/29 07:05:45 in2 Exp $ */
+/* $Id: announce.c,v 1.7 2002/05/10 19:34:51 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -20,6 +20,7 @@
#include "modes.h"
#include "proto.h"
+extern struct bcache_t *brdshm;
extern int b_lines;
extern int p_lines;
extern int TagNum;
@@ -506,8 +507,11 @@ static int AnnounceSelect() {
move(3, 0);
clrtoeol();
move(1, 0);
- make_blist();
- namecomplete("選擇精華區看板:", buf);
+ generalnamecomplete("選擇精華區看板:", buf, sizeof(buf),
+ brdshm->number,
+ completeboard_compar,
+ completeboard_permission,
+ completeboard_getname);
if(*buf)
strcpy(xboard, buf);
if(*xboard && (bp = getbcache(getbnum(xboard)))) {
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 2a340e73..97796674 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -1,4 +1,4 @@
-/* $Id: bbs.c,v 1.6 2002/05/10 16:15:50 in2 Exp $ */
+/* $Id: bbs.c,v 1.7 2002/05/10 19:34:51 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -14,6 +14,7 @@
#include "common.h"
#include "proto.h"
+extern struct bcache_t *brdshm;
static int g_board_names(boardheader_t *fhdr) {
AddNameList(fhdr->brdname);
return 0;
@@ -238,6 +239,7 @@ int whereami(int ent, fileheader_t *fhdr, char *direct) {
pressanykey();
return FULLUPDATE;
}
+
static int do_select(int ent, fileheader_t *fhdr, char *direct) {
char bname[20];
char bpath[60];
@@ -247,11 +249,11 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) {
move(0, 0);
clrtoeol();
- allboardcomplete(MSG_SELECT_BOARD, bname, sizeof(bname));
- /*
- make_blist();
- namecomplete(MSG_SELECT_BOARD, bname);
- */
+ generalnamecomplete(MSG_SELECT_BOARD, bname, sizeof(bname),
+ brdshm->number,
+ completeboard_compar,
+ completeboard_permission,
+ completeboard_getname);
if(bname[0]=='\0' || !(i = getbnum(bname)))
return FULLUPDATE;
bh = getbcache(i);
@@ -736,12 +738,11 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) {
bp = getbcache(currbid);
if (bp && (bp->brdattr & BRD_VOTEBOARD))
return FULLUPDATE;
- allboardcomplete("轉錄本文章於看板:", xboard, sizeof(xboard));
- /*
- make_blist();
- namecomplete(MSG_SELECT_BOARD, bname);
- namecomplete("轉錄本文章於看板:", xboard);
- */
+ generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard),
+ brdshm->number,
+ completeboard_compar,
+ completeboard_permission,
+ completeboard_getname);
if(*xboard == '\0' || !haspostperm(xboard))
return FULLUPDATE;
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index 6a635f39..34c629cb 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -1,4 +1,4 @@
-/* $Id: mail.c,v 1.5 2002/04/30 11:15:29 ptt Exp $ */
+/* $Id: mail.c,v 1.6 2002/05/10 19:34:51 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -14,6 +14,7 @@
#include "modes.h"
#include "proto.h"
+extern struct bcache_t *brdshm;
extern int TagNum;
extern int b_lines; /* Screen bottom line number: t_lines-1 */
extern char save_title[]; /* used by editor when inserting */
@@ -1111,13 +1112,16 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) {
char genbuf[200];
char genbuf2[4];
- make_blist();
move(2, 0);
clrtoeol();
move(3, 0);
clrtoeol();
move(1, 0);
- namecomplete("轉錄本文章於看板:", xboard);
+ generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard),
+ brdshm->number,
+ completeboard_compar,
+ completeboard_permission,
+ completeboard_getname);
if(*xboard == '\0' || !haspostperm(xboard))
return FULLUPDATE;
@@ -1231,8 +1235,13 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) {
move(3, 0);
clrtoeol();
move(1, 0);
- make_blist();
- namecomplete("輸入看版名稱 (直接Enter進入私人信件夾):", buf);
+
+ generalnamecomplete("輸入看版名稱 (直接Enter進入私人信件夾):",
+ buf, sizeof(buf),
+ brdshm->number,
+ completeboard_compar,
+ completeboard_permission,
+ completeboard_getname);
if(*buf)
strcpy(xboard, buf);
if(*xboard && (bp = getbcache(getbnum(xboard)))) {
diff --git a/mbbsd/name.c b/mbbsd/name.c
index 1e37db2b..aafac786 100644
--- a/mbbsd/name.c
+++ b/mbbsd/name.c
@@ -1,4 +1,4 @@
-/* $Id: name.c,v 1.2 2002/05/10 16:15:50 in2 Exp $ */
+/* $Id: name.c,v 1.3 2002/05/10 19:34:51 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -473,28 +473,32 @@ void usercomplete(char *prompt, char *data) {
}
}
-int ab_findbound(char *str, int *START, int *END)
+int gnc_findbound(char *str, int *START, int *END,
+ size_t nmemb, int (*compar)(int, char *, int))
{
int start, end, mid, cmp, strl;
strl = strlen(str);
- start = 0, end = brdshm->number - 1;
+ start = 0, end = nmemb - 1;
while( start != end && ((mid = (start + end) / 2) != start) ){
- cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl);
+ cmp = compar(mid, str, strl);
+ //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl);
if( cmp >= 0 )
end = mid;
else
start = mid;
}
++start;
- if( strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0 ){
+ //if( strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0 ){
+ if( compar(start, str, strl) != 0 ){
*START = *END = -1;
return -1;
}
*START = start;
- end = brdshm->number - 1;
+ end = nmemb - 1;
while( start != end && ((mid = (start + end) / 2) != start) ){
- cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl);
+ cmp = compar(mid, str, strl);
+ //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl);
if( cmp <= 0 )
start = mid;
else
@@ -504,25 +508,26 @@ int ab_findbound(char *str, int *START, int *END)
return 0;
}
-#define ab_havepermission(where) \
- Ben_Perm(brdshm->sorted[0][where])
-
-int ab_completeone(char *data, int start, int end)
+int gnc_completeone(char *data, int start, int end,
+ int (*permission)(int), char* (*getname)(int))
{
int i, count, at;
for( i = start, at = count = 0 ; i <= end && count < 2 ; ++i )
- if( ab_havepermission(i) ){
+ if( permission(i) ){
at = i;
++count;
}
if( count == 1 ){
- strcpy(data, brdshm->sorted[0][at]->brdname);
+ strcpy(data, getname(at));
return 1;
}
return 0;
}
-void allboardcomplete(char *prompt, char *data, int len)
+
+void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb,
+ int (*compar)(int, char *, int),
+ int (*permission)(int), char* (*getname)(int))
{
int x, y, origx, origy, ch, i, morelist = -1, col;
int start, end, ptr;
@@ -545,8 +550,8 @@ void allboardcomplete(char *prompt, char *data, int len)
data[ptr] = 0;
outc('\n');
if( ptr != 0 ){
- ab_findbound(data, &start, &end);
- ab_completeone(data, start, end);
+ gnc_findbound(data, &start, &end, nmemb, compar);
+ gnc_completeone(data, start, end, permission, getname);
}
break;
}
@@ -555,9 +560,9 @@ void allboardcomplete(char *prompt, char *data, int len)
continue;
if( morelist == -1 ){
- if( ab_findbound(data, &start, &end) == -1 )
+ if( gnc_findbound(data, &start, &end, nmemb, compar) == -1 )
continue;
- if( ab_completeone(data, start, end) ){
+ if( gnc_completeone(data, start, end, permission, getname) ){
move(origy, origx);
outs(data);
ptr = strlen(data);
@@ -577,9 +582,9 @@ void allboardcomplete(char *prompt, char *data, int len)
col = 0;
while(len + col < 79) {
for( i = 0 ; morelist <= end && i < p_lines ; ++morelist){
- if( ab_havepermission(morelist) ){
+ if( permission(morelist) ){
move(3 + i, col);
- prints("%s ", brdshm->sorted[0][morelist]->brdname);
+ prints("%s ", getname(morelist));
++i;
}
}
@@ -610,11 +615,11 @@ void allboardcomplete(char *prompt, char *data, int len)
data[ptr] = ch;
++ptr;
data[ptr] = 0;
- if( ab_findbound(data, &start, &end) < 0 )
+ if( gnc_findbound(data, &start, &end, nmemb, compar) < 0 )
data[--ptr] = 0;
else{
for( i = start ; i <= end ; ++i )
- if( ab_havepermission(i) )
+ if( permission(i) )
break;
if( i == end + 1 )
data[--ptr] = 0;
@@ -639,3 +644,19 @@ void allboardcomplete(char *prompt, char *data, int len)
outc('\n');
}
}
+
+int completeboard_compar(int where, char *str, int len)
+{
+ return strncasecmp(brdshm->sorted[0][where]->brdname, str, len);
+}
+
+int completeboard_permission(int where)
+{
+ return Ben_Perm(brdshm->sorted[0][where]);
+}
+
+char *completeboard_getname(int where)
+{
+ return brdshm->sorted[0][where]->brdname;
+}
+