Skip to content

Latest commit

 

History

History
93 lines (82 loc) · 2.35 KB

assemble.c

File metadata and controls

93 lines (82 loc) · 2.35 KB
 
Dec 10, 2008
Dec 10, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* MojoShader; generate shader programs from bytecode of compiled
* Direct3D shaders.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
#include <stdio.h>
#include <stdlib.h>
#include "mojoshader.h"
Feb 12, 2009
Feb 12, 2009
14
15
static int assemble(const char *fname, const char *buf, int len,
const char *outfile)
Dec 10, 2008
Dec 10, 2008
16
17
18
19
20
21
22
23
24
25
26
{
FILE *io = fopen(outfile, "wb");
if (io == NULL)
{
printf(" ... fopen('%s') failed.\n", outfile);
return 0;
} // if
const MOJOSHADER_parseData *pd;
int retval = 0;
Feb 12, 2009
Feb 12, 2009
27
28
pd = MOJOSHADER_assemble(fname, buf, len, NULL, 0, NULL, 0,
NULL, 0, NULL, NULL, NULL, NULL, NULL);
Feb 3, 2009
Feb 3, 2009
29
30
31
32
33
if (pd->error_count > 0)
{
int i;
for (i = 0; i < pd->error_count; i++)
{
Feb 12, 2009
Feb 12, 2009
34
35
printf("%s:%d: ERROR: %s\n",
pd->errors[i].filename ? pd->errors[i].filename : "???",
Feb 3, 2009
Feb 3, 2009
36
37
38
39
pd->errors[i].error_position,
pd->errors[i].error);
} // for
} // if
Dec 10, 2008
Dec 10, 2008
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
else
{
if (pd->output != NULL)
{
if (fwrite(pd->output, pd->output_len, 1, io) != 1)
printf(" ... fwrite('%s') failed.\n", outfile);
else if (fclose(io) == EOF)
printf(" ... fclose('%s') failed.\n", outfile);
else
retval = 1;
} // if
} // else
MOJOSHADER_freeParseData(pd);
return retval;
} // assemble
int main(int argc, char **argv)
{
int retval = 1;
if (argc != 3)
Feb 11, 2009
Feb 11, 2009
63
printf("\n\nUSAGE: %s <inputfile> <outputfile>\n\n", argv[0]);
Dec 10, 2008
Dec 10, 2008
64
65
66
67
68
69
70
71
72
73
else
{
const char *infile = argv[1];
const char *outfile = argv[2];
FILE *io = fopen(infile, "rb");
if (io == NULL)
printf(" ... fopen('%s') failed.\n", infile);
else
{
char *buf = (char *) malloc(1000000);
Feb 11, 2009
Feb 11, 2009
74
int rc = fread(buf, 1, 1000000, io);
Dec 10, 2008
Dec 10, 2008
75
76
77
78
79
fclose(io);
if (rc == EOF)
printf(" ... fread('%s') failed.\n", infile);
else
{
Feb 12, 2009
Feb 12, 2009
80
if (assemble(infile, buf, rc, outfile))
Dec 10, 2008
Dec 10, 2008
81
retval = 0;
Dec 10, 2008
Dec 10, 2008
82
83
else
remove(outfile);
Dec 10, 2008
Dec 10, 2008
84
85
86
87
88
89
90
91
92
free(buf);
} // else
} // for
} // else
return retval;
} // main
// end of assemble.c ...