Csound Csound-dev Csound-tekno Search About

[Csnd] CsOptions using --env with a value containing spaces

Date2024-06-14 20:02
From"Jeanette C."
Subject[Csnd] CsOptions using --env with a value containing spaces
Hey hey,
is there a way to set an environment variable to a path which contains spaces. 
Simple example:
directory: "my folder"
--env:INCDIR="my folder"
I have tried the above, the same with single quotes and the same with a 
backslash '\' to escape the space without any quotes. The use-case is, of 
course, for a directory over which I don't have any control, part of a basic 
system path.

Any help is appreciated!

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

You should never try to change me
I can be nobody else
And I like the way I am <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-20 15:34
FromRichard Knight
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Hi
I have just tried doing this on Windows and Linux and both seem to work 
(Csound 6.16 and 6.19) with a quoted path containing spaces - seemed to 
work with absolute and relative paths as well. Also seems to work with 
the --omacro flag as well which has similar syntax to --env.
Which OS are you using? Only thought would be if you are on windows and 
have backslash path separator, that might need to be changed to forward 
slash (or escaped)..

all the best
Richard

On 2024-06-14 20:02, Jeanette C. wrote:
> Hey hey,
> is there a way to set an environment variable to a path which contains
> spaces. Simple example:
> directory: "my folder"
> --env:INCDIR="my folder"
> I have tried the above, the same with single quotes and the same with
> a backslash '\' to escape the space without any quotes. The use-case
> is, of course, for a directory over which I don't have any control,
> part of a basic system path.
> 
> Any help is appreciated!
> 
> Best wishes,
> 
> Jeanette
> 
> --
>  * Website: http://juliencoder.de - for summer is a state of sound
>  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
>  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
>  * GitHub: https://github.com/jeanette-c
> 
> You should never try to change me
> I can be nobody else
> And I like the way I am <3
> (Britney Spears)
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-20 22:25
From"Jeanette C."
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Hi Richard,
thanks for your reply and testing on both operating systems. I am on Linux and 
run Csound 6.18 . So did you try something like:
--env:INCDIR="/path to/include dir"
I mean the basic format, not the relative or absolute bits. I tried different 
versions and none of it worked. I couldn't include the file in that directory. 
How about a slash at the end, the style of quotation mark, etc.?

Best wishes and many thanks,

Jeanette

Jun 20 2024, Richard Knight has written:

> Hi
> I have just tried doing this on Windows and Linux and both seem to work 
> (Csound 6.16 and 6.19) with a quoted path containing spaces - seemed to work 
> with absolute and relative paths as well. Also seems to work with the 
> --omacro flag as well which has similar syntax to --env.
> Which OS are you using? Only thought would be if you are on windows and have 
> backslash path separator, that might need to be changed to forward slash (or 
> escaped)..
>
> all the best
> Richard
>
> On 2024-06-14 20:02, Jeanette C. wrote:
>>  Hey hey,
>>  is there a way to set an environment variable to a path which contains
>>  spaces. Simple example:
>>  directory: "my folder"
>>  --env:INCDIR="my folder"
>>  I have tried the above, the same with single quotes and the same with
>>  a backslash '\' to escape the space without any quotes. The use-case
>>  is, of course, for a directory over which I don't have any control,
>>  part of a basic system path.
>>
>>  Any help is appreciated!
>>
>>  Best wishes,
>>
>>  Jeanette
>>
>>  --
>>   * Website: http://juliencoder.de - for summer is a state of sound
>>   * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
>>   * Audiobombs: https://www.audiobombs.com/users/jeanette_c
>>   * GitHub: https://github.com/jeanette-c
>>
>>  You should never try to change me
>>  I can be nobody else
>>  And I like the way I am <3
>>  (Britney Spears)
>>
>>  Csound mailing list
>>  Csound@listserv.heanet.ie
>>  https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>  Send bugs reports to
>>         https://github.com/csound/csound/issues
>>  Discussions of bugs and features can be posted here
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>       https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
>

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

All you people look at me like I'm a little girl.
Well did you ever think it be okay for me to step into this world. <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-21 01:08
FromRichard Knight
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Hi

That's strange - yes, I tried something like that - I created a file 
include.inc in /tmp/csound test/include dir , with just a prints 
statement. Then I created a csd in /tmp which had the line
     #include "include.inc"

... and ran while in /tmp by typing
      csound --env:INCDIR="/tmp/csound test/include dir" run.csd

which worked and the prints statement - also the following worked, ie 
the relative path
     csound --env:INCDIR="csound test/include dir" run.csd

if you run csound with -v then it might give some indication of what is 
going on/going wrong - if I run
     csound -v --env:INCDIR="/tmp/csound test/include dir" run.csd


then somewhere in the output are these:

     decode_long env:INCDIR=csound test/include dirs
     Environment variable 'INCDIR' has been set to 'csound test/include 
dirs'

and also it will show the search path when it gets to parsing the 
#include:
     Creating search path cache for 'INCDIR':
         1: "csound test/include dir/"


Hopefully with -v somewhere in the output, there should be some hints of 
what's happening wrong!
all the best,
Richard

On 2024-06-20 22:25, Jeanette C. wrote:
> Hi Richard,
> thanks for your reply and testing on both operating systems. I am on
> Linux and run Csound 6.18 . So did you try something like:
> --env:INCDIR="/path to/include dir"
> I mean the basic format, not the relative or absolute bits. I tried
> different versions and none of it worked. I couldn't include the file
> in that directory. How about a slash at the end, the style of
> quotation mark, etc.?
> 
> Best wishes and many thanks,
> 
> Jeanette

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-21 13:18
From"Jeanette C."
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Attachmentscsd_include_exaple.zip  
Hi Richard,
I have attached an example. The zipfile will unpack into a main example folder 
that has a subfolder. There are two .csd files, that have the env option in 
their CsOptions block. When you comment these out and use
csound --env:INCDIR="include folder" inc_file.csd
it works. When you use the env option from the CSD file, it does not work. 
Inspecting the output of csound with -v it shows that the include folder is 
set to:
'^Cinclude folder'
So somehow the Csound parser introduced a control-C character there.

Do you get the same result?

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

Say hello to the girl that I am! <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-21 14:55
FromRichard Knight
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Ah right, I see - when I use --env on the command line with these, they 
work - but I missed that you are trying to use these in CsOptions - and 
yes I get the same result with that approach in that it doesn't work.
I'm not seeing the prepended ^C though.
I think it may be a bug in the CsOptions parser, from what I can see 
that's in Top/one_file.c in the source, from line 232. At a glance it 
looks like it is supposed to handle spaces in quotes, but I may have a 
play around later and see if I can figure out what's happening.

On 2024-06-21 13:18, Jeanette C. wrote:
> Hi Richard,
> I have attached an example. The zipfile will unpack into a main
> example folder that has a subfolder. There are two .csd files, that
> have the env option in their CsOptions block. When you comment these
> out and use
> csound --env:INCDIR="include folder" inc_file.csd
> it works. When you use the env option from the CSD file, it does not
> work. Inspecting the output of csound with -v it shows that the
> include folder is set to:
> '^Cinclude folder'
> So somehow the Csound parser introduced a control-C character there.
> 
> Do you get the same result?
> 
> Best wishes,
> 
> Jeanette

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-21 16:01
FromRichard Knight
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Actually does it work with INCDIR specified in CsOptions even without 
spaces?
Fiddled about with the source a bit, looked like both command line and 
CsOptions --env flags are being parsed the same - then realised it 
doesn't even work for me with any INCDIR specified in CsOptions, so 
--env may be one of the flags that can only be passed as a command line 
flag (there are a few mentioned in the manual, but not env...)

On 2024-06-21 14:55, Richard Knight wrote:
> Ah right, I see - when I use --env on the command line with these,
> they work - but I missed that you are trying to use these in CsOptions
> - and yes I get the same result with that approach in that it doesn't
> work.
> I'm not seeing the prepended ^C though.
> I think it may be a bug in the CsOptions parser, from what I can see
> that's in Top/one_file.c in the source, from line 232. At a glance it
> looks like it is supposed to handle spaces in quotes, but I may have a
> play around later and see if I can figure out what's happening.
> 
> On 2024-06-21 13:18, Jeanette C. wrote:
>> Hi Richard,
>> I have attached an example. The zipfile will unpack into a main
>> example folder that has a subfolder. There are two .csd files, that
>> have the env option in their CsOptions block. When you comment these
>> out and use
>> csound --env:INCDIR="include folder" inc_file.csd
>> it works. When you use the env option from the CSD file, it does not
>> work. Inspecting the output of csound with -v it shows that the
>> include folder is set to:
>> '^Cinclude folder'
>> So somehow the Csound parser introduced a control-C character there.
>> 
>> Do you get the same result?
>> 
>> Best wishes,
>> 
>> Jeanette
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-21 17:21
From"Jeanette C."
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Hi Richard,
include paths without space work, perahsp there is no quotation required? Yes, 
it is the quotation. I just tried putting double quotes around the include 
directory to set and it promptly failed. This is reproduceable. It seems to be 
the parsing of quoted strings in the CsdOptions block, especially the 
beginning of them.

When you look at the .log files that were part of the zip, can you see that a 
control-C character had been inserted, or does your editor not show that? It 
being control characters, different terminals/viewers deal with it 
differently. I opened it in vim on a Linux TTY. It's a headless system.

Best wishes and thanks for all your efforts!

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

There must be another way
Cause I believe in taking chances
But who am I to say - What a girl is to do <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-21 21:47
FromRichard Knight
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Hmm ok seem to be honing in a bit - I agree, in CsOptions anything 
quoted for --env:INCDIR seems to fail even if it has no spaces.

Yes - it looks like a control-C has been inserted and I missed that 
before in my output.
It definitely does look to be happening in the Top/one_file.c file - it 
deals with the closing " OK, but the opening " it replaces with ctrl-C 
(ascii code 3) on the lines commented with
     /* ETX char used to mark the limits of a string */

-not figured out how to best fix it yet - may be worth filing a bug 
report on github!


On 2024-06-21 17:21, Jeanette C. wrote:
> Hi Richard,
> include paths without space work, perahsp there is no quotation
> required? Yes, it is the quotation. I just tried putting double quotes
> around the include directory to set and it promptly failed. This is
> reproduceable. It seems to be the parsing of quoted strings in the
> CsdOptions block, especially the beginning of them.
> 
> When you look at the .log files that were part of the zip, can you see
> that a control-C character had been inserted, or does your editor not
> show that? It being control characters, different terminals/viewers
> deal with it differently. I opened it in vim on a Linux TTY. It's a
> headless system.
> 
> Best wishes and thanks for all your efforts!
> 
> Jeanette

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-22 07:01
FromScott Sitar
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Greetings, and sorry to interrupt mid conversation!  I think I might have a line on what's going on here. (For reference, I'm on MacOS, but I don't think this bug is platform-specific)

This is also happening in cs7, and I think I've got the start of a patch that fixes it.  There seem to be two separate issues here (references to the cs7 code):

1) In Top/one_file.c, readOptions() (https://github.com/csound/csound/blob/develop/Top/one_file.c#L337), we are replacing the opening quotation mark with an ETX, but if the character following the closing quotation mark is whitespace (it will be a newline in the examples given), we replace the closing quotation mark with a NULL rather than an ETX.  So, we probably always want to replace the closing quotation mark with an ETX, and then optionally replace the following whitespace with a NULL.

2) In Engine/envvar.c, csoundParseEnv() (https://github.com/csound/csound/blob/develop/Engine/envvar.c#L376), we determine where the value should start, but we don't take into account that it might be an ETX-delimited string and adjust our bounds accordingly.

Putting together the following super rough patch below seems to fix the problem.  This kind of string manipulation has many pitfalls, so I haven't blunder-checked myself too carefully yet.  If this kind of approach seems okay with everyone, I can get a PR up this weekend.  It also shouldn't be too bad to get a test case for this under tests/c, so I could put that in the PR as well.

---------------

diff --git a/Engine/envvar.c b/Engine/envvar.c
index 96e0f6de3..7a3f4afdf 100644
--- a/Engine/envvar.c
+++ b/Engine/envvar.c
@@ -349,7 +349,7 @@ int csoundInitEnv(CSOUND *csound)
 
 int csoundParseEnv(CSOUND *csound, const char *s)
 {
-    char  *name, *value, msg[256];
+    char  *name, *value, *end_str, msg[256];
     int   append_mode, retval;
 
     /* copy string constant */
@@ -373,6 +373,17 @@ int csoundParseEnv(CSOUND *csound, const char *s)
       retval = CSOUND_ERROR;
       goto err_return;
     }
+    /* check if we have a quoted string bounded by ETX characters */
+    if (*value == 3) {
+      end_str = strchr(value + 1, '\03');
+      if (UNLIKELY(end_str == NULL)) {
+        retval = CSOUND_ERROR;
+        goto err_return;
+      } else {
+        *end_str = '\0';
+        value++;
+      }
+    }
     /* set variable */
     if (!append_mode)
       retval = csoundSetEnv(csound, name, value);
diff --git a/Top/one_file.c b/Top/one_file.c
index 5a82bbb4c..645e1ebf5 100644
--- a/Top/one_file.c
+++ b/Top/one_file.c
@@ -334,13 +334,11 @@ int readOptions(CSOUND *csound, CORFIL *cf, int readingCsOptions)
             p++;
           }
           if (*p == '"') {
+            *p = 3;
             if (isspace(*(p+1))) {
-              *p = '\0';
+              *(p+1) = '\0';
               break;
             }
-            else {
-              *p = 3;
-            }
           }
         }
         p++;

On Fri, Jun 21, 2024 at 1:47 PM Richard Knight <richard@1bpm.net> wrote:
Hmm ok seem to be honing in a bit - I agree, in CsOptions anything
quoted for --env:INCDIR seems to fail even if it has no spaces.

Yes - it looks like a control-C has been inserted and I missed that
before in my output.
It definitely does look to be happening in the Top/one_file.c file - it
deals with the closing " OK, but the opening " it replaces with ctrl-C
(ascii code 3) on the lines commented with
     /* ETX char used to mark the limits of a string */

-not figured out how to best fix it yet - may be worth filing a bug
report on github!


On 2024-06-21 17:21, Jeanette C. wrote:
> Hi Richard,
> include paths without space work, perahsp there is no quotation
> required? Yes, it is the quotation. I just tried putting double quotes
> around the include directory to set and it promptly failed. This is
> reproduceable. It seems to be the parsing of quoted strings in the
> CsdOptions block, especially the beginning of them.
>
> When you look at the .log files that were part of the zip, can you see
> that a control-C character had been inserted, or does your editor not
> show that? It being control characters, different terminals/viewers
> deal with it differently. I opened it in vim on a Linux TTY. It's a
> headless system.
>
> Best wishes and thanks for all your efforts!
>
> Jeanette

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2024-06-22 13:14
From"Jeanette C."
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Hi Richard and Scott,
thanks again for your research and the potential patch. I would have been lost 
with these details. -- I'm looking forward to a fix upstream.

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

I used to think
I had the answers to everything
But now I know
... :) <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-06-22 15:52
FromRichard Knight
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces

Ah great!
Thanks for the work on this and the detailed explanation - I tried the patch and it works with the files we've been testing so looks good to me.

 


On 2024-06-22 07:01, Scott Sitar wrote:

Greetings, and sorry to interrupt mid conversation!  I think I might have a line on what's going on here. (For reference, I'm on MacOS, but I don't think this bug is platform-specific)
 
This is also happening in cs7, and I think I've got the start of a patch that fixes it.  There seem to be two separate issues here (references to the cs7 code):
 
1) In Top/one_file.c, readOptions() (https://github.com/csound/csound/blob/develop/Top/one_file.c#L337), we are replacing the opening quotation mark with an ETX, but if the character following the closing quotation mark is whitespace (it will be a newline in the examples given), we replace the closing quotation mark with a NULL rather than an ETX.  So, we probably always want to replace the closing quotation mark with an ETX, and then optionally replace the following whitespace with a NULL.
 
2) In Engine/envvar.c, csoundParseEnv() (https://github.com/csound/csound/blob/develop/Engine/envvar.c#L376), we determine where the value should start, but we don't take into account that it might be an ETX-delimited string and adjust our bounds accordingly.
 
Putting together the following super rough patch below seems to fix the problem.  This kind of string manipulation has many pitfalls, so I haven't blunder-checked myself too carefully yet.  If this kind of approach seems okay with everyone, I can get a PR up this weekend.  It also shouldn't be too bad to get a test case for this under tests/c, so I could put that in the PR as well.
 
---------------
 
diff --git a/Engine/envvar.c b/Engine/envvar.c
index 96e0f6de3..7a3f4afdf 100644
--- a/Engine/envvar.c
+++ b/Engine/envvar.c
@@ -349,7 +349,7 @@ int csoundInitEnv(CSOUND *csound)
 
 int csoundParseEnv(CSOUND *csound, const char *s)
 {
-    char  *name, *value, msg[256];
+    char  *name, *value, *end_str, msg[256];
     int   append_mode, retval;
 
     /* copy string constant */
@@ -373,6 +373,17 @@ int csoundParseEnv(CSOUND *csound, const char *s)
       retval = CSOUND_ERROR;
       goto err_return;
     }
+    /* check if we have a quoted string bounded by ETX characters */
+    if (*value == 3) {
+      end_str = strchr(value + 1, '\03');
+      if (UNLIKELY(end_str == NULL)) {
+        retval = CSOUND_ERROR;
+        goto err_return;
+      } else {
+        *end_str = '\0';
+        value++;
+      }
+    }
     /* set variable */
     if (!append_mode)
       retval = csoundSetEnv(csound, name, value);
diff --git a/Top/one_file.c b/Top/one_file.c
index 5a82bbb4c..645e1ebf5 100644
--- a/Top/one_file.c
+++ b/Top/one_file.c
@@ -334,13 +334,11 @@ int readOptions(CSOUND *csound, CORFIL *cf, int readingCsOptions)
             p++;
           }
           if (*p == '"') {
+            *p = 3;
             if (isspace(*(p+1))) {
-              *p = '\0';
+              *(p+1) = '\0';
               break;
             }
-            else {
-              *p = 3;
-            }
           }
         }
         p++;

On Fri, Jun 21, 2024 at 1:47 PM Richard Knight <richard@1bpm.net> wrote:
Hmm ok seem to be honing in a bit - I agree, in CsOptions anything
quoted for --env:INCDIR seems to fail even if it has no spaces.

Yes - it looks like a control-C has been inserted and I missed that
before in my output.
It definitely does look to be happening in the Top/one_file.c file - it
deals with the closing " OK, but the opening " it replaces with ctrl-C
(ascii code 3) on the lines commented with
     /* ETX char used to mark the limits of a string */

-not figured out how to best fix it yet - may be worth filing a bug
report on github!


On 2024-06-21 17:21, Jeanette C. wrote:
> Hi Richard,
> include paths without space work, perahsp there is no quotation
> required? Yes, it is the quotation. I just tried putting double quotes
> around the include directory to set and it promptly failed. This is
> reproduceable. It seems to be the parsing of quoted strings in the
> CsdOptions block, especially the beginning of them.
>
> When you look at the .log files that were part of the zip, can you see
> that a control-C character had been inserted, or does your editor not
> show that? It being control characters, different terminals/viewers
> deal with it differently. I opened it in vim on a Linux TTY. It's a
> headless system.
>
> Best wishes and thanks for all your efforts!
>
> Jeanette

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2024-06-23 04:35
FromScott Sitar
SubjectRe: [Csnd] CsOptions using --env with a value containing spaces
Awesome, thanks for testing!  I'm glad it worked.  I've opened a PR for it now, but after some thought, I took a slightly different approach.  I wasn't entirely satisfied with knowledge of our special control character mechanisms leaking out into a general purpose argument decoder/environment variable handler.  I've also left some notes on a few other issues I found while looking at this in the PR comments, and I'm happy to help out by making it a little more robust with some more future changes.

Scott

On Sat, Jun 22, 2024 at 7:52 AM Richard Knight <richard@1bpm.net> wrote:

Ah great!
Thanks for the work on this and the detailed explanation - I tried the patch and it works with the files we've been testing so looks good to me.

 


On 2024-06-22 07:01, Scott Sitar wrote:

Greetings, and sorry to interrupt mid conversation!  I think I might have a line on what's going on here. (For reference, I'm on MacOS, but I don't think this bug is platform-specific)
 
This is also happening in cs7, and I think I've got the start of a patch that fixes it.  There seem to be two separate issues here (references to the cs7 code):
 
1) In Top/one_file.c, readOptions() (https://github.com/csound/csound/blob/develop/Top/one_file.c#L337), we are replacing the opening quotation mark with an ETX, but if the character following the closing quotation mark is whitespace (it will be a newline in the examples given), we replace the closing quotation mark with a NULL rather than an ETX.  So, we probably always want to replace the closing quotation mark with an ETX, and then optionally replace the following whitespace with a NULL.
 
2) In Engine/envvar.c, csoundParseEnv() (https://github.com/csound/csound/blob/develop/Engine/envvar.c#L376), we determine where the value should start, but we don't take into account that it might be an ETX-delimited string and adjust our bounds accordingly.
 
Putting together the following super rough patch below seems to fix the problem.  This kind of string manipulation has many pitfalls, so I haven't blunder-checked myself too carefully yet.  If this kind of approach seems okay with everyone, I can get a PR up this weekend.  It also shouldn't be too bad to get a test case for this under tests/c, so I could put that in the PR as well.
 
---------------
 
diff --git a/Engine/envvar.c b/Engine/envvar.c
index 96e0f6de3..7a3f4afdf 100644
--- a/Engine/envvar.c
+++ b/Engine/envvar.c
@@ -349,7 +349,7 @@ int csoundInitEnv(CSOUND *csound)
 
 int csoundParseEnv(CSOUND *csound, const char *s)
 {
-    char  *name, *value, msg[256];
+    char  *name, *value, *end_str, msg[256];
     int   append_mode, retval;
 
     /* copy string constant */
@@ -373,6 +373,17 @@ int csoundParseEnv(CSOUND *csound, const char *s)
       retval = CSOUND_ERROR;
       goto err_return;
     }
+    /* check if we have a quoted string bounded by ETX characters */
+    if (*value == 3) {
+      end_str = strchr(value + 1, '\03');
+      if (UNLIKELY(end_str == NULL)) {
+        retval = CSOUND_ERROR;
+        goto err_return;
+      } else {
+        *end_str = '\0';
+        value++;
+      }
+    }
     /* set variable */
     if (!append_mode)
       retval = csoundSetEnv(csound, name, value);
diff --git a/Top/one_file.c b/Top/one_file.c
index 5a82bbb4c..645e1ebf5 100644
--- a/Top/one_file.c
+++ b/Top/one_file.c
@@ -334,13 +334,11 @@ int readOptions(CSOUND *csound, CORFIL *cf, int readingCsOptions)
             p++;
           }
           if (*p == '"') {
+            *p = 3;
             if (isspace(*(p+1))) {
-              *p = '\0';
+              *(p+1) = '\0';
               break;
             }
-            else {
-              *p = 3;
-            }
           }
         }
         p++;

On Fri, Jun 21, 2024 at 1:47 PM Richard Knight <richard@1bpm.net> wrote:
Hmm ok seem to be honing in a bit - I agree, in CsOptions anything
quoted for --env:INCDIR seems to fail even if it has no spaces.

Yes - it looks like a control-C has been inserted and I missed that
before in my output.
It definitely does look to be happening in the Top/one_file.c file - it
deals with the closing " OK, but the opening " it replaces with ctrl-C
(ascii code 3) on the lines commented with
     /* ETX char used to mark the limits of a string */

-not figured out how to best fix it yet - may be worth filing a bug
report on github!


On 2024-06-21 17:21, Jeanette C. wrote:
> Hi Richard,
> include paths without space work, perahsp there is no quotation
> required? Yes, it is the quotation. I just tried putting double quotes
> around the include directory to set and it promptly failed. This is
> reproduceable. It seems to be the parsing of quoted strings in the
> CsdOptions block, especially the beginning of them.
>
> When you look at the .log files that were part of the zip, can you see
> that a control-C character had been inserted, or does your editor not
> show that? It being control characters, different terminals/viewers
> deal with it differently. I opened it in vim on a Linux TTY. It's a
> headless system.
>
> Best wishes and thanks for all your efforts!
>
> Jeanette

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here