Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChucK mistaking directory delimiters for escape characters on Windows. #90

Open
ericheep opened this issue Mar 13, 2017 · 4 comments
Open
Assignees

Comments

@ericheep
Copy link
Contributor

ericheep commented Mar 13, 2017

On Windows using CMD or PowerShell, ChucK seems to mistake directory delimiters for escape characters. This is especially tricky when autocomplete in these environments always prefixes the current directory .\, so a \ combined with the first letter of ChucK file is mistaken for an escape character.

chuck-error

This error is only present on Windows as far as I can tell, it is not present on OSX.

EDIT: Turns out I'm incorrect about it not being present on OSX. Prefixing .\ when running ChucK from terminal does not work (and I suppose it shouldn't).

screen shot 2017-03-13 at 3 35 07 pm

@ericheep
Copy link
Contributor Author

Hmm, it seems it's this chunk in util_string.cpp that is the part of the issue, which only runs if there is a \ in the command.

if( s[i] == '\\' && (i+1) < s.length() )
{
    // check next char
    if( s[i+1] == ':' || s[i+1] == '\\' )
    {
        // add
        mask[i] = 1;
        // skip next character
        i++;
    }
    else
    {
        // error: recognized escape target
        fprintf( stderr, "[chuck]: unrecognized escape sequence: \\%c", s[i+1] );
        // return false
        ret = FALSE;
        // go clean
        goto done;
    }
}

It seems like we're stopping ChucK from loading a file if it encounters an escape sequence in the command, I'm unsure of how we can accommodate both loading a command with backslaches (for example, the command chuck C:\Users\eric\Desktop\test.ck will error out) and killing ChucK when it encounters an escape character. I'm also a bit unsure of the necessity of the latter, and I'm curious about its use case.

@spencersalazar
Copy link
Member

spencersalazar commented Mar 14, 2017

This is actually a pretty big historical disaster area in ChucK and has been changed/redesigned/fixed several times in the face of competing priorities/demands.

Basically ChucK uses : as a separator for command line arguments to individual scripts (e.g. chuck test.ck:3:4:5 will supply 3, 4, and 5 as me.arg(0), me.arg(1) and me.arg(2) respectively). This creates a problem on Windows when filenames like e.g. c:\file.ck are parsed as running c.ck with the argument \file.ck.

It becomes even more fun when, on Windows, you want to run a script that takes a ChucK file passed as a command line argument and exports it to a WAV file passed as a command line argument. This is how miniAudicle Export works: by running as a subprocess e.g. chuck c:/Program Files/ChucK/scripts/export.ck:c\:/path/to/inputfile.ck:c\:/path/to/outputfile.wav. Its pretty nasty, but it works, and depends on a structured, reliable way to distinguish : used as part of a path or command line argument and : used as a command line argument separator. At some point we decided to use \ at the expense of Windows command line users, which were assumed to be few in number, to ensure reliability for Windows miniAudicle Export users, assumed to be many more in comparison.

chuck is still usable on the command line in Windows; you have to use / as a directory separator instead of \. They usually work interchangeably and few things will complain, though \ will be used by default for e.g. tab completion as you have noted. Unfortunately to change this it would have to be fairly clear that any proposed solution will still be able to work correctly with miniAudicle exporting, drive letters in file names, allow : characters to be included in command line arguments, and do all of these in ways that are not overly inconvenient or inconsistent on other platforms.

@ericheep
Copy link
Contributor Author

From what you're saying, it seems that the only way correct this in a manner that would be acceptable on other platforms would be to change the method in which command line arguments are separated (e.g. using spaces instead of colons). But this big of a change doesn't sound likely without some considerable effort as well as a consensus from the ChucK community, so I won't pin my hopes on it.

The main driver for me on this issue was being able to run a ChucK shred from inside of an alternative IDE, and the manner in which a ChucK plugin would determine the path of the buffer was prohibiting that (as it would default to Windows type pathing), but there are workarounds for those issues.

@spencersalazar
Copy link
Member

Alternative IDE support is probably a bigger priority than pure command line support, so if any other ideas come up that don't involve big user-facing changes, Im all ears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants