glsl/apps: Assert that ftell does not return an error.
[mesa.git] / src / glsl / apps / tokenise.c
index 9f95424f5c89930de6e06573c9292fb3dde069ef..b4c6d609300f4a2d09bdc395bb48f3d8f3a59b02 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <assert.h>
 #include "../pp/sl_pp_public.h"
 
@@ -39,13 +40,13 @@ main(int argc,
    long size;
    char *inbuf;
    struct sl_pp_purify_options options;
-   char *outbuf;
    struct sl_pp_context *context;
    struct sl_pp_token_info *tokens;
    FILE *out;
    unsigned int i;
 
    if (argc != 3) {
+      printf("Usage: tokenize infile outfile\n");
       return 1;
    }
 
@@ -56,6 +57,7 @@ main(int argc,
 
    fseek(in, 0, SEEK_END);
    size = ftell(in);
+   assert(size != -1);
    fseek(in, 0, SEEK_SET);
 
    out = fopen(argv[2], "wb");
@@ -87,35 +89,25 @@ main(int argc,
 
    memset(&options, 0, sizeof(options));
 
-   if (sl_pp_purify(inbuf, &options, &outbuf)) {
-      fprintf(out, "$PURIFYERROR\n");
-
-      free(inbuf);
-      fclose(out);
-      return 1;
-   }
-
-   free(inbuf);
-
-   context = sl_pp_context_create();
+   context = sl_pp_context_create(inbuf, &options);
    if (!context) {
       fprintf(out, "$CONTEXERROR\n");
 
-      free(outbuf);
+      free(inbuf);
       fclose(out);
       return 1;
    }
 
-   if (sl_pp_tokenise(context, outbuf, &tokens)) {
+   if (sl_pp_tokenise(context, &tokens)) {
       fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context));
 
       sl_pp_context_destroy(context);
-      free(outbuf);
+      free(inbuf);
       fclose(out);
       return 1;
    }
 
-   free(outbuf);
+   free(inbuf);
 
    for (i = 0; tokens[i].token != SL_PP_EOF; i++) {
       switch (tokens[i].token) {
@@ -219,11 +211,11 @@ main(int argc,
          break;
 
       case SL_PP_MODASSIGN:
-         fprintf(out, "%= ");
+         fprintf(out, "%%= ");
          break;
 
       case SL_PP_MODULO:
-         fprintf(out, "% ");
+         fprintf(out, "%% ");
          break;
 
       case SL_PP_LSHIFTASSIGN: