int find_status(struct cv_list cur_cv, struct cv_list *cv, int num_cv, char *name1, char *name2) { int i = 0; struct I src1, dst1, src2, dst2; int res = -1; char name[50]; src1 = assign_I(cur_cv.a1, cur_cv.a2); dst1 = assign_I(cur_cv.b1, cur_cv.b2); for( i = 0; i < num_cv; i++ ) { src2 = assign_I(cv[i].a1, cv[i].a2); dst2 = assign_I(cv[i].b1, cv[i].b2); if( (strcmp( cv[i].name2, "NAN" ) != 0) && (strcmp( cv[i].name3, "NAN") != 0) ) { strcpy( name, cv[i].name2 ); } else if( (strcmp( cv[i].name2, "NAN" ) == 0) && (strcmp( cv[i].name3, "NAN") != 0) ) { strcpy( name, cv[i].name3 ); } else if( (strcmp( cv[i].name3, "NAN" ) == 0) && (strcmp( cv[i].name2, "NAN") != 0) ) { strcpy( name, cv[i].name2 ); } else { fatalf("both out-species not found %s %s\n", cv[i].name2, cv[i].name3); } if( (cur_cv.fid == cv[i].fid) && ( ((strict_almost_equal(src1, src2) == true) && (strict_almost_equal(dst1, dst2) == true)) || ( (strict_almost_equal(src1, dst2) == true) && (strict_almost_equal(dst1, src2) == true) )) && (strcmp(name1, cv[i].name1) == 0) && (strcmp(name2, name) == 0)) { res = i; } } if( res == -1 ) { fatalf("status not found %d\n", cur_cv.fid); } return(res); }
void get_spename(char *configfile) { FILE *fp; char buf[500], sn[20]; int tag, die, r, i; fp = ckopen(configfile, "r"); die = 0; while(fgets(buf, 500, fp)) { if (buf[0] == '>' && strstr(buf, "species") != NULL) { die = 1; while(fgets(buf, 500, fp)) { if (buf[0] == '\n') break; if (sscanf(buf, "%s %d", sn, &tag) != 2) fatalf("cannot parse species %s", buf); strcpy(Spename[Spesz], sn); Spetag[Spesz] = tag; ++Spesz; } } if (die == 1) break; } fclose(fp); if (Spesz > MAXSPE) fatalf("MAXSPE %d too small (%d)", MAXSPE, Spesz); for (i = r = 0; i < Spesz; i++) if (Spetag[i] == 0) ++r; if (r == 0) fatal("ref species not specified"); if (r > 1) fatal("ref speices more than one"); }
void get_args (int argc, char **argv, int *output_mode, struct mafFile **file, char **id, struct MOTIF **motif, int *do_order, int *nrow, float *cutoff, int *misses_allowed) { int i; if (argc < 5 || argc > 12) fatalf (SYNTAX); if (strcmp (argv[1], "-verbose") == 0) *output_mode = VERBOSE; else if (strcmp (argv[1], "-gala") == 0) *output_mode = GALA; else if (strcmp (argv[1], "-hgb") == 0) *output_mode = HGB; else fatalf (SYNTAX); *file = mafOpen (argv[2]); strcpy (*id, argv[4]); i = 5; argc -= 5; while (argc) { if (strcmp (argv[i], "-order") == 0) *do_order = 1; else if (strcmp (argv[i], "-nseq") == 0) { i++; argc--; if (argc == 0) fatal (SYNTAX); *nrow = atoi (argv[i]); if (*nrow < 2) fatal ("Number of sequences must be at least 2.\n"); } else if (strcmp (argv[i], "-cut") == 0) { i++; argc--; if (argc == 0) fatal (SYNTAX); *cutoff = atof (argv[i]); if (*cutoff < 0.0 || *cutoff > 1.0) fatal ("Cutoff value must be between 0 and 1.\n"); } else if (strcmp (argv[i], "-nm") == 0) { i++; argc--; if (argc == 0) fatal (SYNTAX); *misses_allowed = atoi (argv[i]); if (*misses_allowed < 0) fatal ("Number of misses cannot be negative.\n"); } else fatalf (SYNTAX); argc--; i++; } init_motif (motif, argv[3], *cutoff, *id); }
/* ckargs -- check that only certain parameters are set on the command line */ void ckargs(const char *options, int argcx, char **argvx, int non_options) { int i; argc = argcx; argv = argvx; argv0 = argv0 ? argv0 : argv[0]; for (i = non_options+1; i < argc; ++i) if (argv[i][1] != '=') fatalf("Improper command option: '%s'.", argv[i]); else if (!strchr(options, argv[i][0])) fatalf("Available options: %s\n", options); }
int add_one_ops(struct ops_list *ops, int id, char *buf, struct n_pair *contigs, int num_contigs, int *len_sum, int sp_mode) { int ctg_id = -1; char sp_name[LEN_NAME], ctg_name[LEN_NAME]; char name1[LEN_NAME], name2[LEN_NAME]; int count = id; int mode = -1; sscanf(buf, "%*s %*s %*s %*s %*s %*s %*s %d %*s", &mode); if( mode == sp_mode ) { sscanf(buf, "%c %s %d %d %s %d %d %d %d %f", &ops[count].sign, name1, &ops[count].srcStart, &ops[count].srcEnd, name2, &ops[count].dstStart, &ops[count].dstEnd, &ops[count].sp_id, &ops[count].dir, &ops[count].pid); ops[count].ctg_id1 = -1; ops[count].ctg_id2 = -1; if( num_contigs > 0 ) { concat_ctg_name(name1, sp_name, ctg_name); ctg_id = get_ctg_id(sp_name, ctg_name, contigs, num_contigs); if( ctg_id >= num_contigs ) { fatalf("contig id %d exceeds %d in util_ops.c\n", ctg_id, num_contigs); } else if( ctg_id != -1 ) { ops[count].srcStart = ops[count].srcStart + len_sum[ctg_id]; ops[count].srcEnd = ops[count].srcEnd + len_sum[ctg_id]; ops[count].ctg_id1 = ctg_id; } if( ops[count].sign != 'd' ) { concat_ctg_name(name2, sp_name, ctg_name); ctg_id = get_ctg_id(sp_name, ctg_name, contigs, num_contigs); } else { ctg_id = -1; } if( (ops[count].sign != 'd') && ((ctg_id >= num_contigs) || (ctg_id < 0) ) ) { fatalf("contig id %d exceeds %d in util_ops.c\n", ctg_id, num_contigs); } else if( ctg_id != -1 ) { ops[count].dstStart = ops[count].dstStart + len_sum[ctg_id]; ops[count].dstEnd = ops[count].dstEnd + len_sum[ctg_id]; ops[count].ctg_id2 = ctg_id; } else { ops[count].ctg_id2 = ctg_id; } } count = count + 1; } return(count); }
static void split_args(struct entry *e, char *buf) { char *p = buf, *q; char *key, *value; for (;;) { /* skip whitespace before arg */ while (Uisspace(*p)) p++; if (!*p) return; key = p; /* parse the key */ for (q = p ; Uisalnum(*q) ; q++) ; if (*q != '=') fatalf(EX_CONFIG, "configuration file %s: " "bad character '%c' in argument on line %d", MASTER_CONFIG_FILENAME, *q, e->lineno); *q++ = '\0'; /* parse the value */ if (*q == '"') { /* quoted string */ value = ++q; q = strchr(q, '"'); if (!q) fatalf(EX_CONFIG, "configuration file %s: missing \" on line %d", MASTER_CONFIG_FILENAME, e->lineno); *q++ = '\0'; } else { /* simple word */ value = q; while (*q && !Uisspace(*q)) q++; if (*q) *q++ = '\0'; } if (e->nargs == MAXARGS) fatalf(EX_CONFIG, "configuration file %s: too many arguments on line %d", MASTER_CONFIG_FILENAME, e->lineno); e->args[e->nargs].key = key; e->args[e->nargs].value = value; e->nargs++; p = q; } }
double mafScoreRange(struct mafAli *maf, int start, int size) { uchar ai, ar, bi, br; int i; double score; struct mafComp *c1, *c2; if (start < 0 || size <= 0 || start+size > maf->textSize) fatalf("mafScoreRange: start = %d, size = %d, textSize = %d\n", start, size, maf->textSize); if (ss == NULL) fatal("mafScoreRange: scores not initialized"); score = 0.0; for (i = start; i < start+size; ++i) { for (c1 = maf->components; c1 != NULL; c1 = c1->next) { br = c1->text[i]; for (c2 = c1->next; c2 != NULL; c2 = c2->next) { bi = c2->text[i]; score += SS(br,bi); if (i > 0) { ar = c1->text[i-1]; ai = c2->text[i-1]; score -= GAP2(ar,ai,br,bi); } } } } return score; }
void _cgo_sys_thread_start(ThreadStart *ts) { pthread_attr_t attr; sigset_t ign, oset; pthread_t p; size_t size; int err; sigfillset(&ign); pthread_sigmask(SIG_SETMASK, &ign, &oset); // Not sure why the memset is necessary here, // but without it, we get a bogus stack size // out of pthread_attr_getstacksize. C'est la Linux. memset(&attr, 0, sizeof attr); pthread_attr_init(&attr); size = 0; pthread_attr_getstacksize(&attr, &size); // Leave stacklo=0 and set stackhi=size; mstack will do the rest. ts->g->stackhi = size; err = pthread_create(&p, &attr, threadentry, ts); pthread_sigmask(SIG_SETMASK, &oset, nil); if (err != 0) { fatalf("pthread_create failed: %s", strerror(err)); } }
void get_numchr(char *configfile) { FILE *fp; char buf[500]; fp = ckopen(configfile, "r"); while(fgets(buf, 500, fp)) { if (buf[0] == '>' && strstr(buf, "numchr") != NULL) { if (fgets(buf, 500, fp) && sscanf(buf, "%d", &HSACHR) != 1) fatalf("missing numchr string in config file."); break; } } fclose(fp); if (HSACHR == 0) fatalf("missing numchr string in config file."); }
void get_minlen(char *configfile) { FILE *fp; char buf[500]; fp = ckopen(configfile, "r"); while(fgets(buf, 500, fp)) { if (buf[0] == '>' && strstr(buf, "resolution") != NULL) { if (fgets(buf, 500, fp) && sscanf(buf, "%d", &MINLEN) != 1) fatalf("missing resolution string in config file."); break; } } fclose(fp); if (MINLEN == 0) fatalf("missing resolution string in config file."); }
bool is_repeats(struct exons_list *exons, int num_exons, char *name, int from, int to) // exons assume to be already sorted by genomic positions { int i = 0; int mid = 0; bool res = false; struct I reg; if( to > from ) { reg = assign_I(from, to); } else { fatalf("unexpected interval: %d-%d\n", from, to); } mid = quick_search_close_exons(exons, 0, num_exons-1, from); i = mid; while( (res == false) && (i < num_exons) && (exons[i].reg.lower <= to)) { if( width(reg) <= SHORT_LEN_TH ) { // (strcmp(reg, exons[i].reg) == 0) && (almost_subset(reg, exons[i].reg) == true) ) { // printf("%d-%d too short\n", from, to); res = true; } else if( (strcmp(name, exons[i].chr) == 0) && subset(reg, exons[i].reg) ) { // printf("%d-%d belongs to %s %d-%d\n", from, to, exons[i].chr, exons[i].reg.lower, exons[i].reg.upper); res = true; } i++; } return(res); }
void get_netdir(char *configfile) { FILE *fp; char buf[500]; fp = ckopen(configfile, "r"); while(fgets(buf, 500, fp)) { if (buf[0] == '>' && strstr(buf, "netdir") != NULL) { if (fgets(buf, 500, fp) && sscanf(buf, "%s", Netdir) != 1) fatalf("missing netdir string in config file."); break; } } fclose(fp); if (Netdir[0] == '\0') fatalf("missing netdir string in config file."); }
int width(struct I temp) { if( temp.lower > temp.upper ) { fatalf("empty interval in (%d,%d)", temp.lower, temp.upper); } else return(temp.upper - temp.lower); }
void get_treestr2(char *configfile) { FILE *fp; char buf[500]; fp = ckopen(configfile, "r"); while(fgets(buf, 500, fp)) { if (buf[0] == '>' && strstr(buf, "tree2") != NULL) { if (fgets(buf, 500, fp) && sscanf(buf, "%s", Treestr2) != 1) fatalf("missing tree string in config file."); break; } } fclose(fp); if (Treestr2[0] == '\0') fatalf("missing tree string in config file."); }
/* ckopen -------------------------------------- open file; check for success */ FILE *ckopen(const char *name, const char *mode) { FILE *fp; if ((fp = fopen(name, mode)) == NULL) fatalf("Cannot open %s.", name); return fp; }
int get_level(char *s) { int i = 0; while (s[i] == ' ') ++i; if (i > MAXDEP) fatalf("MAXDEP = %d not enough", MAXDEP); return i; }
void read_ops_file(char *name, FILE *f, struct ops_list *ops, int num_ops, int sp_mode, struct n_pair *contigs, int num_contigs, char *ref_name) { char buf[1000]; bool is_in = false; char temp_name1[LEN_NAME], temp_name2[LEN_NAME]; int *len_sum; int count = 0; if( num_contigs > 0 ) { len_sum = (int *) ckalloc(sizeof(int) * num_contigs); cal_length_sum(len_sum, contigs, num_contigs); } strcpy(temp_name1, ""); strcpy(temp_name2, ""); fseek(f, 0, SEEK_SET); while(fgets(buf, 500, f)) { if( buf[0] == '#' ) { is_in = false; sscanf(buf, "%*s %s %s", temp_name1, temp_name2); if( (strcmp(temp_name1, ref_name) == 0) && (strcmp(temp_name2, name) == 0 )) { is_in = true; } count = 0; } else { if( is_in == true ) { if( sp_mode == SELF1 ) { count = add_one_ops(ops, count, buf, contigs, num_contigs, len_sum, sp_mode); } else if( sp_mode == SELF2 ) { count = add_one_ops(ops, count, buf, contigs, num_contigs, len_sum, sp_mode); } else { fatalf("%d: mode must be %d or %d in util_ops.c\n", sp_mode, SELF1, SELF2); } } if( count > num_ops ) { fatalf("counting events mismatches: %d in %s\n", num_ops, name); } } } if( num_contigs > 0 ) free(len_sum); }
Logfile * logfileOpen(const char *path, size_t bufsz, int fatal_flag) { Logfile *lf; const char *patharg; int ret; debug(50, 1) ("logfileOpen: opening log %s\n", path); CBDATA_INIT_TYPE(Logfile); lf = cbdataAlloc(Logfile); xstrncpy(lf->path, path, MAXPATHLEN); patharg = path; /* need to call the per-logfile-type code */ if (strncmp(path, "stdio:", 6) == 0) { patharg = path + 6; ret = logfile_mod_stdio_open(lf, patharg, bufsz, fatal_flag); } else if (strncmp(path, "daemon:", 7) == 0) { patharg = path + 7; ret = logfile_mod_daemon_open(lf, patharg, bufsz, fatal_flag); } else if (strncmp(path, "udp:", 4) == 0) { patharg = path + 4; ret = logfile_mod_udp_open(lf, patharg, bufsz, fatal_flag); #if HAVE_SYSLOG } else if (strncmp(path, "syslog:", 7) == 0) { patharg = path + 7; ret = logfile_mod_syslog_open(lf, patharg, bufsz, fatal_flag); #endif } else { ret = logfile_mod_stdio_open(lf, patharg, bufsz, fatal_flag); } if (!ret) { if (fatal_flag) fatalf("logfileOpen: path %s: couldn't open!\n", path); else debug(50, 1) ("logfileOpen: path %s: couldn't open!\n", path); lf->f_close(lf); cbdataFree(lf); return NULL; } assert(lf->data != NULL); if (fatal_flag) lf->flags.fatal = 1; lf->sequence_number = 0; return lf; }
int spe_idx(char *sname) { int i; for (i = 0; i < Spesz; i++) if (same_string(Spename[i], sname)) break; if (i == Spesz) fatalf("unkonwn species %s", sname); return i; }
void get_chaindir(char *configfile) { FILE *fp; char buf[500]; fp = ckopen(configfile, "r"); while(fgets(buf, 500, fp)) { if (buf[0] == '#' || buf[0] == '\n') continue; if (buf[0] == '>' && strstr(buf, "chaindir") != NULL) { if (fgets(buf, 500, fp) && sscanf(buf, "%s", Chaindir) != 1) fatalf("missing chaindir string in config file."); break; } } fclose(fp); if (Chaindir[0] == '\0') fatalf("missing chaindir string in config file."); }
int FreePM_session::InitDevice(int _dev_type, FreePM_DeskTop *pDesktop) { int rc,id,idd,nx,ny, bytes_PerPixel; static int params[4]; PBYTE pBmpBuffer = NULL; static int LbmpBuffOld = 0; int LbmpBuff; switch(_dev_type) { case FPM_DEV_PMWIN: /* */ debug(7, 0) ("FreePM_session::InitDevice PMWIN: %d \n", _dev_type); pDesktop->GetPar(nx, ny, bytes_PerPixel); debug(7, 0)("nx=%u, ny=%u, bpp=%u\n", nx, ny, bytes_PerPixel); if(pBmpBuffer) { LbmpBuff = bytes_PerPixel * nx * (ny+2)+4; if(LbmpBuff != LbmpBuffOld) pBmpBuffer = (BYTE *) realloc(pBmpBuffer,LbmpBuff); } else { LbmpBuff = bytes_PerPixel * nx * (ny+2)+4; pBmpBuffer = (BYTE *)malloc(LbmpBuff); } LbmpBuffOld = LbmpBuff; debug(7, 0) ("pDesktop=%lx\n", pDesktop); //pDesktop->pVBuffmem = (int *) initGD(nx, ny); pDesktop->pVBuffmem = pBmpBuffer; /* start separate thread for PM window */ params[0] = (int)pDesktop; params[1] = (int)pDesktop->pVBuffmem; params[2] = (int)(&_DeskTopSendQueue); params[3] = 0; id = _beginthread(_FPM_PMWinStart,NULL, THREAD_STACK_SIZE * 16, (void *)params); break; case FPM_DEV_PMWIN_DIR: debug(7, 0) ("WARNING:FreePM_session::InitDevice device PMWIN_DIR not yet supported\n"); break; case FPM_DEV_SERVERMEM: debug(7, 0) ("FreePM_session::InitDevice SERVERMEM\n", _dev_type); pDesktop->GetPar(nx, ny, bytes_PerPixel); /*rc = initGD( nx, ny);*/ pDesktop->pVBuffmem = (int *) initGD(nx, ny); debug(7, 0) ("WARNING:FreePM_session::InitDevice device SERVERMEM not yet supported\n"); break; default: debug(7, 0) ("WARNING:FreePM_session::InitDevice device %i not supported\n", _dev_type); fatalf("Device not supported"); break; } return rc; }
void ctx_load_program(struct context *ctx, const char *name, const char *vertpath, const char *fragpath) { struct program *p = program_load(name, vertpath, fragpath); if (! p) fatalf("ctx", "failed to load program '%s'", name); ctx_setup_program(ctx, p); list_push(&ctx->programs, p); }
static void do_select_init() { kdpfd = epoll_create(Squid_MaxFD); if (kdpfd < 0) fatalf("comm_select_init: epoll_create(): %s\n", xstrerror()); fd_open(kdpfd, FD_UNKNOWN, "epoll ctl"); commSetCloseOnExec(kdpfd); epoll_state = xcalloc(Squid_MaxFD, sizeof(*epoll_state)); }
// inittls allocates a thread-local storage slot for g. // // It finds the first available slot using pthread_key_create and uses // it as the offset value for runtime.tlsg. static void inittls(void **tlsg, void **tlsbase) { pthread_key_t k; int i, err; err = pthread_key_create(&k, nil); if(err != 0) { fatalf("pthread_key_create failed: %d", err); } pthread_setspecific(k, (void*)magic1); for (i=0; i<PTHREAD_KEYS_MAX; i++) { if (*(tlsbase+i) == (void*)magic1) { *tlsg = (void*)(i*sizeof(void *)); pthread_setspecific(k, 0); return; } } fatalf("could not find pthread key"); }
/* find a value in the hashtable or die if the key does not exist in the hash*/ void* must_find_hashtable(hashtable* const hash, const char* const name, const int len) { pre(name != NULL); bin* bin = lookup_hashtable(hash, name, len); if(bin == NULL){ fatalf("did not find %s in the hash", name); } return bin->val; }
// inittls allocates a thread-local storage slot for g. // // It finds the first available slot using pthread_key_create and uses // it as the offset value for runtime.tls_g. static void inittls(void **tlsg, void **tlsbase) { pthread_key_t k; int i, err; void *handle, *get_ver; // Check for Android Q where we can use the free TLS_SLOT_APP slot. handle = dlopen("libc.so", RTLD_LAZY); if (handle == NULL) { fatalf("inittls: failed to dlopen main program"); return; } // android_get_device_api_level is introduced in Android Q, so its mere presence // is enough. get_ver = dlsym(handle, "android_get_device_api_level"); dlclose(handle); if (get_ver != NULL) { *tlsg = (void *)(TLS_SLOT_APP*sizeof(void *)); return; } err = pthread_key_create(&k, nil); if(err != 0) { fatalf("pthread_key_create failed: %d", err); } pthread_setspecific(k, (void*)magic1); // If thread local slots are laid out as we expect, our magic word will // be located at some low offset from tlsbase. However, just in case something went // wrong, the search is limited to sensible offsets. PTHREAD_KEYS_MAX was the // original limit, but issue 19472 made a higher limit necessary. for (i=0; i<384; i++) { if (*(tlsbase+i) == (void*)magic1) { *tlsg = (void*)(i*sizeof(void *)); pthread_setspecific(k, 0); return; } } fatalf("inittls: could not find pthread key"); }
void read_configuration(const char* const filename, hashtable* const id2chroms, hashtable* insertlengths, uint* const averagecoverage) { size_t n = 1; char* fptr = ckalloc(n + 1); char rgname[128]; // name of the library uint minsize; // minimum size in a proper pair uint maxsize; // maximum size in a proper pair char chrom[128]; // chromosome uint meancov; // mean coverage on that chromosome FILE* fp = ckopen(filename,"r"); while(getline(&fptr, &n, fp) != -1){ if(strncmp(fptr, "IL", 2) == 0){ if(sscanf(fptr, "IL %s %u %u\n", rgname, &minsize, &maxsize) != 3){ fatalf("error in reading the insert length range: %s", fptr); } int32_t* range = ckalloc(2*sizeof(int32_t)); range[0] = minsize; range[1] = maxsize; add_hashtable(insertlengths,rgname,strlen(rgname),range); } else if(averagecoverage && (strncmp(fptr, "RC", 2) == 0)){ if(sscanf(fptr, "RC %s %u\n", chrom, &meancov) != 2){ fatalf("error in reading the mean coverage: %s", fptr); } averagecoverage[must_find_hashtable_int(id2chroms, chrom, strlen(chrom))] = meancov; } else { fatalf("unknown tag in configuration: %s", fptr); } } ckfree(fptr); fclose(fp); }
/* ckalloc -------------------------------- allocate space; check for success */ void *ckalloc(size_t amount) { void *p; if ((long)amount < 0) /* was "<= 0" -CR */ fatal("ckalloc: request for negative space."); if (amount == 0) amount = 1; /* ANSI portability hack */ if ((p = malloc(amount)) == NULL) fatalf("Ran out of memory trying to allocate %lu.", (unsigned long)amount); return p; }
struct mafFile *mafOpen(char *fileName, int verbose) { struct mafFile *mf; FILE *fp; char buf[500], *s; mf = ckalloc(sizeof(struct mafFile)); mf->next = NULL; fp = mf->fp = ckopen(fileName, "r"); if (fgets(buf, 500, fp) == NULL) fatalf("empty file %s", fileName); if (sscanf(buf, "##maf version=%d", &(mf->version)) != 1) fatalf("improper maf header line: %s", buf); if ((s = strstr(buf, "scoring=")) != NULL) mf->scoring = copy_string(s+8); else mf->scoring = NULL; mf->alignments = NULL; mf->fileName = copy_string(fileName); mf->line_nbr = 0; mf->verbose = verbose; return mf; }
int get_id_in_list(char *name, struct sp_list *list, int num_sp) { int i; i = 0; while( ( i < num_sp) && (strcmp(name, list[i].name) != 0) ) i++; if( i >= num_sp ) { fatalf("error: no species name exist in %s\n", name); return(num_sp); } else return(list[i].id); }