t_uint ls_list_dir(t_lsentry *lsentry, t_lsargs *args) { DIR *dir; t_hack *hck; GROSCON; if ((dir = opendir(lsentry->path)) == NULL) { ls_error(lsentry->name, FALSE); return (0); } hck = init_ls_hack(); while ((hck->dent = readdir(dir))) { hck->path = ls_mkpath(lsentry->path, hck->dent->d_name); if (lstat(hck->path, &(hck->inf)) == -1) { ls_error(lsentry->name, FALSE); continue ; } ls_add_dcontent(args, hck); if (args->flags & FLAG_R && S_ISDIR(hck->inf.st_mode)) ls_add_subdirs(args, hck, &ret); ft_memdel((void**)&(hck->path)); } closedir(dir), ls_list_dir_cont(HCKLOL), free(hck); return (ret); }
/* Find absolute performance */ void find_abs_performance(double *intercept, double *slope, int clear_cache, int verbose, int cpubench) { int min_param = 1; int pcount = 10; int i; /* Try to get precise measurements at max_params points */ double *xval = calloc(pcount, sizeof(double)); double *yval = calloc(pcount, sizeof(double)); for (i = 0; i < pcount; i++) { xval[i] = i+min_param; if (cpubench) yval[i] = fcyc_full(cpufunct, i+min_param, clear_cache, 3, 0.00000, 1000, 0); else yval[i] = fcyc_full(funct, i+min_param, clear_cache, 3, 0.00000, 1000, 0); } /* Now perform least squares fit */ *intercept = ls_intercept(xval, yval, pcount); *slope = ls_slope(xval, yval, pcount); if (verbose) { double avg_err = ls_error(xval, yval, pcount, LS_AVG); double max_err = ls_error(xval, yval, pcount, LS_MAX); printf("Slope = %0.1f, Intercept = %.1f, max err = %f, avg err = %f\n", *slope, *intercept, max_err, avg_err); } }
/* Find cpe for function f, which allows cnt up to maxcnt, using specified number of sample points. If data_file, then print data so that can plot points with Excel smethod determines method for generating samples */ double find_cpe_full(elem_fun_t f, int maxcnt, int samples, FILE *data_file, sample_t smethod, double bias, int verbose) { int i; int cnt; double cpe; double overhead = 0.0; double *cnt_val = calloc(samples, sizeof(double)); double *cycle_val = calloc(samples, sizeof(double)); /* Do the samples */ srandom(SEED); for (i = 0; i < samples; i++) { cnt = get_cnt(i, samples, maxcnt, smethod, bias); cnt_val[i] = cnt; cycle_val[i] = measure_function(f, cnt); } /* Fit data */ cpe = ls_slope(cnt_val, cycle_val, samples); if (data_file) overhead = ls_intercept(cnt_val, cycle_val, samples); if (data_file && verbose) { /* Print x values */ fprintf(data_file, "Cnt\t0"); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.0f", cnt_val[i]); fprintf(data_file, "\n"); /* Print y values */ fprintf(data_file, "Cycs.\t"); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.2f", cycle_val[i]); fprintf(data_file, "\n"); #if 0 /* Print (y-b)/x values */ fprintf(data_file, "CPE"); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.2f", (cycle_val[i]-overhead)/cnt_val[i]); fprintf(data_file, "\n"); #endif /* Print ax*b values */ fprintf(data_file, "Interp.\t%.2f", overhead); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.2f", cpe*cnt_val[i]+overhead); fprintf(data_file, "\n"); } if (data_file && verbose) { /* Print results */ fprintf(data_file, "cpe\t%.2f\tovhd\t%.2f\tavgerr\t\%.3f\tmaxerr\t\%.3f\n", cpe, overhead, ls_error(cnt_val, cycle_val, samples, LS_AVG), ls_error(cnt_val, cycle_val, samples, LS_MAX)); } free(cnt_val); free(cycle_val); return cpe; }
int is_directory(struct dirent *file, t_file *fold, t_set set) { struct stat statbuff; char *tmp; tmp = ft_strjoin(fold->name, file->d_name); if (!lstat(tmp, &statbuff) && S_ISDIR(statbuff.st_mode)) { if (!(set.flag & 8) && file->d_name[0] == '.') { free(tmp); return (0); } if ((file->d_name[0] == '.') && ((file->d_name[1] == '\0') || (file->d_name[1] == '.' && file->d_name[2] == '\0'))) { free(tmp); return (0); } free(tmp); return (1); } else if (lstat(tmp, &statbuff)) ls_error(ERRNO, file->d_name); free(tmp); return (0); }
static int legal_option(const char *op, unsigned int flag, int *ok) { int i; i = 1; if (op[0] == '-' && op[1]) { if (op[0] == '-' && op[1] == '-' && !op[2]) { *ok = 0; return (flag); } while (op[i]) { if (!(flag = option(flag, op[i]))) ls_error(op[i]); i++; } } else { *ok = 0; } return (flag); }
void ls_process_args(t_lsargs *args) { t_lst *elem; elem = NULL; while ((elem = ft_lstpop(&(args->unk))) != NULL) ls_error((char*)elem->data, FALSE); if (args->nfiles) ls_process_files(args); if (args->ndirs) { if (args->nfiles) ft_putchar('\n'); ls_process_dirs(args); } }