Exemplo n.º 1
0
int
sam_header_record_lt(sam_header_record_t *r1, sam_header_record_t *r2)
{
  char **tags_unq = NULL;
  if(r1->type != r2->type || 0 != tagcmp(r1->tag, r2->tag)) {
      debug("[%s] found inconsistency in the sam header [%c%c,%c%c]\n", __func__, 
            r1->tag[0], r1->tag[1],
            r2->tag[0], r2->tag[1]);
      exit(1);
  }
  tags_unq = (char**)SAM_HEADER_TAGS_UNQ[r1->type];
  while(NULL != tags_unq && NULL != (*tags_unq)) {
      char *v1 = sam_header_record_get(r1, (*tags_unq));
      char *v2 = sam_header_record_get(r2, (*tags_unq));
      if(NULL != v1 && NULL != v2) {
          int c = strcmp(v1, v2);
          if(c < 0) return 1;
          else if(0 < c) return 0;
      }
      else if(NULL != v1 && NULL == v2) {
          return 1;
      }
      else if(NULL == v1 && NULL != v2) {
          return 0;
      }

      tags_unq++;

  }
  return 0;
}
Exemplo n.º 2
0
static int32_t
sam_header_tag2int(const char *tag, const char **tags)
{
  int32_t i = 0;
  while(NULL != (*tags)) {
      if(0 == tagcmp((*tags), tag)) return i;
      tags++;
      i++;
  }
  return -1;
}
Exemplo n.º 3
0
static int nameComparison (tagFile *const file)
{
	int result;
	if (file->search.ignorecase)
	{
		if (file->search.partial)
			result = tagnuppercmp (file->search.name, file->name.buffer,
					file->search.nameLength);
		else
			result = taguppercmp (file->search.name, file->name.buffer);
	}
	else
	{
		if (file->search.partial)
			result = tagncmp (file->search.name, file->name.buffer,
					file->search.nameLength);
		else
			result = tagcmp (file->search.name, file->name.buffer);
	}
	return result;
}
Exemplo n.º 4
0
/* Called for a click on an inspector button.  BUTTON is the button
   object and TAG is the tag value (which is guaranteed not to be
   NULL).  INSTID is the instance ID of the button. */
void
proc_inspector_button_click (LPDISPATCH button, const char *tag, int instid)
{
  LPMESSAGE message;
  HWND hwnd = NULL; /* Fixme  */

  if (!tagcmp (tag, "GpgOL_Inspector_Encrypt"))
    {  
      toggle_button (button, tag, instid);
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Sign"))
    {  
      toggle_button (button, tag, instid);
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Verify")
           || !tagcmp (tag, "GpgOL_Inspector_Crypto_Info"))
    {
      LPDISPATCH inspector;

      message = get_message_from_button (instid, &inspector);
      if (message)
        {
          if (message_incoming_handler (message, hwnd, true))
            message_display_handler (message, inspector, hwnd);
          message->Release ();
        }
      if (inspector)
        {
          update_crypto_info (inspector);
          inspector->Release ();
        }
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-0"))
    {
      log_debug ("%s:%s: command Debug0 (showInfo) called\n",
                 SRCNAME, __func__);
      message = get_message_from_button (instid, NULL);
      if (message)
        {
          message_show_info (message, hwnd);
          message->Release ();
        }
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-1"))
    {
      log_debug ("%s:%s: command Debug1 (not used) called\n",
                 SRCNAME, __func__);
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-2"))
    {
      log_debug ("%s:%s: command Debug2 (change message class) called", 
                 SRCNAME, __func__);
      message = get_message_from_button (instid, NULL);
      if (message)
        {
          /* We sync here. */
          mapi_change_message_class (message, 1);
          message->Release ();
        }
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-3"))
    {
      log_debug ("%s:%s: command Debug3 (revert_message_class) called", 
                 SRCNAME, __func__);
      message = get_message_from_button (instid, NULL);
      if (message)
        {
          int rc = gpgol_message_revert (message, 1, 
                                         KEEP_OPEN_READWRITE|FORCE_SAVE);
          log_debug ("%s:%s: gpgol_message_revert returns %d\n", 
                     SRCNAME, __func__, rc);
          message->Release ();
        }
    }

}
Exemplo n.º 5
0
int analyze(DB* stat_db, DBT* block_dbt, db_recno_t dup_count, DB* ldb, DB* primary){
	DBT lkey, lval;
	DBT first_pkey, second_pkey;
	DBT rec1, rec2;
    DBT sd_dbt, sk_dbt;
	DBC* lcur, *pcur1, *pcur2;
    stat_data sd;
    void *old1, *old2;
	double match_n, nonmatch_n;
	u_int32_t match_d, nonmatch_d, all;
	
	match_n = nonmatch_n = match_d = nonmatch_d = 0;
	
	DBT_CLEAR(lkey);
	DBT_CLEAR(lval);
	DBT_CLEAR(first_pkey);
	DBT_CLEAR(second_pkey);
    DBT_CLEAR(rec1);
    DBT_CLEAR(rec2);
    DBT_CLEAR(sd_dbt);
    DBT_CLEAR(sk_dbt);
	
	ldb->cursor(ldb, NULL, &lcur, 0);
    primary->cursor(primary, NULL, &pcur1, 0);
    primary->cursor(primary, NULL, &pcur2, 0);
	
	while(DB_NOTFOUND != lcur->get(lcur, &lkey, &lval, DB_NEXT)){
		first_index(NULL, &lkey, &lval, &first_pkey);
		second_index(NULL, &lkey, &lval, &second_pkey);

        old1 = first_pkey.data;
        old2 = second_pkey.data;

		pcur1->get(pcur1, &first_pkey, &rec1, DB_SET);
		pcur2->get(pcur2, &second_pkey, &rec2, DB_SET);

        if(tagcmp((DbRecord*)rec1.data, (DbRecord*)rec2.data)==0){
			match_n += *(double*)lval.data;
			++match_d;
		}
		else {
			nonmatch_n += *(double*)lval.data;
			++nonmatch_d;
		}

        free(old1);
        free(old2);
	}

    lcur->close(lcur);
    pcur1->close(pcur1);
    pcur2->close(pcur2);

    //open likelihood database
    match_n += dup_count;
    match_d += dup_count;
    sd.density = (match_n+nonmatch_n)/(match_d+nonmatch_d);
    sd.precision = match_n/match_d;
    sd.recall = nonmatch_n/nonmatch_d;
    sd.match_n = match_n;
    sd.nonmatch_n = nonmatch_n;
    sd.match_d = match_d;
    sd.nonmatch_d = nonmatch_d;
    sd.Pr_M = PR_M;
    sd.Pr_T = PR_T;

    sd_dbt.data = &sd;
    sd_dbt.size = sizeof(stat_data);

    stat_db->put(stat_db, NULL, block_dbt, &sd_dbt, DB_NOOVERWRITE);

    //create block tag, PR_M, PR_T stuct
    //create stat struct
    //write key-data pair to bdb
    //later on, index the database by block, Pr_M, and Pr_T
	
	//printf("density: %g, precision: %g of %lu, recall: %g of %lu\n", (match_n+nonmatch_n)/(match_d+nonmatch_d), match_n/match_d, match_d, 1-nonmatch_n/nonmatch_d, nonmatch_d);
	return(0);
}
Exemplo n.º 6
0
int clump(DBC* orig, DB* ldb, DB* first, DB* second, DB* match, DB* prim){
    int i, write_cycle, changed, m=1, ret=0, no_matches;
    double val;
    int(*key_func)(DB*, const DBT*, const DBT*, DBT*);
    DBC* prim_cur_i, prim_cur_j, *first_cur, *second_cur, *match_cur;
    DBC* fs[2];
    //DBC* carray[3];
    DBT match_key;
    DBT ldb_key, ldb_dat;
    DBT dummy_dat;
    DBT key_i, pkey_i, data_i;
    DBT key_j, pkey_j, data_j;
    db_recno_t m_count;
    void* old;

    char invnum_buf[16];
    char *tagp;

    DBT_CLEAR(key_i);
    DBT_CLEAR(pkey_i);
    DBT_CLEAR(data_i);

    DBT_CLEAR(key_j);
    DBT_CLEAR(pkey_j);
    DBT_CLEAR(data_j);

    DBT_CLEAR(match_key);
    DBT_CLEAR(dummy_dat);

    DBT_CLEAR(ldb_key);
    DBT_CLEAR(ldb_dat);

    match_key.data = &m;
    match_key.size = sizeof(int);

    ret = first->cursor(first, NULL, &first_cur, 0);
    ret = second->cursor(second, NULL, &second_cur, 0);
    if(ret)
        printf("Cursor creation problem! %d\n", ret);
    fs[0] = first_cur;
    fs[1] = second_cur;
   /* 
    match->cursor(match, NULL, &match_cur, 0);
    no_matches = match_cur->get(match_cur, &match_key, &dummy_dat, DB_SET);
    printf("likelihood!: %g\n", *(double*)dummy_dat.data);
    match_cur->count(match_cur, &m_count, 0);
    printf("matches: %u\n", (size_t)m_count);
    */
    
    //return(0);

    changed=1;
    while(changed){
        //Repeat until none of the tags change.
        //printf("again!\n");
        changed=0;
        orig->dup(orig, &prim_cur_i, DB_POSITION);
        prim_cur_i->pget(prim_cur_i, &key_i, &pkey_i, &data_i, DB_CURRENT); //primary get.
        do {
            //Check for a tag
            tagp = has_tag((DbRecord*)data_i.data);
            if(tagp==NULL){
                apply_tag((DbRecord*)data_i.data, NULL);
                tagp = has_tag((DbRecord*)data_i.data);
                if(tagp == NULL){
                    printf("SERIOUS PROBLEM in tag application. Aborting.\n ");
                    exit(1);
                }
                //prim->put(prim, NULL, &pkey_i, &data_i, 0);
            }
            //memcpy(invnum_buf, tagp, 16);
            //printf("invnum_buf: %s\n", invnum_buf);
            //key_i.data = invnum_buf;
            //key_i.size = strlen(invnum_buf);
            for(write_cycle=0; write_cycle<2; ++write_cycle){
                //In the first pass, find the minimum tag that this record is associated with
                //In the second pass, write that tag to all records.
                if(write_cycle)
                    prim->put(prim, NULL, &pkey_i, &data_i, 0);

                for(i=0; i<2; ++i){
                //For each pass here, look for the record being the first in the comparison
                //then the second in the comparison
                    if(DB_NOTFOUND == (ret = fs[i]->pget(fs[i], &pkey_i, &key_i, &dummy_dat, DB_SET))){
                        //printf("join failed!\n");
                        continue;
                    }

                    do{
                        //printf("Keys: %s, ", (char*)key_i.data);
                        //printf("Sim: %f, ", *(double*)dummy_dat.data);
                        if(*(double*)dummy_dat.data < PR_T){
                        //    printf("\n");
                            continue;
                        }
                        key_func = i ? first_index : second_index;
                        key_func(first /*dummy*/, &key_i, &dummy_dat /*dummy*/, &pkey_j);
                        old = pkey_j.data;
                        //pkey_j.flags = DB_DBT_USERMEM;
                        //printf("ldb_key: %s\n", (char*)key_i.data);
                        //printf("pkey_j: %lu\n", *(u_long*)pkey_j.data);
                        prim->get(prim, NULL, &pkey_j, &data_j, 0);

                        if(!write_cycle){
                            if(tagcmp((DbRecord*)data_i.data, (DbRecord*)data_j.data) > 0){
                                apply_tag((DbRecord*)data_i.data,
                                    has_tag((DbRecord*)data_j.data));
                                //printf("\tNew Min: %s\n", has_tag((DbRecord*)data_i.data));
                                changed=1;
                            }
                            free(old);
                            continue;
                        }

                        //printf("Old Invnum_N: %s, ", ((DbRecord*)data_j.data)->Invnum_N);
                        if(tagcmp((DbRecord*)data_i.data, (DbRecord*)data_j.data)!=0){
                            apply_tag(((DbRecord*)data_j.data), has_tag((DbRecord*)data_i.data));
                            prim->put(prim, NULL, &pkey_j, &data_j, 0);
                            prim->get(prim, NULL, &pkey_j, &data_j, 0);
                            changed=1;
                        }
                        //printf("New Invnum_N: %s\n", ((DbRecord*)data_j.data)->Invnum_N);
                        //free(pkey_j.data);
                        free(old);
                    } while(DB_NOTFOUND != fs[i]->pget(fs[i], &pkey_i, &key_i, &dummy_dat, DB_NEXT_DUP));
                }//First, second idx
            }//Write cycle
        } while(DB_NOTFOUND !=
          prim_cur_i->pget(prim_cur_i, &key_i, &pkey_i, &data_i, DB_NEXT_DUP));
    }//changed
    first_cur->close(first_cur);
    second_cur->close(second_cur);
    return(0);
}