static char * read_module_list(char *buf, void ***tables, uint *num_mods) { char path[MAXIMUM_PATH]; uint i; uint version; PRINT(3, "Reading module table...\n"); /* versione number */ PRINT(4, "Reading version number"); if (dr_sscanf(buf, "DRCOV VERSION: %u\n", &version) != 1 && version != DRCOV_VERSION) { WARN(2, "Failed to read version number"); return NULL; } buf = move_to_next_line(buf); /* module table header */ PRINT(4, "Reading Module Table Header\n"); if (dr_sscanf(buf, "Module Table: %d\n", num_mods) != 1) { WARN(2, "Failed to read module table"); return NULL; } buf = move_to_next_line(buf); /* module lists */ PRINT(4, "Reading Module Lists\n"); *tables = calloc(*num_mods, sizeof(*tables)); for (i = 0; i < *num_mods; i++) { uint mod_id; uint64 mod_size; void *bb_table; /* assuming the string is something like: "0, 2207744, /bin/ls" */ /* XXX: i#1143: we do not use dr_sscanf since it does not support %[] */ if (sscanf(buf, " %u, %"INT64_FORMAT"u, %[^\n\r]", &mod_id, &mod_size, path) != 3) ASSERT(false, "Failed to read module table"); buf = move_to_next_line(buf); PRINT(5, "Module: %u, "PFX", %s\n", mod_id, (ptr_uint_t)mod_size, path); bb_table = hashtable_lookup(&module_htable, path); if (bb_table == NULL) { if (mod_size >= UINT_MAX) ASSERT(false, "module size is too large"); if (strstr(path, "<unknown>") != NULL || (mod_filter != NULL && strstr(path, mod_filter) == NULL)) bb_table = BB_TABLE_IGNORE; else bb_table = bb_table_create((uint)mod_size); PRINT(4, "Create bb table "PFX" for module %s\n", (ptr_uint_t)bb_table, path); num_module_htable_entries++; if (!hashtable_add(&module_htable, path, bb_table)) ASSERT(false, "Failed to add new module"); } (*tables)[i] = bb_table; } return buf; }
int check_for_closing_quote(t_var *var, char **tmp, t_list **alst) { int i; char *del[2]; t_list *el; i = 0; while (LN_S[i] && !is_valid_quote(var, LN_S, i)) i++; if (!LN_S[i]) return (0); PROMPT_LEN = PROMPT_LEN_VALUE; i++; del[0] = *tmp; *tmp = ft_strjoin(*tmp, "\n"); ft_strdel(&del[0]); del[0] = *tmp; del[1] = ft_strndup(LN_S, i - 1); *tmp = ft_strjoin(*tmp, del[1]); ft_strdel(&del[0]); ft_strdel(&del[1]); el = ft_lstnew((void *)ft_strdup(*tmp), sizeof(char *)); ft_strdel(tmp); LN_S += i; ft_lstadd_last(alst, el); move_to_next_line(var); return (1); }
//index is the same for gnuplot //using [init:fin] in fit function of gnuplot //*ndata is # of data for fitting //*ninit is the row # of the first data for fitting in the indexed subset data. //*nfin is the row # of the last data. void num_of_line(char *file, int index, double init, double fin, int *ndata, int *ninit, int *nfin) { FILE *pFile; char c; int m = 0; int t=1; int i; double read; pFile=fopen (file,"r"); while(t!=index){ if(blank_line(pFile)) {t++;} else move_to_next_line(pFile); } do{ if(blank_line(pFile)==0) { m++; fscanf(pFile, "%lf", &read); if(m==1){ if(read>=init) { *ninit=1; } else *ninit=2; } if(m!=1) if(read<init) *ninit=m+1; if(read<=fin) *nfin=m; move_to_next_line(pFile); } else { *ndata=*nfin-*ninit+1; return; } }while (1); fclose(pFile); }
drcovlib_status_t drmodtrack_offline_read(file_t file, const char **map, OUT void **handle, OUT uint *num_mods) { module_read_info_t *info = NULL; uint i; uint64 file_size; size_t map_size = 0; const char *buf, *map_start; uint version; if (handle == NULL || num_mods == NULL) return DRCOVLIB_ERROR_INVALID_PARAMETER; if (file == INVALID_FILE) { if (map == NULL) return DRCOVLIB_ERROR_INVALID_PARAMETER; map_start = *map; } else { if (!dr_file_size(file, &file_size)) return DRCOVLIB_ERROR_INVALID_PARAMETER; map_size = (size_t)file_size; map_start = (char *) dr_map_file(file, &map_size, 0, NULL, DR_MEMPROT_READ, 0); if (map_start == NULL || map_size < file_size) return DRCOVLIB_ERROR_INVALID_PARAMETER; /* assume bad perms or sthg */ } if (map_start == NULL) return DRCOVLIB_ERROR_INVALID_PARAMETER; buf = map_start; /* Module table header, handling the pre-versioning legacy format. */ if (dr_sscanf(buf, "Module Table: %u\n", num_mods) == 1) version = 1; else if (dr_sscanf(buf, "Module Table: version %u, count %u\n", &version, num_mods) != 2 || version != MODULE_FILE_VERSION) goto read_error; buf = move_to_next_line(buf); if (version > 1) { // Skip header line buf = move_to_next_line(buf); } info = (module_read_info_t *)dr_global_alloc(sizeof(*info)); if (file != INVALID_FILE) { info->map = map_start; info->map_size = map_size; } else info->map = NULL; info->num_mods = *num_mods; info->mod = (module_read_entry_t *)dr_global_alloc(*num_mods * sizeof(*info->mod)); /* module lists */ for (i = 0; i < *num_mods; i++) { uint mod_id; if (version == 1) { if (dr_sscanf(buf, " %u, %" INT64_FORMAT"u, %[^\n\r]", &mod_id, &info->mod[i].size, info->mod[i].path) != 3 || mod_id != i) goto read_error; } else { app_pc end, entry; #ifdef WINDOWS uint checksum, timestamp; if (dr_sscanf(buf, " %u, "PIFX", "PIFX", "PIFX", 0x%x, 0x%x, %[^\n\r]", &mod_id, &info->mod[i].base, &end, &entry, &checksum, ×tamp, info->mod[i].path) != 7 || mod_id != i) goto read_error; #else if (dr_sscanf(buf, " %u, "PIFX", "PIFX", "PIFX", %[^\n\r]", &mod_id, &info->mod[i].base, &end, &entry, info->mod[i].path) != 5 || mod_id != i) goto read_error; #endif info->mod[i].size = end - info->mod[i].base; } buf = move_to_next_line(buf); } if (file == INVALID_FILE) *map = buf; *handle = (void *)info; return DRCOVLIB_SUCCESS; read_error: if (info != NULL) { dr_global_free(info->mod, *num_mods * sizeof(*info->mod)); dr_global_free(info, sizeof(*info)); } if (file != INVALID_FILE) dr_unmap_file((char *)map_start, map_size); return DRCOVLIB_ERROR; }
int main(int argc, char *argv[]) { int ndata; int n; double width; double init, fin; int ninit, nfin; double *x,*y, *sig; double a, b, siga, sigb; double chi2, q; int mwt; char c; int t; double ave; double error; int i,j; FILE *ifile; double minx; double errx; //There is no blank line separating data in the data file. int index=1; if(strcmp(argv[1],"--h")==0) help_message(); if(strcmp(argv[1], "3")==0) { mwt=1; } else { mwt=0; } sscanf(argv[1], "%d", &n); sscanf(argv[3], "%lf", &width); sscanf(argv[4], "%lf", &init); fin=init+width; printf("#minx\t y_int\t y_int_err\t slope\t slope_err\t chi2\t q\n"); while(1){ num_of_line(argv[2], index, init, fin, &ndata, &ninit, &nfin); //Terminate when there is no data to fit, because the access point has already reached EOF or the block size width is too small. if(ndata==0) exit(-1); if((ifile=fopen( argv[2], "r"))==NULL) { printf( "File open error : %s\n\a", argv[2]); exit(-1); } x=(double *) calloc(ndata+1, sizeof(double)); y=(double *) calloc(ndata+1, sizeof(double)); sig = (double *) calloc(ndata+1, sizeof(double)); t=1; while(t!=index){ if(blank_line(ifile)) {t++;} else move_to_next_line(ifile); } for(i=0;i<ninit-1;i++) move_to_next_line(ifile); for (i=1;i<=ndata;i++){ if(fscanf(ifile, "%lf", x+i)==EOF) { ndata=i-1; break; } if(fscanf(ifile, "%lf", y+i)==EOF) { ndata=i-1; break; } if(mwt) if(fscanf(ifile, "%lf", sig+i)==EOF) { ndata=i-1; break; } } fit(x, y, ndata, sig, mwt, &a, &b, &siga, &sigb, &chi2, &q); ave_error1(ndata, x, &minx, &errx); //printf("%f\t %.15e\t %.15e\t %.15e\t %.15e\t %lf\t %lf\n", minx, a,siga, b,sigb,chi2,q); printf("%f\t %.15e\t %.15e\t %.15e\t %.15e\t %lf\t %lf\n", minx, a,siga, b,sigb,chi2,q); free(x); free(y); free(sig); init+=width; fin+=width; } }