[svn] More testparse tweakage. trunk
authoricculus
Thu, 27 Mar 2008 23:22:33 -0400
branchtrunk
changeset 53 8c856f73908e
parent 52 305ddf21d660
child 54 b2b64d39df0f
[svn] More testparse tweakage.
testparse.c
--- a/testparse.c	Thu Mar 27 23:15:01 2008 -0400
+++ b/testparse.c	Thu Mar 27 23:22:33 2008 -0400
@@ -42,19 +42,22 @@
 } // shader_type
 
 
-static void do_parse(unsigned char *buf, int len, const char *prof)
+static void do_parse(const unsigned char *buf, const int len, const char *prof)
 {
     const MOJOSHADER_parseData *pd;
 
     pd = MOJOSHADER_parse(prof, buf, len, Malloc, Free);
     printf("PROFILE: %s\n", prof);
-    printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
-    printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
-    printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
     if (pd->error != NULL)
         printf("ERROR: %s\n", pd->error);
-    if (pd->output != NULL)
-        printf("OUTPUT:\n%s\n", pd->output);
+    else
+    {
+        printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
+        printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
+        printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
+        if (pd->output != NULL)
+            printf("OUTPUT:\n%s\n", pd->output);
+    } // else
     printf("\n\n");
     MOJOSHADER_freeParseData(pd);
 } // do_parse
@@ -62,30 +65,30 @@
 
 int main(int argc, char **argv)
 {
-    int i;
-
     printf("MojoShader testparse\n");
     printf("Compiled against version %d\n", MOJOSHADER_VERSION);
     printf("Linked against version %d\n", MOJOSHADER_version());
     printf("\n");
 
-    if (argc == 1)
-        printf("No files specified.\n");
+    if (argc <= 2)
+        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
     else
     {
-        for (i = 1; i < argc; i++)
+        const char *profile = argv[1];
+        int i;
+
+        for (i = 2; i < argc; i++)
         {
             FILE *io = fopen(argv[i], "rb");
             printf("FILE: %s\n", argv[i]);
             if (io == NULL)
-                printf("fopen('%s') failed.\n", argv[i]);
+                printf(" ... fopen('%s') failed.\n", argv[i]);
             else
             {
                 unsigned char *buf = (unsigned char *) malloc(1000000);
                 int rc = fread(buf, 1, 1000000, io);
                 fclose(io);
-                do_parse(buf, rc, MOJOSHADER_PROFILE_D3D);
-                do_parse(buf, rc, MOJOSHADER_PROFILE_GLSL);
+                do_parse(buf, rc, profile);
                 free(buf);
             } // else
         } // for