From adedce85568f23eecaa3fb5203622fc6423b7675 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 16 Apr 2018 13:52:54 -0700 Subject: [PATCH] SCP: Add quoted string argument to SET ENV otherwise trim whitespace Previously, unexpected values might end up being set when using SET ENV if there were trailing whitespace on the line being parsed. Any such white space is now explicitly trimmed before the environment variable is set. Once we do that, we need to provide a way to deliberately set an environment variable with trailing spaces. This is now achieved by using a quoted string value specified as: SET ENV -S var="value " The quotes are removed prior to setting the environment variable value. The contents of the quoted string are parsed the same as EXPECT and SEND arguments. --- scp.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scp.c b/scp.c index 43025dd0..5072376b 100644 --- a/scp.c +++ b/scp.c @@ -4575,8 +4575,20 @@ if (sim_switches & SWMASK ('P')) { else cptr = deflt; } -else +else { cptr = get_glyph (cptr, varname, '='); /* get environment variable name */ + strlcpy (cbuf, cptr, sizeof(cbuf)); + sim_trim_endspc (cbuf); + cptr = cbuf; + if (sim_switches & SWMASK ('S')) { /* Quote String argument? */ + uint32 str_size; + + get_glyph_quoted (cptr, cbuf, 0); + if (SCPE_OK != sim_decode_quoted_string (cbuf, (uint8 *)cbuf, &str_size)) + return sim_messagef (SCPE_ARG, "Invalid quoted string: %s\n", cbuf); + cbuf[str_size] = '\0'; + } + } setenv(varname, cptr, 1); return SCPE_OK; }