utils/finderrors.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 29 May 2012 02:43:24 -0400
changeset 1104 9147482e1ec7
parent 956 7888858a6777
child 1117 f6712bf72c19
permissions -rw-r--r--
Allow sampler type remapping. Allows workaround for Shader Model 1 not specifying what a sampler should be in the bytecode itself.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     1
/**
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     3
 *  Direct3D shaders.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     4
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     6
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     7
 *  This file written by Ryan C. Gordon.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     8
 */
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     9
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include <stdio.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <stdlib.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include <string.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <stdarg.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <sys/types.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <errno.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include "mojoshader.h"
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    19
#if FINDERRORS_COMPILE_SHADERS
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    20
#include "SDL.h"
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    21
static void *lookup(const char *fnname, void *unused)
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    22
{
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    23
    (void) unused;
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    24
    return SDL_GL_GetProcAddress(fnname);
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    25
} // lookup
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    26
#endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    27
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    28
#ifdef _MSC_VER
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    29
#define WIN32_LEAN_AND_MEAN 1
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    30
#include <windows.h>
260
5b5fc8c5661b More Windows fixes: include malloc.h for alloca() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 259
diff changeset
    31
#include <malloc.h>  // for alloca().
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    32
#define snprintf _snprintf
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    33
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    34
#include <dirent.h>
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    35
#endif
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    36
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    37
#define report printf
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    38
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    39
static int do_file(const char *profile, const char *dname, const char *fn, int *total)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    40
{
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    41
    int do_quit = 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    42
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    43
    #if FINDERRORS_COMPILE_SHADERS
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    44
    SDL_Event e;  // pump event queue to keep OS happy.
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    45
    while (SDL_PollEvent(&e))
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    46
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    47
        if (e.type == SDL_QUIT)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    48
            do_quit = 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    49
    } // while
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    50
    SDL_GL_SwapBuffers();
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    51
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    52
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    53
    if (do_quit)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    54
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    55
        report("FAIL: user requested quit!\n");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    56
        return 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    57
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    58
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    59
    int assembly = 0;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    60
    if (strstr(fn, ".bytecode") != NULL)
517
ec3f6fa441d3 Removed debug code.
Ryan C. Gordon <icculus@icculus.org>
parents: 515
diff changeset
    61
        assembly = 0;
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    62
    else if (strstr(fn, ".disasm") != NULL)
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    63
        assembly = 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    64
    else
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    65
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    66
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    67
    (*total)++;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    68
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    69
    char *fname = (char *) alloca(strlen(fn) + strlen(dname) + 1);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    70
    sprintf(fname, "%s/%s", dname, fn);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    71
    FILE *io = fopen(fname, "rb");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    72
    if (io == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    73
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    74
        report("FAIL: %s fopen() failed.\n", fname);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    75
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    76
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    77
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    78
    static unsigned char buf[1024 * 256];
562
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
    79
    int rc = fread(buf, 1, sizeof (buf), io);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    80
    fclose(io);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    81
    if (rc == -1)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    82
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    83
        report("FAIL: %s %s\n", fname, strerror(errno));
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    84
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    85
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    86
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    87
    if (assembly)
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    88
    {
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    89
        const MOJOSHADER_parseData *a;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    90
509
88c18d64e95b Make sure assembly source in test program is null-terminated.
Ryan C. Gordon <icculus@icculus.org>
parents: 507
diff changeset
    91
        buf[rc] = '\0';  // make sure the source is null-terminated.
578
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 577
diff changeset
    92
        a = MOJOSHADER_assemble(fname, (char *) buf, rc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
562
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
    93
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
    94
        if (a->error_count > 0)
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    95
        {
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
    96
            report("FAIL: %s (line %d) %s\n",
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
    97
                a->errors[0].filename ? a->errors[0].filename : "???",
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
    98
                a->errors[0].error_position,
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
    99
                a->errors[0].error);
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   100
            return 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   101
        } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   102
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   103
        else if (a->output_len > sizeof (buf))
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   104
        {
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   105
            report("FAIL: %s buffer overflow in finderrors.c\n", fname);
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   106
            return 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   107
        } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   108
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   109
        rc = a->output_len;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   110
        memcpy(buf, a->output, rc);
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   111
        MOJOSHADER_freeParseData(a);
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   112
    } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   113
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   114
    #if FINDERRORS_COMPILE_SHADERS
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 956
diff changeset
   115
    MOJOSHADER_glShader *shader = MOJOSHADER_glCompileShader(buf, rc, NULL, 0, NULL, 0);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   116
    if (shader == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   117
        report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   118
    else
437
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   119
    {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   120
        const MOJOSHADER_parseData *pd = MOJOSHADER_glGetShaderParseData(shader);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   121
        MOJOSHADER_glShader *v = (pd->shader_type == MOJOSHADER_TYPE_VERTEX) ? shader : NULL;
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   122
        MOJOSHADER_glShader *p = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? shader : NULL;
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   123
        MOJOSHADER_glProgram *program = MOJOSHADER_glLinkProgram(v, p);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   124
        if (program == NULL)
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   125
            report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   126
        else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   127
        {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   128
            report("PASS: %s\n", fname);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   129
            MOJOSHADER_glDeleteProgram(program);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   130
        } // else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   131
        MOJOSHADER_glDeleteShader(shader);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   132
    }
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   133
    #else
456
39a9be44129d Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   134
    const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, NULL, 0, NULL, NULL, NULL);
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   135
    if (pd->error_count == 0)
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   136
        report("PASS: %s\n", fname);
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   137
	else
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   138
	{
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   139
		int i;
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   140
		for (i = 0; i < pd->error_count; i++)
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   141
		{
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   142
			report("FAIL: %s (position %d) %s\n", pd->errors[i].filename,
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   143
			       pd->errors[i].error_position, pd->errors[i].error);
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   144
		} // for
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   145
	} // else
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   146
    MOJOSHADER_freeParseData(pd);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   147
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   148
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   149
    return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   150
} // do_file
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   151
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   152
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   153
static int do_dir(const char *dname, const char *profile)
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    int total = 0;
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   156
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   157
#ifdef _MSC_VER
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   158
    WIN32_FIND_DATA dent;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   159
    HANDLE dirp = INVALID_HANDLE_VALUE;
259
68ba103e17e4 More Windows fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 258
diff changeset
   160
    FindFirstFileA(dname, &dent);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   161
    if (dirp != INVALID_HANDLE_VALUE)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   162
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   163
        do
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   164
        {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   165
            if (!do_file(profile, dname, dent.cFileName, &total))
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   166
                break;
259
68ba103e17e4 More Windows fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 258
diff changeset
   167
        } while (FindNextFileA(dirp, &dent) != 0);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   168
        CloseHandle(dirp);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   169
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   170
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   171
    struct dirent *dent = NULL;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    DIR *dirp = opendir(dname);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    if (dirp != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
    {
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
        while ((dent = readdir(dirp)) != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
        {
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   177
            if (!do_file(profile, dname, dent->d_name, &total))
172
f81c6cb14140 finderrors.c now pumps event queue and paints the SDL window.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   178
                break;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
        } // while
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
        closedir(dirp);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
    } // if
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   182
#endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    return total;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
} // do_dir
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
int main(int argc, char **argv)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    //printf("MojoShader finderrors\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   191
    //printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   192
    //printf("Linked against changeset %s\n", MOJOSHADER_changeset());
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    //printf("\n");
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    if (argc <= 2)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
        printf("\n\nUSAGE: %s <profile> [dir1] ... [dirN]\n\n", argv[0]);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    {
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
        int total = 0;
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   200
        int i;
224
4acaf8199665 Moved finderrors.c from GL calls to MOJOSHADER_gl* functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
   201
        const char *profile = argv[1];
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   203
        #if FINDERRORS_COMPILE_SHADERS
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   204
        SDL_Init(SDL_INIT_VIDEO);
224
4acaf8199665 Moved finderrors.c from GL calls to MOJOSHADER_gl* functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
   205
        SDL_GL_LoadLibrary(NULL);
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   206
        SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
   207
        printf("Best profile is '%s'\n", MOJOSHADER_glBestProfile(lookup, 0));
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   208
        MOJOSHADER_glContext *ctx;
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
   209
        ctx = MOJOSHADER_glCreateContext(profile, lookup, 0, 0, 0, 0);
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   210
        if (ctx == NULL)
227
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   211
        {
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   212
            printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
227
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   213
            SDL_Quit();
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   214
            return 1;
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   215
        } // if
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   216
        MOJOSHADER_glMakeContextCurrent(ctx);
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   217
        #endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   218
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
        for (i = 2; i < argc; i++)
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   220
            total += do_dir(argv[i], profile);
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   222
        printf("Saw %d files.\n", total);
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   224
        #if FINDERRORS_COMPILE_SHADERS
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   225
        MOJOSHADER_glDestroyContext(ctx);
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   226
        SDL_Quit();
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   227
        #endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    } // else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
    return 0;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
} // main
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
// end of finderrors.c ...
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234