Hi Chris,
I'll implement all your suggestion and corrections in a new patch. Most of
them are easy to add I think. Find some comments in the email
On Wed, Sep 30, 2009 at 10:58 PM, Chris Foster <chris42f@...> wrote:
> Hi Ricardo,
>
> On Sun, Sep 27, 2009 at 04:12:57PM +0100, Ricardo Mayor wrote:
> > Hello,
> > Find attached a patch for the bug "*Escaped strings in RSL not working".
> > According *to ri specs, the supported escape string are
> >
> > \n linefeed (newline)
> > \r carriage return
> > \t horizontal tab
> > \b backspace
> > \f form feed
> > \\ backslash
> > \" double quote
> > \ddd character code ddd (octal)
> > \newline no character ? both are ignored
>
> I think these may be the escape sequences specified in the part of the
> RISpec
> which deals with the RIB format, not the renderman shading language?
>
> Here's what I see in my copy of the RISpec (around page 117):
>
> " Strings are used to name external objects (texture maps, for
> example). String literals (or
> " constants) are enclosed in double quotes, as in the C language, and
> may contain any of the
> " standard C "escape sequences" (such as \n for newline or \" for a quote).
>
> So actually I guess we should support a few more things which are in the C
> language but not part of the RIB syntax:
>
> \a
> \v
> \'
> \?
> \ooo
> \x hh
> \x hhh
> (According to http://msdn.microsoft.com/en-us/library/h21280bw(VS.80).aspx<http://msdn.microsoft.com/en-us/library/h21280bw%28VS.80%29.aspx>
> )
>
I agree with. this. I misinterpreted the specs. Anyway most of this new
escape characteres are easy to add.**
>
> I've also got some suggestions to make the code a bit easier to read. To
> begin
> with, please consider putting this chunk of code into its own function
> (eg, LoadString() or whatever). CqShaderVM::LoadProgram() is a monster
> function already, let's not make it any huger!
>
> Yes, I'll do it.
> Other suggestions follow:
>
> > diff --git a/libs/shadervm/shadervm.cpp b/libs/shadervm/shadervm.cpp
> > index 225670a..a8d693e 100644
> > --- a/libs/shadervm/shadervm.cpp
> > +++ b/libs/shadervm/shadervm.cpp
> > @@ -1279,11 +1279,89 @@ void CqShaderVM::LoadProgram( std::istream* pFile
> )
> > ( *pFile ) >> std::ws;
> > char c;
> > CqString s( "" );
> > + bool escapeChar = false, escapeNumeric = false;
> > + CqString capturedNumber( "" );
> > +
> > pFile->get
> > ();
> > - while ( ( c = pFile->get
> > - () ) != '"' )
> > - s += c;
> > + while ( (( c = pFile->get() ) != '"') || escapeChar
> )
> > + {
> > +
> > + if (escapeNumeric)
> > + {
> > + if(c < '0' or c > '9')
> > + {
> > + char number =
> strtoul(capturedNumber.c_str(), NULL, 8);
> > + s+= number;
> > + escapeChar = false;
> > + escapeNumeric = false;
> > + capturedNumber = "";
> > + }
> > + }
> > + if(escapeChar)
> > + {
> > + //Treatment for escape char
> > + switch(c){
>
> Please use opening braces on their own line for consistency with the rest
> of
> the codebase.
>
I installed Artistic style to check the code style but.. Where is the
style file?
>
> > + case 'n':
> > + s += '\n';
> > + escapeChar = false;
> > + break;
> > + case 'r':
> > + s += '\r';
> > + escapeChar = false;
> > + break;
> > + case 't':
> > + s += '\t';
> > + escapeChar = false;
> > + break;
> > + case 'b':
> > + s += '\b';
> > + escapeChar = false;
> > + break;
> > + case 'f':
> > + s += '\f';
> > + escapeChar = false;
> > + break;
> > + case '"':
> > + s += '"';
> > + escapeChar = false;
> > + break;
> > + case '\\':
> > + s += '\\';
> > + escapeChar = false;
> > + break;
> > + case '0':
> > + case '1':
> > + case '2':
> > + case '3':
> > + case '4':
> > + case '5':
> > + case '6':
> > + case '7':
> > + case '8':
> > + case '9':
> > +
> > + capturedNumber +=
> c;
> > + if
> (capturedNumber.length() == 3)
> > + {
> > +
> escapeNumeric = false;
> > + escapeChar
> = false;
> > + s +=
> (char)strtoul(capturedNumber.c_str(), NULL, 8);
> > + }
> > + else
> > +
> escapeNumeric = true;
> > + break;
>
> When I was reading through this code, I got rather confused by the handling
> of
> capturedNumber, since it appears in two different places and there's two
> different places where it's converted to a char using strtoul(). I suggest
> just using a nested loop inside this part of the case statement to confine
> octal handling logic to a single place in the code. When you encounter the
> end of the octal number you can use the function pFile->unget() to put back
> the terminating character into the input stream. (For an example of
> something
> very similar, see CqRibLexer::readString() in riblexer.cpp.)
>
I wrote the code in this way to avoid using file->unget() when the length of
the number is less than 3. Anyway I´ll check it
>
> > + default :
> > + escapeChar = false;
> > + break;
> > + }
> > + }
> > + else
> > + if (c == '\\')
> > + escapeChar = true;
> > + else
> > + s += c;
> > + }
> > AddString( s.c_str(), pProgramArea );
> > }
> > break;
>
> Just attach any changes as a new patch, thanks :-)
> ~Chris.
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9-12, 2009. Register now!
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Aqsis-development mailing list
> Aqsis-development@...
> https://lists.sourceforge.net/lists/listinfo/aqsis-development
>
|