From 0779dae1fb9221e7ffb4fe2c2634be8ea1c6aaf2 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Sat, 10 Feb 2018 00:22:39 +0000
Subject: [PATCH] Handle ANSI strings (Application Program String, Device
 Control String, Privacy Message, Operating System Command, Start Of String)
 in outcom.

---
 src/sbbs3/con_out.cpp | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/sbbs3/con_out.cpp b/src/sbbs3/con_out.cpp
index 00bc8d127d..b72e8ecdc7 100644
--- a/src/sbbs3/con_out.cpp
+++ b/src/sbbs3/con_out.cpp
@@ -179,6 +179,17 @@ void sbbs_t::outchar(char ch)
 {
 	int		i;
 
+	/*
+	 * outchar_esc values:
+	 * 0: No sequence
+	 * 1: ESC
+	 * 2: CSI
+	 * 3: Final byte
+     * 4: APS, DCS, PM, or OSC
+     * 5: SOS
+     * 6: ESC inside of SOS
+     */
+
 	if(console&CON_ECHO_OFF)
 		return;
 	if(ch==ESC)
@@ -186,6 +197,10 @@ void sbbs_t::outchar(char ch)
 	else if(outchar_esc==1) {
 		if(ch=='[')
 			outchar_esc++;
+		else if(ch=='_' || ch=='P' || ch == '^' || ch == ']')
+			outchar_esc=4;
+		else if(ch=='X')
+			outchar_esc=5;
 		else
 			outchar_esc=0;
 	}
@@ -193,6 +208,24 @@ void sbbs_t::outchar(char ch)
 		if(ch>='@' && ch<='~')
 			outchar_esc++;
 	}
+	else if(outchar_esc==4) {	// APS, DCS, PM, or OSC
+		if (ch == ESC)
+			outchar_esc = 1;
+		if (!((ch >= 0x08 && ch <= 0x0d) || (ch >= 0x20 && ch <= 0x7e)))
+			outchar_esc = 0;
+	}
+	else if(outchar_esc==5) {	// SOS
+		if (ch == ESC)
+			outchar_esc++;
+	}
+	else if(outchar_esc==6) {	// ESC inside SOS
+		if (ch == '\\')
+			outchar_esc = 1;
+		else if (ch == 'X')
+			outchar_esc = 0;
+		else
+			outchar_esc = 5;
+	}
 	else
 		outchar_esc=0;
 	if(term_supports(NO_EXASCII) && ch&0x80)
-- 
GitLab