finderrors.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 20 Dec 2008 05:48:38 -0500
changeset 524 03eea2f0762c
parent 517 ec3f6fa441d3
child 536 5af65fe6e917
permissions -rw-r--r--
First (incomplete!) shot at more robust CTAB support. Assembler can now add it, but we still need to parse it better and report it all back to the app in MOJOSHADER_parse().
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"
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    21
#endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    22
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    23
#ifdef _MSC_VER
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    24
#define WIN32_LEAN_AND_MEAN 1
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    25
#include <windows.h>
260
5b5fc8c5661b More Windows fixes: include malloc.h for alloca() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 259
diff changeset
    26
#include <malloc.h>  // for alloca().
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    27
#define snprintf _snprintf
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    28
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    29
#include <dirent.h>
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    30
#endif
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    31
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    32
#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
    33
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    34
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
    35
{
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    36
    int do_quit = 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    37
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    38
    #if FINDERRORS_COMPILE_SHADERS
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    39
    SDL_Event e;  // pump event queue to keep OS happy.
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    40
    while (SDL_PollEvent(&e))
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    41
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    42
        if (e.type == SDL_QUIT)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    43
            do_quit = 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    44
    } // while
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    45
    SDL_GL_SwapBuffers();
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    46
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    47
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    48
    if (do_quit)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    49
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    50
        report("FAIL: user requested quit!\n");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    51
        return 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    52
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    53
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    54
    int assembly = 0;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    55
    if (strstr(fn, ".bytecode") != NULL)
517
ec3f6fa441d3 Removed debug code.
Ryan C. Gordon <icculus@icculus.org>
parents: 515
diff changeset
    56
        assembly = 0;
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    57
    else if (strstr(fn, ".disasm") != NULL)
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    58
        assembly = 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    59
    else
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    60
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    61
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    62
    (*total)++;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    63
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    64
    char *fname = (char *) alloca(strlen(fn) + strlen(dname) + 1);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    65
    sprintf(fname, "%s/%s", dname, fn);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    66
    FILE *io = fopen(fname, "rb");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    67
    if (io == NULL)
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
        report("FAIL: %s fopen() failed.\n", fname);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    70
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    71
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    72
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    73
    static unsigned char buf[1024 * 256];
509
88c18d64e95b Make sure assembly source in test program is null-terminated.
Ryan C. Gordon <icculus@icculus.org>
parents: 507
diff changeset
    74
    int rc = fread(buf, 1, sizeof (buf)-1, io);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    75
    fclose(io);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    76
    if (rc == -1)
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
        report("FAIL: %s %s\n", fname, strerror(errno));
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    79
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    80
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    81
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    82
    if (assembly)
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    83
    {
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    84
        const MOJOSHADER_parseData *a;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    85
509
88c18d64e95b Make sure assembly source in test program is null-terminated.
Ryan C. Gordon <icculus@icculus.org>
parents: 507
diff changeset
    86
        buf[rc] = '\0';  // make sure the source is null-terminated.
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 517
diff changeset
    87
        a = MOJOSHADER_assemble((char *) buf, 0, 0, 0, 0, 0, 0, 0);
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    88
        if (a->error)
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    89
        {
507
0dd7a913f498 Added line number to assembler errors in finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 503
diff changeset
    90
            report("FAIL: %s (line %d) %s\n", fname, a->error_position, a->error);
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    91
            return 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    92
        } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    93
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    94
        else if (a->output_len > sizeof (buf))
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    95
        {
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    96
            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
    97
            return 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    98
        } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    99
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   100
        rc = a->output_len;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   101
        memcpy(buf, a->output, rc);
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   102
        MOJOSHADER_freeParseData(a);
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   103
    } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   104
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   105
    #if FINDERRORS_COMPILE_SHADERS
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 437
diff changeset
   106
    MOJOSHADER_glShader *shader = MOJOSHADER_glCompileShader(buf, rc, NULL, 0);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   107
    if (shader == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   108
        report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   109
    else
437
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   110
    {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   111
        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
   112
        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
   113
        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
   114
        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
   115
        if (program == NULL)
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   116
            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
   117
        else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   118
        {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   119
            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
   120
            MOJOSHADER_glDeleteProgram(program);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   121
        } // else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   122
        MOJOSHADER_glDeleteShader(shader);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   123
    }
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   124
    #else
456
39a9be44129d Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   125
    const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, NULL, 0, NULL, NULL, NULL);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   126
    if (pd->error != NULL)
475
ea119c8ce5cd Added error position information to MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 456
diff changeset
   127
        report("FAIL: %s (position %d) %s\n", fname, pd->error_position, pd->error);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   128
    else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   129
        report("PASS: %s\n", fname);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   130
    MOJOSHADER_freeParseData(pd);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   131
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   132
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   133
    return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   134
} // do_file
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   135
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   136
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   137
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
   138
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    int total = 0;
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   140
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   141
#ifdef _MSC_VER
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   142
    WIN32_FIND_DATA dent;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   143
    HANDLE dirp = INVALID_HANDLE_VALUE;
259
68ba103e17e4 More Windows fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 258
diff changeset
   144
    FindFirstFileA(dname, &dent);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   145
    if (dirp != INVALID_HANDLE_VALUE)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   146
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   147
        do
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
            if (!do_file(profile, dname, dent.cFileName, &total))
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   150
                break;
259
68ba103e17e4 More Windows fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 258
diff changeset
   151
        } while (FindNextFileA(dirp, &dent) != 0);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   152
        CloseHandle(dirp);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   153
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   154
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   155
    struct dirent *dent = NULL;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    DIR *dirp = opendir(dname);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    if (dirp != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    {
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
        while ((dent = readdir(dirp)) != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
        {
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   161
            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
   162
                break;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
        } // while
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
        closedir(dirp);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    } // if
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   166
#endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    return total;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
} // do_dir
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
int main(int argc, char **argv)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
    //printf("MojoShader finderrors\n");
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    //printf("Compiled against version %d\n", MOJOSHADER_VERSION);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    //printf("Linked against version %d\n", MOJOSHADER_version());
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    //printf("\n");
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    if (argc <= 2)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
        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
   181
    else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    {
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
        int total = 0;
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   184
        int i;
224
4acaf8199665 Moved finderrors.c from GL calls to MOJOSHADER_gl* functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
   185
        const char *profile = argv[1];
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   187
        #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
   188
        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
   189
        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
   190
        SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 260
diff changeset
   191
        printf("Best profile is '%s'\n", MOJOSHADER_glBestProfile(SDL_GL_GetProcAddress));
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   192
        MOJOSHADER_glContext *ctx;
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   193
        ctx = MOJOSHADER_glCreateContext(profile, SDL_GL_GetProcAddress, 0, 0, 0);
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   194
        if (ctx == NULL)
227
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   195
        {
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   196
            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
   197
            SDL_Quit();
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   198
            return 1;
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   199
        } // if
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   200
        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
   201
        #endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   202
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
        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
   204
            total += do_dir(argv[i], profile);
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   206
        printf("Saw %d files.\n", total);
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   208
        #if FINDERRORS_COMPILE_SHADERS
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   209
        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
   210
        SDL_Quit();
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   211
        #endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
    } // else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
    return 0;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
} // main
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
// end of finderrors.c ...
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218