mojoshader_assembler.c
changeset 572 cdc8bb82f7d2
parent 571 f8f81d832fa0
child 573 1cd1d99a79cb
equal deleted inserted replaced
571:f8f81d832fa0 572:cdc8bb82f7d2
   980 
   980 
   981 
   981 
   982 static int parse_num(Context *ctx, const int floatok, uint32 *value)
   982 static int parse_num(Context *ctx, const int floatok, uint32 *value)
   983 {
   983 {
   984     union { float f; int32 si32; uint32 ui32; } cvt;
   984     union { float f; int32 si32; uint32 ui32; } cvt;
   985 
   985     int negative = 0;
   986     const Token token = nexttoken(ctx);
   986     Token token = nexttoken(ctx);
       
   987 
       
   988     if (token == ((Token) '-'))
       
   989     {
       
   990         negative = 1;
       
   991         token = nexttoken(ctx);
       
   992     } // if
       
   993 
   987     if (token == TOKEN_INT_LITERAL)
   994     if (token == TOKEN_INT_LITERAL)
   988     {
   995     {
   989         int d = 0;
   996         int d = 0;
   990         sscanf(ctx->token, "%d", &d);
   997         sscanf(ctx->token, "%d", &d);
   991         cvt.si32 = (int32) d;
   998         if (floatok)
       
   999             cvt.f = (float) ((negative) ? -d : d);
       
  1000         else
       
  1001             cvt.si32 = (int32) ((negative) ? -d : d);
   992     } // if
  1002     } // if
   993     else if (token == TOKEN_FLOAT_LITERAL)
  1003     else if (token == TOKEN_FLOAT_LITERAL)
   994     {
  1004     {
   995         if (!floatok)
  1005         if (!floatok)
   996         {
  1006         {
   997             fail(ctx, "Expected whole number");
  1007             fail(ctx, "Expected whole number");
   998             *value = 0;
  1008             *value = 0;
   999             return 0;
  1009             return 0;
  1000         } // if
  1010         } // if
  1001         sscanf(ctx->token, "%f", &cvt.f);
  1011         sscanf(ctx->token, "%f", &cvt.f);
       
  1012         if (negative)
       
  1013             cvt.f = -cvt.f;
  1002     } // if
  1014     } // if
  1003     else
  1015     else
  1004     {
  1016     {
  1005         fail(ctx, "Expected number");
  1017         fail(ctx, "Expected number");
  1006         *value = 0;
  1018         *value = 0;