1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-09-19 22:35:07 +00:00

Allow setting environment variables with space in values

This commit is contained in:
Luke Ceddia 2024-06-02 22:50:20 +10:00
parent ac2777fd20
commit 1d5a8d79b8
3 changed files with 60 additions and 6 deletions

View file

@ -70,13 +70,11 @@ void sub_environ(qbs *str) {
buf = (char *)malloc(str->len + 1);
buf[str->len] = '\0';
memcpy(buf, str->chr, str->len);
// Name and value may be separated by = or space
separator = strchr(buf, ' ');
if (!separator) {
separator = strchr(buf, '=');
}
if (!separator) {
// Name and value may be separated by = or space, whichever appears first.
separator = buf + strcspn(buf, " =");
if (*separator == '\0') {
// It is an error is there is no separator
free(buf);
error(5);
return;
}

View file

@ -0,0 +1,48 @@
$CONSOLE:ONLY
ON ERROR GOTO ehandler
'Test setting with =
ENVIRON "FOO=BAR"
PRINT ENVIRON$("FOO")
'Test settings with space
ENVIRON "VAR VAL"
PRINT ENVIRON$("VAR")
'Test setting value with spaces with = separator
ENVIRON "ABC=DEF GHI"
PRINT ENVIRON$("ABC")
'Test setting value with spaces with space separator
ENVIRON "JKL MNO PQR"
PRINT ENVIRON$("JKL")
'Test overwriting existing
ENVIRON "X=XY"
ENVIRON "X=ZZZ"
PRINT ENVIRON$("X")
'Test unset variable with = separator
ENVIRON "NAME=LUKE"
ENVIRON "NAME="
PRINT "["; ENVIRON$("NAME"); "]"
'Test unset variable with space separator
ENVIRON "TEXT BOO"
ENVIRON "TEXT "
PRINT "["; ENVIRON$("TEXT"); "]"
'Test no separator
ENVIRON "NOSEP"
SYSTEM
ehandler:
print "Error"; ERR; "line"; _ERRORLINE
RESUME NEXT

View file

@ -0,0 +1,8 @@
BAR
VAL
DEF GHI
MNO PQR
ZZZ
[]
[]
Error 5 line 42