From 4b646401b00a7b5ec0d53d7499a22be3955e90ed Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Thu, 19 Feb 2009 07:21:31 +0000
Subject: [PATCH] Get rid of the macros: GOTOXY, ANSI_SAVE, and ANSI_RESTORE
 and replace usage with ansi_gotoxy(), ansi_save(), and ansi_restore()
 functions.

---
 src/sbbs3/atcodes.cpp | 32 ++++++++++++++++++++------------
 src/sbbs3/chat.cpp    | 22 +++++++++++-----------
 src/sbbs3/getstr.cpp  |  8 ++++----
 src/sbbs3/sbbsdefs.h  |  3 ---
 4 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/src/sbbs3/atcodes.cpp b/src/sbbs3/atcodes.cpp
index 6e4685c81d..d69cfa6eea 100644
--- a/src/sbbs3/atcodes.cpp
+++ b/src/sbbs3/atcodes.cpp
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html		*
  *																			*
  * This program is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU General Public License				*
@@ -636,26 +636,34 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 		return("\r\n");
 
 	if(!strcmp(sp,"PUSHXY")) {
-		ANSI_SAVE();
+		ansi_save();
 		return(nulstr);
 	}
 
 	if(!strcmp(sp,"POPXY")) {
-		ANSI_RESTORE();
+		ansi_restore();
 		return(nulstr);
 	}
 
-	if(!strcmp(sp,"UP"))
-		return("\x1b[A");
+	if(!strcmp(sp,"UP")) {
+		cursor_up();
+		return(nulstr);
+	}
 
-	if(!strcmp(sp,"DOWN"))
-		return("\x1b[B");
+	if(!strcmp(sp,"DOWN")) {
+		cursor_down();
+		return(nulstr);
+	}
 
-	if(!strcmp(sp,"RIGHT"))
-		return("\x1b[C");
+	if(!strcmp(sp,"RIGHT")) {
+		cursor_right();
+		return(nulstr);
+	}
 
-	if(!strcmp(sp,"LEFT"))
-		return("\x1b[D");
+	if(!strcmp(sp,"LEFT")) {
+		cursor_left();
+		return(nulstr);
+	}
 
 	if(!strncmp(sp,"UP:",3)) {
 		safe_snprintf(str,maxlen,"\x1b[%dA",atoi(sp+3));
@@ -681,7 +689,7 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
 		tp=strchr(sp,',');
 		if(tp!=NULL) {
 			tp++;
-			GOTOXY(atoi(sp+7),atoi(tp));
+			ansi_gotoxy(atoi(sp+7),atoi(tp));
 		}
 		return(nulstr);
 	}
diff --git a/src/sbbs3/chat.cpp b/src/sbbs3/chat.cpp
index 4d8cc4a490..625ce6a408 100644
--- a/src/sbbs3/chat.cpp
+++ b/src/sbbs3/chat.cpp
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html		*
  *																			*
  * This program is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU General Public License				*
@@ -881,12 +881,12 @@ void sbbs_t::privchat(bool local)
 	if(sys_status&SS_SPLITP) {
 		lncntr=0;
 		CLS;
-		ANSI_SAVE();
+		ansi_save();
 #if 0
 		if(local)
 			bprintf(text[SysopIsHere],cfg.sys_op);
 #endif
-		GOTOXY(1,13);
+		ansi_gotoxy(1,13);
 		remote_y=1;
 		bprintf(local ? local_sep : sep
 			,thisnode.misc&NODE_MSGW ? 'T':' '
@@ -933,8 +933,8 @@ void sbbs_t::privchat(bool local)
 					}
 					remote_y=1+remoteline;
 					bputs("\1i_\1n");  /* Fake cursor */
-					ANSI_SAVE();
-					GOTOXY(1,13);
+					ansi_save();
+					ansi_gotoxy(1,13);
 					bprintf(local ? local_sep : sep
 						,thisnode.misc&NODE_MSGW ? 'T':' '
 						,sectostr(timeleft,tmp)
@@ -963,7 +963,7 @@ void sbbs_t::privchat(bool local)
 					localchar=0;
 
 					if(sys_status&SS_SPLITP && local_y==24) {
-						GOTOXY(1,13);
+						ansi_gotoxy(1,13);
 						bprintf(local ? local_sep : sep
 							,thisnode.misc&NODE_MSGW ? 'T':' '
 							,sectostr(timeleft,tmp)
@@ -973,7 +973,7 @@ void sbbs_t::privchat(bool local)
 							rprintf("\x1b[%d;1H\x1b[K",x+1);
 							if(y<=localline)
 								bprintf("%s\r\n",localbuf[y]); }
-						GOTOXY(1,local_y=(15+localline));
+						ansi_gotoxy(1,local_y=(15+localline));
 						localline=0; }
 					else {
 						if(localline>=4)
@@ -1021,7 +1021,7 @@ void sbbs_t::privchat(bool local)
 			activity=1;
 			if(sys_status&SS_SPLITP && !remote_activity) {
 				ansi_getxy(&x,&y);
-				ANSI_RESTORE();
+				ansi_restore();
 			}
 			attr(cfg.color[clr_chatremote]);
 			if(sys_status&SS_SPLITP && !remote_activity)
@@ -1061,7 +1061,7 @@ void sbbs_t::privchat(bool local)
 							if(i<=remoteline)
 								bprintf("%s\r\n",remotebuf[i]); }
 						remoteline=0;
-						GOTOXY(1, remote_y=6); }
+						ansi_gotoxy(1, remote_y=6); }
 					else {
 						if(remoteline>=4)
 							for(i=0;i<4;i++)
@@ -1086,8 +1086,8 @@ void sbbs_t::privchat(bool local)
 
 		if(sys_status&SS_SPLITP && remote_activity) {
 			bputs("\1i_\1n");  /* Fake cursor */
-			ANSI_SAVE();
-			GOTOXY(x,y); 
+			ansi_save();
+			ansi_gotoxy(x,y); 
 		}
 
 		now=time(NULL);
diff --git a/src/sbbs3/getstr.cpp b/src/sbbs3/getstr.cpp
index 8b3032a3b9..6db55dbfad 100644
--- a/src/sbbs3/getstr.cpp
+++ b/src/sbbs3/getstr.cpp
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html		*
  *																			*
  * This program is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU General Public License				*
@@ -636,8 +636,8 @@ long sbbs_t::getnum(ulong max, ulong dflt)
 
 void sbbs_t::insert_indicator(void)
 {
-	ANSI_SAVE();
-	GOTOXY(cols,1);
+	ansi_save();
+	ansi_gotoxy(cols,1);
 	uchar z=curatr;                       /* and go to EOL */
 	if(console&CON_INSERT) {
 		attr(BLINK|BLACK|(LIGHTGRAY<<4));
@@ -647,5 +647,5 @@ void sbbs_t::insert_indicator(void)
 		outchar(' ');
 	}
 	attr(z);
-	ANSI_RESTORE();
+	ansi_restore();
 }
diff --git a/src/sbbs3/sbbsdefs.h b/src/sbbs3/sbbsdefs.h
index caec2ea26a..087e91e8b9 100644
--- a/src/sbbs3/sbbsdefs.h
+++ b/src/sbbs3/sbbsdefs.h
@@ -831,9 +831,6 @@ enum {							/* Values of mode for userlist function     */
 						  nodesync(); }
 #define ASYNC			{ getnodedat(cfg.node_num,&thisnode,0); \
 						  nodesync(); }
-#define ANSI_SAVE() 	rputs("\x1b[s")
-#define ANSI_RESTORE()	rputs("\x1b[u")
-#define GOTOXY(x,y)     rprintf("\x1b[%d;%dH",y,x);
 #define TM_YEAR(yy)		((yy)%100)
 #define sbbs_beep(f,d)	BEEP(f,d)
 #define mswait(x)		SLEEP(x)
-- 
GitLab