# HG changeset patch # User Ryan C. Gordon # Date 1393366499 18000 # Node ID 119bbce82c8d180daf1e8d1d184f1d8e772fc190 # Parent 870fb459298d16490f76758c20a3d0489f4ede78 Allow finderrors to troll through subdirectories. diff -r 870fb459298d -r 119bbce82c8d utils/finderrors.c --- a/utils/finderrors.c Tue Feb 25 14:10:15 2014 -0500 +++ b/utils/finderrors.c Tue Feb 25 17:14:59 2014 -0500 @@ -33,14 +33,35 @@ #define snprintf _snprintf #else #include +#include #endif #define report printf +static int isdir(const char *dname) +{ +#ifdef _MSC_VER + WIN32_FILE_ATTRIBUTE_DATA winstat; + if (!GetFileAttributesExA(dname, GetFileExInfoStandard, &winstat)) + return 0; + return winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; +#else + struct stat statbuf; + if (stat(dname, &statbuf) == -1) + return 0; + return S_ISDIR(statbuf.st_mode); +#endif +} + +static int do_dir(const char *dname, const char *profile); + static int do_file(const char *profile, const char *dname, const char *fn, int *total) { int do_quit = 0; + if ((strcmp(fn, ".") == 0) || (strcmp(fn, "..") == 0)) + return 1; // skip these. + #if FINDERRORS_COMPILE_SHADERS SDL_Event e; // pump event queue to keep OS happy. while (SDL_PollEvent(&e)) @@ -57,6 +78,15 @@ return 0; } // if + char *fname = (char *) alloca(strlen(fn) + strlen(dname) + 2); + sprintf(fname, "%s/%s", dname, fn); + + if (isdir(fname)) + { + *total += do_dir(fname, profile); + return 1; + } // if + int assembly = 0; if (strstr(fn, ".bytecode") != NULL) assembly = 0; @@ -67,8 +97,6 @@ (*total)++; - char *fname = (char *) alloca(strlen(fn) + strlen(dname) + 2); - sprintf(fname, "%s/%s", dname, fn); FILE *io = fopen(fname, "rb"); if (io == NULL) {