chashion / alembic

Automatically exported from code.google.com/p/alembic
Other
0 stars 0 forks source link

Maya AbcExport shoud parse -j argument instead of split #226

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. AbcExport to an Alembic file with white space
AbcExport -j "-frameRange 1 24 -file \"C:/white space/test.abc\""; 

2. callbacks have white space or single/double quote marks
AbcExport -j "-frameRange 1 24 -melPerFrameCallback \"print (\\\"#FRAME\\\")\" 
-file C:/test.abc"; 

What is the expected output? What do you see instead?
AbcExport should parse -j argument correctly, just like normal MEL commands.
Maya reports an error if there are white space, single/double quote marks in 
arguments within -j.

What version of the product are you using? On what operating system?
1.0 on all platforms.

Please provide any additional information below.
Here is the approach we use:
AbcExport.cpp, replace jobArgsStr.split(' ', jobArgsArray); with
{
            // parse the job arguments
            // e.g. -perFrameCallbackMel "print \"something\"" will be splitted to
            //    [0] -perFrameCallbackMel
            //    [1] print "something"
            enum State {
                kArgument,               // parsing an argument (not quoted)
                kDoubleQuotedString,     // parsing a double quoted string
                kSingleQuotedString,     // parsing a single quoted string
            };

            State state = kArgument;
            MString stringBuffer;
            for (unsigned int charIdx = 0; charIdx < jobArgsStr.numChars(); charIdx++) {
                MString ch = jobArgsStr.substringW(charIdx, charIdx);
                switch (state) {
                case kArgument:
                    if (ch == " ") {
                        // space terminates the current argument
                        if (stringBuffer.length() > 0) {
                            jobArgsArray.append(stringBuffer);
                            stringBuffer.clear();
                        }
                        // goto another argument
                        state = kArgument;
                    }
                    else if (ch == "\"") {
                        if (stringBuffer.length() > 0) {
                            // double quote is part of the argument
                            stringBuffer += ch;
                        }
                        else {
                            // goto double quoted string
                            state = kDoubleQuotedString;
                        }
                    }
                    else if (ch == "'") {
                        if (stringBuffer.length() > 0) {
                            // single quote is part of the argument
                            stringBuffer += ch;
                        }
                        else {
                            // goto single quoted string
                            state = kSingleQuotedString;
                        }
                    }
                    else {
                        stringBuffer += ch;
                    }
                    break;
                case kDoubleQuotedString:
                    // double quote terminates the current string
                    if (ch == "\"") {
                        jobArgsArray.append(stringBuffer);
                        stringBuffer.clear();
                        state = kArgument;
                    }
                    else if (ch == "\\") {
                        // escaped character
                        MString nextCh = (++charIdx < jobArgsStr.numChars())
                            ? jobArgsStr.substringW(charIdx, charIdx) : "\\";
                        if (nextCh == "n")       stringBuffer += "\n";
                        else if (nextCh == "t")  stringBuffer += "\t";
                        else if (nextCh == "r")  stringBuffer += "\r";
                        else if (nextCh == "\\") stringBuffer += "\\";
                        else if (nextCh == "'")  stringBuffer += "'";
                        else if (nextCh == "\"") stringBuffer += "\"";
                        else                     stringBuffer += nextCh;
                    }
                    else {
                        stringBuffer += ch;
                    }
                    break;
                case kSingleQuotedString:
                    // single quote terminates the current string
                    if (ch == "'") {
                        jobArgsArray.append(stringBuffer);
                        stringBuffer.clear();
                        state = kArgument;
                    }
                    else if (ch == "\\") {
                        // escaped character
                        MString nextCh = (++charIdx < jobArgsStr.numChars())
                            ? jobArgsStr.substringW(charIdx, charIdx) : "\\";
                        if (nextCh == "n")       stringBuffer += "\n";
                        else if (nextCh == "t")  stringBuffer += "\t";
                        else if (nextCh == "r")  stringBuffer += "\r";
                        else if (nextCh == "\\") stringBuffer += "\\";
                        else if (nextCh == "'")  stringBuffer += "'";
                        else if (nextCh == "\"") stringBuffer += "\"";
                        else                     stringBuffer += nextCh;
                    }
                    else {
                        stringBuffer += ch;
                    }
                    break;
                }
            }

            // the rest of the argument
            if (stringBuffer.length() > 0) {
                jobArgsArray.append(stringBuffer);
            }
        }

Thanks!

Original issue reported on code.google.com by shinc...@gmail.com on 1 Sep 2011 at 7:01

GoogleCodeExporter commented 9 years ago
This was done in 1.0.1

Original comment by miller.lucas on 14 Oct 2011 at 11:55