testparse.c
branchtrunk
changeset 142 e064b4cefb4e
parent 113 8ebf445c5305
child 148 645003ec6623
equal deleted inserted replaced
141:997857107c39 142:e064b4cefb4e
    40 
    40 
    41     return NULL;  // shouldn't hit this.
    41     return NULL;  // shouldn't hit this.
    42 } // shader_type
    42 } // shader_type
    43 
    43 
    44 
    44 
    45 static void do_parse(const unsigned char *buf, const int len, const char *prof)
    45 static int do_parse(const unsigned char *buf, const int len, const char *prof)
    46 {
    46 {
    47     const MOJOSHADER_parseData *pd;
    47     const MOJOSHADER_parseData *pd;
       
    48     int retval = 0;
    48 
    49 
    49     pd = MOJOSHADER_parse(prof, buf, len, Malloc, Free, NULL);
    50     pd = MOJOSHADER_parse(prof, buf, len, Malloc, Free, NULL);
    50     printf("PROFILE: %s\n", prof);
    51     printf("PROFILE: %s\n", prof);
    51     if (pd->error != NULL)
    52     if (pd->error != NULL)
    52         printf("ERROR: %s\n", pd->error);
    53         printf("ERROR: %s\n", pd->error);
    53     else
    54     else
    54     {
    55     {
       
    56         retval = 1;
    55         printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
    57         printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
    56         printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
    58         printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
    57         printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
    59         printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
    58 
    60 
    59         printf("ATTRIBUTES:");
    61         printf("ATTRIBUTES:");
   102             printf("\n");
   104             printf("\n");
   103         } // if
   105         } // if
   104     } // else
   106     } // else
   105     printf("\n\n");
   107     printf("\n\n");
   106     MOJOSHADER_freeParseData(pd);
   108     MOJOSHADER_freeParseData(pd);
       
   109 
       
   110     return retval;
   107 } // do_parse
   111 } // do_parse
   108 
   112 
   109 
   113 
   110 int main(int argc, char **argv)
   114 int main(int argc, char **argv)
   111 {
   115 {
       
   116     int retval = 0;
       
   117 
   112     printf("MojoShader testparse\n");
   118     printf("MojoShader testparse\n");
   113     printf("Compiled against version %d\n", MOJOSHADER_VERSION);
   119     printf("Compiled against version %d\n", MOJOSHADER_VERSION);
   114     printf("Linked against version %d\n", MOJOSHADER_version());
   120     printf("Linked against version %d\n", MOJOSHADER_version());
   115     printf("\n");
   121     printf("\n");
   116 
   122 
   130             else
   136             else
   131             {
   137             {
   132                 unsigned char *buf = (unsigned char *) malloc(1000000);
   138                 unsigned char *buf = (unsigned char *) malloc(1000000);
   133                 int rc = fread(buf, 1, 1000000, io);
   139                 int rc = fread(buf, 1, 1000000, io);
   134                 fclose(io);
   140                 fclose(io);
   135                 do_parse(buf, rc, profile);
   141                 if (!do_parse(buf, rc, profile))
       
   142                     retval = 1;
   136                 free(buf);
   143                 free(buf);
   137             } // else
   144             } // else
   138         } // for
   145         } // for
   139     } // else
   146     } // else
   140 
   147 
   141     return 0;
   148     return retval;
   142 } // main
   149 } // main
   143 
   150 
   144 // end of testparse.c ...
   151 // end of testparse.c ...
   145 
   152