[Csnd-dev] Spaces in csoundSetOption

Eduardo Moguillansky <[email protected]>
Newsgroups gmane.comp.audio.csound.devel
Message-ID <CAHFFss+Q+GEehaZyBGNJjuC5OKAk4UicnDp4NGmMAQqLh6SNPw@mail.gmail.com>
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.