/* ----------------------------------------------------------------------------- * * (C) Krasimir Angelov, 2005 * * ---------------------------------------------------------------------------*/ #include char *findModule(const char *location, const char *moduleName, const char *extensions[]) { char *fpath; HANDLE hFind; char *s, *segment; size_t location_len, moduleName_len; WIN32_FIND_DATA findFileData; location_len = strlen(location); moduleName_len = strlen(moduleName); fpath = (char *) malloc(location_len+moduleName_len+15); if (!fpath) return NULL; if (location_len > 0) { strcpy(fpath, location); if (fpath[location_len-1] != '\\' && fpath[location_len-1] != '/') { fpath[location_len] = '\\'; fpath[location_len+1] = '\0'; location_len++; } } s = fpath+location_len; segment = s; while (*moduleName) { if (*moduleName == '.') { *s = '\0'; hFind = FindFirstFile(fpath, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { free(fpath); return NULL; } FindClose(hFind); strcpy(segment, findFileData.cFileName); *(s++) = '\\'; segment = s; moduleName++; } else *(s++) = *(moduleName++); } *(s++) = '.'; for (; *extensions; extensions++) { strcpy(s, *extensions); hFind = FindFirstFile(fpath, &findFileData); if (hFind != INVALID_HANDLE_VALUE) { strcpy(segment, findFileData.cFileName); FindClose(hFind); break; } } if (*extensions == NULL) { free(fpath); return NULL; } segment = strdup(fpath+location_len); free(fpath); return segment; }