utils/finderrors.c
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Tue, 07 Jul 2020 17:44:32 -0400
changeset 1278 be0f548f321f
parent 1156 6e760a19f456
permissions -rw-r--r--
spirv: Fix bogus detection of PSIZE0
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"
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
    21
static SDL_Window *sdlwindow = NULL;
904
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    22
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
    23
{
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    24
    (void) unused;
5989f0d4185a Added data argument to GL entry point lookup callback.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
    25
    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
    26
} // lookup
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    27
#endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    28
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    29
#ifdef _MSC_VER
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    30
#define WIN32_LEAN_AND_MEAN 1
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    31
#include <windows.h>
260
5b5fc8c5661b More Windows fixes: include malloc.h for alloca() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 259
diff changeset
    32
#include <malloc.h>  // for alloca().
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    33
#define snprintf _snprintf
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    34
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    35
#include <dirent.h>
1138
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    36
#include <sys/stat.h>
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    37
#endif
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    38
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    39
#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
    40
1138
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    41
static int isdir(const char *dname)
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    42
{
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    43
#ifdef _MSC_VER
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    44
    WIN32_FILE_ATTRIBUTE_DATA winstat;
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    45
    if (!GetFileAttributesExA(dname, GetFileExInfoStandard, &winstat))
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    46
        return 0;
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    47
    return winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    48
#else
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    49
    struct stat statbuf;
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    50
    if (stat(dname, &statbuf) == -1)
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    51
        return 0;
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    52
    return S_ISDIR(statbuf.st_mode);
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    53
#endif
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    54
}
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    55
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    56
static int do_dir(const char *dname, const char *profile);
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    57
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    58
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
    59
{
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    60
    int do_quit = 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    61
1138
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    62
    if ((strcmp(fn, ".") == 0) || (strcmp(fn, "..") == 0))
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    63
        return 1;  // skip these.
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    64
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    65
    #if FINDERRORS_COMPILE_SHADERS
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    66
    SDL_Event e;  // pump event queue to keep OS happy.
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    67
    while (SDL_PollEvent(&e))
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
        if (e.type == SDL_QUIT)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    70
            do_quit = 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    71
    } // while
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
    72
    SDL_GL_SwapWindow(sdlwindow);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    73
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    74
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    75
    if (do_quit)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    76
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    77
        report("FAIL: user requested quit!\n");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    78
        return 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    79
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    80
1138
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    81
    char *fname = (char *) alloca(strlen(fn) + strlen(dname) + 2);
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    82
    sprintf(fname, "%s/%s", dname, fn);
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    83
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    84
    if (isdir(fname))
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    85
    {
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    86
        *total += do_dir(fname, profile);
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    87
        return 1;
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    88
    } // if
119bbce82c8d Allow finderrors to troll through subdirectories.
Ryan C. Gordon <icculus@icculus.org>
parents: 1137
diff changeset
    89
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    90
    int assembly = 0;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    91
    if (strstr(fn, ".bytecode") != NULL)
517
ec3f6fa441d3 Removed debug code.
Ryan C. Gordon <icculus@icculus.org>
parents: 515
diff changeset
    92
        assembly = 0;
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    93
    else if (strstr(fn, ".disasm") != NULL)
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    94
        assembly = 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    95
    else
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    96
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    97
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    98
    (*total)++;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    99
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   100
    FILE *io = fopen(fname, "rb");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   101
    if (io == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   102
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   103
        report("FAIL: %s fopen() failed.\n", fname);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   104
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   105
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   106
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   107
    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
   108
    int rc = fread(buf, 1, sizeof (buf), io);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   109
    fclose(io);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   110
    if (rc == -1)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   111
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   112
        report("FAIL: %s %s\n", fname, strerror(errno));
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   113
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   114
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   115
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   116
    if (assembly)
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   117
    {
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   118
        const MOJOSHADER_parseData *a;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   119
509
88c18d64e95b Make sure assembly source in test program is null-terminated.
Ryan C. Gordon <icculus@icculus.org>
parents: 507
diff changeset
   120
        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
   121
        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
   122
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   123
        if (a->error_count > 0)
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   124
        {
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   125
            report("FAIL: %s (line %d) %s\n",
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   126
                a->errors[0].filename ? a->errors[0].filename : "???",
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   127
                a->errors[0].error_position,
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   128
                a->errors[0].error);
503
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   129
            return 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   130
        } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   131
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   132
        else if (a->output_len > sizeof (buf))
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   133
        {
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   134
            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
   135
            return 1;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   136
        } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   137
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   138
        rc = a->output_len;
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   139
        memcpy(buf, a->output, rc);
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   140
        MOJOSHADER_freeParseData(a);
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   141
    } // if
ec8e7739cf5d Let finderrors work on assembly programs.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   142
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   143
    #if FINDERRORS_COMPILE_SHADERS
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 956
diff changeset
   144
    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
   145
    if (shader == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   146
        report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   147
    else
437
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   148
    {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   149
        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
   150
        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
   151
        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
   152
        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
   153
        if (program == NULL)
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   154
            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
   155
        else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   156
        {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   157
            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
   158
            MOJOSHADER_glDeleteProgram(program);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   159
        } // else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   160
        MOJOSHADER_glDeleteShader(shader);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   161
    }
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   162
    #else
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1138
diff changeset
   163
    const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, NULL, buf, rc, NULL, 0, NULL, 0, NULL, NULL, NULL);
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   164
    if (pd->error_count == 0)
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   165
        report("PASS: %s\n", fname);
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   166
	else
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   167
	{
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   168
		int i;
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   169
		for (i = 0; i < pd->error_count; i++)
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   170
		{
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   171
			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
   172
			       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
   173
		} // for
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 904
diff changeset
   174
	} // else
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   175
    MOJOSHADER_freeParseData(pd);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   176
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   177
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   178
    return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   179
} // do_file
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   180
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   181
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   182
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
   183
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    int total = 0;
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   185
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   186
#ifdef _MSC_VER
1137
870fb459298d Fixed Windows file finding.
Ryan C. Gordon <icculus@icculus.org>
parents: 1136
diff changeset
   187
	const size_t wildcardlen = strlen(dname) + 3;
870fb459298d Fixed Windows file finding.
Ryan C. Gordon <icculus@icculus.org>
parents: 1136
diff changeset
   188
	char *wildcard = (char *) alloca(wildcardlen);
870fb459298d Fixed Windows file finding.
Ryan C. Gordon <icculus@icculus.org>
parents: 1136
diff changeset
   189
	SDL_snprintf(wildcard, wildcardlen, "%s\\*", dname);
870fb459298d Fixed Windows file finding.
Ryan C. Gordon <icculus@icculus.org>
parents: 1136
diff changeset
   190
870fb459298d Fixed Windows file finding.
Ryan C. Gordon <icculus@icculus.org>
parents: 1136
diff changeset
   191
    WIN32_FIND_DATAA dent;
870fb459298d Fixed Windows file finding.
Ryan C. Gordon <icculus@icculus.org>
parents: 1136
diff changeset
   192
    HANDLE dirp = FindFirstFileA(wildcard, &dent);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   193
    if (dirp != INVALID_HANDLE_VALUE)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   194
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   195
        do
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   196
        {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   197
            if (!do_file(profile, dname, dent.cFileName, &total))
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   198
                break;
259
68ba103e17e4 More Windows fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 258
diff changeset
   199
        } while (FindNextFileA(dirp, &dent) != 0);
1137
870fb459298d Fixed Windows file finding.
Ryan C. Gordon <icculus@icculus.org>
parents: 1136
diff changeset
   200
        FindClose(dirp);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   201
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   202
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   203
    struct dirent *dent = NULL;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    DIR *dirp = opendir(dname);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    if (dirp != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
    {
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
        while ((dent = readdir(dirp)) != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
        {
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   209
            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
   210
                break;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
        } // while
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
        closedir(dirp);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
    } // if
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   214
#endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    return total;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
} // do_dir
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
int main(int argc, char **argv)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
    //printf("MojoShader finderrors\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   223
    //printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   224
    //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
   225
    //printf("\n");
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
    if (argc <= 2)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
        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
   229
    else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
    {
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   231
        int okay = 0;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
        int total = 0;
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   233
        int i;
224
4acaf8199665 Moved finderrors.c from GL calls to MOJOSHADER_gl* functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
   234
        const char *profile = argv[1];
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   236
        #if FINDERRORS_COMPILE_SHADERS
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   237
        MOJOSHADER_glContext *ctx = NULL;
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   238
        if (SDL_Init(SDL_INIT_VIDEO) == -1)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   239
            fprintf(stderr, "SDL_Init() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   240
        else if (SDL_GL_LoadLibrary(NULL) == -1)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   241
            fprintf(stderr, "SDL_GL_LoadLibrary() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   242
        else if ((sdlwindow = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL)) == NULL)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   243
            fprintf(stderr, "SDL_CreateWindow() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   244
        else if (SDL_GL_CreateContext(sdlwindow) == NULL)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   245
            fprintf(stderr, "SDL_GL_CreateContext() error: %s\n", SDL_GetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   246
        else if ((ctx = MOJOSHADER_glCreateContext(profile, lookup, 0, 0, 0, 0)) == NULL)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   247
            fprintf(stderr, "MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   248
        else
227
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   249
        {
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   250
            printf("Best profile is '%s'\n", MOJOSHADER_glBestProfile(lookup, 0, NULL, NULL, NULL));
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   251
            MOJOSHADER_glMakeContextCurrent(ctx);
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   252
            okay = 1;
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   253
        }
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   254
        #else
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   255
        okay = 1;
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   256
        #endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   257
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   258
        if (okay)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   259
        {
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   260
            for (i = 2; i < argc; i++)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   261
                total += do_dir(argv[i], profile);
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   262
            printf("Saw %d files.\n", total);
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   263
        } // if
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   265
        #if FINDERRORS_COMPILE_SHADERS
1134
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   266
        if (ctx)
be31bd0ee0a2 Moved to SDL2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1119
diff changeset
   267
            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
   268
        SDL_Quit();
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   269
        #endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    } // else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    return 0;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
} // main
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
// end of finderrors.c ...
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276