コード例 #1
0
void addToIntTable(char *sname, int *val) {
 
  struct intVartable *s;

  HASH_FIND_STR(itable, sname, s);

 if(CDG_Module==1){
  if (s == NULL) {
    s = (struct intVartable *)malloc(sizeof(struct intVartable));
    s->sname = (char *)malloc(sizeof(char) * (strlen(sname) + 1));
    strcpy(s->sname, sname);
    HASH_ADD_STR(itable, sname, s);
  
  s->value = val;
 }
}

else
 {
  if (s == NULL) {
    s = (struct intVartable *)malloc(sizeof(struct intVartable));
    s->sname = (char *)malloc(sizeof(char) * (strlen(sname) + 1));
    strcpy(s->sname, sname);
    HASH_ADD_STR(itable, sname, s);
  s->value = val;
 }
  if(noInsertionInTables == 0)
    s->value = val;

 }


//printf("Added to int table: %s val: %d\n", sname,(s->value));

}
コード例 #2
0
ファイル: avon.c プロジェクト: AutonomyLab/avon
void tree_insert_model( const char* name, 
												const char* prototype,
												av_interface_t interface,
												const char* parent_name )
{
	assert(name);
	
  if( _tree == NULL ) // i.e. nothing in the tree yet
		{
			// set up the root node for the sim itself
			bzero(&_root,sizeof(_root));
			strncpy(_root.id,"sim",strlen("sim"));
			strncpy(_root.prototype, _root.id, strlen(_root.id));

			_root.interface = AV_INTERFACE_SIM;
			utarray_new( _root.children, &ut_str_icd ); // initialize string array 			
			_av_node_t* rootp = &_root; // macro needs a pointer arg
			HASH_ADD_STR( _tree, id, rootp );
	 }
  
  assert( name && strlen(name) < NAME_LEN_MAX ); 
  assert( parent_name == NULL || strlen(parent_name) < NAME_LEN_MAX ); 
  
  // insert this new node into the tree
  
  _av_node_t *node = malloc( sizeof(_av_node_t));
  assert(node);
  bzero(node,sizeof(_av_node_t));
  
  strncpy(node->id,name,NAME_LEN_MAX);
	node->interface = interface;
	strncpy( node->prototype, prototype, strlen(prototype));
  utarray_new( node->children, &ut_str_icd ); // initialize string array 
  
  // add the node to the tree, keyed on the name  
  HASH_ADD_STR( _tree, id, node );
  
  // did something happen?
  assert( _tree != NULL );
  
  // add the child to the parent  
  _av_node_t *parent_node = NULL;
  
  if( parent_name )
	 HASH_FIND_STR( _tree, parent_name, parent_node );
  else
		parent_node = &_root;

  assert( parent_node );
  
  utarray_push_back( parent_node->children, &name );
}
コード例 #3
0
ファイル: topsig-stop.c プロジェクト: tachappell/topsig
void InitStoplistConfig()
{
  char *stoplist_path = Config("STOPLIST");
  if (stoplist_path == NULL) {
    return;
  }

  FILE *fp = fopen(stoplist_path, "rb");
  if (fp == NULL) {
    fprintf(stderr, "Unable to load stoplist: %s\n", stoplist_path);
    return;
  }
  char term[TERM_MAX_LEN+1];

  for (;;) {
    if (fscanf(fp, "%s\n", term) < 1) break;
    strToLower(term);
    Stem(term);
    Stopword *newStopword;
    HASH_FIND_STR(stoplist, term, newStopword);
    if (newStopword == NULL) {
      newStopword = malloc(sizeof(Stopword));
      strcpy(newStopword->t, term);
      HASH_ADD_STR(stoplist, t, newStopword);
    }
  }
  fclose(fp);
}
コード例 #4
0
ファイル: tokenset.c プロジェクト: crowja/constats
int tokenset_add( struct tokenset *p, char *n )
{
   struct _token *s;

   HASH_FIND_STR( p->tokens, n, s );

   if ( !_IS_NULL( s ) )
      return s->id;

   s = ( struct _token * ) malloc( sizeof ( struct _token ) );
   s->text = malloc( ( 1 + strlen( n ) ) * sizeof ( char ) );
   strcpy( s->text, n );

   s->id = p->count;

#if 0
   HASH_ADD_STR( p->tokens, text, s );
#else
   HASH_ADD_KEYPTR( hh, p->tokens, s->text, strlen( s->text ), s );
#endif

   p->count += 1;                                /* ready to map next entry */

   return s->id;
}
コード例 #5
0
ファイル: autotuning_lib.c プロジェクト: 8l/rose
// internal function to insert a pair to the hash table
static void add_hash_entry(const char* function_name, funcPointerT fpt)
{
  ns_t * s;
  s =malloc (sizeof(ns_t));
  if (!s)
  {
    printf("Fatal error: add_hash_entry() malloc() for s failed!\n");
    assert(0);
  }

#if 0
  if ((s->func_name=malloc(strlen(function_name)+1)) == NULL)
  {
    printf("Fatal error: add_hash_entry() malloc() for s->func_name failed!\n");
    assert(0);
  }
  else
#endif    
  {
    strcpy(s->func_name, function_name);
    s->fp = fpt;
//    HASH_ADD_INT(entries, func_name,s);
    HASH_ADD_STR(entries, func_name,s);
  }
}
コード例 #6
0
ファイル: vcfHetPerScaf.c プロジェクト: git-cambridge/KentLib
int fillSizes(char *sizes)
/**
 * Fills the hash table of chrom sizes
 *
 *
 *
 */
{
  struct lineFile *lf;
  lf = lineFileOpen(sizes,TRUE);
  char *line;
  struct sizes_hash *s;
  while(lineFileNextReal(lf,&line)){
    char *split[2];
    chopByWhite(line,split,2);
    s = malloc(sizeof(struct sizes_hash));
    strcpy(s->name, split[0]);
    s->length = atoi(split[1]);
    int i;
    for(i=0;i<NUMSAMPLES;i++)
      s->numHets[i] = 0;
    HASH_ADD_STR(chrSizes,name,s);
  }
  return 0;
}
コード例 #7
0
ファイル: indexer.c プロジェクト: mc4/Systems_Programming
/* 
 * indexes a word, calling other functions to check and add to hashtable
 * returns 1 on success, otherwise it returns 0
 */
int indexWord( char *key, char *filename ) {
	if( key == NULL || filename == NULL ) {  // ya dun gooffed
		return 0;
	}

	TokenPtr word, search;

	HASH_FIND_STR(words, key, search);
	// if the word exists in the hash table, check its fileNodes
	if ( search ) {
		// shouldn't happen in current implementation
		if ( search -> fileHead == NULL ) {
			addFileNode( search, filename );
		} else if ( !strcmp(filename, (search->fileHead->filename)) ) {      // file already exists for word
			search->fileHead->tokenCount++;
		} else { // file doesn't exist for word
			addFileNode( search, filename );
		}

	} else {  // word doesn't exist in the hashtable, create new word and file
		if ( (word = (TokenPtr) malloc(sizeof(struct Token))) == NULL ) exit(-1);
		char *newKey = (char *) malloc(sizeof(char) * strlen(key));
		strcpy(newKey, key);
		word -> key = newKey;
		word -> fileHead = NULL;
		HASH_ADD_STR( words, key, word );
		addFileNode( word, filename );
	}
	return 1;
}
コード例 #8
0
void update_timer( char *key, double value ) {
  syslog(LOG_DEBUG, "update_timer ( %s, %f )\n", key, value);
  statsd_timer_t *t;
  syslog(LOG_DEBUG, "HASH_FIND_STR '%s'\n", key);
  HASH_FIND_STR( timers, key, t );
  syslog(LOG_DEBUG, "after HASH_FIND_STR '%s'\n", key);
  if (t) {
    syslog(LOG_DEBUG, "Updating old timer entry");
    wait_for_timers_lock();
    utarray_push_back(t->values, &value);
    t->count++;
    remove_timers_lock();
  } else {
    syslog(LOG_DEBUG, "Adding new timer entry");
    t = malloc(sizeof(statsd_timer_t));

    strcpy(t->key, key);
    t->count = 0;
    utarray_new(t->values, &timers_icd);
    utarray_push_back(t->values, &value);
    t->count++;

    wait_for_timers_lock();
    HASH_ADD_STR( timers, key, t );
    remove_timers_lock();
  }
}
コード例 #9
0
ファイル: test11.c プロジェクト: RamJett/uthash
int main(int argc,char *argv[])
{
    name_rec *name, *names=NULL;
    char linebuf[BUFLEN];
    FILE *file;

    file = fopen( "test11.dat", "r" );
    if (file == NULL) {
        perror("can't open: ");
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        name = (name_rec*)malloc(sizeof(name_rec));
        if (name == NULL) {
            exit(-1);
        }
        strcpy(name->boy_name, linebuf);
        HASH_ADD_STR(names,boy_name,name);
    }

    fclose(file);
    HASH_SORT(names,namecmp);
    for(name=names; name!=NULL; name=(name_rec*)(name->hh.next)) {
        printf("%s",name->boy_name);
    }

    return 0;
}
コード例 #10
0
ファイル: test14.c プロジェクト: Agyar/uthash
int main(int argc,char *argv[]) {
    name_rec *name, *names=NULL;
    char linebuf[BUFLEN];
    FILE *file;
    int i=0,j=0;

    if ( (file = fopen( "test14.dat", "r" )) == NULL ) {
        perror("can't open: "); 
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        i++;
        if ( (name = (name_rec*)malloc(sizeof(name_rec))) == NULL) exit(-1);
        strncpy(name->boy_name,linebuf,BUFLEN);
        HASH_ADD_STR(names,boy_name,name);
    }

    fseek(file,0,SEEK_SET);

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        HASH_FIND_STR(names,linebuf,name);
        if (!name) printf("failed to find: %s", linebuf);
        else j++;
    }
    fclose(file);
    printf("lookup on %d of %d names succeeded\n", j, i);
   return 0;
}
コード例 #11
0
ファイル: test66.c プロジェクト: Agyar/uthash
int main(int argc, char*argv[]) {
    person_t *people=NULL, *person;
    const char **name;
    const char * names[] = { "bob", "jack", "gary", "ty", "bo", "phil", "art", 
                      "gil", "buck", "ted", NULL };
    int id=0;

    for(name=names; *name; name++) {
        if ( (person = (person_t*)malloc(sizeof(person_t))) == NULL) exit(-1);
        strncpy(person->first_name, *name,10);
        person->id = id++;
        HASH_ADD_STR(people,first_name,person);
        printf("added %s (id %d)\n", person->first_name, person->id);
    }

    person=NULL;
    person_t **p=&person;

    for(name=names; *name; name++) {
        HASH_FIND_STR(people,*name,*p);
        if (person) 
            printf("found %s (id %d)\n", person->first_name, person->id);
        else 
            printf("failed to find %s\n", *name);
    }
   return 0;
}
コード例 #12
0
ファイル: helperNew.c プロジェクト: rajshukla/Testgen
void del_vnameHash(char* key){
	vnameHash* v;
        HASH_FIND_STR(vnames, key, v);
        if(v != NULL){
        	int occ;
        	char find = '_';
        	const char *ptr = strrchr(v->vname_occ, find);
		if(ptr) {	
   			int i = strlen(v->vname_occ);
		        int s = ptr - v->vname_occ + 1;
    			char *occStr = (char*) malloc(sizeof(char)*(i-s+1));
  	  		strncpy(occStr, v->vname_occ + s, i-s);
  	  		occ = atoi(occStr);
			if(occ == 0){
				HASH_DEL( vnames, v);
				printf("Old Hash: %s\n", v->vname_occ);
			}
			else{
				printf("Old Hash: %s\n", v->vname_occ);
				occ--;
				char* newVarname_occ = (char*) malloc(sizeof(char)*(s+5));
				strncpy(newVarname_occ, v->vname_occ, s);
				char tmp[5];
				sprintf(tmp,"%d",occ);
				strcat(newVarname_occ,tmp);
				HASH_DEL( vnames, v);
				vnameHash* vnew = (vnameHash*)malloc(sizeof(vnameHash));
				strcpy(vnew->vname_occ,newVarname_occ);
				strcpy(vnew->vname,key);
				printf("New Hash: %s\n", vnew->vname_occ);
        			HASH_ADD_STR(vnames, vname, vnew);
			}
		}
        }
}
コード例 #13
0
ファイル: commutil.c プロジェクト: Niharikareddy/mpich
int MPIR_Comm_register_hint(const char *hint_key, MPIR_Comm_hint_fn_t fn, void *state)
{
    int mpi_errno = MPI_SUCCESS;
    struct MPIR_Comm_hint_fn_elt *hint_elt = NULL;
    MPID_MPI_STATE_DECL(MPID_STATE_MPIR_COMM_REGISTER_HINT);

    MPID_MPI_FUNC_ENTER(MPID_STATE_MPIR_COMM_REGISTER_HINT);

    if (MPID_hint_fns == NULL) {
        MPIR_Add_finalize(free_hint_handles, NULL, MPIR_FINALIZE_CALLBACK_PRIO - 1);
    }

    hint_elt = MPIU_Malloc(sizeof(struct MPIR_Comm_hint_fn_elt));
    strncpy(hint_elt->name, hint_key, MPI_MAX_INFO_KEY);
    hint_elt->state = state;
    hint_elt->fn = fn;

    HASH_ADD_STR(MPID_hint_fns, name, hint_elt);

  fn_exit:
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPIR_COMM_REGISTER_HINT);
    return mpi_errno;
  fn_fail:
    goto fn_exit;
}
コード例 #14
0
ファイル: emit_keys.c プロジェクト: RamJett/uthash
int main(int argc,char *argv[])
{
    name_rec *name, *names=NULL;
    char linebuf[BUFLEN];
    FILE *file;
    int i=0;

    if (argc != 2) {
        fprintf(stderr,"usage: %s file\n", argv[0]);
        exit(-1);
    }

    if ( (file = fopen( argv[1], "r" )) == NULL ) {
        perror("can't open: ");
        exit(-1);
    }

    while (fgets(linebuf,BUFLEN,file) != NULL) {
        name = (name_rec*)malloc(sizeof(name_rec));
        if (name == NULL) {
            exit(-1);
        }
        strcpy(name->boy_name, linebuf);
        HASH_ADD_STR(names,boy_name,name);
        i++;
    }

    fprintf(stderr,"%d keys emitted.\n", i);
    fclose(file);
    return 0;
}
コード例 #15
0
ファイル: hashadd.c プロジェクト: T-G-P/SearchMeCapn
void add_node(struct Node *fileNode, void *token){
    struct hash *h;
    int toAdd = 0;
    HASH_FIND_STR(tokenHash, token, h);
    if(h == NULL){
        h = (struct hash*)malloc(sizeof(struct hash));
        h->token  = token;
        h->file = fileNode;
        h->file->count = 1;
        HASH_ADD_STR(tokenHash, token, h); //add this hash node to the hash table
    }
    else{
        struct Node* ptr = h->file;
        while(ptr!= NULL){        //finding the file here so we can increment its count
            if(fileNode->fileName == ptr->fileName){
                h->file->count++;
                toAdd = 1;  //this file exists in the hash and we just incremented the counter
                break;
            }else{
                ptr = ptr->next;
            }
        }
        if(toAdd == 0){
            ptr = fileNode;
            ptr->count++;
            ptr->next = h->file;
            h->file = ptr;  //making the pointer the head of the linked list
        }
    }
}
コード例 #16
0
ファイル: counters.c プロジェクト: togga/statsd-c
void update_timer(char *key, double value)
{
    DPRINTF("update_timer ( %s, %f )\n", key, value);
    statsd_timer_t *t;
    DPRINTF("HASH_FIND_STR '%s'\n", key);
    HASH_FIND_STR( timers, key, t );
    DPRINTF("after HASH_FIND_STR '%s'\n", key);
    if (t)
    {
        DPRINTF("Updating old timer entry\n");
        utarray_push_back(t->values, &value);
        t->count++;
    }
    else
    {
        DPRINTF("Adding new timer entry\n");
        t = malloc(sizeof(statsd_timer_t));

        strcpy(t->key, key);
        t->count = 0;
        utarray_new(t->values, &timers_icd);
        utarray_push_back(t->values, &value);
        t->count++;

        HASH_ADD_STR( timers, key, t );
    }
}
コード例 #17
0
void update_counter( char *key, double value, double sample_rate ) {
  syslog(LOG_DEBUG, "update_counter ( %s, %f, %f )\n", key, value, sample_rate);
  statsd_counter_t *c;
  HASH_FIND_STR( counters, key, c );
  if (c) {
    syslog(LOG_DEBUG, "Updating old counter entry");
    if (sample_rate == 0) {
      wait_for_counters_lock();
      c->value = c->value + value;
      remove_counters_lock();
    } else {
      wait_for_counters_lock();
      c->value = c->value + ( value * ( 1 / sample_rate ) );
      remove_counters_lock();
    }
  } else {
    syslog(LOG_DEBUG, "Adding new counter entry");
    c = malloc(sizeof(statsd_counter_t));

    strcpy(c->key, key);
    c->value = 0;
    if (sample_rate == 0) {
      c->value = value;
    } else {
      c->value = value * ( 1 / sample_rate );
    }

    wait_for_counters_lock();
    HASH_ADD_STR( counters, key, c );
    remove_counters_lock();
  }
}
コード例 #18
0
ファイル: symbolicExec.c プロジェクト: rajshukla/Testgen
void add_entryToSTable(char *vname, char *sname, void *val, void *address, int type) {
    if(getExecutionFlag() == 1) {
        struct sym_table *s;

        char* hash_vn = get_vnameHash(vname);
        if(hash_vn != NULL) {
            HASH_FIND_STR(stable, hash_vn, s);
        }
        else {
            HASH_FIND_STR(stable, vname, s);
        }

        //HASH_FIND_STR(stable, vname, s);
        if (s == NULL) {
            s = (struct sym_table *)malloc(sizeof(struct sym_table));
            s->vname = (char *)calloc((strlen(vname) + 1), sizeof(char));
            strcpy(s->vname, vname);
            HASH_ADD_STR(stable, vname, s);


        }
        s->fval = addNewFields(sname, val, address, type);
        // printf("Added: %s for %s in symbol table\n", s->vname, sname);
    }
}
コード例 #19
0
/* Initialize htable with the metrics known by the system */
int init_known_metrics()
{
  /* Initialize PAPI library */
  int retval;

  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if (retval != PAPI_VER_CURRENT) {
    fprintf(stderr, "Error! PAPI_library_init %d\n",retval);

    PAPI_shutdown();
  }

  /* Initialize custom metrics storage */
  HASH_CLEAR(hh, callbacks_storage);

  for(int i = 0; i < available_metrics_no; ++i) {
    htable *new_pair = NULL;
    new_pair = malloc(sizeof(htable));

    if (!new_pair) {
        fprintf(stderr, "can't alloc memory for the new pair\n");
        exit(-1);
    }

    strcpy(new_pair->key, callbacks[i].alias);
    new_pair->value = callbacks[i].func;

    /* insert the new pair in callbacks_storage */
    HASH_ADD_STR(callbacks_storage, key, new_pair);
  }

  return 0;
}
コード例 #20
0
ファイル: mq_queue_manage.c プロジェクト: bigtreetree/ucmq
/*
 * 函 数:hash_add_queue_kv
 * 功 能:hash表中添加新的险
 */
mq_queue_t* hash_add_queue_kv(const char* qname, mq_queue_t* queue)
{
    int qname_len = 0;
    mq_queue_list_t* tmp_queue = NULL;

    qname_len = strlen(qname);
    if (qname_len < 0)
    {
        log_warn("Add hash fail, Invalid key");
        return false;
    }

    tmp_queue = (mq_queue_list_t*)malloc(sizeof(mq_queue_list_t));
    if (tmp_queue == NULL)
    {
        log_warn("Add hash fail, errno[%d], error msg[%s]", errno, strerror(errno));
        return false;
    }
    memset(tmp_queue, '\0', sizeof(mq_queue_list_t));
    /* Key setvar */
    memcpy(tmp_queue->qname, qname, strlen(qname));
    /* Value setvar */
    memcpy(&(tmp_queue->mq_queue), queue, sizeof(mq_queue_t));
    /* Qname: name of key field */
    HASH_ADD_STR(g_mq_qlist, qname, tmp_queue);

    return &tmp_queue->mq_queue;
}
コード例 #21
0
void add_signal(struct frame_struct *db, int frameId, char *signalName, int startBit, int signalLength, int is_big_endian, int signedState, float factor, float offset, float min, float max, char *unit, char *receiverList, unsigned char isMultiplexer, unsigned char muxId)
{
	struct frame_struct *frame;
	struct signal_struct *newSignal;

	frame = find_frame(db, frameId);
	
	newSignal = malloc(sizeof(struct signal_struct));
	strcpy(newSignal->name, signalName);
	newSignal->startBit = startBit;
	newSignal->signalLength = signalLength;
	newSignal->is_big_endian = is_big_endian;
	newSignal->is_signed = signedState;
	newSignal->factor = factor;
	newSignal->offset = offset;
	newSignal->min = min;
	newSignal->max = max;
        
        
        if(isMultiplexer > 0)
        {
            frame->isMultiplexed = 1;
        }
        newSignal->isMultiplexer = isMultiplexer;
        newSignal->muxId = muxId;
	
	strcpy(newSignal->unit, unit);
	strcpy(newSignal->receiverList, receiverList);

	HASH_ADD_STR( frame->signals, name, newSignal );
}
コード例 #22
0
ファイル: dict.c プロジェクト: jrbalsano/knode-language
Entry addToDict(Dict d, int et, char *key, ...) {
  va_list ap;
  va_start(ap, key);
  Entry entry = (Entry)malloc(sizeof(struct entry));
  strncpy(entry->key, key, sizeof(entry->key));
  char *sval;
  char ival;
  char dval;
  switch(et) {
    case echar:
      sval = va_arg(ap, char *);
      strncpy(entry->value.str, sval, sizeof(entry->key));
      break;
    case eint:
      ival = va_arg(ap, int);
      entry->value.num = ival;
      break;
    case edouble:
      dval = va_arg(ap, double);
      entry->value.dub = dval;
      break;
  }
  HASH_ADD_STR(d->entries, key, entry);
  return entry;
}
コード例 #23
0
ファイル: helperNew.c プロジェクト: rajshukla/Testgen
void add_vnameHash(char* key, char* value) {
    vnameHash* v;
    HASH_FIND_STR(vnames, key, v);
    if(v==NULL){
	v = (vnameHash*)malloc(sizeof(vnameHash));
	strcpy(v->vname_occ,value);
	strcpy(v->vname,key);
        HASH_ADD_STR(vnames, vname, v);
    }
    else{
    	HASH_DEL( vnames, v);
    	v = (vnameHash*)malloc(sizeof(vnameHash));
	strcpy(v->vname_occ,value);
	strcpy(v->vname,key);
        HASH_ADD_STR(vnames, vname, v);
    }
}
コード例 #24
0
ファイル: hook.c プロジェクト: jollywho/nav
void augroup_add(char *key)
{
  log_msg("HOOK", "GROUP ADD");
  Augroup *aug = malloc(sizeof(Augroup));
  aug->key = strdup(key);

  augroup_remove(key);
  HASH_ADD_STR(aug_tbl, key, aug);
}
コード例 #25
0
ファイル: UnitTest.c プロジェクト: 899/swoole
void _swUnitTest_setup(swUnitTest_Func func, char *func_name, int run_times)
{
	swHashTable_unitTst *u;
	u = (swHashTable_unitTst *) malloc(sizeof(swHashTable_unitTst));
	u->key = func_name;
	u->func = func;
	u->run_times = run_times;
	HASH_ADD_STR(unitTest_ht, key, u);
}
コード例 #26
0
ファイル: router.c プロジェクト: sanket28/URL-Router-C
/*
 * This adds the URL to the RestAPI hashmap
 */
void addURL(char *url, struct Response (*restFunc)()) {
	struct RestAPI *tmp = malloc(sizeof(struct RestAPI));

	tmp->restUrl = url;
	tmp->func = restFunc;
	HASH_ADD_STR(router, restUrl, tmp);

	printf("Added Route: %s\n", url);
}
コード例 #27
0
ファイル: topfilt.c プロジェクト: tachappell/topsig
int main(int argc, char **argv)
{
  if (argc < 5) {
    fprintf(stderr, "usage: {input sigfile} {output sigfile} {document ids to filter} {0=exclude 1=include}\n");
    return 0;
  }
  FILE *fi;
  FILE *fo;
  FILE *fids;
  if ((fi = fopen(argv[1], "rb"))) {
    if ((fo = fopen(argv[2], "wb"))) {
      fids = fopen(argv[3], "rb");
      for (;;) {
        char docname[256];
        if (fscanf(fids, "%[^\n]\n", docname) < 1) break;
        filt *f = malloc(sizeof(filt));
        strcpy(f->docname, docname);
        HASH_ADD_STR(filterhash, docname, f);
      }
      int do_filter = atoi(argv[4]);
      readSigHeader(fi);
      rewind(fi);
      unsigned char *fileheader_buffer = malloc(cfg.headersize);
      fread(fileheader_buffer, 1, cfg.headersize, fi);
      fwrite(fileheader_buffer, 1, cfg.headersize, fo);
      free(fileheader_buffer);

      unsigned char *sigheader_buffer = malloc(cfg.sig_offset);
      unsigned char *sig_buffer = malloc(cfg.sig_width / 8);

      for (;;) {
        if (fread(sigheader_buffer, 1, cfg.sig_offset, fi) == 0) break;
        fread(sig_buffer, 1, cfg.sig_width / 8, fi);

        filt *f;
        HASH_FIND_STR(filterhash, (char *)sigheader_buffer, f);
        int exclude = f == NULL ? 1 : 0;
        int include = f == NULL ? 0 : 1;
        if (do_filter ? exclude : include) {
          fwrite(sigheader_buffer, 1, cfg.sig_offset, fo);
          fwrite(sig_buffer, 1, cfg.sig_width / 8, fo);
        }
      }
      free(sigheader_buffer);
      free(sig_buffer);
      fclose(fids);
      fclose(fo);
    } else {
      fprintf(stderr, "Unable to open output file\n");
    }
    fclose(fi);
  } else {
    fprintf(stderr, "Unable to open input file\n");
  }

  return 0;
}
コード例 #28
0
ファイル: compl.c プロジェクト: Hummer12007/nav
static void compl_add(char *fmt_compl, fn_context **parent)
{
  log_msg("COMPL", "compl_add");
  log_msg("COMPL", "%s", fmt_compl);
  int pidx = 0;
  int grpc = count_subgrps(fmt_compl, ";");
  if (grpc < 1) {
    log_msg("COMPL", "invalid format");
    return;
  }

  char *line = strdup(fmt_compl);
  fn_context *cx = malloc(sizeof(fn_context));
  fn_context **args = malloc(grpc*sizeof(fn_context*));

  char *keyptr;
  char *saveptr;
  char *lhs = strtok_r(line, ";", &saveptr);
  fn_context *find;

  keyptr = strdup(lhs);

  char *param = strtok_r(NULL, ";", &saveptr);
  for (pidx = 0; pidx < grpc; pidx++) {
    if (compl_param(&args[pidx], param) == -1)
      goto breakout;
    param = strtok_r(NULL, ";", &saveptr);
  }

  find = NULL;
  cx->key = keyptr;
  cx->argc = grpc;
  cx->params = args;
  cx->cmpl = NULL;

  HASH_FIND_STR(*parent, keyptr, find);
  if (find) {
    log_msg("COMPL", "ERROR: context already defined");
    goto breakout;
  }
  else {
    log_msg("*|*", "%s %s %s", cx->key, args[0]->key, keyptr);
    HASH_ADD_STR(*parent, key, cx);
  }
  free(line);

  return;
breakout:
  log_msg("**", "CLEANUP");
  for (pidx = pidx - 1; pidx > 0; pidx--) {
    free(args[pidx]);
  }
  free(cx);
  free(args);
  free(line);
  return;
}
コード例 #29
0
ファイル: load_dbs.c プロジェクト: NoSeatbelts/taxonomer_0.5
void load_seqid_taxid_rel(char * seqid_taxid_file){
    seqid_taxid_rel = NULL;
    tax_to_seqs = NULL;
    gzFile seq_tax = gzopen(seqid_taxid_file, "r");
    kseq_t * seq_t = kseq_init(seq_tax);
    struct seqid_taxid_single * tstr;
    struct taxid_seqid * tts;
    int l = 0;
    
    while ((l = kseq_read(seq_t)) >= 0) {
        //add taxid related to seqid
        uint64_t tmp_taxid = 0;
        HASH_FIND_STR(seqid_taxid_rel, seq_t->name.s, tstr);
        if (tstr == NULL) {
            if (seq_t->name.l > SEQID_SIZE) {
                printf("seqid %s is too long, must be less than 100 characters.  Exiting...", seq_t->name.s);
                exit(1);
            }
            tstr = (struct seqid_taxid_single *)malloc(sizeof(struct seqid_taxid_single));
            memset(tstr->seqid, '\0', SEQID_SIZE*sizeof(char));
            strncpy(tstr->seqid, seq_t->name.s, seq_t->name.l);
            tmp_taxid = strtoull(seq_t->seq.s, NULL, 10);
            tstr->taxid = tmp_taxid;
            HASH_ADD_STR(seqid_taxid_rel, seqid, tstr);
            
        }
        else {
            printf("%s already seen in hash",seq_t->name.s);
        }
        
        //add seqid(s) related to taxid
        HASH_FIND(hh, tax_to_seqs, &tmp_taxid, sizeof(uint64_t), tts);
        if (tts == NULL) {
            tts = (struct taxid_seqid *)malloc(sizeof(struct taxid_seqid));
            tts->taxid = tmp_taxid;
            tts->num_seqids = 0;
            tts->max_seqs = 10;
            tts->seqids = (char **)malloc(sizeof(char *)*10);
            tts->seqids[tts->num_seqids] = (char *)calloc(SEQID_SIZE,sizeof(char));
            strncpy(tts->seqids[tts->num_seqids], seq_t->name.s, seq_t->name.l);
            tts->num_seqids++;
            HASH_ADD(hh, tax_to_seqs, taxid, sizeof(uint64_t), tts);
        }
        else {
            if (tts->num_seqids >= tts->max_seqs) {
                tts->max_seqs = 2 * tts->max_seqs;
                tts->seqids = (char **)realloc(tts->seqids, sizeof(char *)*tts->max_seqs);
            }
            tts->seqids[tts->num_seqids] = (char *)calloc(SEQID_SIZE,sizeof(char));
            strncpy(tts->seqids[tts->num_seqids], seq_t->name.s, seq_t->name.l);
            tts->num_seqids++;
        }
    }
    gzclose(seq_tax);
}
コード例 #30
0
ファイル: pyParser.c プロジェクト: niubenben/fcitx
void InitPYSplitData(FcitxPinyinConfig* pyconfig)
{
    size_t size = sizeof(pySplitData) / sizeof(pySplitData[0]);
    int i = 0;
    for (i = 0; i < size; i ++) {
        PYMappedSplitData* data = fcitx_utils_malloc0(sizeof(PYMappedSplitData));
        sprintf(data->py, "%s %s", pySplitData[i].py1, pySplitData[i].py2);
        data->freq = pySplitData[i].freq;
        HASH_ADD_STR(pyconfig->splitData, py, data);
    }
}