void PULSEreadOpener::add_file_name_windows(const CHAR* file_name, BOOL unique) { HANDLE h; WIN32_FIND_DATA info; h = FindFirstFile(file_name, &info); if (h != INVALID_HANDLE_VALUE) { // find the path int len = strlen(file_name); while (len && file_name[len] != '\\') len--; if (len) { len++; CHAR full_file_name[512]; strncpy(full_file_name, file_name, len); do { sprintf(&full_file_name[len], "%s", info.cFileName); add_file_name(full_file_name, unique); } while (FindNextFile(h, &info)); } else { do { add_file_name(info.cFileName, unique); } while (FindNextFile(h, &info)); } FindClose(h); } }
void PULSEreadOpener::set_file_name(const CHAR* file_name, BOOL unique) { #ifdef _WIN32 add_file_name_windows(file_name, unique); #else // _WIN32 add_file_name(file_name, unique); #endif // _WIN32 }
void count_files(char *dir, long *idx_range_count, long idx_range[MAX_IDX_RANGE][2], long *max_file_size) { struct dirent *de = NULL; DIR *d = NULL; char path[256]; long file_names[MAX_FILE_PER_FOLDER]; char file_types[MAX_FILE_PER_FOLDER]; int file_count = 0; int i; struct stat file_stat; d = opendir(dir); if(d == NULL) return; // Loop while not NULL while ((de = readdir(d)) != NULL) { if (de->d_name[0] != '.') { add_file_name(atol(de->d_name), de->d_type, file_names, file_types, &file_count); } } for (i = 0; i < file_count; i++) { if (file_types[i] == DT_DIR) { sprintf(path, "%s/%ld", dir, file_names[i]); count_files(path, idx_range_count, idx_range, max_file_size); } else if (file_types[i] == DT_REG) { add_idx_to_range(file_names[i], idx_range_count, idx_range); sprintf(path, "%s/%ld", dir, file_names[i]); stat(path, &file_stat); if (file_stat.st_size > *max_file_size) *max_file_size = file_stat.st_size; } } closedir(d); }
void traverse_dirs( char * parent_dir, char * include) { DIR *d; struct dirent *f; struct stat finfo; char *dirname, *newname = NULL; char *newbase = NULL; dev_t parent_dev = (dev_t)0; int i; size_t l; size_t parent_len; int has_exclude; char *aparent; if(parent_dir == NULL || include == NULL) return; has_exclude = !is_empty_sl(exclude_sl) && (use_gtar_excl || use_star_excl); aparent = g_strjoin(NULL, parent_dir, "/", include, NULL); /* We (may) need root privs for the *stat() calls here. */ set_root_privs(1); if(stat(parent_dir, &finfo) != -1) parent_dev = finfo.st_dev; parent_len = strlen(parent_dir); push_name(aparent); for(; (dirname = pop_name()) != NULL; free(dirname)) { if(has_exclude && calc_check_exclude(dirname+parent_len+1)) { continue; } if((d = opendir(dirname)) == NULL) { perror(dirname); continue; } l = strlen(dirname); if(l > 0 && dirname[l - 1] != '/') { g_free(newbase); newbase = g_strconcat(dirname, "/", NULL); } else { g_free(newbase); newbase = g_strdup(dirname); } while((f = readdir(d)) != NULL) { int is_symlink = 0; int is_dir; int is_file; if(is_dot_or_dotdot(f->d_name)) { continue; } g_free(newname); newname = g_strconcat(newbase, f->d_name, NULL); if(lstat(newname, &finfo) == -1) { g_fprintf(stderr, "%s/%s: %s\n", dirname, f->d_name, strerror(errno)); continue; } if(finfo.st_dev != parent_dev) continue; #ifdef S_IFLNK is_symlink = ((finfo.st_mode & S_IFMT) == S_IFLNK); #endif is_dir = ((finfo.st_mode & S_IFMT) == S_IFDIR); is_file = ((finfo.st_mode & S_IFMT) == S_IFREG); if (!(is_file || is_dir || is_symlink)) { continue; } { int is_excluded = -1; for(i = 0; i < ndumps; i++) { add_file_name(i, newname); if(is_file && (time_t)finfo.st_ctime >= dumpdate[i]) { if(has_exclude) { if(is_excluded == -1) is_excluded = calc_check_exclude(newname+parent_len+1); if(is_excluded == 1) { i = ndumps; continue; } } add_file(i, &finfo); } } if(is_dir) { if(has_exclude && calc_check_exclude(newname+parent_len+1)) continue; push_name(newname); } } } #ifdef CLOSEDIR_VOID closedir(d); #else if(closedir(d) == -1) perror(dirname); #endif } /* drop root privs -- we're done with the permission-sensitive calls */ set_root_privs(0); amfree(newbase); amfree(newname); amfree(aparent); }
BOOL PULSEreadOpener::parse(int argc, char* argv[]) { int i; for (i = 1; i < argc; i++) { if (argv[i][0] == '\0') { continue; } else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"-help") == 0) { PULSEfilter().usage(); PULSEtransform().usage(); usage(); return TRUE; } else if (strcmp(argv[i],"-i") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs at least 1 argument: file_name or wild_card\n", argv[i]); return FALSE; } *argv[i]='\0'; i+=1; do { #ifdef _WIN32 add_file_name_windows(argv[i]); #else // _WIN32 add_file_name(argv[i]); #endif // _WIN32 *argv[i]='\0'; i+=1; } while (i < argc && *argv[i] != '-'); i-=1; } else if (strcmp(argv[i],"-inside_tile") == 0) { if ((i+3) >= argc) { fprintf(stderr,"ERROR: '%s' needs 3 arguments: ll_x, ll_y, size\n", argv[i]); return FALSE; } if (inside_tile == 0) inside_tile = new F32[3]; inside_tile[0] = (F32)atof(argv[i+1]); inside_tile[1] = (F32)atof(argv[i+2]); inside_tile[2] = (F32)atof(argv[i+3]); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; i+=3; } else if (strcmp(argv[i],"-inside_circle") == 0) { if ((i+3) >= argc) { fprintf(stderr,"ERROR: '%s' needs 3 arguments: center_x, center_y, radius\n", argv[i]); return FALSE; } if (inside_circle == 0) inside_circle = new F64[3]; inside_circle[0] = atof(argv[i+1]); inside_circle[1] = atof(argv[i+2]); inside_circle[2] = atof(argv[i+3]); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; i+=3; } else if (strcmp(argv[i],"-inside") == 0 || strcmp(argv[i],"-inside_rectangle") == 0) { if ((i+4) >= argc) { fprintf(stderr,"ERROR: '%s' needs 4 arguments: min_x, min_y, max_x, max_y\n", argv[i]); return FALSE; } if (inside_rectangle == 0) inside_rectangle = new F64[4]; inside_rectangle[0] = atof(argv[i+1]); inside_rectangle[1] = atof(argv[i+2]); inside_rectangle[2] = atof(argv[i+3]); inside_rectangle[3] = atof(argv[i+4]); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; *argv[i+4]='\0'; i+=4; } else if (strcmp(argv[i],"-lof") == 0) { if ((i+1) >= argc) { fprintf(stderr,"ERROR: '%s' needs 1 argument: list_of_files\n", argv[i]); return FALSE; } FILE* file = fopen(argv[i+1], "r"); if (file == 0) { fprintf(stderr, "ERROR: cannot open '%s'\n", argv[i+1]); return FALSE; } CHAR line[1024]; while (fgets(line, 1024, file)) { // find end of line int len = strlen(line) - 1; // remove extra white spaces and line return at the end while (len > 0 && ((line[len] == '\n') || (line[len] == ' ') || (line[len] == '\t') || (line[len] == '\012'))) { line[len] = '\0'; len--; } add_file_name(line); } *argv[i]='\0'; *argv[i+1]='\0'; i+=1; } else if (strcmp(argv[i],"-rescale") == 0) { if ((i+3) >= argc) { fprintf(stderr,"ERROR: '%s' needs 3 arguments: rescale_x, rescale_y, rescale_z\n", argv[i]); return FALSE; } F64 scale_factor[3]; scale_factor[0] = atof(argv[i+1]); scale_factor[1] = atof(argv[i+2]); scale_factor[2] = atof(argv[i+3]); set_scale_factor(scale_factor); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; i+=3; } else if (strcmp(argv[i],"-reoffset") == 0) { if ((i+3) >= argc) { fprintf(stderr,"ERROR: '%s' needs 3 arguments: reoffset_x, reoffset_y, reoffset_z\n", argv[i]); return FALSE; } F64 offset[3]; offset[0] = atof(argv[i+1]); offset[1] = atof(argv[i+2]); offset[2] = atof(argv[i+3]); set_offset(offset); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; i+=3; } else if (strcmp(argv[i],"-files_are_flightlines") == 0) { set_files_are_flightlines(TRUE); *argv[i]='\0'; } else if (strcmp(argv[i],"-iadd_extra") == 0) { if ((i+3) >= argc) { fprintf(stderr,"ERROR: '%s' needs 3 arguments: data_type name description\n", argv[i]); return FALSE; } if (((i+4) < argc) && (argv[i+4][0] != '-')) { if (((i+5) < argc) && (argv[i+5][0] != '-')) { add_extra_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4]), atof(argv[i+5])); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; *argv[i+4]='\0'; *argv[i+5]='\0'; i+=5; } else { add_extra_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4])); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; *argv[i+4]='\0'; i+=4; } } else { add_extra_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3]); *argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; *argv[i+3]='\0'; i+=3; } } else if (strcmp(argv[i],"-single") == 0) { set_merged(FALSE); *argv[i]='\0'; } else if (strcmp(argv[i],"-merged") == 0) { set_merged(TRUE); *argv[i]='\0'; } else if (strcmp(argv[i],"-populate") == 0) { set_populate_header(TRUE); *argv[i]='\0'; } else if (strcmp(argv[i],"-do_not_populate") == 0) { set_populate_header(FALSE); *argv[i]='\0'; } } if (filter) filter->clean(); else filter = new PULSEfilter(); if (!filter->parse(argc, argv)) { delete filter; return FALSE; } if (!filter->active()) { delete filter; filter = 0; } if (transform) transform->clean(); else transform = new PULSEtransform(); if (!transform->parse(argc, argv)) { delete transform; return FALSE; } if (!transform->active()) { delete transform; transform = 0; } return TRUE; }