testparse.c
branchtrunk
changeset 53 8c856f73908e
parent 50 427f32b5eeff
child 92 bc1bb138e855
equal deleted inserted replaced
52:305ddf21d660 53:8c856f73908e
    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(unsigned char *buf, int len, const char *prof)
    45 static void 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 
    48 
    49     pd = MOJOSHADER_parse(prof, buf, len, Malloc, Free);
    49     pd = MOJOSHADER_parse(prof, buf, len, Malloc, Free);
    50     printf("PROFILE: %s\n", prof);
    50     printf("PROFILE: %s\n", prof);
    51     printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
       
    52     printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
       
    53     printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
       
    54     if (pd->error != NULL)
    51     if (pd->error != NULL)
    55         printf("ERROR: %s\n", pd->error);
    52         printf("ERROR: %s\n", pd->error);
    56     if (pd->output != NULL)
    53     else
    57         printf("OUTPUT:\n%s\n", pd->output);
    54     {
       
    55         printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
       
    56         printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
       
    57         printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
       
    58         if (pd->output != NULL)
       
    59             printf("OUTPUT:\n%s\n", pd->output);
       
    60     } // else
    58     printf("\n\n");
    61     printf("\n\n");
    59     MOJOSHADER_freeParseData(pd);
    62     MOJOSHADER_freeParseData(pd);
    60 } // do_parse
    63 } // do_parse
    61 
    64 
    62 
    65 
    63 int main(int argc, char **argv)
    66 int main(int argc, char **argv)
    64 {
    67 {
    65     int i;
       
    66 
       
    67     printf("MojoShader testparse\n");
    68     printf("MojoShader testparse\n");
    68     printf("Compiled against version %d\n", MOJOSHADER_VERSION);
    69     printf("Compiled against version %d\n", MOJOSHADER_VERSION);
    69     printf("Linked against version %d\n", MOJOSHADER_version());
    70     printf("Linked against version %d\n", MOJOSHADER_version());
    70     printf("\n");
    71     printf("\n");
    71 
    72 
    72     if (argc == 1)
    73     if (argc <= 2)
    73         printf("No files specified.\n");
    74         printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
    74     else
    75     else
    75     {
    76     {
    76         for (i = 1; i < argc; i++)
    77         const char *profile = argv[1];
       
    78         int i;
       
    79 
       
    80         for (i = 2; i < argc; i++)
    77         {
    81         {
    78             FILE *io = fopen(argv[i], "rb");
    82             FILE *io = fopen(argv[i], "rb");
    79             printf("FILE: %s\n", argv[i]);
    83             printf("FILE: %s\n", argv[i]);
    80             if (io == NULL)
    84             if (io == NULL)
    81                 printf("fopen('%s') failed.\n", argv[i]);
    85                 printf(" ... fopen('%s') failed.\n", argv[i]);
    82             else
    86             else
    83             {
    87             {
    84                 unsigned char *buf = (unsigned char *) malloc(1000000);
    88                 unsigned char *buf = (unsigned char *) malloc(1000000);
    85                 int rc = fread(buf, 1, 1000000, io);
    89                 int rc = fread(buf, 1, 1000000, io);
    86                 fclose(io);
    90                 fclose(io);
    87                 do_parse(buf, rc, MOJOSHADER_PROFILE_D3D);
    91                 do_parse(buf, rc, profile);
    88                 do_parse(buf, rc, MOJOSHADER_PROFILE_GLSL);
       
    89                 free(buf);
    92                 free(buf);
    90             } // else
    93             } // else
    91         } // for
    94         } // for
    92     } // else
    95     } // else
    93 
    96