nv50: fix build-predicate function
[mesa.git] / src / glsl / apps / version.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <assert.h>
32 #include "../pp/sl_pp_public.h"
33 #include "../pp/sl_pp_purify.h"
34
35
36 int
37 main(int argc,
38 char *argv[])
39 {
40 FILE *in;
41 long size;
42 char *inbuf;
43 struct sl_pp_purify_options options;
44 struct sl_pp_context *context;
45 unsigned int version;
46 FILE *out;
47
48 if (argc != 3) {
49 printf("Usage: version infile outfile\n");
50 return 1;
51 }
52
53 in = fopen(argv[1], "rb");
54 if (!in) {
55 return 1;
56 }
57
58 fseek(in, 0, SEEK_END);
59 size = ftell(in);
60 assert(size != -1);
61 if (size == -1) {
62 return 1;
63 }
64 fseek(in, 0, SEEK_SET);
65
66 out = fopen(argv[2], "wb");
67 if (!out) {
68 fclose(in);
69 return 1;
70 }
71
72 inbuf = malloc(size + 1);
73 if (!inbuf) {
74 fprintf(out, "$OOMERROR\n");
75
76 fclose(out);
77 fclose(in);
78 return 1;
79 }
80
81 if (fread(inbuf, 1, size, in) != size) {
82 fprintf(out, "$READERROR\n");
83
84 free(inbuf);
85 fclose(out);
86 fclose(in);
87 return 1;
88 }
89 inbuf[size] = '\0';
90
91 fclose(in);
92
93 memset(&options, 0, sizeof(options));
94
95 context = sl_pp_context_create(inbuf, &options);
96 if (!context) {
97 fprintf(out, "$CONTEXERROR\n");
98
99 free(inbuf);
100 fclose(out);
101 return 1;
102 }
103
104 if (sl_pp_version(context, &version)) {
105 fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context));
106
107 sl_pp_context_destroy(context);
108 free(inbuf);
109 fclose(out);
110 return -1;
111 }
112
113 sl_pp_context_destroy(context);
114 free(inbuf);
115
116 fprintf(out, "%u\n", version);
117
118 fclose(out);
119
120 return 0;
121 }