Exemple #1
0
int
main(int argc, char *argv[])
{
    int first = 1;
    char buf[80];

    progname = argv[0];

    if (init(argc, argv)) {	/* restored game */
	goto PL;
    }

    for (;;) {
	clear_level();
	make_level();
	put_objects();
	put_stairs();
	add_traps();
	put_mons();
	put_player(party_room);
	print_stats(STAT_ALL);
	if (first) {
	    sprintf(buf, mesg[10], nick_name);
	    message(buf, 0);
	}
    PL:
	first = 0;
	play_level();
	free_stuff(&level_objects);
	free_stuff(&level_monsters);
    }
}
Exemple #2
0
static void get_wbuf_from_data(struct conf **confs,
	struct iobuf *wbuf, struct slist *slist, uint8_t end_flags)
{
	struct blk *blk;
	struct blist *blist=slist->blist;

	for(blk=blist->last_sent; blk; blk=blk->next)
	{
		if(blk->requested)
		{
			iobuf_set(wbuf, CMD_DATA, blk->data, blk->length);
			blk->requested=0;
			blist->last_sent=blk;
			cntr_add(get_cntr(confs), CMD_DATA, 1);
			break;
		}
		else
		{
			cntr_add_same(get_cntr(confs), CMD_DATA);
			if(end_flags&END_BLK_REQUESTS)
			{
				// Force onwards when the server has said that
				// there are no more blocks to request.
				blist->last_sent=blk;
				continue;
			}
		}
		if(blk==blist->last_requested) break;
	}
	// Need to free stuff that is no longer needed.
	free_stuff(slist);
}
Exemple #3
0
static void get_wbuf_from_data(struct conf *conf,
	struct iobuf *wbuf, struct slist *slist,
	struct blist *blist, int blk_requests_end)
{
	struct blk *blk;

	for(blk=blist->last_sent; blk; blk=blk->next)
	{
		if(blk->requested)
		{
			wbuf->cmd=CMD_DATA;
			wbuf->buf=blk->data;
			wbuf->len=blk->length;
			blk->requested=0;
			blist->last_sent=blk;
			cntr_add(conf->cntr, CMD_DATA, 1);
			cntr_add_sentbytes(conf->cntr, blk->length);
			break;
		}
		else
		{
			cntr_add_same(conf->cntr, CMD_DATA);
			if(blk_requests_end)
			{
				// Force onwards when the server has said that
				// there are no more blocks to request.
				blist->last_sent=blk;
				continue;
			}
		}
		if(blk==blist->last_requested) break;
	}
	// Need to free stuff that is no longer needed.
	free_stuff(slist, blist);
}
static void
do_quiesce_test(uint32_t num_objs, uint32_t iters, uint32_t num_snaps)
{
	struct ZS_thread_state *thd_state;
	int i = 0;
	pthread_t           thread_id;
//	uint32_t iter_print_cnt = 0;

	printf("============================= Snapshot Quiesce Test =========================\n");
	fflush(stdout);
	ZSInitPerThreadState(zs_state, &thd_state);	
	open_stuff(thd_state, "cntr_4");
	snapshot_cnt = 0;

	objs_processed = num_objs;
	pthread_create(&thread_id, NULL, (void *)write_data, (void *)(uint64_t)iters);

	for (i = 0; i < num_snaps; i++) {
		create_snapshot(thd_state, i);
		sched_yield();
	}
	pthread_join(thread_id, NULL);
	for (i = 0; i < num_snaps; i++) {
		if ((snap_seqnos[i] - snap_seqnos[i - 1]) != 1 ||
				(snap_seqnos[i] - snap_seqnos[i - 1]) != num_objs) {
			printf("IO is not quiesced when snapshot is in progress\n");
		}
	}

	free_stuff(thd_state);
	ZSReleasePerThreadState(&thd_state);

}
Exemple #5
0
static struct object *low_do_query_phrase( Blob **blobs, int nblobs,
					   double field_c[65])
{
  struct object *res = wf_resultset_new();
  struct tofree *__f = malloc( sizeof( struct tofree ) );
  double max_c=0.0;
  ONERROR e;
  int i, j;
  __f->blobs = blobs;
  __f->nblobs = nblobs;
  __f->res = res;
  __f->tmp    = 0;
  SET_ONERROR( e, free_stuff, __f );


  for( i = 0; i<65; i++ )
    if( field_c[i] > max_c )
      max_c = field_c[i];

  if(  max_c != 0.0 )
  {
    /* Time to do the real work. :-) */
    for( i = 0; i<nblobs; i++ ) /* Forward to first element */
      wf_blob_next( blobs[i] );

    /* Main loop: Find the smallest element in the blob array. */
    while( 1 )
    {
      unsigned int min = 0x7fffffff;

      for( i = 0; i<nblobs; i++ )
	if( blobs[i]->eof )
	  goto end;
	else if( ((unsigned int)blobs[i]->docid) < min )
	  min = blobs[i]->docid;

      if( min == 0x7fffffff )
	goto end;

      for( j = 0, i = 0; i < nblobs; i++ )
	if( blobs[i]->docid != min )
	  goto next;

      handle_phrase_hit( blobs, nblobs, res, min, &field_c, max_c );

    next:
      for( i = 0; i<nblobs; i++ )
	if( blobs[i]->docid == min )
	  wf_blob_next( blobs[i] );
    }
  }
end:
  /* Free workarea and return the result. */

  UNSET_ONERROR( e );
  __f->res = 0;
  free_stuff( __f );
  return res;
}
static void
do_rw_test(uint32_t num_objs, uint32_t iters, uint32_t num_snaps)
{
	struct ZS_thread_state *thd_state;
	int i;
	uint32_t iter_print_cnt = 0;

	printf("============================= Snapshot Read/Write Test =========================\n");
	fflush(stdout);
	ZSInitPerThreadState(zs_state, &thd_state);	
	open_stuff(thd_state, "cntr_1");

	snapshot_cnt = 0;

	/* Write the contents of snapshots */
	for (i = 0; i < num_snaps; i++) {
		printf("Iter: %u: %s %u objects\n", ++iter_print_cnt, 
		     (i%2) ? "Writing": "MPutting", num_objs);
		fflush(stdout);

		if ((i % 2) == 0) {
			do_mput(thd_state, 0, num_objs, i, 0);
		} else {
			do_write(thd_state, 0, num_objs, i, 0);
		}
		printf("Creating Snapshot %u\n", i);
		fflush(stdout);
		create_snapshot(thd_state, i);
	}

	/* Write the remaining iterations */
	for (;i < iters; i++) {
		printf("Iter: %u: %s %u objects\n", ++iter_print_cnt, 
		     (i%2) ? "Writing": "MPutting", num_objs);
		fflush(stdout);

		if ((i % 2) == 0) {
			do_mput(thd_state, 0, num_objs, i, 0);
		} else {
			do_write(thd_state, 0, num_objs, i, 0);
		}
	}

	do_read_verify(thd_state, 0, num_objs, ZS_SUCCESS);

	printf("Doing range query for latest update\n");
	do_read_verify_snapshot(thd_state, 0, num_objs, iters-1, 20);

	for (i = 0; i < num_snaps; i++) {
		do_read_verify_snapshot(thd_state, 0, num_objs, i, 20);
	}

	free_stuff(thd_state);
	ZSReleasePerThreadState(&thd_state);
}
Exemple #7
0
int	i				start_shell(char **environ)
{
	t_term			s_term;
	int				ret;

	ret = -1;
	if (init_mysh(&s_term, environ))
		ret = shell_readloop(&s_term);
	free_stuff(&s_term);
	restore_termcap(s_term.tsave);
	return (ret);
}
Exemple #8
0
void thread_func(void *mydata){
    while(1){
        pthread_mutex_lock(&mut);
        while(todo){
            pthread_mutex_lock(&work_mut);
            struct stuff *work = todo;
            todo = todo->next;
            if(!todo)
                lasttodo = NULL;
            pthread_mutex_unlock(&work_mut);
            work->func(work->data);
            free_stuff(work);
        }
    }
}
Exemple #9
0
int main(void)
{
    int w, h;
    for (h = 0; h < 90; ++h) {
        for (w = 0; w < 120; ++w) {
            map_color_scalar[h][w] = 0.f;
        }
    }

    chat_index = 0;

    TCOD_console_init_root(160, 128, "console rpg v0.01", true);
    TCOD_console_t map_console = TCOD_console_new(122, 92);
    TCOD_console_t chat_console = TCOD_console_new(122, 30);
    TCOD_map_t map = TCOD_map_new(120, 90);
    TCOD_text_t chat = TCOD_text_init(1, 28, 120, 1, 255);
    TCOD_text_set_properties(chat, TCOD_CHAR_BLOCK1, 2, ">> ", 4);
    TCOD_mouse_show_cursor(true);
    TCOD_console_set_keyboard_repeat(0, 50); 
    TCOD_sys_set_fps(60);
    end_game = entering_text = false;
    x = y = 10.f;
    vx = vy = 10.f;
    w_key = a_key = s_key = d_key = false;

    /* TODO generate map properties differently -- load from file, etc. */
    for (h = 0; h < 90; ++h) {
        for (w = 0; w < 120; ++w) {
            if (h == 0 || h == 89 || w == 0 || w == 99 || (w == 24 && h != 14 && h != 15)) {
                TCOD_map_set_properties(map, w, h, false, false);
            }
            else {
                TCOD_map_set_properties(map, w, h, true, true);
            }
        }
    }

    /* TODO game loop */
    while (!end_game && !TCOD_console_is_window_closed()) {
        handle_input(chat);
        update_game(map);
        draw_game(map_console, map, chat_console, chat);
    }

    free_stuff();
    return EXIT_SUCCESS;
}
Exemple #10
0
static void
free_puzzle(Display * display, puzzlestruct * pp)
{
	if (pp->fixbuff != NULL) {
		free(pp->fixbuff);
		pp->fixbuff = (int *) NULL;
	}
	if (pp->bufferBox != None) {
		XFreePixmap(display, pp->bufferBox);
		pp->bufferBox = None;
	}
	free_stuff(display, pp);
	if (pp->logo != None) {
		destroyImage(&pp->logo, &pp->graphics_format);
		pp->logo = None;
	}
}
Exemple #11
0
void handle_signal(int sig)
{
 switch(sig)
 {
  case SIGINT:
   fprintf(stderr, "Interrupt received\n");
   break;
  case SIGQUIT:
   fprintf(stderr, "Quit signal received\n");
   break;
  case SIGTERM:
   fprintf(stderr, "Terminate signal received\n");
  default:
   fprintf(stderr, "Got signal %d\n", sig);
 }
 stop_timer();
 free_stuff();
 exit(0);
}
Exemple #12
0
static void
free_life1d(Display * display, life1dstruct * lp)
{
	int         shade;

	if (lp->stippledGC != None) {
		XFreeGC(display, lp->stippledGC);
		lp->stippledGC = None;
	}
	if (lp->init_bits != 0) {
		for (shade = 0; shade < MAXSTATES; shade++)
			XFreePixmap(display, lp->pixmaps[shade]);
		lp->init_bits = 0;
	}
	if (lp->newcells != NULL) {
		free(lp->newcells);
		lp->newcells = (unsigned char *) NULL;
	}
	if (lp->oldcells != NULL) {
		free(lp->oldcells);
		lp->oldcells = (unsigned char *) NULL;
	}
	if (lp->buffer != NULL) {
		free(lp->buffer);
		lp->buffer = (unsigned char *) NULL;
	}
	if (lp->previousBuffer != NULL) {
		free(lp->previousBuffer);
		lp->previousBuffer = (unsigned char *) NULL;
	}
	if (lp->nextstate != NULL) {
		free(lp->nextstate);
		lp->nextstate = (char *) NULL;
	}
	free_stuff(display, lp);
	if (lp->logo != None) {
		destroyImage(&lp->logo, &lp->graphics_format);
		lp->logo = None;
	}
}
Exemple #13
0
static struct object *low_do_query_or( Blob **blobs,
					  int nblobs,
					  double field_c[65],
					  double prox_c[8],
					  int cutoff)
{
  struct object *res = wf_resultset_new();
  struct tofree *__f = malloc( sizeof( struct tofree ) );
  double max_c=0.0, max_p=0.0;
  ONERROR e;
  int i, j;
  Blob **tmp;
  tmp = calloc( nblobs, sizeof( Blob *) );

  __f->res = res;
  __f->blobs = blobs;
  __f->nblobs = nblobs;
  __f->tmp    = tmp;
  SET_ONERROR( e, free_stuff, __f );


  for( i = 0; i<65; i++ )
    if( field_c[i] > max_c )
      max_c = field_c[i];

  for( i = 0; i<8; i++ )
    if( prox_c[i] > max_p )
      max_p = prox_c[i];

  if( max_p != 0.0 && max_c != 0.0 )
  {
    /* Time to do the real work. :-) */
    for( i = 0; i<nblobs; i++ ) /* Forward to first element */
      wf_blob_next( blobs[i] );

    /* Main loop: Find the smallest element in the blob array. */
    while( 1 )
    {
      unsigned int min = 0x7fffffff;

      for( i = 0; i<nblobs; i++ )
	if( !blobs[i]->eof && ((unsigned int)blobs[i]->docid) < min )
	  min = blobs[i]->docid;

      if( min == 0x7fffffff )
	break;

      for( j = 0, i = 0; i < nblobs; i++ )
	if( blobs[i]->docid == min && !blobs[i]->eof )
	  tmp[j++] = blobs[i];

      handle_hit( tmp, j, res, min, &field_c, &prox_c, max_c, max_p, cutoff );

      for( i = 0; i<j; i++ )
	wf_blob_next( tmp[i] );
    }
  }
  /* Free workarea and return the result. */

  UNSET_ONERROR( e );
  __f->res = 0;
  free_stuff( __f );
  return res;
}
Exemple #14
0
static void
do_rangeupdate_test(uint32_t num_objs, uint32_t iters, uint32_t num_snaps)
{
	struct ZS_thread_state *thd_state;
	int i = 0;
	uint32_t objs_updated = 0;
	ZS_status_t status;
	char *key;
	uint32_t keylen;
	char *act_value = NULL;
	uint64_t act_vallen;
	char *new_data = NULL;
	int error = 0;

//	uint32_t iter_print_cnt = 0;

	printf("============================= Snapshot RangeUpdate Test =========================\n");
	fflush(stdout);
	ZSInitPerThreadState(zs_state, &thd_state);	

	/* Test case 1: Let there be objects in snapshot, create new in active container and do
	   rangeupdate on all keys, should be able to read updated data for all the keys and read old data
	   for keys in snapshot */
	open_stuff(thd_state, "cntr_3");
	snapshot_cnt = 0;

	do_mput(thd_state, 0, (num_objs + (num_objs % 2))/2, 0, 0);
	create_snapshot(thd_state, i);
	do_mput(thd_state, (num_objs + (num_objs % 2))/2, (num_objs - (num_objs % 2))/2, 1, 0);
	ZSRangeUpdate(thd_state, cguid, "key_", strlen("key_"), range_update_cb, NULL, NULL, NULL, &objs_updated);
	printf("RangeUpdated objs_update: %d\n", objs_updated);
	if (objs_updated != num_objs) {
		printf("ERROR: All objects are not updated\n");
		return;
	}
	key = malloc(ZS_MAX_KEY_LEN);
	for (i = 0; i < num_objs; i++) {
		sprintf(key, "key_%04d", i);
		keylen = strlen(key) + 1;
		act_value = NULL;
		status = ZSReadObject(thd_state, cguid, key, keylen,
		                       &act_value, &act_vallen);
		if (status != ZS_SUCCESS) {
			printf("ERROR: ZSRead returned status=%s, expected status=%s for "
			        "key %d\n", ZSStrError(status), ZSStrError(ZS_SUCCESS), i);
			error++;
			fflush(stdout);
			free(key);
			break;
		}

		if (values[i].vallen + length_incr != act_vallen) {
			fprintf(stdout, "ERROR: Mismatch: Actual datalen=%u, "
			         "Expected datalen=%u for key %u\n",
			         (uint32_t)act_vallen, (uint32_t)values[i].vallen + length_incr, i);
			error++;
			fflush(stdout);
			free(act_value);
			free(key);
			break;
		}

		new_data = NULL;
		new_data = (char *) malloc(act_vallen);
		gen_data(new_data, act_vallen, 1000 + i);
		if (memcmp(new_data, act_value, act_vallen) != 0) {
			fprintf(stdout, "ERROR: Mismatch: Actual data differs "
			         "with expected data for key %u\n", i);
			error++;
			fflush(stdout);
			break;
		}

		//free(key);
		//free(new_data);
		//free(act_value);
	}
	do_read_verify_snapshot(thd_state, 0, (num_objs + (num_objs % 2))/2, 0, 20);
	free_stuff(thd_state);


	/* Test case 2: Create a subtree having a key with its snapshot data, and rangeupdate on all
	   keys, should be able to read updated data for key and data of the key of each snapshot */
	status = ZS_SUCCESS;

	open_stuff(thd_state, "cntr_3");
	do_mput(thd_state, 0, num_objs, 0, 0);
	create_snapshot(thd_state, 0);

	key = malloc(ZS_MAX_KEY_LEN);
	for (i = 0; i < num_snaps; i++) {
		sprintf(key, "key_%04d", num_objs/2);
		keylen = strlen(key) + 1;
		if (i%2 == 0) {
			act_vallen = OVERFLOW_DATA_SIZE;
		} else {
			act_vallen = INNODE_DATA_SIZE;
		}
		new_data = (char *) malloc(act_vallen);
		gen_data(new_data, act_vallen, 123 + i);
		status = ZSWriteObject(thd_state, cguid, key, keylen, new_data, act_vallen, 0);
		if (status != ZS_SUCCESS) {
			printf("WriteObject failed (%d) error: %s\n", i, ZSStrError(status));
			break;
		}
		create_snapshot(thd_state, i + 1);
		free(new_data);
	}
	objs_processed = 0;
	ZSRangeUpdate(thd_state, cguid, "key_", strlen("key_"), range_update_cb, NULL, NULL, NULL, &objs_updated);
	if (objs_updated != num_objs) {
		printf("ERROR: All objects are not updated\n");
		return;
	}
	for (i = 0; i < num_objs; i++) {
		key = malloc(ZS_MAX_KEY_LEN);
		sprintf(key, "key_%04d", i);
		keylen = strlen(key) + 1;
		act_value = NULL;
		status = ZSReadObject(thd_state, cguid, key, keylen,
		                       &act_value, &act_vallen);
		if (status != ZS_SUCCESS) {
			printf("ZSRead returned status=%s, expected status=%s for "
			        "key %d\n", ZSStrError(status), ZSStrError(ZS_SUCCESS), i);
			error++;
			fflush(stdout);
			free(key);
			break;
		}

		if (values[i].vallen + length_incr != act_vallen) {
			fprintf(stdout, "ERROR: Mismatch: Actual datalen=%u, "
			         "Expected datalen=%u for key %u\n",
			         (uint32_t)act_vallen, (uint32_t)values[i].vallen + length_incr, i);
			error++;
			fflush(stdout);
			free(act_value);
			free(key);
			break;
		}

		new_data = NULL;
		new_data = (char *) malloc(act_vallen);
		gen_data(new_data, act_vallen, 1000 + i);
		if (memcmp(new_data, act_value, act_vallen) != 0) {
			fprintf(stdout, "ERROR: Mismatch: Actual data differs "
			         "with expected data for key %u\n", i);
			error++;
			fflush(stdout);
			break;
		}

		free(key);
		free(new_data);
		free(act_value);
	}

	free_stuff(thd_state);
	ZSReleasePerThreadState(&thd_state);

}
Exemple #15
0
static void
do_delete_test(uint32_t num_objs, uint32_t iters, uint32_t num_snaps)
{
	struct ZS_thread_state *thd_state;
	int i;
	uint32_t iter_print_cnt = 0;

	printf("============================= Snapshot object Delete Test =========================\n");
	fflush(stdout);
	ZSInitPerThreadState(zs_state, &thd_state);	
	open_stuff(thd_state, "cntr_2");

	snapshot_cnt = 0;

	/* Write the contents of snapshots */
	for (i = 0; i < num_snaps; i++) {
		printf("Iter: %u: Mputting %u objects\n", ++iter_print_cnt, 
		       num_objs);
		fflush(stdout);

		do_mput(thd_state, 0, num_objs, i, 0);

		printf("Creating Snapshot %u\n", i);
		fflush(stdout);
		create_snapshot(thd_state, i);
	}

#if 0
#include <string.h>
	printf("Waiting to get confirmation to proceed\n");
	getchar();
#endif

	/* After delete, validate if the latest data is reported
	 * not found and earlier snapshot still intact */
	do_delete(thd_state, 0, num_objs, ZS_SUCCESS);
	do_read_verify(thd_state, 0, num_objs, ZS_OBJECT_UNKNOWN);
	do_read_verify_snapshot(thd_state, 0, num_objs, num_snaps-1, 20);

	/* Do a range query (read/verify active snapshot) and 
	 * ensure that no objects are found */
	printf("Doing range query for latest update\n");
	do_read_verify_snapshot(thd_state, 0, 0, num_snaps, 20);

	/* Do delete on top of tombstone delete and ensure it
	 * says key not found */
	do_delete(thd_state, 0, num_objs, ZS_OBJECT_UNKNOWN);

	for (i = 0; i < num_snaps; i++) {
		printf("Deleting Snapshot %u\n", i+1);
		fflush(stdout);
		delete_snapshot(thd_state, i);
	}

	/* Do another round of insert on top of tombstoned one and
	 * delete them to see if we still see key not found */
	printf("Iter: %u: Mputting %u objects\n", ++iter_print_cnt, 
	       num_objs);
	fflush(stdout);
	do_mput(thd_state, 0, num_objs, iters++, 0);
	do_delete(thd_state, 0, num_objs, ZS_SUCCESS);
	do_read_verify(thd_state, 0, num_objs, ZS_OBJECT_UNKNOWN);
	free_stuff(thd_state);

	ZSReleasePerThreadState(&thd_state);
}