Esempio n. 1
0
extern int *dhash_it(
  BOOLEAN xlate_dna,			/* database is DNA and motifs protein */
  int alen,				/* length of alphabet */
  char *sequence,			/* sequence of sample */
  long length 				/* length of sequence */
)
{
  long i;
  int *hash_seq = NULL;			/* hashed sequence */
  int *h;				/* pointer in hash_seq */
  char *s;				/* pointer in sequence */
  long len;				/* length of sequence */
  int inc;				/* distance to next letter in hashed */

  /*
    Hash sequence from letters to positions in alphabet.
    Three adjacent letters (codons) are hashed if translating DNA. 
  */
  Resize(hash_seq, length+3, int);		/* leave room for padding */
  len = xlate_dna ? length - 2 : length;	/* last full letter or codon */
  for (i=0,s=sequence,h=hash_seq; i<len; i++,s++,h++) 
    *h = chash(xlate_dna, FALSE, s);
  for ( ; i<len+3; i++,h++) *h = alen;		/* pad with alen */

  /*
    Hash sequence to "double letter" logodds alphabet.
  */
  inc = xlate_dna ? 3 : 1;			/* distance to next letter */
  for (i=0, h=hash_seq; i<len; i++,h++) *h = dhash(*h, *(h+inc), alen);

  return hash_seq;
} /* dhash_it */
Esempio n. 2
0
void asy_dump (int len, unsigned char *ptr)
{
	static char dumpbuffer[300];

	char *sptr = dumpbuffer;

	int cnt = 0;

	if (!hfdd_debug || !len) return;

	while (cnt < len)
	{
		if (!isprint (*ptr))
			sptr += sprintf (sptr, "[%02x]", *ptr);
		else
			*sptr++ = *ptr;

		cnt++;
		ptr++;
	}

	*sptr = 0;


#ifndef	HASH_DUMP_CODE
/*
	if (last_dump_hash && last_dump_cnt == 10)
	{
		log (-1, "asy_dump - prev msg repeated %d times", last_dump_cnt);
		last_dump_cnt = 0;
	}
*/

/*
 * 27Aug08, Maiko, Only display if dump content changes, saves space, easier
 * to read the log file. At least I say how many times the message showed up.
 */
	dump_hash = dhash ((unsigned char*)dumpbuffer);
/*
	log (-1, "asy_dump DH %d LDH %d CNT %d LEN %d STRLEN %d",
		dump_hash, last_dump_hash, cnt, len, strlen(dumpbuffer));
*/

	/* always show data out */
	if (dump_hash != last_dump_hash)
	{
		log (-1, "asy_dump (%d) [%s]", len, dumpbuffer);

		last_dump_hash = dump_hash;

		last_dump_cnt = 0;
	}
	else last_dump_cnt++;

#endif

}
Esempio n. 3
0
static ALIASADDRESS *LookupAddress(ALIASNAME *name, int offset)
{
    int str[(sizeof(ALIASNAME *) + sizeof(int))/sizeof(int)];
    int hash;
    ALIASADDRESS *addr, **search;
    IMODE *im;
    LIST *li;
    str[0] = offset;
    *((ALIASNAME **)(str + 1)) = name;
    hash = dhash((UBYTE *)str, sizeof(str));
    search = &addresses[hash];
    while (*search)
    {
        if ((*search)->name == name && (*search)->offset == offset)
            return (*search);
        search = &(*search)->next;
    }
    addr = (*search) = aAlloc(sizeof(ALIASADDRESS));
    addr->name = name;
    addr->offset = offset;
    if (addr->name->byUIV)
    {
        im = addr->name->v.uiv->im;
    }
    else
    {
        im = addr->name->v.name;
    }
    switch (im->offset->type)
    {
        case en_auto:
//			if (im->offset->v.sp->storage_class != sc_parameter)
                break;
        case en_global:
            {
                ALIASLIST *l = aAlloc(sizeof(ALIASLIST));
                l->address = addr;
                AliasUnion(&parmList, l);
            }
            break;
        default:
            break;
    }
    li = aAlloc(sizeof(LIST));
    li->data = addr;
    li->next = name->addresses;
    name->addresses = li;
    return addr;
}
Esempio n. 4
0
static ALIASNAME *GetAliasName(ALIASNAME *name, int offset)
{
    int str[(sizeof(ALIASNAME *) + sizeof(int))/sizeof(int)];
    int hash;
    ALIASNAME *result;
    struct UIVHash **uivs;
    str[0] = offset;
    *((ALIASNAME **)(str + 1)) = name;
    hash = dhash((UBYTE *)str, sizeof(str));
    uivs = &names[hash];
    while (*uivs)
    {
        if ((*uivs)->name == name && (*uivs)->offset == offset)
            return (*uivs)->result;
        uivs = &(*uivs)->next;
    }
	return NULL;
}
Esempio n. 5
0
static ALIASNAME *LookupMem(IMODE *im)
{
    ALIASNAME **p;
    int hash ;
    switch (im->offset->type)
    {
        case en_global:
        case en_label:
        case en_pc:
        case en_auto:
        case en_threadlocal:
            if (im->offset->v.sp->imvalue)
                im = im->offset->v.sp->imvalue;
            break;
        default:
            break;
    }
    hash = dhash((UBYTE *)&im, sizeof(im));
    p = &mem[hash];
    while (*p)
    {
        if (((*p)->byUIV == FALSE && (*p)->v.name == im)
            || ((*p)->byUIV == TRUE && (*p)->v.uiv->im == im && (*p)->v.uiv->offset == NULL))
        {
            return *p;
        }
        p = &(*p)->next;
    }
    *p = aAlloc(sizeof(ALIASNAME));
    (*p)->v.name = im;
    switch(im->offset->type)
    {
        case en_auto:
        case en_label:
        case en_global:
            (*p)->v.uiv = aAlloc(sizeof(UIV));
            (*p)->v.uiv->im = im;		
            (*p)->byUIV = TRUE;
            break;
        default:
            break;
    }
    return *p;
}
Esempio n. 6
0
static ALIASADDRESS *GetAddress(ALIASNAME *name, int offset)
{
    int str[(sizeof(ALIASNAME *) + sizeof(int))/sizeof(int)];
    int hash;
    ALIASADDRESS *addr, **search;
    IMODE *im;
    LIST *li;
    str[0] = offset;
    *((ALIASNAME **)(str + 1)) = name;
    hash = dhash((UBYTE *)str, sizeof(str));
    search = &addresses[hash];
    while (*search)
    {
        if ((*search)->name == name && (*search)->offset == offset)
            return (*search);
        search = &(*search)->next;
    }
	return NULL;
}
Esempio n. 7
0
static ALIASNAME *LookupAliasName(ALIASNAME *name, int offset)
{
    int str[(sizeof(ALIASNAME *) + sizeof(int))/sizeof(int)];
    int hash;
    ALIASNAME *result;
    struct UIVHash **uivs;
    str[0] = offset;
    *((ALIASNAME **)(str + 1)) = name;
    hash = dhash((UBYTE *)str, sizeof(str));
    uivs = &names[hash];
    while (*uivs)
    {
        if ((*uivs)->name == name && (*uivs)->offset == offset)
            return (*uivs)->result;
        uivs = &(*uivs)->next;
    }
    *uivs = aAlloc(sizeof(struct UIVHash));
    (*uivs)->name = name;
    (*uivs)->offset = offset;
    result = aAlloc(sizeof(ALIASNAME));
    result->byUIV = TRUE;
    result->v.uiv = aAlloc(sizeof(UIV));
    if (name->byUIV)
    {
        *result->v.uiv = *name->v.uiv;
        result->v.uiv->alias = NULL;
    }
    else
    {
        result->v.uiv->im = name->v.name;
    }
    result->v.uiv->offset = aAlloc(sizeof(struct UIVOffset));
    result->v.uiv->offset->offset = offset;
    if (name->byUIV)
        result->v.uiv->offset->next = name->v.uiv->offset;
    (*uivs)->result = result;
    return result;
}
Esempio n. 8
0
int remove_unit(unit ** ulist, unit * u)
{
  int result;

  assert(ufindhash(u->no));
  handle_event(u->attribs, "destroy", u);

  result = gift_items(u, GIFT_SELF | GIFT_FRIENDS | GIFT_PEASANTS);
  if (result != 0) {
    make_zombie(u);
    return -1;
  }

  if (u->number)
    set_number(u, 0);
  leave(u, true);
  u->region = NULL;

  uunhash(u);
  if (ulist) {
    while (*ulist != u) {
      ulist = &(*ulist)->next;
    }
    assert(*ulist == u);
    *ulist = u->next;
  }

  u->next = deleted_units;
  deleted_units = u;
  dhash(u->no, u->faction);

  u_setfaction(u, NULL);
  u->region = NULL;

  return 0;
}