33 #ifndef REGEXP_WORKAROUND 38 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) 45 #define MAX_DIR_PATH 2048 46 #define FILE_LIST_SIZE 20 48 #ifndef REGEXP_WORKAROUND 69 const char *searchdir,
78 #ifdef REGEXP_WORKAROUND 80 #else // regex enabled 84 char **temp_file_list = NULL;
85 char *curr_dir = NULL;
91 int path_name_size = 1024;
97 if (searchdir == NULL || product == NULL || path == NULL ||
98 orbit == NULL || version == NULL || filecnt == NULL ||
102 dir_path = (
char *)searchdir;
105 if (stat(dir_path, &dir_stat) == -1) {
110 if (!
S_ISDIR(dir_stat.st_mode)) {
117 curr_dir = (
char*)malloc(path_name_size *
sizeof(
char));
118 while (getcwd(curr_dir,path_name_size) == NULL)
120 path_name_size += 1024;
121 curr_dir = (
char*)realloc(curr_dir,path_name_size *
sizeof(
char));
125 if (chdir(dir_path) == -1) {
133 sprintf(temp,
"MISR_AM1_%s_P%s_O%s_%s.hdf",product,path,
135 else if (strlen(camera) == 0)
136 sprintf(temp,
"MISR_AM1_%s_P%s_O%s_%s.hdf",product,path,
139 sprintf(temp,
"MISR_AM1_%s_P%s_O%s_%s_%s.hdf",product,path,
140 orbit,camera,version);
146 temp_file_list = (
char**)calloc(max,
sizeof(
int*));
151 findfile(&preg,&count,&max,&temp_file_list,&status);
154 *filenames = temp_file_list;
157 chdir_status = chdir(curr_dir);
159 perror(
"chdir error: ");
168 if (temp_file_list != NULL)
171 if (curr_dir != NULL)
173 chdir_status = chdir(curr_dir);
175 perror(
"chdir error: ");
184 #ifndef REGEXP_WORKAROUND 190 struct stat dir_stat;
192 char **temp_file_list;
218 len = strlen(cwd) + strlen(entry->
d_name) + 2;
220 (*file_list)[*
count] = (
char*)malloc(len *
sizeof(
char));
223 temp_file_list = (
char**)calloc(*max +
FILE_LIST_SIZE,
sizeof(
int*));
224 if (temp_file_list == NULL)
232 for (i = 0; i < *
count; ++i)
233 temp_file_list[i] = (*file_list)[i];
235 temp_file_list[*
count] = (
char*)malloc(len *
sizeof(
char));
236 *file_list = temp_file_list;
239 strcpy((*file_list)[*count],cwd);
240 strcat((*file_list)[*count],
"/");
241 strcat((*file_list)[*count],entry->
d_name);
246 if (stat(entry->
d_name, &dir_stat) == -1)
253 if (strcmp(entry->
d_name,
".") == 0)
256 if (strcmp(entry->
d_name,
"..") == 0)
263 if (chdir(entry->
d_name) == -1)
270 findfile(preg,count,max,file_list,status);
273 if (chdir(
"..") == -1)
HDFFCLIBAPI intf intf intf * count
MTKt_status MtkStringListFree(int strcnt, char **strlist[])
Free string list.
#define MTK_ERR_CODE_JUMP(code)
LIBTRE_DLL_IMPEXP void regfree(regex_t *preg)
LIBTRE_DLL_IMPEXP int regcomp(regex_t *preg, const char *regex, int cflags)
HDFFCLIBAPI int32 float32 * max
MTKt_status MtkFindFileList(const char *searchdir, const char *product, const char *camera, const char *path, const char *orbit, const char *version, int *filecnt, char **filenames[])
Find files in a directory tree, using regular expressions.
static void findfile(const regex_t *preg, int *count, int *max, char ***file_list, MTKt_status *status)
struct dirent * readdir(DIR *dirp)
DIR * opendir(char *name) const
LIBTRE_DLL_IMPEXP int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)