summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mbbsd/assess.c4
-rw-r--r--mbbsd/bbs.c8
-rw-r--r--mbbsd/go.c8
-rw-r--r--mbbsd/gomo.c7
-rw-r--r--mbbsd/kaede.c3
-rw-r--r--mbbsd/reversi.c7
-rw-r--r--mbbsd/visio.c43
7 files changed, 50 insertions, 30 deletions
diff --git a/mbbsd/assess.c b/mbbsd/assess.c
index c1bb90ed..25847c13 100644
--- a/mbbsd/assess.c
+++ b/mbbsd/assess.c
@@ -93,7 +93,7 @@ u_fixgoodpost(void)
}
while (!endinput && newgp < MAXGP)
{
- int y, x = 0;
+ int y;
boardheader_t *bh = NULL;
move(1, 0); clrtobot();
@@ -123,7 +123,7 @@ u_fixgoodpost(void)
bh = getbcache(bid);
strlcpy(bname, bh->brdname, sizeof(bname));
prints("已找到看板 --> %s\n", bname);
- getyx(&y, &x);
+ y = vgety();
// loop AID query
while (newgp < MAXGP)
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 035bc8a6..9c165bc0 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -4084,8 +4084,12 @@ ReadSelect(void)
Read();
changed = 1;
}
- // no need to set utmpbid here...
- // setutmpbid(0);
+ // need to set utmpbid here...
+ // because Read() just restores settings.
+ // and 's' directly calls here.
+ // so if we don't reset then utmpbid will be out-of-sync.
+ // fix someday...
+ setutmpbid(0);
currutmp->mode = mode0;
currstat = stat0;
return changed;
diff --git a/mbbsd/go.c b/mbbsd/go.c
index aca63de4..aa5451ca 100644
--- a/mbbsd/go.c
+++ b/mbbsd/go.c
@@ -834,8 +834,8 @@ go_genlog(ChessInfo* info, FILE* fp, ChessGameResult result)
const static char ColName[] = "ABCDEFGHJKLMNOPQRST";
const int nStep = info->history.used;
char buf[ANSILINELEN] = "";
- int i, x, y;
- int sethand = 0;
+ int i, sethand = 0;
+ VREFCUR cur;
if (nStep > 0) {
const go_step_t* const step =
@@ -844,14 +844,14 @@ go_genlog(ChessInfo* info, FILE* fp, ChessGameResult result)
sethand = step->loc.r;
}
- getyx(&y, &x);
+ cur = vcur_save();
for (i = 1; i <= 22; i++)
{
move(i, 0);
inansistr(buf, sizeof(buf)-1);
fprintf(fp, "%s\n", buf);
}
- move(y, x);
+ vcur_restore(cur);
fprintf(fp, "\n");
fprintf(fp, "按 z 可進入打譜模式\n");
diff --git a/mbbsd/gomo.c b/mbbsd/gomo.c
index b18fe5d0..5507913f 100644
--- a/mbbsd/gomo.c
+++ b/mbbsd/gomo.c
@@ -422,16 +422,17 @@ gomo_genlog(ChessInfo* info, FILE* fp, ChessGameResult result)
{
char buf[ANSILINELEN] = "";
const int nStep = info->history.used;
- int i, x, y;
+ int i;
+ VREFCUR cur;
- getyx(&y, &x);
+ cur = vcur_save();
for (i = 1; i <= 18; i++)
{
move(i, 0);
inansistr(buf, sizeof(buf)-1);
fprintf(fp, "%s\n", buf);
}
- move(y, x);
+ vcur_restore(cur);
fprintf(fp, "\n");
fprintf(fp, "按 z 可進入打譜模式\n");
diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c
index 321d52e8..c3a8f797 100644
--- a/mbbsd/kaede.c
+++ b/mbbsd/kaede.c
@@ -116,8 +116,7 @@ outslr(const char *left, int leftlen, const char *right, int rightlen)
void
out_lines(const char *str, int line)
{
- int y, x;
- getyx(&y, &x);
+ int y = vgety();
while (*str && line) {
if (*str == '\n')
{
diff --git a/mbbsd/reversi.c b/mbbsd/reversi.c
index d29d8613..eec0c8c3 100644
--- a/mbbsd/reversi.c
+++ b/mbbsd/reversi.c
@@ -345,16 +345,17 @@ reversi_genlog(ChessInfo* info, FILE* fp, ChessGameResult result)
{
char buf[ANSILINELEN] = "";
const int nStep = info->history.used;
- int i, x, y;
+ int i;
+ VREFCUR cur;
- getyx(&y, &x);
+ cur = vcur_save();
for (i = 2; i <= 21; i++)
{
move(i, 0);
inansistr(buf, sizeof(buf)-1);
fprintf(fp, "%s\n", buf);
}
- move(y, x);
+ vcur_restore(cur);
fprintf(fp, "\n");
fprintf(fp, "按 z 可進入打譜模式\n");
diff --git a/mbbsd/visio.c b/mbbsd/visio.c
index 59a69c2e..b4845f59 100644
--- a/mbbsd/visio.c
+++ b/mbbsd/visio.c
@@ -27,6 +27,11 @@
#define SAFE_MAX_COL (MAX_COL-1)
#define VBUFLEN (ANSILINELEN)
+// this is a special strlen to speed up processing.
+// warning: x MUST be #define x "msg".
+// otherwise you need to use real strlen.
+#define MACROSTRLEN(x) (sizeof(x)-1)
+
// ---- UTILITIES ----------------------------------------------------
inline void
outnc(int n, unsigned char c)
@@ -41,17 +46,12 @@ nblank(int n)
outnc(n, ' ');
}
-// this is a special strlen to speed up processing.
-// warning: x MUST be #define x "msg".
-// otherwise you need to use real strlen.
-#define MACROSTRLEN(x) (sizeof(x)-1)
-
-// ---- VSOREF API --------------------------------------------------
+// ---- VREF API --------------------------------------------------
/**
* vscr_save(): 傳回目前畫面的備份物件。
*/
-VSOREF
+VREFSCR
vscr_save(void)
{
// TODO optimize memory allocation someday.
@@ -65,9 +65,9 @@ vscr_save(void)
* vscr_restore(obj): 使用並刪除畫面的備份物件。
*/
void
-vscr_restore(VSOREF obj)
+vscr_restore(VREFSCR obj)
{
- screen_backup_t *o = (screen_backup_t*)o;
+ screen_backup_t *o = (screen_backup_t*)obj;
if (o)
{
scr_restore(o);
@@ -79,24 +79,25 @@ vscr_restore(VSOREF obj)
/**
* vcur_save(): 傳回目前游標的備份物件。
*/
-VSOREF
+VREFCUR
vcur_save(void)
{
// XXX 偷懶不 new object 了, pointer 夠大
int y, x;
+ VREFCUR v;
getyx(&y, &x);
- y = ((unsigned short)y << 16) | (unsigned short)x;
- return (VSOREF)NULL + y;
+ v = ((unsigned short)y << 16) | (unsigned short)x;
+ return v;
}
/**
* vcur_restore(obj): 使用並刪除游標的備份物件。
*/
void
-vcur_restore(VSOREF o)
+vcur_restore(VREFCUR o)
{
int y, x;
- y = (unsigned int)(o - NULL);
+ y = (unsigned int)(o);
x = (unsigned short)(y & 0xFFFF);
y = (unsigned short)(y >> 16);
move(y, x);
@@ -124,6 +125,20 @@ vpad(int n, const char *pattern)
if (n) nblank(n);
}
+/**
+ * vgety(): 取得目前所在位置的行數
+ *
+ * 考慮到 ANSI 系統,getyx() 較為少用且危險。
+ * vgety() 安全而明確。
+ */
+inline int
+vgety(void)
+{
+ int y, x;
+ getyx(&y, &x);
+ return y;
+}
+
// ---- HIGH LEVEL API -----------------------------------------------
/**