From fb2ad7ddea885cf4e8fab9cd4387254caa64d99c Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Sat, 23 Jan 2021 18:51:41 -0800
Subject: [PATCH] JS module command-lines now supported quoted arguments
 (w/white-space)

Example:
Command-line: ?showargs   " a b c "d "e f"
argc = 3
argv[0] = ' a b c '
argv[1] = 'd'
argv[2] = 'e f'

This resolves a long-standing TODO comment.

Also, fixed a problem where multiple spaces between the module name and the first argument would result in argv[0] being set to an empty string.
---
 src/sbbs3/exec.cpp | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/src/sbbs3/exec.cpp b/src/sbbs3/exec.cpp
index 8659d549bd..2e8512e401 100644
--- a/src/sbbs3/exec.cpp
+++ b/src/sbbs3/exec.cpp
@@ -1,10 +1,5 @@
-/* exec.cpp */
-// vi: tabstop=4
-
 /* Synchronet command shell/module interpretter */
 
-/* $Id: exec.cpp,v 1.116 2020/08/01 18:34:24 rswindell Exp $ */
-
 /****************************************************************************
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
@@ -18,21 +13,9 @@
  * See the GNU General Public License for more details: gpl.txt or			*
  * http://www.fsf.org/copyleft/gpl.html										*
  *																			*
- * Anonymous FTP access to the most recent released source is available at	*
- * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
- *																			*
- * Anonymous CVS access to the development source and modification history	*
- * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
- *     (just hit return, no password is necessary)							*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
- *																			*
  * For Synchronet coding style and modification guidelines, see				*
  * http://www.synchro.net/source.html										*
  *																			*
- * You are encouraged to submit any modifications (preferably in Unix diff	*
- * format) via e-mail to mods@synchro.net									*
- *																			*
  * Note: If this box doesn't appear square, then you need to fix your tabs.	*
  ****************************************************************************/
 
@@ -594,6 +577,7 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* sco
 	if(p!=NULL) {
 		*p=0;
 		args=p+1;
+		SKIP_WHITESPACE(args);
 	}
 	fname=cmdline;
 
@@ -635,13 +619,17 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* sco
 		JS_DefineProperty(js_cx, js_scope, "argv", OBJECT_TO_JSVAL(argv)
 			,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE);
 
-		/* TODO: Handle quoted "one arg" syntax here? */
+		/* Handle quoted "one arg" syntax here */
 		if(args!=NULL && argv!=NULL) {
 			while(*args) {
-				p=strchr(args,' ');
+				if(*args == '"') {
+					args++;
+					p = strchr(args, '"');
+				}
+				else
+					p = strchr(args, ' ');
 				if(p!=NULL)
 					*p=0;
-				while(*args && *args==' ') args++; /* Skip spaces */
 				JSString* arg = JS_NewStringCopyZ(js_cx, args);
 				if(arg==NULL)
 					break;
@@ -651,7 +639,8 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir, JSObject* sco
 				argc++;
 				if(p==NULL)	/* last arg */
 					break;
-				args+=(strlen(args)+1);
+				args = p + 1;
+				SKIP_WHITESPACE(args);
 			}
 		}
 		JS_DefineProperty(js_cx, js_scope, "argc", INT_TO_JSVAL(argc)
-- 
GitLab