Mesa (glsl-pp-rework-2): glsl/apps: Always write out error condition.

Michał Król michal at kemper.freedesktop.org
Thu Sep 17 10:16:42 UTC 2009


Module: Mesa
Branch: glsl-pp-rework-2
Commit: 69bdd47dba1f7331a632316e4f9cc9942fb93ca4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=69bdd47dba1f7331a632316e4f9cc9942fb93ca4

Author: Michal Krol <michal at vmware.com>
Date:   Thu Sep 17 10:45:16 2009 +0200

glsl/apps: Always write out error condition.

---

 src/glsl/apps/purify.c   |   21 +++++++++++++++------
 src/glsl/apps/tokenise.c |   28 +++++++++++++++++++++-------
 src/glsl/apps/version.c  |   29 ++++++++++++++++++++++++-----
 3 files changed, 60 insertions(+), 18 deletions(-)

diff --git a/src/glsl/apps/purify.c b/src/glsl/apps/purify.c
index 7dff8ae..d4c5370 100644
--- a/src/glsl/apps/purify.c
+++ b/src/glsl/apps/purify.c
@@ -54,14 +54,26 @@ main(int argc,
    size = ftell(in);
    fseek(in, 0, SEEK_SET);
 
+   out = fopen(argv[2], "wb");
+   if (!out) {
+      fclose(in);
+      return 1;
+   }
+
    inbuf = malloc(size + 1);
    if (!inbuf) {
+      fprintf(out, "$OOMERROR\n");
+
+      fclose(out);
       fclose(in);
       return 1;
    }
 
    if (fread(inbuf, 1, size, in) != size) {
+      fprintf(out, "$READERROR\n");
+
       free(inbuf);
+      fclose(out);
       fclose(in);
       return 1;
    }
@@ -72,18 +84,15 @@ 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);
 
-   out = fopen(argv[2], "wb");
-   if (!out) {
-      free(outbuf);
-      return 1;
-   }
-
    fwrite(outbuf, 1, strlen(outbuf), out);
 
    free(outbuf);
diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c
index 64b0a2f..1746e20 100644
--- a/src/glsl/apps/tokenise.c
+++ b/src/glsl/apps/tokenise.c
@@ -60,14 +60,26 @@ main(int argc,
    size = ftell(in);
    fseek(in, 0, SEEK_SET);
 
+   out = fopen(argv[2], "wb");
+   if (!out) {
+      fclose(in);
+      return 1;
+   }
+
    inbuf = malloc(size + 1);
    if (!inbuf) {
+      fprintf(out, "$OOMERROR\n");
+
+      fclose(out);
       fclose(in);
       return 1;
    }
 
    if (fread(inbuf, 1, size, in) != size) {
+      fprintf(out, "$READERROR\n");
+
       free(inbuf);
+      fclose(out);
       fclose(in);
       return 1;
    }
@@ -78,32 +90,34 @@ 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);
 
    if (sl_pp_context_init(&context)) {
+      fprintf(out, "$CONTEXERROR\n");
+
       free(outbuf);
+      fclose(out);
       return 1;
    }
 
    if (sl_pp_tokenise(&context, outbuf, &tokens)) {
+      fprintf(out, "$ERROR: `%s'\n", context.error_msg);
+
       sl_pp_context_destroy(&context);
       free(outbuf);
+      fclose(out);
       return 1;
    }
 
    free(outbuf);
 
-   out = fopen(argv[2], "wb");
-   if (!out) {
-      sl_pp_context_destroy(&context);
-      free(tokens);
-      return 1;
-   }
-
    for (i = 0; tokens[i].token != SL_PP_EOF; i++) {
       switch (tokens[i].token) {
       case SL_PP_WHITESPACE:
diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c
index 9e57904..50c564b 100644
--- a/src/glsl/apps/version.c
+++ b/src/glsl/apps/version.c
@@ -60,14 +60,26 @@ main(int argc,
    size = ftell(in);
    fseek(in, 0, SEEK_SET);
 
+   out = fopen(argv[2], "wb");
+   if (!out) {
+      fclose(in);
+      return 1;
+   }
+
    inbuf = malloc(size + 1);
    if (!inbuf) {
+      fprintf(out, "$OOMERROR\n");
+
+      fclose(out);
       fclose(in);
       return 1;
    }
 
    if (fread(inbuf, 1, size, in) != size) {
+      fprintf(out, "$READERROR\n");
+
       free(inbuf);
+      fclose(out);
       fclose(in);
       return 1;
    }
@@ -78,39 +90,46 @@ 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);
 
    if (sl_pp_context_init(&context)) {
+      fprintf(out, "$CONTEXERROR\n");
+
       free(outbuf);
+      fclose(out);
       return 1;
    }
 
    if (sl_pp_tokenise(&context, outbuf, &tokens)) {
+      fprintf(out, "$ERROR: `%s'\n", context.error_msg);
+
       sl_pp_context_destroy(&context);
       free(outbuf);
+      fclose(out);
       return 1;
    }
 
    free(outbuf);
 
    if (sl_pp_version(&context, tokens, &version, &tokens_eaten)) {
+      fprintf(out, "$ERROR: `%s'\n", context.error_msg);
+
       sl_pp_context_destroy(&context);
       free(tokens);
+      fclose(out);
       return -1;
    }
 
    sl_pp_context_destroy(&context);
    free(tokens);
 
-   out = fopen(argv[2], "wb");
-   if (!out) {
-      return 1;
-   }
-
    fprintf(out,
            "%u\n%u\n",
            version,




More information about the mesa-commit mailing list