Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption

vlz <[email protected]>
Newsgroups gmane.comp.audio.csound.devel
Message-ID <[email protected]>
I checked and this code works

 res = csoundSetOption(csound, "-o dac -m 6");

so you can have spaces between the arguments. There is a problem with more than a single space, which I
can look into.

> On 9 Jan 2025, at 09:55, vlz <[email protected]> wrote:
> 
> *Warning*
> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> I wrote this new code, because the 6.x version was problematic. I can look into improving it. 
> 
> Prof. Victor Lazzarini 
> Maynooth University
> Ireland
> 
>> On 9 Jan 2025, at 09:17, Eduardo Moguillansky <[email protected]> wrote:
>> 
>>  Hi, 
>> 
>> Directly using the API in c (csound 7) I don't seem to be able to set an option which includes a space. In particular, setting the -o or --output option with a device which includes a space does not seem to work in any case. Looking at the source code it seems that a very naive string splitting code was added to csound 7. 
>> 
>> csound 6
>> 
>> PUBLIC int csoundSetOption(CSOUND *csound, const char *option){
>>     /* if already compiled and running, return */
>>     if (csound->engineStatus & CS_STATE_COMP) return 1;
>>     else {
>>     const char *args[2] = {"csound", option};
>>     csound->info_message_request = 1;
>>     return (argdecode(csound, 1, args) ? 0 : 1);
>>     }
>> }
>> 
>> csound 7
>> 
>> /* count whitespaces */
>>     while (*sp++ != '\0') {
>>       if (*sp == ' ') {
>>         cnt++;
>>         *sp = '\0';
>>         sp++;
>>       }
>>     }
>>     args = (char **)mcalloc(csound, sizeof(char *) * (cnt + 2));
>>     args[0] = "csound";
>>     args[1] = sp = options;
>>     cnt = 1;
>>     /* split into separate args */
>>     while (*opt) {
>>       if (*opt == ' ') {
>>         args[++cnt] = sp + 1;
>>       }
>>       sp++;
>>       opt++;
>>     }
>> 
>>     ret = argdecode(csound, cnt, (const char **)args);
>>     mfree(csound, args);
>>     mfree(csound, options);
>> 
>> I don't know the rationale behind this inclusion but I think that at least some form of escaping or quotation should be added to the splitting. For me the actual solution would be to remove the splitting at the API level.
>> 
>> cheers
>> Eduardo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.