From fdd2b3680e118fadf2da667c5e1d5e4dc6465e77 Mon Sep 17 00:00:00 2001
From: Michael Long <mlong@bizjournals.com>
Date: Tue, 15 Dec 2020 19:39:23 -0500
Subject: [PATCH] improvements from feedback dosemu.ini filename comments
 changes code changes

---
 ctrl/{dosemu1.conf => dosemu.conf}    |  0
 ctrl/sbbs.ini                         |  6 ++++--
 exec/{dosemulaunch.ini => dosemu.ini} | 10 ++++------
 exec/external.bat                     |  2 +-
 src/sbbs3/chk_ar.cpp                  |  5 ++++-
 src/sbbs3/xtrn.cpp                    | 27 ++++++++++++++-------------
 6 files changed, 27 insertions(+), 23 deletions(-)
 rename ctrl/{dosemu1.conf => dosemu.conf} (100%)
 rename exec/{dosemulaunch.ini => dosemu.ini} (81%)

diff --git a/ctrl/dosemu1.conf b/ctrl/dosemu.conf
similarity index 100%
rename from ctrl/dosemu1.conf
rename to ctrl/dosemu.conf
diff --git a/ctrl/sbbs.ini b/ctrl/sbbs.ini
index e1f4967a11..bd6c61f6e7 100644
--- a/ctrl/sbbs.ini
+++ b/ctrl/sbbs.ini
@@ -98,9 +98,11 @@
 ; Must install install/termcap or terminfo to use the following TERM setting:
 ; ExternalTermANSI = ansi-bbs
 	ExternalTermDumb = dumb
+
 ; To setup the dosemu cmd path and ini:
-;DOSemuPath = /usr/bin/dosemu.bin
-;DOSemuConfPath = /etc/dosemu/dosemu.conf
+UseDOSemu = false
+DOSemuPath = /usr/bin/dosemu.bin
+DOSemuConfPath = /sbbs/ctrl/dosemu.conf
 
 ; At what size to send the current output buffer regardless of timeout
 ; ie: Send output whenever there are at least this many bytes waiting.
diff --git a/exec/dosemulaunch.ini b/exec/dosemu.ini
similarity index 81%
rename from exec/dosemulaunch.ini
rename to exec/dosemu.ini
index 0047505a3f..f5320995f4 100644
--- a/exec/dosemulaunch.ini
+++ b/exec/dosemu.ini
@@ -1,14 +1,12 @@
 ; This script contains the command line to execute DOSEMU
 ;
-; The first non-comment line in this file is used
-;
 ; You can copy this file to customize for any specific games that need changes
-; by creating dosemulaunch_XTRNCODE.bat
+; by placing a copy of this file into the external program's startup directory.
 ;
 ; The following substitutions will be performed on this file:
 ; $TERM sets 'TERM=linux' (used on events, etc.)
-; $CTRLDIR = ctrl dir
-; $NODEDIR = node dir
+; $CTRLDIR = path to synchronet ctrl dir
+; $NODEDIR = path to synchronet node dir
 ; $DOSEMUBIN = path to dosemu.bin
 ; $VIRTCONF = appends virtual when needed (ie fossil) (-I"serial { virtual com 1 }")
 ; $DOSEMUCONF = path to global dosemu conf
@@ -16,7 +14,7 @@
 ; $EXTLOG = external log (used on events)
 ; add -I'keystroke "\r"' if you need that behavior back
 ;
-; for standard external programs, put it in the global "cmd" key
+; for com/uart/fossil i/o external programs, put it in the global "cmd" key
 ; for intercept i/o programs, you can override by putting "cmd" key under [stdio] section
 cmd=/usr/bin/env $TERM HOME=$CTRLDIR QUIET=1 DOSDRIVE_D=$NODEDIR NODEDIR=$NODEDIR $DOSEMUBIN -I"video { none }" $VIRTUALCONF -f$DOSEMUCONF -E$EXTBAT -o$NODEDIRdosemu_boot.log $EXTLOG
 [stdio]
diff --git a/exec/external.bat b/exec/external.bat
index 96eb8039df..9b6ffeaed5 100644
--- a/exec/external.bat
+++ b/exec/external.bat
@@ -6,7 +6,7 @@
 
 E:
 
-REM Switch to game dir, unless its not defined
+REM Switch to startup dir, unless its not defined
 REM If not defined, go to node dir (external editors use this)
 IF "%STARTDIR%"=="" D:
 IF NOT "%STARTDIR%"=="" CD %STARTDIR%
diff --git a/src/sbbs3/chk_ar.cpp b/src/sbbs3/chk_ar.cpp
index 3cf9510822..95f36075e9 100644
--- a/src/sbbs3/chk_ar.cpp
+++ b/src/sbbs3/chk_ar.cpp
@@ -223,8 +223,11 @@ bool sbbs_t::ar_exp(const uchar **ptrptr, user_t* user, client_t* client)
 				result=_not;
 				if(startup->options&BBS_OPT_NO_DOS)
 					break;
-				#if defined(_WIN32) || defined(__linux__) || defined(__FreeBSD__)
+				#if defined(_WIN32) || defined(__FreeBSD__)
 					result=!_not;
+				#elif defined(__linux__)
+					if (startup->usedosemu) 
+						result=!_not;
 				#endif
 				break;
 			case AR_WIN32:
diff --git a/src/sbbs3/xtrn.cpp b/src/sbbs3/xtrn.cpp
index eb044325be..614f2f9cc3 100644
--- a/src/sbbs3/xtrn.cpp
+++ b/src/sbbs3/xtrn.cpp
@@ -1214,6 +1214,9 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
 		const char datadrive[] = DOSEMU_DATA_DRIVE;
 		const char execdrive[] = DOSEMU_EXEC_DRIVE;
 		const char nodedrive[] = DOSEMU_NODE_DRIVE;
+		
+		const char external_bat_fn[] = "external.bat";
+		const char dosemu_cnf_fn[] = "dosemu.conf";
 
 		SAFECOPY(str,startup_dir);
 		if(*(p=lastchar(str))=='/')		/* kill trailing slash */
@@ -1246,7 +1249,7 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
 
 		SAFECOPY(nodedir_dos,cfg.node_dir);
 		REPLACE_CHARS(nodedir_dos,'/','\\',p);
-
+ 
 		p=lastchar(nodedir_dos);
 		if (*p=='\\') *p=0;
 
@@ -1277,16 +1280,16 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
 		 *
 		 * First check startup_dir, then check cfg.ctrl_dir
 		 */
-		sprintf(str,"%sdosemu.conf",startup_dir);
+		SAFEPRINTF2(str,"%s%s",startup_dir, dosemu_cnf_fn);
 		if (!fexist(str)) {
 			/* If we can't find it in the door dir, look for the configured one */
 			SAFECOPY(str,(cmdstr(startup->dosemuconf_path,nulstr,nulstr,tok)));
 			if (!fexist(str)) {
 				/* If we couldn't find either, try for the system one, then
 				 * error out. */
-				SAFECOPY(str,"/etc/dosemu/dosemu.conf");
+				SAFEPRINTF(str,"/etc/dosemu/%s", dosemu_cnf_fn);
 				if (!fexist(str)) {
-					SAFECOPY(str,"/etc/dosemu.conf");
+					SAFEPRINTF(str,"/etc/%s", dosemu_cnf_fn);
 					if (!fexist(str)) {
 						errormsg(WHERE,ERR_READ,str,0);
 						return(-1);
@@ -1300,7 +1303,7 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
 		else SAFECOPY(dosemuconf,str);  /* using door-specific conf */
 
 		/* Create the external bat here to be placed in the node dir. */
-		SAFEPRINTF(str,"%sexternal.bat",cfg.node_dir);
+		SAFEPRINTF2(str,"%s%s",cfg.node_dir,external_bat_fn);
 		if(!(dosemubatfp=fopen(str,"w+"))) {
 			errormsg(WHERE,ERR_CREATE,str,0);
 			return(-1);
@@ -1351,10 +1354,10 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
 
 		/* now append exec/external.bat (which is editable) to this 
 		 generated file */
-		SAFEPRINTF(str,"%sexternal.bat",startup_dir);
+		SAFEPRINTF2(str,"%s%s",startup_dir,external_bat_fn);
 
 		if ((startup_dir == cfg.node_dir) || !fexist(str)) {
-			SAFEPRINTF(str,"%sexternal.bat",cfg.exec_dir);
+			SAFEPRINTF2(str,"%s%s",cfg.exec_dir, external_bat_fn);
 			if (!fexist(str)) {
 				errormsg(WHERE,ERR_READ,str,0);
 				return(-1);
@@ -1422,13 +1425,11 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
 		if (!isdir(str)) {
 			mkdir(str, 0755);
 		}
-
 		strcat(str, "/disclaimer");
 		ftouch(str);
 
 		/* Set up the command for dosemu to execute with 'unix -e'. */
-
-		SAFEPRINTF(externalbat,"%sexternal.bat",nodedrive);
+		SAFEPRINTF2(externalbat,"%s%s",nodedrive, external_bat_fn);
 
 		/* need TERM=linux for maintenance programs to work
 		 * (dosemu won't start with no controlling terminal)
@@ -1448,12 +1449,12 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
 		 * Get the global emu launch command
 		 */
 		 /* look for file in startup dir */
-		SAFEPRINTF(str,"%sdosemulaunch.ini",startup_dir);
+		SAFEPRINTF(str,"%sdosemu.ini",startup_dir);
 		if (!fexist(str)) {
 	    	/* look for file in ctrl dir */        
-    		SAFEPRINTF(str,"%sdosemulaunch.ini",cfg.exec_dir);
+    		SAFEPRINTF(str,"%sdosemu.ini",cfg.exec_dir);
 			if (!fexist(str)) {
-                errormsg(WHERE,ERR_OPEN,"dosemulaunch.ini", 0);
+                errormsg(WHERE,ERR_OPEN,"dosemu.ini", 0);
                 return(-1);
 			}
 		}
-- 
GitLab