Exemplo n.º 1
0
/*
	Take an array of measumrements representing summaries of different channels.
	Return a recomended channel.
	Interference is evil, get rid of that first.
	Then hunt for lowest Other bss traffic.
	Don't forget that channels with low duration times may not have accurate readings.
	For the moment, do not overwrite input array.
*/
int
cca_analyze(cca_congest_channel_req_t *input[], int num_chans, uint flags, chanspec_t *answer)
{
	uint8 bitmap[CEIL(MAX_CCA_CHANNELS, NBBY)];	/* 38 Max channels needs 5 bytes  = 40 */
	int i, left, winner;
	uint32 min_obss = 1 << 30;

	ASSERT(num_chans < MAX_CCA_CHANNELS);
	for (i = 0; i < (int)sizeof(bitmap); i++)
		bitmap[i] = 0;

	/* Initially, all channels are up for consideration */
	for (i = 0; i < num_chans; i++) {
		if (input[i]->chanspec)
			setbit(bitmap, i);
	}
	cca_info(bitmap, num_chans, &left, &i);
	if (!left)
		return CCA_ERRNO_TOO_FEW;

	/* Filter for 2.4 GHz Band */
	if (flags & CCA_FLAG_2G_ONLY) {
		for (i = 0; i < num_chans; i++) {
			if (!CHSPEC_IS2G(input[i]->chanspec))
				clrbit(bitmap, i);
		}
	}
	cca_info(bitmap, num_chans, &left, &i);
	if (!left)
		return CCA_ERRNO_BAND;

	/* Filter for 5 GHz Band */
	if (flags & CCA_FLAG_5G_ONLY) {
		for (i = 0; i < num_chans; i++) {
			if (!CHSPEC_IS5G(input[i]->chanspec))
				clrbit(bitmap, i);
		}
	}
	cca_info(bitmap, num_chans, &left, &i);
	if (!left)
		return CCA_ERRNO_BAND;

	/* Filter for Duration */
	if (!(flags & CCA_FLAG_IGNORE_DURATION)) {
		for (i = 0; i < num_chans; i++) {
			if (input[i]->secs[0].duration < CCA_THRESH_MILLI)
				clrbit(bitmap, i);
		}
	}
	cca_info(bitmap, num_chans, &left, &i);
	if (!left)
		return CCA_ERRNO_DURATION;

	/* Filter for 1 6 11 on 2.4 Band */
	if (flags &  CCA_FLAGS_PREFER_1_6_11) {
		int tmp_channel = spec_to_chan(input[i]->chanspec);
		int is2g = CHSPEC_IS2G(input[i]->chanspec);
		for (i = 0; i < num_chans; i++) {
			if (is2g && tmp_channel != 1 && tmp_channel != 6 && tmp_channel != 11)
				clrbit(bitmap, i);
		}
	}
	cca_info(bitmap, num_chans, &left, &i);
	if (!left)
		return CCA_ERRNO_PREF_CHAN;

	/* Toss high interference interference */
	if (!(flags & CCA_FLAG_IGNORE_INTERFER)) {
		for (i = 0; i < num_chans; i++) {
			if (input[i]->secs[0].interference > CCA_THRESH_INTERFERE)
				clrbit(bitmap, i);
		}
		cca_info(bitmap, num_chans, &left, &i);
		if (!left)
			return CCA_ERRNO_INTERFER;
	}

	/* Now find lowest obss */
	winner = 0;
	for (i = 0; i < num_chans; i++) {
		if (isset(bitmap, i) && input[i]->secs[0].congest_obss < min_obss) {
			winner = i;
			min_obss = input[i]->secs[0].congest_obss;
		}
	}
	*answer = input[winner]->chanspec;

	return 0;
}
Exemplo n.º 2
0
void bl_metal(){
    setbit(PTC,0);
    delay_ms(1);
    clrbit(PTC,0);
    delay_ms(1);
}
Exemplo n.º 3
0
void
ravage()
{
	while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount);
	if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){
		Time++;
		switch(wordvalue[wordnumber]){
			case NORMGOD:
				puts("You attack the goddess, and she screams as you beat her.  She falls down");
				puts("crying and tries to hold her torn and bloodied dress around her.");
				power += 5;
				pleasure += 8;
				ego -= 10;
				wordnumber--;
				godready = -30000;
				murder();
				win = -30000;
				break;
			case NATIVE:
				puts("The girl tries to run, but you catch her and throw her down.  Her face is");
				puts("bleeding, and she screams as you tear off her clothes.");
				power += 3;
				pleasure += 5;
				ego -= 10;
				wordnumber--;
				murder();
				if (rnd(100) < 50){
					puts("Her screams have attracted attention.  I think we are surrounded.");
					setbit(location[ahead].objects,WOODSMAN);
					setbit(location[ahead].objects,DEADWOOD);
					setbit(location[ahead].objects,MALLET);
					setbit(location[back].objects,WOODSMAN);
					setbit(location[back].objects,DEADWOOD);
					setbit(location[back].objects,MALLET);
					setbit(location[left].objects,WOODSMAN);
					setbit(location[left].objects,DEADWOOD);
					setbit(location[left].objects,MALLET);
					setbit(location[right].objects,WOODSMAN);
					setbit(location[right].objects,DEADWOOD);
					setbit(location[right].objects,MALLET);
				}
				break;
			default:
				puts("You are perverted.");
		}
	}
	else
		puts("Who?");
}
Exemplo n.º 4
0
int cicom0_v500_trans_config(UINT32 src_addr, UINT32 des_addr, UINT32 num_8)
{	
    UINT32 i;
    
    UINT32 pdu_len;
    
    UINT32 alg_sel= 0x0 ;//gea3
    UINT32 cb     = 0x00;//cipher_cb 
    UINT32 ck1_1  = 0x2bb97c23;
    UINT32 ck1_2  = 0x76d0dbb8;
    UINT32 ck1_3  = 0x00000000;
    UINT32 ck1_4  = 0x00000000;
    UINT32 cc1    = 0x1f927f6c;
    
if(ck_addr == 0)
{
	ck_addr        = (UINT32)osl_cachedma_malloc(1024);
}
if(lli_prm == 0) 
{
	lli_prm        = (UINT32)osl_cachedma_malloc(1024);
}
    pdu_len = num_8*8;
    
    setbit(SYSCTRL_SCMISCCTRL, Cicom_sel ,0x1);//select W(0) / G(1)
    
    //cacheDisable(1);/*需要确认是否要实现,zuofenghua*/??
    
    // cfg the lli_param
    set32( (lli_prm + 0x00000000), ck_addr                      );//CK_ADDR              
    set32( (lli_prm + 0x00000004), cc1                          );//CC                   
    set32( (lli_prm + 0x00000008), pdu_len                      );//SRC_PDU_TOTAL_LEN    
    set32( (lli_prm + 0x0000000c), 0x00000002                   );//CUSTOM_CFG
    set32( (lli_prm + 0x00000010), src_addr                     );//LLI_SRC_PDU_SEG_ADDR 
    set32( (lli_prm + 0x00000014), des_addr                     );//LLI_DST_TTF_SEG_ADDR
    set32( (lli_prm + 0x00000018), 0x00000000                   );//LLI_DST_MBX_SEG_ADDR
    set32( (lli_prm + 0x0000001c), 0x00000000                   );//LLI_PRM_ADDR      
 
    // cfg the key_data
    set32( (ck_addr + 0x00000000), ck1_1);
    set32( (ck_addr + 0x00000004), ck1_2);
    set32( (ck_addr + 0x00000008), ck1_3);
    set32( (ck_addr + 0x0000000c), ck1_4);
    
    //set registers
    set32(asicCICOMPRIOR_SELECT     , 0x00000000           );
    set32(asicCICOMLLI_PARAM_ADDR_DL, lli_prm              );
    setbits(asicCICOMGLOBAL_CFG_DL  , 1, 0, alg_sel        );  
    setbits(asicCICOMGLOBAL_CFG_DL  , 11, 8, 0x0           );  
    setbits(asicCICOMGLOBAL_CFG_DL  , 20, 16, cb           );  
    set32(asicCICOMINT_EN_DL        , 0x00000000           );//int enable
    //set32(asicCICOMEN_DL            , 0x00000001           );//start cicom
    
    // initial memory
	for( i = 0; i < num_8/4; i++ )
	{
		set32( src_addr+0x4*i, 0x5a5a5a5a+i );
		set32( des_addr+0x4*i, 0x0 );
	}
	
	return 0;
}
Exemplo n.º 5
0
int
main ()
{
  int c;
  unsigned int x = 15;          // 1111

  printf ("x = %d (1111)\n\n", 15);

  printf ("XOR\n");
  printf ("x ^ 0 = %d   (x)\n", x ^ 0);
  printf ("x ^ 1 = %d   ~(x)\n", x ^ 15);
  printf ("x ^ x = %d    (0)\n\n", x ^ x);

  printf ("AND\n");
  printf ("x & 0 = %d    (0)\n", x & 0);
  printf ("x & 1 = %d   (x)\n", x & 15);
  printf ("x & x = %d   (x)\n\n", x & x);

  printf ("OR\n");
  printf ("x | 0 = %d   (x)\n", x | 0);
  printf ("x | 1 = %d   (1)\n", x | 15);
  printf ("x | x = %d   (x)\n\n", x | x);

  printf ("NOT\n");
  printf ("~x = %d     ~(x)\n", ~x);
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (~x, c));

  printf ("\n\n");

  printf ("x = %d (1010)\n", x = 10);
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));

  printf ("\n");
  printf ("set bit %d to 1: %d\n", 2, x = setbit (x, 2));
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));

  printf ("\n");
  printf ("clear bit %d to 0: %d\n", 3, x = clearbit (x, 3));
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));

  printf ("\n");
  printf ("x = %d (1111)\n", x = 15);
  printf ("clear most significant bits through bit %d: %d\n", 2,
      x = clearbits_msb (x, 2));
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));

  printf ("\n");
  printf ("x = %d (1111)\n", x = 15);
  printf ("clear least significant bits through bit %d: %d\n", 1,
      x = clearbits_lsb (x, 1));
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));

  printf ("\n");
  printf ("x = %d (1111)\n", x = 15);
  printf ("update bit %d to 0: %d\n", 2, x = updatebit (x, 2, 0));
  printf ("update bit %d to 1: %d\n", 3, x = updatebit (x, 3, 1));
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));

  printf ("\n");
  printf ("x = %d (1111)\n", x = 15);
  printf ("update bit %d to 0 (C support): %d\n", 2, x = updatebit_c (x, 2, 0));
  printf ("update bit %d to 1 (C support): %d\n", 3, x = updatebit_c (x, 3, 1));
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));

  printf ("\n");
  printf ("toggle bit %d: %d\n", 1, x = togglebit (x, 1));
  printf ("toggle bit %d: %d\n", 3, x = togglebit (x, 3));
  for (c = 3; c >= 0; --c)
    printf ("get %d bit: %d\n", c, getbit (x, c));
}
Exemplo n.º 6
0
/*
 * Calculates the specified regexp for the specified class if it's not calculated
 */
static guint
rspamd_re_cache_exec_re (struct rspamd_task *task,
		struct rspamd_re_runtime *rt,
		rspamd_regexp_t *re,
		struct rspamd_re_class *re_class,
		gboolean is_strong)
{
	guint ret = 0, i, re_id;
	GList *cur, *headerlist;
	GHashTableIter it;
	struct raw_header *rh;
	const gchar *in;
	gboolean raw = FALSE;
	struct mime_text_part *part;
	struct rspamd_url *url;
	struct rspamd_re_cache *cache = rt->cache;
	gpointer k, v;
	gsize len;

	msg_debug_re_cache ("get to the slow path for re type: %s: %s",
			rspamd_re_cache_type_to_string (re_class->type),
			rspamd_regexp_get_pattern (re));
	re_id = rspamd_regexp_get_cache_id (re);

	switch (re_class->type) {
	case RSPAMD_RE_HEADER:
	case RSPAMD_RE_RAWHEADER:
		/* Get list of specified headers */
		headerlist = rspamd_message_get_header (task,
				re_class->type_data,
				is_strong);

		if (headerlist) {
			cur = headerlist;

			while (cur) {
				rh = cur->data;
				if (re_class->type == RSPAMD_RE_RAWHEADER) {
					in = rh->value;
					raw = TRUE;
				}
				else {
					in = rh->decoded;
					/* Validate input */
					if (!in || !g_utf8_validate (in, -1, NULL)) {
						cur = g_list_next (cur);
						continue;
					}
				}

				/* Match re */
				if (in) {
					ret = rspamd_re_cache_process_regexp_data (rt, re,
							task->task_pool, in, strlen (in), raw);
					debug_task ("checking header %s regexp: %s -> %d",
							re_class->type_data,
							rspamd_regexp_get_pattern (re), ret);
				}

				cur = g_list_next (cur);
			}
		}
		break;
	case RSPAMD_RE_ALLHEADER:
		raw = TRUE;
		in = task->raw_headers_content.begin;
		len = task->raw_headers_content.len;
		ret = rspamd_re_cache_process_regexp_data (rt, re,
				task->task_pool, in, len, raw);
		debug_task ("checking allheader regexp: %s -> %d",
				rspamd_regexp_get_pattern (re), ret);
		break;
	case RSPAMD_RE_MIME:
	case RSPAMD_RE_RAWMIME:
		/* Iterate throught text parts */
		for (i = 0; i < task->text_parts->len; i++) {
			part = g_ptr_array_index (task->text_parts, i);

			/* Skip empty parts */
			if (IS_PART_EMPTY (part)) {
				continue;
			}

			/* Check raw flags */
			if (!IS_PART_UTF (part)) {
				raw = TRUE;
			}
			/* Select data for regexp */
			if (re_class->type == RSPAMD_RE_RAWMIME) {
				in = part->orig->data;
				len = part->orig->len;
				raw = TRUE;
			}
			else {
				in = part->content->data;
				len = part->content->len;
			}

			if (len > 0) {
				ret = rspamd_re_cache_process_regexp_data (rt, re,
						task->task_pool, in, len, raw);
				debug_task ("checking mime regexp: %s -> %d",
						rspamd_regexp_get_pattern (re), ret);
			}
		}
		break;
	case RSPAMD_RE_URL:
		g_hash_table_iter_init (&it, task->urls);

		while (g_hash_table_iter_next (&it, &k, &v)) {
			url = v;
			in = url->string;
			len = url->urllen;
			raw = FALSE;

			ret = rspamd_re_cache_process_regexp_data (rt, re,
					task->task_pool, in, len, raw);
		}

		g_hash_table_iter_init (&it, task->emails);

		while (g_hash_table_iter_next (&it, &k, &v)) {
			url = v;
			in = url->string;
			len = url->urllen;
			raw = FALSE;

			ret = rspamd_re_cache_process_regexp_data (rt, re,
					task->task_pool, in, len, raw);
		}

		debug_task ("checking url regexp: %s -> %d",
				rspamd_regexp_get_pattern (re), ret);
		break;
	case RSPAMD_RE_BODY:
		raw = TRUE;
		in = task->msg.begin;
		len = task->msg.len;

		ret = rspamd_re_cache_process_regexp_data (rt, re, task->task_pool, in,
				len, raw);
		debug_task ("checking rawbody regexp: %s -> %d",
				rspamd_regexp_get_pattern (re), ret);
		break;
	case RSPAMD_RE_MAX:
		msg_err_task ("regexp of class invalid has been called: %s",
				rspamd_regexp_get_pattern (re));
		break;
	}

#if WITH_HYPERSCAN
	if (!rt->cache->disable_hyperscan) {
		rspamd_re_cache_finish_class (rt, re_class);
	}
#endif

	setbit (rt->checked, re_id);

	return rt->results[re_id];
}
Exemplo n.º 7
0
static void liveOut()
{
    BITINT inWorkList[8192];
    unsigned short *workList = sAlloc((blockCount + 1) * sizeof(unsigned short));
    int i;
    int head = 0, tail = 0;
    int tempDWords = (tempCount + BITINTBITS-1)/BITINTBITS;
    memset(inWorkList, 0, (blockCount + BITINTBITS-1)/BITINTBITS * sizeof(BITINT));
    workList[head++] = exitBlock;
    setbit(inWorkList, exitBlock);
    while (tail != head)
    {
        unsigned n = workList[tail++];
        BLOCKLIST *bl = blockArray[n]->pred;
        while (bl)
        {
            BITINT *b;
            BITINT r;
            n = bl->block->blocknum;
            b = inWorkList + (n/BITINTBITS);
            r = 1 << (n % BITINTBITS);
            if (!(*b & r))
            {
                *b |= r;
                workList[head++] = n;
            }
            bl = bl->next;
        }
    }
    tail = 0;
    while (head != tail)
    {
        BOOL changed = FALSE;
        unsigned n = workList[tail];
        BLOCK *b = blockArray[n];
        BLOCKLIST *bl = b->succ;
        int j;
        BITINT *gen, *kills, *live, *outb;
        if (++tail == blockCount + 1)
            tail = 0;
        clearbit(inWorkList, n);
        memset(b->liveOut, 0 , tempDWords * sizeof(BITINT));
        while (bl)
        {
            live = bl->block->liveIn;
            outb = b->liveOut;
            for (j=0; j < tempDWords; j++, live++, outb++)
            {
                if (*live)
                    *outb |= *live;
            }
            bl = bl->next;
        }
        live = b->liveIn;
        gen = b->liveGen;
        kills = b->liveKills;
        outb = b->liveOut;
        for (j=0; j < tempDWords; j++, gen++,kills++,live++, outb++)
        {
            BITINT c = *gen | (*outb & ~*kills);
            if (changed)
                *live = c;
            else if (c != *live)
            {
                *live = c;
                changed = TRUE;
            }
        }
        if (changed)
        {
            bl = b->pred;
            while (bl)
            {
                BITINT *b;
                BITINT r;
                n = bl->block->blocknum;
                b = inWorkList + (n/BITINTBITS);
                r = 1 << (n % BITINTBITS);
                if (!(*b & r))
                {
                    *b |= r;
                    workList[head] = n;
                    if (++head == blockCount + 1)
                        head = 0;
                }
                bl = bl->next;
            }
        }
    }
    /* in the ICD file display live variables at the end of each block */
    if (cparams.prm_icdfile)
    {
        for (i = 0; i < blockCount; i++)
        {
            if (blockArray[i])
            {
                QUAD *t = blockArray[i]->tail->fwd;
                /* this doesn't follow the normal handling rules
                 * so we remove and insert it by hand
                 */
                if (t && t->dc.opcode == i_blockend)
                {
                    t->back->fwd = t->fwd;
                    if (t->fwd)
                        t->fwd->back = t->back;
                }
                    
                if (blockArray[i]->liveOut)
                {
                    QUAD *q = Alloc(sizeof(QUAD));
                    t = blockArray[i]->tail;
                    q->dc.opcode = i_blockend;
                    q->dc.v.data = blockArray[i]->liveOut;
                    q->block = blockArray[i];
                    q->fwd = t->fwd;
                    q->back = t;
                    if (t->fwd)
                        t->fwd->back = q;
                    t->fwd = q;
                }
            }
        }
    }
}
Exemplo n.º 8
0
/*
 * Determine whether an inode can be allocated.
 *
 * Check to see if an inode is available, and if it is,
 * allocate it using tode in the specified cylinder group.
 */
static daddr_t
ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipref, int mode)
{
	struct m_ext2fs *fs;
	struct buf *bp;
	struct ext2mount *ump;
	int error, start, len;
	char *ibp, *loc;
	ipref--; /* to avoid a lot of (ipref -1) */
	if (ipref == -1)
		ipref = 0;
	fs = ip->i_e2fs;
	ump = ip->i_ump;
	if (fs->e2fs_gd[cg].ext2bgd_nifree == 0)
		return (0);
	EXT2_UNLOCK(ump);	
	error = bread(ip->i_devvp, fsbtodb(fs,
		fs->e2fs_gd[cg].ext2bgd_i_bitmap),
		(int)fs->e2fs_bsize, NOCRED, &bp);
	if (error) {
		brelse(bp);
		EXT2_LOCK(ump);
		return (0);
	}
	if (fs->e2fs_gd[cg].ext2bgd_nifree == 0) {
		/*
		 * Another thread allocated the last i-node in this
		 * group while we were waiting for the buffer.
		 */
		brelse(bp);
		EXT2_LOCK(ump);
		return (0);
	}
	ibp = (char *)bp->b_data;
	if (ipref) {
		ipref %= fs->e2fs->e2fs_ipg;
		if (isclr(ibp, ipref))
			goto gotit;
	}
	start = ipref / NBBY;
	len = howmany(fs->e2fs->e2fs_ipg - ipref, NBBY);
	loc = memcchr(&ibp[start], 0xff, len);
	if (loc == NULL) {
		len = start + 1;
		start = 0;
		loc = memcchr(&ibp[start], 0xff, len);
		if (loc == NULL) {
			printf("cg = %d, ipref = %lld, fs = %s\n",
				cg, (long long)ipref, fs->e2fs_fsmnt);
			panic("ext2fs_nodealloccg: map corrupted");
			/* NOTREACHED */
		}
	}
	ipref = (loc - ibp) * NBBY + ffs(~*loc) - 1;
gotit:
	setbit(ibp, ipref);
	EXT2_LOCK(ump);
	fs->e2fs_gd[cg].ext2bgd_nifree--;
	fs->e2fs->e2fs_ficount--;
	fs->e2fs_fmod = 1;
	if ((mode & IFMT) == IFDIR) {
		fs->e2fs_gd[cg].ext2bgd_ndirs++;
		fs->e2fs_total_dir++;
	}
	EXT2_UNLOCK(ump);
	bdwrite(bp);
	return (cg * fs->e2fs->e2fs_ipg + ipref +1);
}
Exemplo n.º 9
0
void
pass5(void)
{
	int c;
	struct m_ext2fs *fs = &sblock;
	daddr_t dbase, dmax;
	daddr_t d;
	uint32_t i, j;
	struct inodesc idesc[3];
	struct bufarea *ino_bitmap = NULL, *blk_bitmap = NULL;
	char *ibmap, *bbmap;
	u_int32_t cs_ndir, cs_nbfree, cs_nifree;
	char msg[255];

	cs_ndir = 0;
	cs_nbfree = 0;
	cs_nifree = 0;

	ibmap = malloc(fs->e2fs_bsize);
	bbmap = malloc(fs->e2fs_bsize);
	if (ibmap == NULL || bbmap == NULL) {
		errexit("out of memory");
	}

	for (c = 0; c < fs->e2fs_ncg; c++) {
		u_int32_t nbfree = 0;
		u_int32_t nifree = 0;
		u_int32_t ndirs = 0;

		nbfree = 0;
		nifree = fs->e2fs.e2fs_ipg;
		ndirs = 0;

		if (blk_bitmap == NULL) {
			blk_bitmap = getdatablk(fs2h32(fs->e2fs_gd[c].ext2bgd_b_bitmap),
				fs->e2fs_bsize);
		} else {
			getblk(blk_bitmap, fs2h32(fs->e2fs_gd[c].ext2bgd_b_bitmap),
				fs->e2fs_bsize);
		}
		if (ino_bitmap == NULL) {
			ino_bitmap = getdatablk(fs2h32(fs->e2fs_gd[c].ext2bgd_i_bitmap),
				fs->e2fs_bsize);
		} else {
			getblk(ino_bitmap, fs2h32(fs->e2fs_gd[c].ext2bgd_i_bitmap),
				fs->e2fs_bsize);
		}
		memset(bbmap, 0, fs->e2fs_bsize);
		memset(ibmap, 0, fs->e2fs_bsize);
		memset(&idesc[0], 0, sizeof idesc);
		for (i = 0; i < 3; i++) {
			idesc[i].id_type = ADDR;
		}       

		j = fs->e2fs.e2fs_ipg * c + 1;

		for (i = 0; i < fs->e2fs.e2fs_ipg; j++, i++) {
			if ((j < EXT2_FIRSTINO) && (j != EXT2_ROOTINO)) {
				setbit(ibmap, i);
				nifree--;
				continue;
			}
			if (j > fs->e2fs.e2fs_icount) {
				setbit(ibmap, i);
				continue;
			}
			switch (statemap[j]) {

			case USTATE:
				break;

			case DSTATE:
			case DCLEAR:
			case DFOUND:
				ndirs++;
				/* fall through */

			case FSTATE:
			case FCLEAR:
				nifree--;
				setbit(ibmap, i);
				break;

			default:
				errexit("BAD STATE %d FOR INODE I=%"PRIu32,
				    statemap[j], j);
			}
		}

		/* fill in unused par of the inode map */
		for (i = fs->e2fs.e2fs_ipg / NBBY; i < (uint32_t)fs->e2fs_bsize; i++)
			ibmap[i] = 0xff; 

		dbase = c * sblock.e2fs.e2fs_bpg +
		    sblock.e2fs.e2fs_first_dblock;
		dmax = (c+1) * sblock.e2fs.e2fs_bpg +
		    sblock.e2fs.e2fs_first_dblock;

		for (i = 0, d = dbase;
		     d < dmax;
		     d ++, i ++) {
			if (testbmap(d) || d >= sblock.e2fs.e2fs_bcount) {
				setbit(bbmap, i);
				continue;
			} else {
				nbfree++;
			}

		}
		cs_nbfree += nbfree;
		cs_nifree += nifree;
		cs_ndir += ndirs;

		if (debug && (fs2h16(fs->e2fs_gd[c].ext2bgd_nbfree) != nbfree ||
					  fs2h16(fs->e2fs_gd[c].ext2bgd_nifree) != nifree ||
					  fs2h16(fs->e2fs_gd[c].ext2bgd_ndirs) != ndirs)) {
			printf("summary info for cg %d is %d, %d, %d,"
					"should be %d, %d, %d\n", c,
					fs2h16(fs->e2fs_gd[c].ext2bgd_nbfree),
					fs2h16(fs->e2fs_gd[c].ext2bgd_nifree),
					fs2h16(fs->e2fs_gd[c].ext2bgd_ndirs),
					nbfree,
					nifree,
					ndirs);
		}
		(void)snprintf(msg, sizeof(msg),
		    "SUMMARY INFORMATIONS WRONG FOR CG #%d", c);
		if ((fs2h16(fs->e2fs_gd[c].ext2bgd_nbfree) != nbfree ||
			fs2h16(fs->e2fs_gd[c].ext2bgd_nifree) != nifree ||
			fs2h16(fs->e2fs_gd[c].ext2bgd_ndirs) != ndirs) &&
			dofix(&idesc[0], msg)) {
			fs->e2fs_gd[c].ext2bgd_nbfree = h2fs16(nbfree);
			fs->e2fs_gd[c].ext2bgd_nifree = h2fs16(nifree);
			fs->e2fs_gd[c].ext2bgd_ndirs = h2fs16(ndirs);
			sbdirty();
		}

		if (debug && memcmp(blk_bitmap->b_un.b_buf, bbmap, fs->e2fs_bsize)) {
			printf("blk_bitmap:\n");
			print_bmap(blk_bitmap->b_un.b_buf, fs->e2fs_bsize);
			printf("bbmap:\n");
			print_bmap(bbmap, fs->e2fs_bsize);
		}

		(void)snprintf(msg, sizeof(msg),
		    "BLK(S) MISSING IN BIT MAPS #%d", c);
		if (memcmp(blk_bitmap->b_un.b_buf, bbmap, fs->e2fs_bsize) &&
			dofix(&idesc[1], msg)) {
			memcpy(blk_bitmap->b_un.b_buf, bbmap, fs->e2fs_bsize);
			dirty(blk_bitmap);
		}
		if (debug && memcmp(ino_bitmap->b_un.b_buf, ibmap, fs->e2fs_bsize)) {
			printf("ino_bitmap:\n");
			print_bmap(ino_bitmap->b_un.b_buf, fs->e2fs_bsize);
			printf("ibmap:\n");
			print_bmap(ibmap, fs->e2fs_bsize);
		}
		(void)snprintf(msg, sizeof(msg),
		    "INODE(S) MISSING IN BIT MAPS #%d", c);
		if (memcmp(ino_bitmap->b_un.b_buf, ibmap, fs->e2fs_bsize) &&
			dofix(&idesc[1], msg)) {
			memcpy(ino_bitmap->b_un.b_buf, ibmap, fs->e2fs_bsize);
			dirty(ino_bitmap);
		}

	}
	if (debug && (fs->e2fs.e2fs_fbcount != cs_nbfree ||
		fs->e2fs.e2fs_ficount != cs_nifree)) {
		printf("summary info bad in superblock: %d, %d should be %d, %d\n",
		fs->e2fs.e2fs_fbcount, fs->e2fs.e2fs_ficount,
		cs_nbfree, cs_nifree);
	}
	if ((fs->e2fs.e2fs_fbcount != cs_nbfree ||
		fs->e2fs.e2fs_ficount != cs_nifree)
	    && dofix(&idesc[0], "SUPERBLK SUMMARY INFORMATION BAD")) {
		fs->e2fs.e2fs_fbcount = cs_nbfree;
		fs->e2fs.e2fs_ficount = cs_nifree;
		sbdirty();
	}
	free(ibmap);
	free(bbmap);
}
Exemplo n.º 10
0
/*
 * Determine whether a block can be allocated.
 *
 * Check to see if a block of the appropriate size is available,
 * and if it is, allocate it.
 */
static daddr_t
ext2_alloccg(struct inode *ip, int cg, daddr_t bpref, int size)
{
	struct m_ext2fs *fs;
	struct buf *bp;
	struct ext2mount *ump;
	daddr_t bno, runstart, runlen;
	int bit, loc, end, error, start;
	char *bbp;
	/* XXX ondisk32 */
	fs = ip->i_e2fs;
	ump = ip->i_ump;
	if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0)
		return (0);
	EXT2_UNLOCK(ump);
	error = bread(ip->i_devvp, fsbtodb(fs,
		fs->e2fs_gd[cg].ext2bgd_b_bitmap),
		(int)fs->e2fs_bsize, NOCRED, &bp);
	if (error) {
		brelse(bp);
		EXT2_LOCK(ump);
		return (0);
	}
	if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0) {
		/*
		 * Another thread allocated the last block in this
		 * group while we were waiting for the buffer.
		 */
		brelse(bp);
		EXT2_LOCK(ump);
		return (0);
	}
	bbp = (char *)bp->b_data;

	if (dtog(fs, bpref) != cg)
		bpref = 0;
	if (bpref != 0) {
		bpref = dtogd(fs, bpref);
		/*
		 * if the requested block is available, use it
		 */
		if (isclr(bbp, bpref)) {
			bno = bpref;
			goto gotit;
		}
	}
	/*
	 * no blocks in the requested cylinder, so take next
	 * available one in this cylinder group.
	 * first try to get 8 contigous blocks, then fall back to a single
	 * block.
	 */
	if (bpref)
		start = dtogd(fs, bpref) / NBBY;
	else
		start = 0;
	end = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
retry:
	runlen = 0;
	runstart = 0;
	for (loc = start; loc < end; loc++) {
		if (bbp[loc] == (char)0xff) {
			runlen = 0;
			continue;
		}

		/* Start of a run, find the number of high clear bits. */
		if (runlen == 0) {
			bit = fls(bbp[loc]);
			runlen = NBBY - bit;
			runstart = loc * NBBY + bit;
		} else if (bbp[loc] == 0) {
			/* Continue a run. */
			runlen += NBBY;
		} else {
			/*
			 * Finish the current run.  If it isn't long
			 * enough, start a new one.
			 */
			bit = ffs(bbp[loc]) - 1;
			runlen += bit;
			if (runlen >= 8) {
				bno = runstart;
				goto gotit;
			}

			/* Run was too short, start a new one. */
			bit = fls(bbp[loc]);
			runlen = NBBY - bit;
			runstart = loc * NBBY + bit;
		}

		/* If the current run is long enough, use it. */
		if (runlen >= 8) {
			bno = runstart;
			goto gotit;
		}
	}
	if (start != 0) {
		end = start;
		start = 0;
		goto retry;
	}

	bno = ext2_mapsearch(fs, bbp, bpref);
	if (bno < 0){
		brelse(bp);
		EXT2_LOCK(ump);
		return (0);
	}
gotit:
#ifdef INVARIANTS
	if (isset(bbp, bno)) {
		printf("ext2fs_alloccgblk: cg=%d bno=%jd fs=%s\n",
			cg, (intmax_t)bno, fs->e2fs_fsmnt);
		panic("ext2fs_alloccg: dup alloc");
	}
#endif
	setbit(bbp, bno);
	EXT2_LOCK(ump);
	ext2_clusteracct(fs, bbp, cg, bno, -1);
	fs->e2fs->e2fs_fbcount--;
	fs->e2fs_gd[cg].ext2bgd_nbfree--;
	fs->e2fs_fmod = 1;
	EXT2_UNLOCK(ump);
	bdwrite(bp);
	return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno);
}
Exemplo n.º 11
0
/*
 * Determine whether a cluster can be allocated.
 */
static daddr_t
ext2_clusteralloc(struct inode *ip, int cg, daddr_t bpref, int len)
{
	struct m_ext2fs *fs;
	struct ext2mount *ump;
	struct buf *bp;
	char *bbp;
	int bit, error, got, i, loc, run;
	int32_t *lp;
	daddr_t bno;

	fs = ip->i_e2fs;
	ump = ip->i_ump;

	if (fs->e2fs_maxcluster[cg] < len)
		return (0);

	EXT2_UNLOCK(ump);
	error = bread(ip->i_devvp,
	    fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap),
	    (int)fs->e2fs_bsize, NOCRED, &bp);
	if (error)
		goto fail_lock;

	bbp = (char *)bp->b_data;
	EXT2_LOCK(ump);
	/*
	 * Check to see if a cluster of the needed size (or bigger) is
	 * available in this cylinder group.
	 */
	lp = &fs->e2fs_clustersum[cg].cs_sum[len];
	for (i = len; i <= fs->e2fs_contigsumsize; i++)
		if (*lp++ > 0)
			break;
	if (i > fs->e2fs_contigsumsize) {
		/*
		 * Update the cluster summary information to reflect
		 * the true maximum-sized cluster so that future cluster
		 * allocation requests can avoid reading the bitmap only
		 * to find no cluster.
		 */
		lp = &fs->e2fs_clustersum[cg].cs_sum[len - 1];
			for (i = len - 1; i > 0; i--)
				if (*lp-- > 0)
					break;
		fs->e2fs_maxcluster[cg] = i;
		goto fail;
	}
	EXT2_UNLOCK(ump);

	/* Search the bitmap to find a big enough cluster like in FFS. */
	if (dtog(fs, bpref) != cg)
		bpref = 0;
	if (bpref != 0)
		bpref = dtogd(fs, bpref);
	loc = bpref / NBBY;
	bit = 1 << (bpref % NBBY);
	for (run = 0, got = bpref; got < fs->e2fs->e2fs_fpg; got++) {
		if ((bbp[loc] & bit) != 0)
			run = 0;
		else {
			run++;
			if (run == len)
				break;
		}
		if ((got & (NBBY - 1)) != (NBBY - 1))
			bit <<= 1;
		else {
			loc++;
			bit = 1;
		}
	}

	if (got >= fs->e2fs->e2fs_fpg)
		goto fail_lock;

	/* Allocate the cluster that we found. */
	for (i = 1; i < len; i++)
		if (!isclr(bbp, got - run + i))
			panic("ext2_clusteralloc: map mismatch");

	bno = got - run + 1;
	if (bno >= fs->e2fs->e2fs_fpg)
		panic("ext2_clusteralloc: allocated out of group");

	EXT2_LOCK(ump);
	for (i = 0; i < len; i += fs->e2fs_fpb) {
		setbit(bbp, bno + i);
		ext2_clusteracct(fs, bbp, cg, bno + i, -1);
		fs->e2fs->e2fs_fbcount--;
		fs->e2fs_gd[cg].ext2bgd_nbfree--;
	}
	fs->e2fs_fmod = 1;
	EXT2_UNLOCK(ump);

	bdwrite(bp);
	return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno);

fail_lock:
	EXT2_LOCK(ump);
fail:
	brelse(bp);
	return (0);
}
Exemplo n.º 12
0
Arquivo: name.c Projeto: phreddrick/GB
void bless(int Playernum, int Governor, int APcount)
{
    planettype *planet;
    racetype *Race;
    int who, amount, Mod;
    char commod;
    
    Race = races[Playernum-1];
    if(!Race->God) {
	notify(Playernum, Governor, "You are not privileged to use this command.\n");
	return;
    }
    if(Dir[Playernum-1][Governor].level != LEVEL_PLAN) {
	notify(Playernum, Governor, "Please cs to the planet in question.\n");
	return;
    }
    who = atoi(args[1]);
    if(who<1 || who>Num_races) {
	notify(Playernum, Governor, "No such player number.\n");
	return;
    }
    if(argn<3) {
	notify(Playernum, Governor, "Syntax: bless <player> <what> <+amount>\n");
	return;
    }
    amount = atoi(args[3]);
    
    Race = races[who-1];
    /* race characteristics? */
    Mod = 1;

    if(match(args[2], "money")) {
	Race->governor[0].money += amount;
	sprintf(buf, "Deity gave you %d money.\n", amount);
    } else if(match(args[2], "password")) {
	strcpy(Race->password, args[3]);
	sprintf(buf, "Deity changed your race password to `%s'\n", args[3]);
    } else if(match(args[2], "morale")) {
	Race->morale += amount;
	sprintf(buf, "Deity gave you %d morale.\n", amount); 
    } else if(match(args[2], "pods")) {
	Race->pods = 1;
	sprintf(buf, "Deity gave you pod ability.\n");
    } else if(match(args[2], "nopods")) {
	Race->pods = 0;
	sprintf(buf, "Deity took away pod ability.\n");
    } else if(match(args[2], "collectiveiq")) {
        Race->collective_iq = 1;
	sprintf(buf, "Deity gave you collective intelligence.\n");
    } else if(match(args[2], "nocollectiveiq")) {
	Race->collective_iq = 0;
	sprintf(buf, "Deity took away collective intelligence.\n");
    } else if(match(args[2], "maxiq")) {
	Race->IQ_limit = atoi(args[3]);
	sprintf(buf, "Deity gave you a maximum IQ of %d.\n",Race->IQ_limit);
    } else if(match(args[2], "mass")) {
	Race->mass = atof(args[3]);
	sprintf(buf, "Deity gave you %.2f mass.\n", Race->mass);
    } else if(match(args[2], "metabolism")) {
	Race->metabolism = atof(args[3]);
	sprintf(buf, "Deity gave you %.2f metabolism.\n", Race->metabolism);
    } else if(match(args[2], "adventurism")) {
	Race->adventurism = atof(args[3]);
	sprintf(buf, "Deity gave you %-3.0f%% adventurism.\n", Race->adventurism*100.0);
    } else if(match(args[2], "birthrate")) {
	Race->birthrate = atof(args[3]);
	sprintf(buf, "Deity gave you %.2f birthrate.\n", Race->birthrate);
    } else if(match(args[2], "fertility")) {
	Race->fertilize = amount;
	sprintf(buf, "Deity gave you a fetilization ability of %d.\n", amount);
    } else if(match(args[2], "IQ")) {
	Race->IQ = amount;
	sprintf(buf, "Deity gave you %d IQ.\n", amount);
    } else if(match(args[2], "fight")) {
	Race->fighters = amount;
	sprintf(buf, "Deity set your fighting ability to %d.\n", amount);
    } else if(match(args[2], "technology")) {
	Race->tech += (double)amount;
	sprintf(buf, "Deity gave you %d technology.\n", amount);
    } else if(match(args[2], "guest")) {
	Race->Guest = 1;
	sprintf(buf, "Deity turned you into a guest race.\n");
    } else if(match(args[2], "god")) {
	Race->God = 1;
	sprintf(buf, "Deity turned you into a deity race.\n");
    } else if(match(args[2], "mortal")) {
	Race->God = 0;
	Race->Guest = 0;
	sprintf(buf, "Deity turned you into a mortal race.\n");
/* sector preferences */
    } else if(match(args[2], "water")) {
	Race->likes[SEA] = 0.01*(double)amount;
	sprintf(buf, "Deity set your water preference to %d%%\n", amount);
    } else if(match(args[2], "land")) {
	Race->likes[LAND] = 0.01*(double)amount;
	sprintf(buf, "Deity set your land preference to %d%%\n", amount);
    } else if(match(args[2], "mountain")) {
	Race->likes[MOUNT] = 0.01*(double)amount;
	sprintf(buf, "Deity set your mountain preference to %d%%\n", amount);
    } else if(match(args[2], "gas")) {
	Race->likes[GAS] = 0.01*(double)amount;
	sprintf(buf, "Deity set your gas preference to %d%%\n", amount);
    } else if(match(args[2], "ice")) {
	Race->likes[ICE] = 0.01*(double)amount;
	sprintf(buf, "Deity set your ice preference to %d%%\n", amount);
    } else if(match(args[2], "forest")) {
	Race->likes[FOREST] = 0.01*(double)amount;
	sprintf(buf, "Deity set your forest preference to %d%%\n", amount);
    } else if(match(args[2], "desert")) {
	Race->likes[DESERT] = 0.01*(double)amount;
	sprintf(buf, "Deity set your desert preference to %d%%\n", amount);
    } else if(match(args[2], "plated")) {
	Race->likes[PLATED] = 0.01*(double)amount;
	sprintf(buf, "Deity set your plated preference to %d%%\n", amount);
    } else Mod = 0;
    if(Mod) {
	putrace(Race);
	warn(who, 0, buf);
    }
    if(Mod) return;
    /* ok, must be the planet then */
    commod = args[2][0];
    getplanet(&planet, Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);
    if (match(args[2],"explorebit")) {
	planet->info[who-1].explored = 1;
	getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	setbit(Stars[Dir[Playernum-1][Governor].snum]->explored, who);
	putstar(Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	sprintf(buf, "Deity set your explored bit at /%s/%s.\n",
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
    } else if (match(args[2],"noexplorebit")) {
        planet->info[who-1].explored = 0;
        sprintf(buf, "Deity reset your explored bit at /%s/%s.\n",
                Stars[Dir[Playernum-1][Governor].snum]->name,
                Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]); 
    } else if (match(args[2],"planetpopulation")) {
	planet->info[who-1].popn = atoi(args[3]);
	planet->popn++;
	sprintf(buf, "Deity set your population variable to %ld at /%s/%s.\n",
		planet->popn,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
    } else if (match(args[2],"inhabited")) {
	getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	setbit(Stars[Dir[Playernum-1][Governor].snum]->inhabited,Playernum);
	putstar(Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	sprintf(buf,"Deity has set your inhabited bit for /%s/%s.\n",
		Stars[Dir[Playernum-1][Governor].snum]->name,
                Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
    } else if (match(args[2],"numsectsowned")) {
	planet->info[who-1].numsectsowned = atoi(args[3]);
	sprintf(buf, "Deity set your \"numsectsowned\" variable at /%s/%s to %d.\n",
                Stars[Dir[Playernum-1][Governor].snum]->name,
                Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum],
		planet->info[who-1].numsectsowned); 
    } else {
    switch(commod) {
      case 'r':
	planet->info[who-1].resource += amount;
	sprintf(buf, "Deity gave you %d resources at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'd':
	planet->info[who-1].destruct += amount;
	sprintf(buf, "Deity gave you %d destruct at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'f':
	planet->info[who-1].fuel += amount;
	sprintf(buf, "Deity gave you %d fuel at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'x':
	planet->info[who-1].crystals += amount;
	sprintf(buf, "Deity gave you %d crystals at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'a':
	getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	Stars[Dir[Playernum-1][Governor].snum]->AP[who-1] += amount;
	putstar(Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	sprintf(buf, "Deity gave you %d action points at %s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name);
	break;
      default:
	notify(Playernum, Governor, "No such commodity.\n");
	free(planet);
	return;
    } }
    putplanet(planet,Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);
    warn_race(who, buf);
    free(planet);
}
Exemplo n.º 13
0
Arquivo: name.c Projeto: phreddrick/GB
void give(int Playernum, int Governor, int APcount)
{
  int who, sh;
  shiptype *ship;
  planettype *planet;
  racetype *Race, *alien;

  if(!(who=GetPlayer(args[1]))) {
    sprintf(buf,"No such player.\n");
    notify(Playernum, Governor, buf);
    return;
  }
  if(Governor) {
      notify(Playernum, Governor, "You are not authorized to do that.\n");
      return;
  }
  alien = races[who-1];
  Race = races[Playernum-1];
  if(alien->Guest && !Race->God) {
      notify(Playernum, Governor, "You can't give this player anything.\n");
      return;
  }
  if(Race->Guest) {
      notify(Playernum, Governor, "You can't give anyone anything.\n");
      return;
  }
  /* check to see if both players are mutually allied */
  if(!Race->God &&
     !(isset(Race->allied, who) && isset(alien->allied, Playernum))) {
    notify(Playernum, Governor, "You two are not mutually allied.\n");
    return;
  }
  sscanf(args[2]+(args[2][0]=='#'), "%d", &sh);

  if(!getship(&ship, sh)) {
    notify(Playernum, Governor, "Illegal ship number.\n");
    return;
  }

  if(ship->owner != Playernum || !ship->alive) {
    DontOwnErr(Playernum, Governor, sh);
    free(ship);
    return;
  }
  if(ship->type == STYPE_POD) {
    notify(Playernum, Governor, "You cannot change the ownership of spore pods.\n");
    free(ship);
    return;
  }

  if((ship->popn+ship->troops) && !Race->God) {
    notify(Playernum, Governor, "You can't give this ship away while it has crew/mil on board.\n");
    free(ship);
    return;
  }
  if(ship->ships && !Race->God) {
      notify(Playernum, Governor, "You can't give away this ship, it has other ships loaded on it.\n");
      free(ship);
      return;
  }
  switch(ship->whatorbits) {
  case LEVEL_UNIV:
    if(!enufAP(Playernum,Governor, Sdata.AP[Playernum-1], APcount)) {
      free(ship);
      return;
    }
    break;
  default:
    if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) {
      free(ship);
      return;
    }
    break;
  }

  ship->owner = who;
  ship->governor = 0;	/* give to the leader */
  capture_stuff(ship);

  putship(ship);

  /* set inhabited/explored bits */
  switch(ship->whatorbits) {
    case LEVEL_UNIV:
      break;
    case LEVEL_STAR:
      getstar(&(Stars[ship->storbits]), (int)ship->storbits);
      setbit(Stars[ship->storbits]->explored, who);
      putstar(Stars[ship->storbits], (int)ship->storbits);
      break;
    case LEVEL_PLAN:
      getstar(&(Stars[ship->storbits]), (int)ship->storbits);
      setbit(Stars[ship->storbits]->explored, who);
      putstar(Stars[ship->storbits], (int)ship->storbits);

      getplanet(&planet, (int)ship->storbits,(int)ship->pnumorbits);
      planet->info[who-1].explored = 1;
      putplanet(planet, (int)ship->storbits,(int)ship->pnumorbits);
      free(planet);

      break;
    default:
      notify(Playernum, Governor, "Something wrong with this ship's scope.\n");
      free(ship);
      return;
      break;
  }

  switch(ship->whatorbits) {
    case LEVEL_UNIV:
      deductAPs(Playernum, Governor,  APcount, 0, 1);
      free(ship);
      return;
      break;
    default:
      deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0);
      break;
  }
  notify(Playernum, Governor, "Owner changed.\n");
  sprintf(buf, "%s [%d] gave you %s at %s.\n", Race->name, Playernum,
	  Ship(ship), prin_ship_orbits(ship));
  warn(who, 0, buf);

if (!Race->God) {
  sprintf(buf, "%s [%d] gives %s [%d] a ship.\n", Race->name,
	  Playernum, alien->name, who);
  post(buf, TRANSFER);
  free(ship);
}
}
Exemplo n.º 14
0
void ScanForInvariants(BLOCK *b)
{
    BLOCKLIST *bl = b->succ;
    QUAD *head = b->head;
    b->preWalk = current++;
    
    while (head != b->tail->fwd)
    {
        QUAD *next = head->fwd;
        if (!head->ignoreMe && head->dc.opcode != i_label && head->dc.opcode != i_assnblock)
        {
            if (head->dc.opcode == i_phi)
            {
                
                
                LOOP *parent = head->block->inclusiveLoopParent;
                struct _phiblock *pb;
                if (!parent->invariantPhiList)
                {
                    LOOP *last = parent->parent;
                    while (last && !last->invariantPhiList)
                        last = last->parent;
                    
                    parent->invariantPhiList = allocbit(tempCount);
                    if (last)
                        memcpy(bits(parent->invariantPhiList), bits(last->invariantPhiList), ((tempCount) + (BITINTBITS-1))/BITINTBITS * sizeof(BITINT));
                }
                pb = head->dc.v.phi->temps;
                while (pb)
                {
                    setbit(parent->invariantPhiList, pb->Tn);
                    pb = pb->next;
                }
                setbit(parent->invariantPhiList, head->dc.v.phi->T0);
            }
            else if ((head->temps & TEMP_ANS) && head->ans->mode == i_direct && head->ans->size < ISZ_FLOAT)
            {
                tempInfo[head->ans->offset->v.sp->value.i]->blockDefines = b;
                if (!tempInfo[head->ans->offset->v.sp->value.i]->inductionLoop && ( head->temps & (TEMP_LEFT | TEMP_RIGHT)))
                {
                    BOOLEAN canMove = TRUE;
                    BLOCK *pbl = NULL, *pbr = NULL;
                    if ((head->temps & TEMP_LEFT) && head->dc.left->mode == i_direct)
                    {
                        pbl = tempInfo[head->dc.left->offset->v.sp->value.i]->blockDefines;
                    }
                    else if (head->dc.left->mode != i_immed)
                        canMove = FALSE;
                    if ((head->temps & TEMP_RIGHT) && head->dc.right->mode == i_direct)
                    {
                        pbr = tempInfo[head->dc.right->offset->v.sp->value.i]->blockDefines;
                    }
                    else if (head->dc.right && head->dc.right->mode != i_immed)
                        canMove = FALSE;
                    if (canMove)
                        canMove = InvariantPhiUsing(head);
                    if (canMove)
                        if (pbl && pbl->preWalk != b->preWalk && pbl->nesting == b->nesting && (!pbr || (pbr->preWalk != b->preWalk && pbr->nesting == b->nesting)))
                            MoveExpression(b, head, pbl, pbr);
                }
                /*
                else if (head->dc.opcode == i_assn && head->dc.left->mode == i_immed)
                {
                    if (!isarithmeticconst(head->dc.left->offset))
                    {
                        LOOP *lp = b->loopParent;
                        if (lp)
                        {
                            BLOCK *b1 = lp->entry;
                            if (b1)
                            {
                                b1 = blockArray[b1->idom];
                                if (b1 && b1 != b)
                                {
//									MoveTo(b1, b, head);
                                }
                            }
                        }
                        
                    }
                }
                */
            }
        }
        head = next;
    }
    while (bl)
    {
        if (!bl->block->preWalk)
        {
            ScanForInvariants(bl->block);
        }
        bl = bl->next;
    }
}
Exemplo n.º 15
0
static gboolean
rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
		struct symbols_cache *cache,
		struct cache_item *item,
		struct cache_savepoint *checkpoint,
		gdouble *total_diff)
{
	guint pending_before, pending_after;
	double t1, t2;
	gdouble diff;
	struct rspamd_task **ptask;
	lua_State *L;
	gboolean check = TRUE;
	const gdouble slow_diff_limit = 1e5;

	if (item->type & (SYMBOL_TYPE_NORMAL|SYMBOL_TYPE_CALLBACK)) {

		g_assert (item->func != NULL);
		/* Check has been started */
		setbit (checkpoint->processed_bits, item->id * 2);

		if (RSPAMD_TASK_IS_EMPTY (task) && !(item->type & SYMBOL_TYPE_EMPTY)) {
			check = FALSE;
		}
		else if (item->condition_cb != -1) {
			/* We also executes condition callback to check if we need this symbol */
			L = task->cfg->lua_state;
			lua_rawgeti (L, LUA_REGISTRYINDEX, item->condition_cb);
			ptask = lua_newuserdata (L, sizeof (struct rspamd_task *));
			rspamd_lua_setclass (L, "rspamd{task}", -1);
			*ptask = task;

			if (lua_pcall (L, 1, 1, 0) != 0) {
				msg_info_task ("call to condition for %s failed: %s",
						item->symbol, lua_tostring (L, -1));
				lua_pop (L, 1);
			}
			else {
				check = lua_toboolean (L, -1);
				lua_pop (L, 1);
			}
		}

		if (check) {
			t1 = rspamd_get_ticks ();
			pending_before = rspamd_session_events_pending (task->s);
			/* Watch for events appeared */
			rspamd_session_watch_start (task->s, rspamd_symbols_cache_watcher_cb,
					item);

			msg_debug_task ("execute %s, %d", item->symbol, item->id);
			item->func (task, item->user_data);

			t2 = rspamd_get_ticks ();
			diff = (t2 - t1) * 1e6;

			if (total_diff) {
				*total_diff += diff;
			}

			if (diff > slow_diff_limit) {
				msg_info_task ("slow rule: %s: %d ms", item->symbol,
						(gint)(diff / 1000.));
			}

			rspamd_set_counter (item, diff);
			rspamd_session_watch_stop (task->s);
			pending_after = rspamd_session_events_pending (task->s);

			if (pending_before == pending_after) {
				/* No new events registered */
				setbit (checkpoint->processed_bits, item->id * 2 + 1);

				return TRUE;
			}

			return FALSE;
		}
		else {
			msg_debug_task ("skipping check of %s as its condition is false",
					item->symbol);
			setbit (checkpoint->processed_bits, item->id * 2 + 1);

			return TRUE;
		}
	}
	else {
		setbit (checkpoint->processed_bits, item->id * 2);
		setbit (checkpoint->processed_bits, item->id * 2 + 1);

		return TRUE;
	}
}
Exemplo n.º 16
0
void
pass5(void)
{
	int c, i, j, blk, frags, basesize, mapsize;
	int inomapsize, blkmapsize;
	struct fs *fs = &sblock;
	ufs2_daddr_t d, dbase, dmax, start;
	int rewritecg = 0;
	struct csum *cs;
	struct csum_total cstotal;
	struct inodesc idesc[3];
	char buf[MAXBSIZE];
	struct cg *cg, *newcg = (struct cg *)buf;
	struct bufarea *cgbp;

	inoinfo(WINO)->ino_state = USTATE;
	memset(newcg, 0, (size_t)fs->fs_cgsize);
	newcg->cg_niblk = fs->fs_ipg;
	if (cvtlevel >= 3) {
		if (fs->fs_maxcontig < 2 && fs->fs_contigsumsize > 0) {
			if (preen)
				pwarn("DELETING CLUSTERING MAPS\n");
			if (preen || reply("DELETE CLUSTERING MAPS")) {
				fs->fs_contigsumsize = 0;
				rewritecg = 1;
				sbdirty();
			}
		}
		if (fs->fs_maxcontig > 1) {
			const char *doit = 0;

			if (fs->fs_contigsumsize < 1) {
				doit = "CREAT";
			} else if (fs->fs_contigsumsize < fs->fs_maxcontig &&
				   fs->fs_contigsumsize < FS_MAXCONTIG) {
				doit = "EXPAND";
			}
			if (doit) {
				i = fs->fs_contigsumsize;
				fs->fs_contigsumsize =
				    MIN(fs->fs_maxcontig, FS_MAXCONTIG);
				if (CGSIZE(fs) > (u_int)fs->fs_bsize) {
					pwarn("CANNOT %s CLUSTER MAPS\n", doit);
					fs->fs_contigsumsize = i;
				} else if (preen ||
				    reply("CREATE CLUSTER MAPS")) {
					if (preen)
						pwarn("%sING CLUSTER MAPS\n",
						    doit);
					fs->fs_cgsize =
					    fragroundup(fs, CGSIZE(fs));
					rewritecg = 1;
					sbdirty();
				}
			}
		}
	}
	basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_firstfield);
	if (sblock.fs_magic == FS_UFS2_MAGIC) {
		newcg->cg_iusedoff = basesize;
	} else {
		/*
		 * We reserve the space for the old rotation summary
		 * tables for the benefit of old kernels, but do not
		 * maintain them in modern kernels. In time, they can
		 * go away.
		 */
		newcg->cg_old_btotoff = basesize;
		newcg->cg_old_boff = newcg->cg_old_btotoff +
		    fs->fs_old_cpg * sizeof(int32_t);
		newcg->cg_iusedoff = newcg->cg_old_boff +
		    fs->fs_old_cpg * fs->fs_old_nrpos * sizeof(u_int16_t);
		memset(&newcg->cg_space[0], 0, newcg->cg_iusedoff - basesize);
	}
	inomapsize = howmany(fs->fs_ipg, CHAR_BIT);
	newcg->cg_freeoff = newcg->cg_iusedoff + inomapsize;
	blkmapsize = howmany(fs->fs_fpg, CHAR_BIT);
	newcg->cg_nextfreeoff = newcg->cg_freeoff + blkmapsize;
	if (fs->fs_contigsumsize > 0) {
		newcg->cg_clustersumoff = newcg->cg_nextfreeoff -
		    sizeof(u_int32_t);
		newcg->cg_clustersumoff =
		    roundup(newcg->cg_clustersumoff, sizeof(u_int32_t));
		newcg->cg_clusteroff = newcg->cg_clustersumoff +
		    (fs->fs_contigsumsize + 1) * sizeof(u_int32_t);
		newcg->cg_nextfreeoff = newcg->cg_clusteroff +
		    howmany(fragstoblks(fs, fs->fs_fpg), CHAR_BIT);
	}
	newcg->cg_magic = CG_MAGIC;
	mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
	memset(&idesc[0], 0, sizeof idesc);
	for (i = 0; i < 3; i++)
		idesc[i].id_type = ADDR;
	memset(&cstotal, 0, sizeof(struct csum_total));
	dmax = blknum(fs, fs->fs_size + fs->fs_frag - 1);
	for (d = fs->fs_size; d < dmax; d++)
		setbmap(d);
	for (c = 0; c < fs->fs_ncg; c++) {
		if (got_siginfo) {
			printf("%s: phase 5: cyl group %d of %d (%d%%)\n",
			    cdevname, c, sblock.fs_ncg,
			    c * 100 / sblock.fs_ncg);
			got_siginfo = 0;
		}
		if (got_sigalarm) {
			setproctitle("%s p5 %d%%", cdevname,
			    c * 100 / sblock.fs_ncg);
			got_sigalarm = 0;
		}
		cgbp = cgget(c);
		cg = cgbp->b_un.b_cg;
		if (!cg_chkmagic(cg))
			pfatal("CG %d: BAD MAGIC NUMBER\n", c);
		newcg->cg_time = cg->cg_time;
		newcg->cg_old_time = cg->cg_old_time;
		newcg->cg_unrefs = cg->cg_unrefs;
		newcg->cg_cgx = c;
		dbase = cgbase(fs, c);
		dmax = dbase + fs->fs_fpg;
		if (dmax > fs->fs_size)
			dmax = fs->fs_size;
		newcg->cg_ndblk = dmax - dbase;
		if (fs->fs_magic == FS_UFS1_MAGIC) {
			if (c == fs->fs_ncg - 1)
				newcg->cg_old_ncyl = howmany(newcg->cg_ndblk,
				    fs->fs_fpg / fs->fs_old_cpg);
			else
				newcg->cg_old_ncyl = fs->fs_old_cpg;
			newcg->cg_old_niblk = fs->fs_ipg;
			newcg->cg_niblk = 0;
		}
		if (fs->fs_contigsumsize > 0)
			newcg->cg_nclusterblks = newcg->cg_ndblk / fs->fs_frag;
		newcg->cg_cs.cs_ndir = 0;
		newcg->cg_cs.cs_nffree = 0;
		newcg->cg_cs.cs_nbfree = 0;
		newcg->cg_cs.cs_nifree = fs->fs_ipg;
		if (cg->cg_rotor >= 0 && cg->cg_rotor < newcg->cg_ndblk)
			newcg->cg_rotor = cg->cg_rotor;
		else
			newcg->cg_rotor = 0;
		if (cg->cg_frotor >= 0 && cg->cg_frotor < newcg->cg_ndblk)
			newcg->cg_frotor = cg->cg_frotor;
		else
			newcg->cg_frotor = 0;
		if (cg->cg_irotor >= 0 && cg->cg_irotor < fs->fs_ipg)
			newcg->cg_irotor = cg->cg_irotor;
		else
			newcg->cg_irotor = 0;
		if (fs->fs_magic == FS_UFS1_MAGIC) {
			newcg->cg_initediblk = 0;
		} else {
			if ((unsigned)cg->cg_initediblk > fs->fs_ipg)
				newcg->cg_initediblk = fs->fs_ipg;
			else
				newcg->cg_initediblk = cg->cg_initediblk;
		}
		memset(&newcg->cg_frsum[0], 0, sizeof newcg->cg_frsum);
		memset(cg_inosused(newcg), 0, (size_t)(mapsize));
		j = fs->fs_ipg * c;
		for (i = 0; i < inostathead[c].il_numalloced; j++, i++) {
			switch (inoinfo(j)->ino_state) {

			case USTATE:
				break;

			case DSTATE:
			case DCLEAR:
			case DFOUND:
			case DZLINK:
				newcg->cg_cs.cs_ndir++;
				/* FALLTHROUGH */

			case FSTATE:
			case FCLEAR:
			case FZLINK:
				newcg->cg_cs.cs_nifree--;
				setbit(cg_inosused(newcg), i);
				break;

			default:
				if (j < (int)ROOTINO)
					break;
				errx(EEXIT, "BAD STATE %d FOR INODE I=%d",
				    inoinfo(j)->ino_state, j);
			}
		}
		if (c == 0)
			for (i = 0; i < (int)ROOTINO; i++) {
				setbit(cg_inosused(newcg), i);
				newcg->cg_cs.cs_nifree--;
			}
		start = -1;
		for (i = 0, d = dbase;
		     d < dmax;
		     d += fs->fs_frag, i += fs->fs_frag) {
			frags = 0;
			for (j = 0; j < fs->fs_frag; j++) {
				if (testbmap(d + j)) {
					if ((Eflag || Zflag) && start != -1) {
						clear_blocks(start, d + j - 1);
						start = -1;
					}
					continue;
				}
				if (start == -1)
					start = d + j;
				setbit(cg_blksfree(newcg), i + j);
				frags++;
			}
			if (frags == fs->fs_frag) {
				newcg->cg_cs.cs_nbfree++;
				if (fs->fs_contigsumsize > 0)
					setbit(cg_clustersfree(newcg),
					    i / fs->fs_frag);
			} else if (frags > 0) {
				newcg->cg_cs.cs_nffree += frags;
				blk = blkmap(fs, cg_blksfree(newcg), i);
				ffs_fragacct(fs, blk, newcg->cg_frsum, 1);
			}
		}
		if ((Eflag || Zflag) && start != -1)
			clear_blocks(start, d - 1);
		if (fs->fs_contigsumsize > 0) {
			int32_t *sump = cg_clustersum(newcg);
			u_char *mapp = cg_clustersfree(newcg);
			int map = *mapp++;
			int bit = 1;
			int run = 0;

			for (i = 0; i < newcg->cg_nclusterblks; i++) {
				if ((map & bit) != 0) {
					run++;
				} else if (run != 0) {
					if (run > fs->fs_contigsumsize)
						run = fs->fs_contigsumsize;
					sump[run]++;
					run = 0;
				}
				if ((i & (CHAR_BIT - 1)) != (CHAR_BIT - 1)) {
					bit <<= 1;
				} else {
					map = *mapp++;
					bit = 1;
				}
			}
			if (run != 0) {
				if (run > fs->fs_contigsumsize)
					run = fs->fs_contigsumsize;
				sump[run]++;
			}
		}
		if (bkgrdflag != 0) {
			cstotal.cs_nffree += cg->cg_cs.cs_nffree;
			cstotal.cs_nbfree += cg->cg_cs.cs_nbfree;
			cstotal.cs_nifree += cg->cg_cs.cs_nifree;
			cstotal.cs_ndir += cg->cg_cs.cs_ndir;
		} else {
			cstotal.cs_nffree += newcg->cg_cs.cs_nffree;
			cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree;
			cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
			cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
		}
		cs = &fs->fs_cs(fs, c);
		if (cursnapshot == 0 &&
		    memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0 &&
		    dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
			memmove(cs, &newcg->cg_cs, sizeof *cs);
			sbdirty();
		}
		if (rewritecg) {
			memmove(cg, newcg, (size_t)fs->fs_cgsize);
			dirty(cgbp);
			continue;
		}
		if (cursnapshot == 0 &&
		    memcmp(newcg, cg, basesize) != 0 &&
		    dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
			memmove(cg, newcg, (size_t)basesize);
			dirty(cgbp);
		}
		if (bkgrdflag != 0 || usedsoftdep || debug)
			update_maps(cg, newcg, bkgrdflag);
		if (cursnapshot == 0 &&
		    memcmp(cg_inosused(newcg), cg_inosused(cg), mapsize) != 0 &&
		    dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) {
			memmove(cg_inosused(cg), cg_inosused(newcg),
			      (size_t)mapsize);
			dirty(cgbp);
		}
	}
	if (cursnapshot == 0 &&
	    memcmp(&cstotal, &fs->fs_cstotal, sizeof cstotal) != 0
	    && dofix(&idesc[0], "SUMMARY BLK COUNT(S) WRONG IN SUPERBLK")) {
		memmove(&fs->fs_cstotal, &cstotal, sizeof cstotal);
		fs->fs_ronly = 0;
		fs->fs_fmod = 0;
		sbdirty();
	}

	/*
	 * When doing background fsck on a snapshot, figure out whether
	 * the superblock summary is inaccurate and correct it when
	 * necessary.
	 */
	if (cursnapshot != 0) {
		cmd.size = 1;

		cmd.value = cstotal.cs_ndir - fs->fs_cstotal.cs_ndir;
		if (cmd.value != 0) {
			if (debug)
				printf("adjndir by %+" PRIi64 "\n", cmd.value);
			if (bkgrdsumadj == 0 || sysctl(adjndir, MIBSIZE, 0, 0,
			    &cmd, sizeof cmd) == -1)
				rwerror("ADJUST NUMBER OF DIRECTORIES", cmd.value);
		}

		cmd.value = cstotal.cs_nbfree - fs->fs_cstotal.cs_nbfree;
		if (cmd.value != 0) {
			if (debug)
				printf("adjnbfree by %+" PRIi64 "\n", cmd.value);
			if (bkgrdsumadj == 0 || sysctl(adjnbfree, MIBSIZE, 0, 0,
			    &cmd, sizeof cmd) == -1)
				rwerror("ADJUST NUMBER OF FREE BLOCKS", cmd.value);
		}

		cmd.value = cstotal.cs_nifree - fs->fs_cstotal.cs_nifree;
		if (cmd.value != 0) {
			if (debug)
				printf("adjnifree by %+" PRIi64 "\n", cmd.value);
			if (bkgrdsumadj == 0 || sysctl(adjnifree, MIBSIZE, 0, 0,
			    &cmd, sizeof cmd) == -1)
				rwerror("ADJUST NUMBER OF FREE INODES", cmd.value);
		}

		cmd.value = cstotal.cs_nffree - fs->fs_cstotal.cs_nffree;
		if (cmd.value != 0) {
			if (debug)
				printf("adjnffree by %+" PRIi64 "\n", cmd.value);
			if (bkgrdsumadj == 0 || sysctl(adjnffree, MIBSIZE, 0, 0,
			    &cmd, sizeof cmd) == -1)
				rwerror("ADJUST NUMBER OF FREE FRAGS", cmd.value);
		}

		cmd.value = cstotal.cs_numclusters - fs->fs_cstotal.cs_numclusters;
		if (cmd.value != 0) {
			if (debug)
				printf("adjnumclusters by %+" PRIi64 "\n", cmd.value);
			if (bkgrdsumadj == 0 || sysctl(adjnumclusters, MIBSIZE, 0, 0,
			    &cmd, sizeof cmd) == -1)
				rwerror("ADJUST NUMBER OF FREE CLUSTERS", cmd.value);
		}
	}
}
Exemplo n.º 17
0
static guint
rspamd_re_cache_process_regexp_data (struct rspamd_re_runtime *rt,
		rspamd_regexp_t *re, rspamd_mempool_t *pool,
		const guchar *in, gsize len,
		gboolean is_raw)
{

	guint64 re_id;
	guint ret = 0;

	re_id = rspamd_regexp_get_cache_id (re);

	if (len == 0 || in == NULL) {
		/* We assume this as absence of the specified data */
		setbit (rt->checked, re_id);
		rt->results[re_id] = ret;
		return ret;
	}

#ifndef WITH_HYPERSCAN
	ret = rspamd_re_cache_process_pcre (rt, re, pool, in, len, is_raw);
	setbit (rt->checked, re_id);
	rt->results[re_id] = ret;
#else
	struct rspamd_re_cache_elt *elt;
	struct rspamd_re_class *re_class;
	struct rspamd_re_hyperscan_cbdata cbdata;

	elt = g_ptr_array_index (rt->cache->re, re_id);
	re_class = rspamd_regexp_get_class (re);

	if (rt->cache->disable_hyperscan || elt->match_type == RSPAMD_RE_CACHE_PCRE) {
		ret = rspamd_re_cache_process_pcre (rt, re, pool, in, len, is_raw);
		setbit (rt->checked, re_id);
		rt->results[re_id] = ret;
	}
	else {
		if (rt->cache->max_re_data > 0 && len > rt->cache->max_re_data) {
			len = rt->cache->max_re_data;
		}

		g_assert (re_class->hs_scratch != NULL);
		g_assert (re_class->hs_db != NULL);

		/* Go through hyperscan API */
		cbdata.in = in;
		cbdata.re = re;
		cbdata.rt = rt;
		cbdata.len = len;
		cbdata.pool = pool;
		rt->stat.bytes_scanned += len;

		if ((hs_scan (re_class->hs_db, in, len, 0, re_class->hs_scratch,
				rspamd_re_cache_hyperscan_cb, &cbdata)) != HS_SUCCESS) {
			ret = 0;
		}
		else {
			ret = rt->results[re_id];
		}
	}
#endif

	return ret;
}
Exemplo n.º 18
0
int main(void)
{
	// Initiera funktionalitet
	init_spi();
	USART_init();
	
	sei(); //Enable global interrupts

	clearbit(PORTC, PINC0); // "Ready to Receive" till Firefly

	// Har autonom-toggle på PA0
	static uint8_t has_pressed_auto;
	clearbit(DDRA, 0);

// Huvudloop
    while(1)
    {

		static uint8_t spi_state = 0; // 0 väntar, 1 skriver
		static uint8_t usart_state = 0; // 0 väntar, 1 skriver
		uint8_t spir, has_spir = 0, usartr, has_usartr = 0;

		if(!has_pressed_auto) {
			if(!(PINA & 0x01)) {
				has_pressed_auto = 1;
				send_spi(COMM_ENABLE_PID);
			}
		}

		// Processa SPI
		if(spi_state == 0) {
			// Kolla om vi har fått nåt
			if(SPSR & (1 << SPIF)) {
				spir = SPDR;
				has_spir = 1;
			}
			// Finns det nåt att skicka?
			else if(spiw_r != spiw_w) {
				SPDR = spiw_data[spiw_r++];
				PORTA ^= (1 << PORTA7);
				spi_state = 1;
			}				
		}
		else if(spi_state == 1) {
			if(SPSR & (1 << SPIF)) {
				uint8_t c;
				spi_state = 0;
				c = SPDR;
				if(c != 0) {
					has_spir = 1;
					spir = c;
				}
			}				
		}

		// Processa USART
		if(usart_state == 0) {
			// Firefly vill sända data
			if(UCSRA & (1 << RXC)) {
				usartr = UDR;
				has_usartr = 1;
			}
			// Vi vill sända data
			else if(usartw_r != usartw_w) {
				usart_state = 1;
				setbit(PORTC, PINC0);
			}				
		}
		else if(usart_state == 1) {
			if(UCSRA & (1 << UDRE)) {
				UDR = usartw_data[usartw_r++];
				usart_state = 0;
				clearbit(PORTC, PINC0);
			}				
		}
	
		// Nu finns data i usartr om has_usartr == 1
		// och i spir om has_spir == 1
		
		if(has_usartr) {
			decode_remote(usartr);
		}
		if(has_spir) {
			send_usart(spir);
		}
    }
}
Exemplo n.º 19
0
static void liveSetup(void)
{
    BRIGGS_SET *exposed = briggsAllocs(tempCount);
    int i;
    for (i=0; i < blockCount; i++)
    {
        struct _block *blk = blockArray[i];
        if (blk && blk->head)
        {
            QUAD *tail = blk->tail;
            int j;
            briggsClear(exposed);
            do
            {
                if (tail->dc.opcode == i_phi)
                {
                    PHIDATA *pd = tail->dc.v.phi;
                    struct _phiblock *pb = pd->temps;
                    hasPhi = TRUE;
                    briggsReset(exposed, pd->T0);
                    clearbit(blk->liveGen, pd->T0);
                    setbit(blk->liveKills, pd->T0);
                    while (pb)
                    {
                        briggsSet(exposed, pb->Tn);
                        setbit(blk->liveGen, pb->Tn);
                        pb = pb->next;
                    }	
                }
                else
                {
                    if (tail->temps & TEMP_ANS)
                    {
                        if (tail->ans->mode == i_direct)
                        {
                            int tnum = tail->ans->offset->v.sp->value.i;
                            briggsReset(exposed, tnum);
                            clearbit(blk->liveGen, tnum);
                            setbit(blk->liveKills, tnum);
                        }
                        else if (tail->ans->mode == i_ind)
                        {
                            if (tail->ans->offset)
                            {
                                briggsSet(exposed, tail->ans->offset->v.sp->value.i);
                                setbit(blk->liveGen, tail->ans->offset->v.sp->value.i);
                            }
                            if (tail->ans->offset2)
                            {
                                briggsSet(exposed, tail->ans->offset2->v.sp->value.i);
                                setbit(blk->liveGen, tail->ans->offset2->v.sp->value.i);
                            }
                        }
                    }
                    if (tail->temps & TEMP_LEFT)
                        if (tail->dc.left->mode == i_ind || tail->dc.left->mode == i_direct)
                        {
                            if (!tail->dc.left->retval)
                            {
                                if (tail->dc.left->offset)
                                {
                                    briggsSet(exposed, tail->dc.left->offset->v.sp->value.i);
                                    setbit(blk->liveGen, tail->dc.left->offset->v.sp->value.i);
                                }
                                if (tail->dc.left->offset2)
                                {
                                    briggsSet(exposed, tail->dc.left->offset2->v.sp->value.i);
                                    setbit(blk->liveGen, tail->dc.left->offset2->v.sp->value.i);
                                }
                            }
                        }
                    if (tail->temps & TEMP_RIGHT)
                        if (tail->dc.right->mode == i_ind || tail->dc.right->mode == i_direct)
                        {
                            if (tail->dc.right->offset)
                            {
                                briggsSet(exposed, tail->dc.right->offset->v.sp->value.i);
                                setbit(blk->liveGen, tail->dc.right->offset->v.sp->value.i);
                            }
                            if (tail->dc.right->offset2)
                            {
                                briggsSet(exposed, tail->dc.right->offset2->v.sp->value.i);
                                setbit(blk->liveGen, tail->dc.right->offset2->v.sp->value.i);
                            }
                        }
                }
                if (tail != blk->head) /* in case tail == head */
                    tail = tail->back; /* skipping the actual block statement */
            } while (tail != blk->head);
            briggsUnion(globalVars, exposed);
        }
    }
    for (i=0; i < globalVars->top; i++)
    {
        int t = globalVars->data[i], j;
        tempInfo[t]->liveAcrossBlock = TRUE;
    }
}
Exemplo n.º 20
0
/*
 * Set the current phy mode and recalculate the active channel
 * set based on the available channels for this mode.  Also
 * select a new default/current channel if the current one is
 * inappropriate for this mode.
 */
int
ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode)
{
	struct ifnet *ifp = &ic->ic_if;
	static const u_int chanflags[] = {
		0,			/* IEEE80211_MODE_AUTO */
		IEEE80211_CHAN_A,	/* IEEE80211_MODE_11A */
		IEEE80211_CHAN_B,	/* IEEE80211_MODE_11B */
		IEEE80211_CHAN_PUREG,	/* IEEE80211_MODE_11G */
		IEEE80211_CHAN_T,	/* IEEE80211_MODE_TURBO	*/
	};
	const struct ieee80211_channel *c;
	u_int modeflags;
	int i;

	/* validate new mode */
	if ((ic->ic_modecaps & (1<<mode)) == 0) {
		DPRINTF(("mode %u not supported (caps 0x%x)\n",
		    mode, ic->ic_modecaps));
		return EINVAL;
	}

	/*
	 * Verify at least one channel is present in the available
	 * channel list before committing to the new mode.
	 */
	if (mode >= nitems(chanflags))
		panic("Unexpected mode %u", mode);
	modeflags = chanflags[mode];
	for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
		c = &ic->ic_channels[i];
		if (mode == IEEE80211_MODE_AUTO) {
			/* ignore turbo channels for autoselect */
			if ((c->ic_flags &~ IEEE80211_CHAN_TURBO) != 0)
				break;
		} else {
			if ((c->ic_flags & modeflags) == modeflags)
				break;
		}
	}
	if (i > IEEE80211_CHAN_MAX) {
		DPRINTF(("no channels found for mode %u\n", mode));
		return EINVAL;
	}

	/*
	 * Calculate the active channel set.
	 */
	memset(ic->ic_chan_active, 0, sizeof(ic->ic_chan_active));
	for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
		c = &ic->ic_channels[i];
		if (mode == IEEE80211_MODE_AUTO) {
			/* take anything but pure turbo channels */
			if ((c->ic_flags &~ IEEE80211_CHAN_TURBO) != 0)
				setbit(ic->ic_chan_active, i);
		} else {
			if ((c->ic_flags & modeflags) == modeflags)
				setbit(ic->ic_chan_active, i);
		}
	}
	/*
	 * If no current/default channel is setup or the current
	 * channel is wrong for the mode then pick the first
	 * available channel from the active list.  This is likely
	 * not the right one.
	 */
	if (ic->ic_ibss_chan == NULL || isclr(ic->ic_chan_active,
	    ieee80211_chan2ieee(ic, ic->ic_ibss_chan))) {
		for (i = 0; i <= IEEE80211_CHAN_MAX; i++)
			if (isset(ic->ic_chan_active, i)) {
				ic->ic_ibss_chan = &ic->ic_channels[i];
				break;
			}
		if ((ic->ic_ibss_chan == NULL) || isclr(ic->ic_chan_active,
		    ieee80211_chan2ieee(ic, ic->ic_ibss_chan)))
			panic("Bad IBSS channel %u",
			    ieee80211_chan2ieee(ic, ic->ic_ibss_chan));
	}

	/*
	 * Reset the scan state for the new mode. This avoids scanning
	 * of invalid channels, ie. 5GHz channels in 11b mode.
	 */
	ieee80211_reset_scan(ifp);

	ic->ic_curmode = mode;
	ieee80211_reset_erp(ic);	/* reset ERP state */

	return 0;
}
Exemplo n.º 21
0
void
ath_hal_dumpkeycache(FILE *fd, int nkeys, int micEnabled)
{
	static const char *keytypenames[] = {
		"WEP-40", 	/* AR_KEYTABLE_TYPE_40 */
		"WEP-104",	/* AR_KEYTABLE_TYPE_104 */
		"#2",
		"WEP-128",	/* AR_KEYTABLE_TYPE_128 */
		"TKIP",		/* AR_KEYTABLE_TYPE_TKIP */
		"AES-OCB",	/* AR_KEYTABLE_TYPE_AES */
		"AES-CCM",	/* AR_KEYTABLE_TYPE_CCM */
		"CLR",		/* AR_KEYTABLE_TYPE_CLR */
	};
	u_int8_t mac[IEEE80211_ADDR_LEN];
	u_int8_t ismic[128/NBBY];
	int entry;
	int first = 1;

	memset(ismic, 0, sizeof(ismic));
	for (entry = 0; entry < nkeys; entry++) {
		u_int32_t macLo, macHi, type;
		u_int32_t key0, key1, key2, key3, key4;

        type = OS_REG_READ(ah, AR_KEYTABLE_TYPE(entry));
		macHi = OS_REG_READ(ah, AR_KEYTABLE_MAC1(entry));
		if ((macHi & AR_KEYTABLE_VALID) == 0 && isclr(ismic, entry) && (type & 0x7))
			continue;
		macLo = OS_REG_READ(ah, AR_KEYTABLE_MAC0(entry));
		macHi <<= 1;
		if (macLo & (1<<31))
			macHi |= 1;
		macLo <<= 1;
		mac[4] = macHi & 0xff;
		mac[5] = macHi >> 8;
		mac[0] = macLo & 0xff;
		mac[1] = macLo >> 8;
		mac[2] = macLo >> 16;
		mac[3] = macLo >> 24;
		type = OS_REG_READ(ah, AR_KEYTABLE_TYPE(entry));
		if ((type & 0x7) == AR_KEYTABLE_TYPE_TKIP && micEnabled)
			setbit(ismic, entry+64);
		key0 = OS_REG_READ(ah, AR_KEYTABLE_KEY0(entry));
		key1 = OS_REG_READ(ah, AR_KEYTABLE_KEY1(entry));
		key2 = OS_REG_READ(ah, AR_KEYTABLE_KEY2(entry));
		key3 = OS_REG_READ(ah, AR_KEYTABLE_KEY3(entry));
		key4 = OS_REG_READ(ah, AR_KEYTABLE_KEY4(entry));
		if (first) {
			fprintf(fd, "\n");
			first = 0;
		}
		fprintf(fd, "KEY[%03u] MAC %s %-7s %02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x\n"
			, entry
			, ether_sprintf(mac)
			, isset(ismic, entry) ? "MIC" : keytypenames[type & 7]
			, (key0 >>  0) & 0xff
			, (key0 >>  8) & 0xff
			, (key0 >> 16) & 0xff
			, (key0 >> 24) & 0xff
			, (key1 >>  0) & 0xff
			, (key1 >>  8) & 0xff
			, (key2 >>  0) & 0xff
			, (key2 >>  8) & 0xff
			, (key2 >> 16) & 0xff
			, (key2 >> 24) & 0xff
			, (key3 >>  0) & 0xff
			, (key3 >>  8) & 0xff
			, (key4 >>  0) & 0xff
			, (key4 >>  8) & 0xff
			, (key4 >> 16) & 0xff
			, (key4 >> 24) & 0xff
		);
	}
}
Exemplo n.º 22
0
int4 main(int4 argc, char* argv[])
{
	unsigned char *filename, *readdb_address, *sequence, code, *wildcardsFilename;
	uint4 descriptionStart = 0, descriptionLength = 0, sequenceLength;
	uint4 encodedLength, numChildren, count;
	char *description;
    struct child* children, *child;
    uint4 candidateNum, change, childNum;
    uint4 numWilds = 0;
	struct wild *wilds, defaultWild, *candidates, bestNewCandidate;
	struct wild *wildSubset, *newCandidates, *bestNewCandidates;
    uint4 sizeWildSubset, numOccurences, numCandidates;
	float defaultWildscore, candidatesScore, bestScore;

	// User must provide FASTA format file at command line
	if (argc < 4)
	{
		fprintf(stderr, "Useage: chooseWilds <database> <Wildcard score constant> <Wildcards output file>\n");
		exit(-1);
	}
	filename = argv[1];
    wildcards_scoringConstant = atof(argv[2]);
    wildcardsFilename = argv[3];

	readdb_open(filename);

    printf("Number of clusters = %u\n", readdb_numberOfClusters);
    printf("Number of sequences = %u\n", readdb_numberOfSequences);
    printf("Number of volumes = %u\n", readdb_numberOfVolumes);
	printf("Total number of letters = %llu\n", readdb_numberOfLetters);
	printf("Length of longest sequence = %u\n", readdb_longestSequenceLength);
	printf("Alphabet type = %s\n", encoding_alphabetTypes[readdb_dbAlphabetType]);

	// Initialize codes array
	encoding_initialize(readdb_dbAlphabetType);

    // Load score matrix
    parameters_findScoringMatrix();
    wildcards_scoreMatrix = scoreMatrix_load(parameters_scoringMatrixPath);

    // Count occurences of each wildcard set
    wildcards_initializeCountOccurences(readdb_longestSequenceLength);
    do
    {
        // Read each sequence in the collection
        while (readdb_readSequence(&sequence, &sequenceLength, &descriptionStart,
                                   &descriptionLength, &encodedLength))
        {
        	// If a protein sequence cluster
            if (encoding_alphabetType == encoding_protein && sequenceLength + 2 != encodedLength)
            {
                // Get the children
                children = readdb_getChildren(sequence, sequenceLength, encodedLength,
                                              descriptionStart, &numChildren);

				// Add to list of occurences
                wildcards_countOccurences(children, numChildren, sequenceLength);

                childNum = 0;
                while (childNum < numChildren)
                {
                    free(children[childNum].edits);
                    free(children[childNum].sequence - 1);
                    childNum++;
                }

                free(children);
            }
        }
	}
    while (readdb_nextVolume());

    // Get final list of number of occurences of each wild
    wilds = wildcards_getOccurences(&numWilds);

    chooseWilds_printOccurenceMatrix(wilds, numWilds);

    // Build default wildcard
	defaultWild.code = 0;
    defaultWild.count = 0;
    code = 0;
    while (code < encoding_numLetters)
    {
    	setbit(defaultWild.code, code);
        code++;
    }

    // Get average score for default wildcard
    wildSubset = wildcards_getSubset(defaultWild, wilds, numWilds, &sizeWildSubset, &numOccurences);
    defaultWildscore = wildcards_averageResidueWildMatch(defaultWild, wildSubset, sizeWildSubset);
	printf("defaultWildScore=%f occurences=%d\n", defaultWildscore, numOccurences);

    // Build up list of wildcard candidates
	candidates = (struct wild*)global_malloc(sizeof(struct wild) * wildcards_numClusterWildcards);
    numCandidates = 0;
    while (numCandidates < wildcards_numClusterWildcards - 1)
    {
    	// Explore each possible option to add to list of candidates
    	count = 0;
        bestScore = 0;
        while (count < numWilds)
        {
//        	printf("set pos %d to ", numCandidates);
//			wildcards_printWildcard(wilds[count].code);
			candidates[numCandidates] = wilds[count];

            // Score a set of candidates
            candidatesScore = wildcards_scoreCandidates(candidates, numCandidates + 1,
                                                        wilds, numWilds, defaultWildscore);
//            printf("Candidates saving=%f\n", candidatesScore);
			if (candidatesScore > bestScore)
            {
            	bestScore = candidatesScore;
                bestNewCandidate = wilds[count];
            }

            count++;
        }

        printf("Score=%f Best new candidate (%d): ", bestScore, numCandidates);
		wildcards_printWildcard(bestNewCandidate.code);
		candidates[numCandidates] = bestNewCandidate;

		numCandidates++;
    }

    newCandidates = (struct wild*)global_malloc(sizeof(struct wild) * wildcards_numClusterWildcards);
    bestNewCandidates = (struct wild*)global_malloc(sizeof(struct wild) * wildcards_numClusterWildcards);

    // Perform hill climbing; consider changing each position
    change = 1;
    while (change)
    {
    	change = 0;
		candidateNum = 0;
        bestScore = 0;
        while (candidateNum < numCandidates)
        {
        	// Start with current candidates
			memcpy(newCandidates, candidates, sizeof(struct wild) * wildcards_numClusterWildcards - 1);

            // Change current position to every possible candidate
            count = 0;
            while (count < numWilds)
            {
                newCandidates[candidateNum] = wilds[count];

                // Score a possible new set of candidates
                candidatesScore = wildcards_scoreCandidates(newCandidates, numCandidates,
                                                            wilds, numWilds, defaultWildscore);

				// Check if best new candidates
                if (candidatesScore > bestScore)
                {
                    bestScore = candidatesScore;
                    memcpy(bestNewCandidates, newCandidates, sizeof(struct wild) *
                           wildcards_numClusterWildcards - 1);
                }

                count++;
            }

        	candidateNum++;
        }

        // Update candidates
        if (bestScore > wildcards_scoreCandidates(candidates, numCandidates,
                                                  wilds, numWilds, defaultWildscore))
		{
        	printf("New bestScore=%f\n", bestScore);
        	memcpy(candidates, bestNewCandidates, sizeof(struct wild) *
                   wildcards_numClusterWildcards - 1);
			change = 1;
        }

		candidateNum = 0;
        while (candidateNum < numCandidates)
        {
			wildcards_printWildcard(candidates[candidateNum].code);
        	candidateNum++;
		}
    }

    // Print out final set of clusters with default wild added
	candidates[numCandidates] = defaultWild; numCandidates++;
	wildcards_scoreCandidates(candidates, numCandidates, wilds, numWilds, defaultWildscore);
	wildcards_outputWildcards(wildcardsFilename);

    printf("%d sequences read.\n", readdb_numberOfSequences);
	fflush(stdout);

    free(candidates);
    free(newCandidates);
    free(bestNewCandidates);

	return 0;
}
Exemplo n.º 23
0
int
t4_set_tracer(struct adapter *sc, struct t4_tracer *t)
{
	int rc;
	struct trace_params tp, *tpp;

	if (t->idx >= NTRACE)
		return (EINVAL);

	rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
	    "t4sett");
	if (rc)
		return (rc);

	/*
	 * If no tracing filter is specified this time then check if the filter
	 * at the index is valid anyway because it was set previously.  If so
	 * then this is a legitimate enable/disable operation.
	 */
	if (t->valid == 0) {
		if (isset(&sc->tracer_valid, t->idx))
			tpp = NULL;
		else
			rc = EINVAL;
		goto done;
	}

	if (t->tp.port > 19 || t->tp.snap_len > 9600 ||
	    t->tp.min_len > M_TFMINPKTSIZE || t->tp.skip_len > M_TFLENGTH ||
	    t->tp.skip_ofst > M_TFOFFSET) {
		rc = EINVAL;
		goto done;
	}

	memcpy(&tp.data[0], &t->tp.data[0], sizeof(tp.data));
	memcpy(&tp.mask[0], &t->tp.mask[0], sizeof(tp.mask));
	tp.snap_len = t->tp.snap_len;
	tp.min_len = t->tp.min_len;
	tp.skip_ofst = t->tp.skip_ofst;
	tp.skip_len = t->tp.skip_len;
	tp.invert = !!t->tp.invert;

	/* convert port to channel iff 0 <= port < 8. */
	if (t->tp.port < 4) {
		if (sc->port[t->tp.port] == NULL) {
			rc = EINVAL;
			goto done;
		}
		tp.port = sc->port[t->tp.port]->tx_chan;
	} else if (t->tp.port < 8) {
		if (sc->port[t->tp.port - 4] == NULL) {
			rc = EINVAL;
			goto done;
		}
		tp.port = sc->port[t->tp.port - 4]->tx_chan + 4;
	}
	tpp = &tp;
done:
	if (rc == 0) {
		rc = -t4_set_trace_filter(sc, tpp, t->idx, t->enabled);
		if (rc == 0) {
			if (t->enabled) {
				setbit(&sc->tracer_valid, t->idx);
				if (sc->tracer_enabled == 0) {
					t4_set_reg_field(sc, A_MPS_TRC_CFG,
					    F_TRCEN, F_TRCEN);
				}
				setbit(&sc->tracer_enabled, t->idx);
			} else {
				clrbit(&sc->tracer_enabled, t->idx);
				if (sc->tracer_enabled == 0) {
					t4_set_reg_field(sc, A_MPS_TRC_CFG,
					    F_TRCEN, 0);
				}
			}
		}
	}
	end_synchronized_op(sc, LOCK_HELD);

	return (rc);
}
Exemplo n.º 24
0
void doship(shiptype *ship, int update)
{
    racetype *Race;
    shiptype *ship2;

    /*ship is active */
    ship->active = 1;

    if(!ship->owner) ship->alive = 0;

    if (ship->alive) {
        /* repair radiation */
        if (ship->rad) {
            ship->active = 1;
            /* irradiated ships are immobile.. */
            /* kill off some people */
            /* check to see if ship is active */
            if(success(ship->rad))
                ship->active = 0;
            if(update) {
                ship->popn = round_rand(ship->popn * .80);
                ship->troops = round_rand(ship->troops * .80);
                if (ship->rad >= (int)REPAIR_RATE)
                    ship->rad -= int_rand(0,(int)REPAIR_RATE);
                else
                    ship->rad -= int_rand(0,(int)ship->rad);
            }
        } else
            ship->active = 1;

        if(!ship->popn && Max_crew(ship) && !ship->docked)
            ship->whatdest = LEVEL_UNIV;

        if (ship->whatorbits != LEVEL_UNIV
                && Stars[ship->storbits]->nova_stage>0) {
            /* damage ships from supernovae */
            /* Maarten: modified to take into account MOVES_PER_UPDATE */
            ship->damage += 5 * Stars[ship->storbits]->nova_stage /
                            ((Armor(ship)+1) * segments);
            if (ship->damage >= 100) {
                kill_ship((int)(ship->owner), ship);
                return;
            }
        }

        if(ship->type==OTYPE_FACTORY && !ship->on) {
            Race = races[ship->owner-1];
            ship->tech = Race->tech;
        }

        if(ship->active)
            Moveship(ship, update, 1, 0);

        ship->size = ship_size(ship);	/* for debugging */

        if(ship->whatorbits==LEVEL_SHIP) {
            (void)getship(&ship2, (int)ship->destshipno);
            if(ship2->owner != ship->owner) {
                ship2->owner = ship->owner;
                ship2->governor = ship->governor;
                putship(ship2);
            }
            free(ship2);
            /* just making sure */
        } else if(ship->whatorbits != LEVEL_UNIV &&
                  (ship->popn || ship->type == OTYPE_PROBE)) {
            /* Though I have often used TWCs for exploring, I don't think it is right */
            /* to be able to map out worlds with this type of junk. Either a manned ship, */
            /* or a probe, which is designed for this kind of work.  Maarten */
            StarsInhab[ship->storbits] = 1;
            setbit(Stars[ship->storbits]->inhabited, ship->owner);
            setbit(Stars[ship->storbits]->explored, ship->owner);
            if(ship->whatorbits == LEVEL_PLAN) {
                planets[ship->storbits][ship->pnumorbits]->info[ship->owner-1].explored = 1;
            }
        }

        /* add ships, popn to total count to add AP's */
        if(update) {
            Power[ship->owner-1].ships_owned++;
            Power[ship->owner-1].resource += ship->resource;
            Power[ship->owner-1].fuel += ship->fuel;
            Power[ship->owner-1].destruct += ship->destruct;
            Power[ship->owner-1].popn += ship->popn;
            Power[ship->owner-1].troops += ship->troops;
        }

        if (ship->whatorbits==LEVEL_UNIV) {
            Sdatanumships[ship->owner-1]++;
            Sdatapopns[ship->owner] += ship->popn;
        } else {
            starnumships[ship->storbits][ship->owner-1]++;
            /* add popn of ships to popn */
            starpopns[ship->storbits][ship->owner-1] += ship->popn;
            /* set inhabited for ship */
            /* only if manned or probe.  Maarten */
            if (ship->popn || ship->type==OTYPE_PROBE) {
                StarsInhab[ship->storbits] = 1;
                setbit(Stars[ship->storbits]->inhabited, ship->owner);
                setbit(Stars[ship->storbits]->explored, ship->owner);
            }
        }

        if (ship->active) {
            /* bombard the planet */
            if (can_bombard(ship) && ship->bombard
                    && ship->whatorbits==LEVEL_PLAN
                    && ship->whatdest==LEVEL_PLAN
                    && ship->deststar== ship->storbits
                    && ship->destpnum== ship->pnumorbits) {
                /* ship bombards planet */
                Stinfo[ship->storbits][ship->pnumorbits].inhab = 1;
            }

            /* repair ship by the amount of crew it has */
            /* industrial complexes can repair (robot ships
               and offline factories can't repair) */
            if(ship->damage && Repair(ship))
                do_repair(ship);

            if(update)
                switch (ship->type) {  /* do this stuff during updates only*/
                case OTYPE_CANIST:
                    do_canister(ship);
                    break;
                case OTYPE_GREEN:
                    do_greenhouse(ship);
                    break;
                case STYPE_MIRROR:
                    do_mirror(ship);
                    break;
                case STYPE_GOD:
                    do_god(ship);
                    break;
                case OTYPE_AP:
                    do_ap(ship);
                    break;
                case OTYPE_VN:	/* Von Neumann machine */
                case OTYPE_BERS:
                    if(!ship->special.mind.progenitor)
                        ship->special.mind.progenitor = 1;
                    do_VN(ship);
                    break;
                case STYPE_OAP:
                    do_oap(ship);
                    break;
                case STYPE_HABITAT:
                    do_habitat(ship);
                    break;
                default:
                    break;
                }
            if(ship->type==STYPE_POD)
                do_pod(ship);
        }
    }
}
Exemplo n.º 25
0
//**************************
void dr_metal(){
    setbit(PTC,0);
    delay_us(200);
    clrbit(PTC,0);
    delay_us(200);
}
Exemplo n.º 26
0
/* initialise bitmap for objects you can move on top of */
void
mjolinitcanmoveto(void)
{
    setbit(mjolcanmovetomap, MJOL_OBJ_FLOOR);
    setbit(mjolcanmovetomap, MJOL_OBJ_CORRIDOR);
    setbit(mjolcanmovetomap, MJOL_OBJ_DOOR);
    setbit(mjolcanmovetomap, MJOL_OBJ_FOOD);
    setbit(mjolcanmovetomap, MJOL_OBJ_WATER);
    setbit(mjolcanmovetomap, MJOL_OBJ_FOUNTAIN);
    setbit(mjolcanmovetomap, MJOL_OBJ_GOLD);
    setbit(mjolcanmovetomap, MJOL_OBJ_SILVER_BULLET);
    setbit(mjolcanmovetomap, MJOL_OBJ_POTION);
    setbit(mjolcanmovetomap, MJOL_OBJ_PLANT);
    setbit(mjolcanmovetomap, MJOL_OBJ_PUNCHCARD);
    setbit(mjolcanmovetomap, MJOL_OBJ_STAIR_DOWN);
    setbit(mjolcanmovetomap, MJOL_OBJ_STAIR_UP);
    setbit(mjolcanmovetomap, MJOL_OBJ_STATUE);
    setbit(mjolcanmovetomap, MJOL_OBJ_TRAP);
    setbit(mjolcanmovetomap, MJOL_OBJ_WAND);
    setbit(mjolcanmovetomap, MJOL_OBJ_SCROLL);
    setbit(mjolcanmovetomap, MJOL_OBJ_RING);
    setbit(mjolcanmovetomap, MJOL_OBJ_ARMOR);
    setbit(mjolcanmovetomap, MJOL_OBJ_CHAIN);
    setbit(mjolcanmovetomap, MJOL_OBJ_CHEST);
    setbit(mjolcanmovetomap, MJOL_OBJ_SUBMACHINE_GUN);
    setbit(mjolcanmovetomap, MJOL_OBJ_HONEY);
    setbit(mjolcanmovetomap, MJOL_OBJ_KNIFE);
    setbit(mjolcanmovetomap, MJOL_OBJ_LOCKPICK);
    setbit(mjolcanmovetomap, MJOL_OBJ_LASER);
    setbit(mjolcanmovetomap, MJOL_OBJ_MACE);
    setbit(mjolcanmovetomap, MJOL_OBJ_MAINFRAME);
    setbit(mjolcanmovetomap, MJOL_OBJ_PIPE);
    setbit(mjolcanmovetomap, MJOL_OBJ_PISTOL);
    setbit(mjolcanmovetomap, MJOL_OBJ_SWORD);
    setbit(mjolcanmovetomap, MJOL_OBJ_WELL);
    setbit(mjolcanmovetomap, MJOL_OBJ_CROSS);
    setbit(mjolcanmovetomap, MJOL_OBJ_ALTAR);

    return;
}
Exemplo n.º 27
0
void
murder()
{
	register int n;

	for (n=0; !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE || n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL || n == HALBERD) && testbit(inven,n)) && n < NUMOFOBJECTS; n++);
	if (n == NUMOFOBJECTS)
		puts("You don't have suitable weapons to kill.");
	else {
		printf("Your %s should do the trick.\n",objsht[n]);
		while (wordtype[++wordnumber] == ADJS);
		switch(wordvalue[wordnumber]){

			case NORMGOD:
				if (testbit(location[position].objects,BATHGOD)){
					puts("The goddess's head slices off.  Her corpse floats in the water.");
					clearbit(location[position].objects,BATHGOD);
					setbit(location[position].objects,DEADGOD);
					power += 5;
					notes[JINXED]++;
				} else if (testbit(location[position].objects,NORMGOD)){
					puts("The goddess pleads but you strike her mercilessly.  Her broken body lies in a\npool of blood.");
					clearbit(location[position].objects,NORMGOD);
					setbit(location[position].objects,DEADGOD);
					power += 5;
					notes[JINXED]++;
					if (wintime)
						live();
				} else puts("I dont see her anywhere.");
				break;
			case TIMER:
				if (testbit(location[position].objects,TIMER)){
					puts("The old man offers no resistance.");
					clearbit(location[position].objects,TIMER);
					setbit(location[position].objects,DEADTIME);
					power++;
					notes[JINXED]++;
				} else puts("Who?");
				break;
			case NATIVE:
				if (testbit(location[position].objects,NATIVE)){
					puts("The girl screams as you cut her body to shreds.  She is dead.");
					clearbit(location[position].objects,NATIVE);
					setbit(location[position].objects,DEADNATIVE);
					power += 5;
					notes[JINXED]++;
				} else puts("What girl?");
				break;
			case MAN:
				if (testbit(location[position].objects,MAN)){
					puts("You strike him to the ground, and he coughs up blood.");
					puts("Your fantasy is over.");
					die(0);
				}
			case -1:
				puts("Kill what?");
				break;

			default:
				if (wordtype[wordnumber] != NOUNS)
					puts("Kill what?");
				else
					printf("You can't kill the %s!\n",objsht[wordvalue[wordnumber]]);
		}
	}
}
Exemplo n.º 28
0
/* initialise bitmap for objects you can pick up */
void
mjolinitcanpickup(void)
{
    setbit(mjolcanpickupmap, MJOL_OBJ_FOOD);
    setbit(mjolcanpickupmap, MJOL_OBJ_WATER);
    setbit(mjolcanpickupmap, MJOL_OBJ_GOLD);
    setbit(mjolcanpickupmap, MJOL_OBJ_SILVER_BULLET);
    setbit(mjolcanpickupmap, MJOL_OBJ_POTION);
    setbit(mjolcanpickupmap, MJOL_OBJ_PLANT);
    setbit(mjolcanpickupmap, MJOL_OBJ_PUNCHCARD);
    setbit(mjolcanpickupmap, MJOL_OBJ_STATUE);
    setbit(mjolcanpickupmap, MJOL_OBJ_WAND);
    setbit(mjolcanpickupmap, MJOL_OBJ_SCROLL);
    setbit(mjolcanpickupmap, MJOL_OBJ_RING);
    setbit(mjolcanpickupmap, MJOL_OBJ_ARMOR);
    setbit(mjolcanpickupmap, MJOL_OBJ_CHAIN);
    setbit(mjolcanpickupmap, MJOL_OBJ_CHEST);
    setbit(mjolcanpickupmap, MJOL_OBJ_SUBMACHINE_GUN);
    setbit(mjolcanpickupmap, MJOL_OBJ_HONEY);
    setbit(mjolcanpickupmap, MJOL_OBJ_KNIFE);
    setbit(mjolcanpickupmap, MJOL_OBJ_LOCKPICK);
    setbit(mjolcanpickupmap, MJOL_OBJ_LASER);
    setbit(mjolcanpickupmap, MJOL_OBJ_MACE);
    setbit(mjolcanpickupmap, MJOL_OBJ_MAINFRAME);
    setbit(mjolcanpickupmap, MJOL_OBJ_PIPE);
    setbit(mjolcanpickupmap, MJOL_OBJ_PISTOL);
    setbit(mjolcanpickupmap, MJOL_OBJ_SWORD);
    setbit(mjolcanpickupmap, MJOL_OBJ_CROSS);

    return;
}
Exemplo n.º 29
0
int
wearit()		/* synonyms = {sheathe, sheath} */
{
	register int n;
	int firstnumber, value;

	firstnumber = wordnumber;
	while(wordtype[++wordnumber] == ADJS);
	while(wordnumber <= wordcount){
		value = wordvalue[wordnumber];
		for (n=0; objsht[value][n]; n++);
		switch(value){

			case -1:
				puts("Wear what?");
				return(firstnumber);

			default:
				printf("You can't wear%s%s!\n",(objsht[value][n-1] == 's' ? " " : " a "),objsht[value]);
				return(firstnumber);

			case KNIFE:
		/*	case SHIRT:	*/
			case ROBE:
			case LEVIS:	/* wearable things */
			case SWORD:
			case MAIL:
			case HELM:
			case SHOES:
			case PAJAMAS:
			case COMPASS:
			case LASER:
			case AMULET:
			case TALISMAN:
			case MEDALION:
			case ROPE:
			case RING:
			case BRACELET:
			case GRENADE:

				if (testbit(inven,value)){
					clearbit(inven,value);
					setbit(wear,value);
					carrying -= objwt[value];
					encumber -= objcumber[value];
					Time++;
					printf("You are now wearing %s %s.\n",(objsht[value][n-1] == 's' ? "the" : "a"), objsht[value]);
				}
				else if (testbit(wear,value))
					printf("You are already wearing the %s.\n", objsht[value]);
				else
					printf("You aren't holding the %s.\n", objsht[value]);
				if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
					wordnumber++;
				else
					return(firstnumber);
		} /* end switch */
	} /* end while */
	puts("Don't be ridiculous.");
	return(firstnumber);
}
Exemplo n.º 30
0
static void minix_setbit(char *a, unsigned i)
{
	setbit(a, i);
}