summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-09-09 15:46:20 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-09-09 15:46:20 +0800
commit973bbd733d1351ea637c221e0f09526e08203a77 (patch)
tree1cf97369ad23f923415a626c4036b6aade38ef28
parenta55228834422fa5d14c27c57f0b39a258425fdcf (diff)
downloadpttbbs-973bbd733d1351ea637c221e0f09526e08203a77.tar
pttbbs-973bbd733d1351ea637c221e0f09526e08203a77.tar.gz
pttbbs-973bbd733d1351ea637c221e0f09526e08203a77.tar.bz2
pttbbs-973bbd733d1351ea637c221e0f09526e08203a77.tar.lz
pttbbs-973bbd733d1351ea637c221e0f09526e08203a77.tar.xz
pttbbs-973bbd733d1351ea637c221e0f09526e08203a77.tar.zst
pttbbs-973bbd733d1351ea637c221e0f09526e08203a77.zip
Remove curredit shared variable.
The "curredit" trick is very poor for task re-entrance. Hope nothing is broken by this change. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5866 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/include/common.h1
-rw-r--r--pttbbs/include/modes.h5
-rw-r--r--pttbbs/include/proto.h2
-rw-r--r--pttbbs/mbbsd/bbs.c39
-rw-r--r--pttbbs/mbbsd/board.c1
-rw-r--r--pttbbs/mbbsd/edit.c26
-rw-r--r--pttbbs/mbbsd/mail.c51
-rw-r--r--pttbbs/mbbsd/read.c2
-rw-r--r--pttbbs/mbbsd/talk.c14
-rw-r--r--pttbbs/mbbsd/var.c1
10 files changed, 59 insertions, 83 deletions
diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h
index eaa5112b..762979eb 100644
--- a/pttbbs/include/common.h
+++ b/pttbbs/include/common.h
@@ -242,6 +242,7 @@
#define EDITFLAG_KIND_NEWPOST (0x00000010)
#define EDITFLAG_KIND_REPLYPOST (0x00000020)
#define EDITFLAG_KIND_SENDMAIL (0x00000040)
+#define EDITFLAG_KIND_MAILLIST (0x00000080)
#define EDITFLAG_WARN_NOSELFDEL (0x00000100)
#define EDIT_ABORTED -1
diff --git a/pttbbs/include/modes.h b/pttbbs/include/modes.h
index b50e9719..7591a58b 100644
--- a/pttbbs/include/modes.h
+++ b/pttbbs/include/modes.h
@@ -137,11 +137,6 @@
#define MODE_SELECT 0x0080 /* 搜尋使用者標題 */
#define MODE_DIRTY 0x0100 /* 是否更動過 userflag */
-/* for curredit */
-#define EDIT_MAIL 1 /* 目前是 mail/board ? */
-#define EDIT_LIST 2 /* 是否為 mail list ? */
-#define EDIT_BOTH 4 /* both reply to author/board ? */
-
/* read.c 中的模式 */
#define TAG_NIN 0 /* 不屬於 TagList */
#define TAG_TOGGLE 1 /* 切換 Taglist */
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h
index 36660f2a..c7ac9a39 100644
--- a/pttbbs/include/proto.h
+++ b/pttbbs/include/proto.h
@@ -89,7 +89,7 @@ void outgo_post(const fileheader_t *fh, const char *board, const char *userid, c
int edit_title(int ent, fileheader_t *fhdr, const char *direct);
int whereami(void);
void set_board(void);
-int do_post(void);
+int do_post(int edflags);
int ReadSelect(void);
int save_violatelaw(void);
int board_select(void);
diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c
index 7cea5953..ae3f65c2 100644
--- a/pttbbs/mbbsd/bbs.c
+++ b/pttbbs/mbbsd/bbs.c
@@ -1234,7 +1234,7 @@ does_board_have_public_bm(const boardheader_t *bp) {
}
static int
-do_post_article()
+do_post_article(int edflags)
{
fileheader_t postfile;
char fpath[PATHLEN], buf[STRLEN];
@@ -1248,7 +1248,7 @@ do_post_article()
"公告" // TN_ANNOUNCE
};
boardheader_t *bp;
- int islocal, posttype=-1, edflags = 0;
+ int islocal, posttype=-1;
char save_title[STRLEN];
const char *reason = "無法發文";
@@ -1349,7 +1349,6 @@ do_post_article()
if (save_title[0] == '\0')
return FULLUPDATE;
- curredit &= ~EDIT_MAIL;
setutmpmode(POSTING);
/* 未具備 Internet 權限者,只能在站內發表文章 */
/* 板主預設站內存檔 */
@@ -1369,8 +1368,8 @@ do_post_article()
Copy(genbuf, fpath);
}
- edflags = EDITFLAG_ALLOWTITLE;
- edflags = solveEdFlagByBoard(currboard, edflags);
+ edflags |= EDITFLAG_ALLOWTITLE;
+ edflags |= solveEdFlagByBoard(currboard, edflags);
if (bp->brdattr & BRD_NOSELFDELPOST)
edflags |= EDITFLAG_WARN_NOSELFDEL;
@@ -1383,13 +1382,6 @@ do_post_article()
};
#endif
- // XXX I think the 'kind' determination looks really weird here.
- // However legacy BBS code here was a mass... so let's workaround it.
- edflags |= (quote_file[0] ?
- EDITFLAG_KIND_REPLYPOST : EDITFLAG_KIND_NEWPOST);
- if (curredit & EDIT_BOTH)
- edflags |= EDITFLAG_KIND_SENDMAIL;
-
money = vedit2(fpath, YEA, &islocal, save_title, edflags);
if (money == EDIT_ABORTED) {
unlink(fpath);
@@ -1531,8 +1523,7 @@ do_post_article()
clrtobot();
/* 回應到原作者信箱 */
-
- if (curredit & EDIT_BOTH) {
+ if (edflags & EDITFLAG_KIND_SENDMAIL) {
char *str, *msg = NULL;
genbuf[0] = 0;
@@ -1580,8 +1571,8 @@ do_post_article()
msg = "作者無法收信";
}
outs(msg);
- curredit ^= EDIT_BOTH;
- } // if (curredit & EDIT_BOTH)
+ }
+
if (currbrdattr & BRD_ANONYMOUS)
do_crosspost(BN_UNANONYMOUS, &postfile, fpath);
#ifdef USE_COOLDOWN
@@ -1602,8 +1593,12 @@ do_post_article()
return FULLUPDATE;
}
+int new_post() {
+ return do_post(EDITFLAG_KIND_NEWPOST);
+}
+
int
-do_post(void)
+do_post(int edflags)
{
boardheader_t *bp;
STATINC(STAT_DOPOST);
@@ -1612,7 +1607,7 @@ do_post(void)
if (bp->brdattr & BRD_VOTEBOARD)
return do_voteboard(0);
else if (!(bp->brdattr & BRD_GROUPBOARD))
- return do_post_article();
+ return do_post_article(edflags);
return 0;
}
@@ -1626,6 +1621,7 @@ static void
do_generalboardreply(/*const*/ fileheader_t * fhdr)
{
char genbuf[3];
+ int edflags = EDITFLAG_KIND_REPLYPOST;
assert(0<=currbid-1 && currbid-1<MAX_BOARD);
@@ -1655,12 +1651,11 @@ do_generalboardreply(/*const*/ fileheader_t * fhdr)
case 'b':
// TODO(piaip) Check if fhdr has valid author.
- curredit = EDIT_BOTH;
+ edflags |= EDITFLAG_KIND_SENDMAIL;
default:
strlcpy(currtitle, fhdr->title, sizeof(currtitle));
strlcpy(quote_user, fhdr->owner, sizeof(quote_user));
- do_post();
- curredit &= ~EDIT_BOTH;
+ do_post(edflags);
}
}
*quote_file = 0;
@@ -4347,7 +4342,7 @@ const onekey_t read_comms[] = {
{ 0, NULL }, // Ctrl('M')
{ 0, NULL }, // Ctrl('N')
{ 0, NULL }, // Ctrl('O') // BETTER NOT USE ^O - UNIX not work
- { 0, do_post }, // Ctrl('P')
+ { 0, new_post }, // Ctrl('P')
{ 0, NULL }, // Ctrl('Q')
{ 0, NULL }, // Ctrl('R')
{ 0, NULL }, // Ctrl('S')
diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c
index e1c4bcb7..2bbb7710 100644
--- a/pttbbs/mbbsd/board.c
+++ b/pttbbs/mbbsd/board.c
@@ -121,7 +121,6 @@ int enter_board(const char *boardname)
set_board();
setbdir(currdirect, currboard);
- curredit &= ~EDIT_MAIL;
return 0;
}
diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c
index b5f5259c..cc2d732b 100644
--- a/pttbbs/mbbsd/edit.c
+++ b/pttbbs/mbbsd/edit.c
@@ -153,17 +153,20 @@ typedef struct editor_internal_t {
textline_t *deleted_line; /* deleted line. Just keep one deleted line. */
textline_t *oldcurrline;
+ struct editor_internal_t *prev;
+
+ int flags; /* editor flags. */
int currln; /* current line of the article. */
- short currpnt; /* current column of the article. */
int totaln; /* last line of the article. */
int curr_window_line; /* current line to the window. */
+ int blockln; /* the row you started to select block. */
+ short currpnt; /* current column of the article. */
short last_margin;
short edit_margin; /* when the cursor moves out of range (say,
t_columns), shift this length of the string
so you won't see the first edit_margin-th
character. */
short lastindent;
- int blockln; /* the row you started to select block. */
char last_phone_mode;
char ifuseanony :1;
@@ -174,15 +177,12 @@ typedef struct editor_internal_t {
char indent_mode :1;
char phone_mode :1;
char raw_mode :1;
+ char synparser; // syntax parser
char *searched_string;
char *sitesig_string;
char *(*substr_fp) ();
- char synparser; // syntax parser
-
- struct editor_internal_t *prev;
-
} editor_internal_t;
// } __attribute__ ((packed))
@@ -1478,7 +1478,9 @@ do_quote(void)
while (*(++ptr) == ' ');
/* 順手牽羊,取得 author's address */
- if ((curredit & EDIT_BOTH) && (str = strchr(quote_user, '.'))) {
+ if ((curr_buf->flags & EDITFLAG_KIND_SENDMAIL) &&
+ (curr_buf->flags & EDITFLAG_KIND_REPLYPOST) &&
+ (str = strchr(quote_user, '.'))) {
strcpy(++str, ptr);
str = strchr(str, ' ');
assert(str);
@@ -1513,7 +1515,8 @@ do_quote(void)
insert_string(buf);
}
else {
- if (curredit & EDIT_LIST) /* 去掉 mail list 之 header */
+ /* 去掉 mail list 之 header */
+ if (curr_buf->flags & EDITFLAG_KIND_MAILLIST)
while (fgets(buf, sizeof(buf), inf) && (!strncmp(buf, "※ ", 3)));
while (fgets(buf, sizeof(buf), inf)) {
if (!strcmp(buf, "--\n"))
@@ -1607,7 +1610,7 @@ void
write_header(FILE * fp, const char *mytitle)
{
assert(mytitle);
- if (curredit & EDIT_MAIL || curredit & EDIT_LIST) {
+ if (curr_buf->flags & (EDITFLAG_KIND_MAILLIST | EDITFLAG_KIND_SENDMAIL)) {
fprintf(fp, "%s %s (%s)\n", str_author1, cuser.userid,
cuser.nickname
);
@@ -1978,7 +1981,8 @@ write_file(const char *fpath, int saveheader, int *islocal, char mytitle[STRLEN]
if (!aborted) {
- if (saveheader && !(curredit & EDIT_MAIL) && check_quote())
+ if (saveheader && !(curr_buf->flags & EDITFLAG_KIND_SENDMAIL) &&
+ check_quote())
return KEEP_EDITING;
assert(*fpath);
@@ -3578,6 +3582,8 @@ vedit2(const char *fpath, int saveheader, int *islocal, char title[STRLEN], int
#endif
enter_edit_buffer();
+ curr_buf->flags = flags;
+
if (*fpath) {
int tmp = read_file(fpath, (flags & EDITFLAG_TEXTONLY) ? 1 : 0);
diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c
index 5bcd4fae..60745e6f 100644
--- a/pttbbs/mbbsd/mail.c
+++ b/pttbbs/mbbsd/mail.c
@@ -746,8 +746,6 @@ do_send(const char *userid, const char *title, const char *log_source)
return -1;
if (!(xuser.userlevel & PERM_READMAIL))
return -3;
-
- curredit |= EDIT_MAIL;
}
/* process title */
if (title)
@@ -950,6 +948,7 @@ multi_send(const char *title)
int recipient, listing;
char genbuf[PATHLEN];
char buf[IDLEN+1];
+ int edflags = EDITFLAG_ALLOWTITLE;
struct Vector namelist;
int i;
const char *p;
@@ -1029,11 +1028,10 @@ multi_send(const char *title)
fprintf(fp, "\n%s\n\n", genbuf);
fclose(fp);
}
- curredit |= EDIT_LIST;
+ edflags |= EDITFLAG_KIND_MAILLIST;
if (vedit(fpath, YEA, NULL, save_title) == EDIT_ABORTED) {
unlink(fpath);
- curredit = 0;
Vector_delete(&namelist);
vmsg(msg_cancel);
return;
@@ -1057,7 +1055,6 @@ multi_send(const char *title)
}
hold_mail(fpath, NULL, save_title);
unlink(fpath);
- curredit = 0;
Vector_delete(&namelist);
} else {
Vector_delete(&namelist);
@@ -1134,6 +1131,7 @@ mail_all(void)
char genbuf[200];
int i, unum;
char *userid;
+ int edflags;
char save_title[STRLEN];
vs_hdr("給所有使用者的系統通告");
@@ -1152,15 +1150,13 @@ mail_all(void)
}
*quote_file = 0;
- curredit |= EDIT_MAIL;
- if (vedit(fpath, YEA, NULL, save_title) == EDIT_ABORTED) {
- curredit = 0;
+ edflags = EDITFLAG_ALLOWTITLE | EDITFLAG_KIND_SENDMAIL;
+ if (vedit2(fpath, YEA, NULL, save_title, edflags) == EDIT_ABORTED) {
unlink(fpath);
outs(msg_cancel);
pressanykey();
return 0;
}
- curredit = 0;
setutmpmode(MAILALL);
vs_hdr("寄信中...");
@@ -1670,8 +1666,8 @@ mail_reply(int ent, fileheader_t * fhdr, const char *direct)
vs_hdr("回 信");
- /* 判斷是 boards 或 mail */
- if (curredit & EDIT_MAIL)
+ /* Trick: mail 回信時 ent/direct=0, currstat = RMAIL. */
+ if (currstat == RMAIL)
setuserfile(quote_file, fhdr->filename);
else
setbfile(quote_file, currboard, fhdr->filename);
@@ -1733,7 +1729,6 @@ mail_reply(int ent, fileheader_t * fhdr, const char *direct)
prints("\n收信人: %s\n標 題: %s\n", uid, save_title);
/* edit, then send the mail */
- ent = curredit;
switch (do_send(uid, save_title, __FUNCTION__)) {
case -1:
outs(err_uid);
@@ -1747,16 +1742,14 @@ mail_reply(int ent, fileheader_t * fhdr, const char *direct)
case 0:
/* success */
- if ( direct && /* for board, no direct */
- (curredit & EDIT_MAIL) &&
- !(fhdr->filemode & FILE_REPLIED))
+ if (direct && /* for board, no direct */
+ !(fhdr->filemode & FILE_REPLIED))
{
fhdr->filemode |= FILE_REPLIED;
substitute_fileheader(direct, fhdr, fhdr, oent);
}
break;
}
- curredit = ent;
pressanykey();
quote_user[0]='\0';
quote_file[0]='\0';
@@ -1766,19 +1759,6 @@ mail_reply(int ent, fileheader_t * fhdr, const char *direct)
}
static int
-mail_edit(int ent GCC_UNUSED, fileheader_t * fhdr, const char *direct)
-{
- char genbuf[PATHLEN];
-
- if (!HasUserPerm(PERM_SYSOP))
- return DONOTHING;
-
- setdirpath(genbuf, direct, fhdr->filename);
- veditfile(genbuf);
- return FULLUPDATE;
-}
-
-static int
mail_nooutmail(int ent GCC_UNUSED, fileheader_t * fhdr GCC_UNUSED,
const char *direct GCC_UNUSED)
{
@@ -2116,21 +2096,28 @@ int
m_read(void)
{
int back_bid;
+ static int cReEntrance = 0;
+
if (!HasUserPerm(PERM_READMAIL))
return DONOTHING;
+ if (cReEntrance > 0) {
+ vmsg("抱歉,您之前已在信箱中。");
+ return FULLUPDATE;
+ }
+
if (get_num_records(currmaildir, sizeof(fileheader_t))) {
int was_in_digest = currmode & MODE_DIGEST;
currmode &= ~MODE_DIGEST;
- curredit = EDIT_MAIL;
back_bid = currbid;
currbid = 0;
+ cReEntrance++;
i_read(RMAIL, currmaildir, mailtitle, maildoent, mail_comms, -1);
currbid = back_bid;
- curredit = 0;
currmode |= was_in_digest;
setmailalert();
+ cReEntrance--;
return 0;
} else {
outs("您沒有來信");
@@ -2288,7 +2275,7 @@ static const onekey_t mail_comms[] = {
{ 0, NULL }, // 'B'
{ 0, NULL }, // 'C'
{ 1, del_range_mail }, // 'D'
- { 1, mail_edit }, // 'E'
+ { 0, NULL }, // 'E'
{ 0, NULL }, // 'F'
{ 0, NULL }, // 'G'
{ 0, NULL }, // 'H'
diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c
index c9d19805..1913378b 100644
--- a/pttbbs/mbbsd/read.c
+++ b/pttbbs/mbbsd/read.c
@@ -1365,7 +1365,7 @@ i_read(int cmdmode, const char *direct, void (*dotitle) (),
}
/* no break */
case READ_REDRAW:
- if (curredit & EDIT_MAIL)
+ if (currstat == RMAIL)
vs_footer(" 鴻雁往返 ",
" (R/y)回信 (x)站內轉寄 (d/D)刪信 (^P)寄發新信 \t(←/q)離開");
else
diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c
index 402554db..53308fc7 100644
--- a/pttbbs/mbbsd/talk.c
+++ b/pttbbs/mbbsd/talk.c
@@ -2601,7 +2601,6 @@ userlist(void)
prints("[寄信] 收信人:%s", userid);
my_send(userid);
setutmpmode(LUSERS);
- curredit = 0;
redrawall = redraw = 1;
}
break;
@@ -2671,15 +2670,10 @@ userlist(void)
case 'r':
if (HasBasicUserPerm(PERM_LOGINOK)) {
- if (curredit & EDIT_MAIL) {
- /* deny reentrance, which may cause many problems */
- vmsg("你進入使用者列表前就已經在閱\讀信件了");
- } else {
- // XXX in fact we should check size here...
- // chkmailbox();
- m_read();
- setutmpmode(LUSERS);
- }
+ // XXX in fact we should check size here...
+ // chkmailbox();
+ m_read();
+ setutmpmode(LUSERS);
redrawall = redraw = 1;
}
break;
diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c
index 5b2429d1..6efbd822 100644
--- a/pttbbs/mbbsd/var.c
+++ b/pttbbs/mbbsd/var.c
@@ -132,7 +132,6 @@ const char * const str_pager_modes[PAGER_MODES] =
int usernum;
int currmode = 0;
int currsrmode = 0;
-int curredit = 0;
int currbid;
char quote_file[80] = "\0";
char quote_user[80] = "\0";