Skip to content
Snippets Groups Projects
Commit 47f8c020 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

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.
parent 99346600
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #1192 passed
/* 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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment