static void *read_det_cov(void *vd) { int i,err; FILE *fptr; string *s; tokens *tok; void *tbuf; char *p,*p1,cc,*fname; struct contig *c,*ctg; struct tdc_par *tp; count *ct,ct1,ct2; struct lk_compress *lkc; u_int32_t x; tp=vd; ctg=tp->ctg; lkc=tp->lkc; while((fname=get_input_file())) { s=0; tok=0; tbuf=0; err=0; fptr=open_readfile(fname,&i,lkc); if(!fptr) return 0; printf("Reading detailed coverage file '%s'\n",fname); c=0; ct=0; x=0; while(!err) { s=fget_string(fptr,s,&tbuf); if(!s->len) break; tok=tokenize(get_cstring(s),'\t',tok); if(tok->n_tok==2) { p=tok->toks[0]; if(*p=='>') { if(!c || strcmp(c->name,p+1)) { HASH_FIND_STR(ctg,p+1,c); } if(c) { p=tok->toks[1]; x=strtoul(p,&p1,10)-1; if(p==p1 || *p1) { err=10; fprintf(stderr,"(a) Bad file format\n"); } ct=c->counts; } } } else if(c) { if(tok->n_tok!=1) { fprintf(stderr,"(b) Bad file format\n"); err=-1; } p=tok->toks[0]; while(x<c->size && (cc=*p++)) { if(cc>=33 && cc<=125) { cc-=33; ct1=(count)cc; } else if(cc==126) { ct1=(count)strtoul(p,&p1,16); p=p1+1; } else { fprintf(stderr,"(c) Bad file format (%d) '%s'\n",cc,tok->toks[0]); err=-1; } if(!err) { pthread_mutex_lock(&c->mut); ct2=ct[x]; if(ct2<MAX_COUNT) { if(MAX_COUNT-ct2<ct1) ct[x]=MAX_COUNT; else ct[x]=ct2+ct1; } pthread_mutex_unlock(&c->mut); x++; } } } } fclose(fptr); if(s) free_string(s); if(tok) free_tokens(tok); if(tbuf) free_fget_buffer(&tbuf); signal(SIGCHLD,SIG_DFL); while(waitpid(-1,&i,WNOHANG)>0); } return 0; }
void get_input_file(int& optind, int argc, char** argv, function<void(istream&)> callback) { // Just combine the two operations below in the way they're supposed to be used together get_input_file(get_input_file_name(optind, argc, argv), callback); }
int run_test(int argc, char **argv, unsigned int test_num, Test *test, char **fifos) { char *in_file = NULL; int in_fd = -1; char **out_files = NULL; int *out_fds = NULL; int fifo_fds[MAX_READERS]; pid_t child = 0; int i, res = 0, wres; /* Write some information about the test to the log */ print_test_info(test_num, test); assert(test->npipes <= MAX_READERS); for (i = 0; i < MAX_READERS; i++) fifo_fds[i] = -1; /* Open any output files needed */ if (test->nfiles > 0) { if (0 != get_output_files(test, &out_files, &out_fds)) goto BAIL; } /* Create an input file if the test needs one */ if (test->in_type == IN_FILE) { if (NULL == (in_file = get_input_file(test))) goto BAIL; } /* Start the program under test */ child = start_prog(argc, argv, test, &in_fd, in_file, fifos, out_files); if (child < 0) goto BAIL; /* Open any named pipes required */ if (test->npipes > 0) { if (0 != open_fifos(test->npipes, fifos, fifo_fds)) goto BAIL; } if (test->npipes) { /* reading from pipes, run the full poll loop */ res = run_poll_loop(test, in_fd, fifo_fds, fifos); /* Close any pipes that are still open */ if (0 != close_fifos(test->npipes, fifos, fifo_fds)) { res = -1; } } else if (test->in_type == IN_PIPE || test->in_type == IN_SLOW_PIPE) { /* only sending to a pipe, so just shove the data down it */ size_t offset = 0; if (gen_data("pipe", in_fd, test->in_len, &offset, 0, 0) != test->in_len) { res = -1; } if (0 != close(in_fd)) { perror("Closing pipe"); res = -1; } } /* Wait for the program to finish and check the exit status */ wres = wait_child(child); if (-99 == wres) goto BAIL; if (wres < 0) res = -1; /* Check the contents of any regular files that were created */ if (test->nfiles > 0) { if (0 != check_output_files(test, out_fds, out_files)) res = -1; } /* Clean up */ if (NULL != in_file) remove_files(&in_file, 1); if (test->nfiles > 0) { remove_files(out_files, test->nfiles); } return res; BAIL: /* Something went wrong, clean up and return 99 */ if (NULL != in_file) remove_files(&in_file, 1); if (test->nfiles > 0 && NULL != out_files) { remove_files(out_files, test->nfiles); } if (test->npipes > 0) { close_fifos(test->npipes, fifos, fifo_fds); } return 99; }